Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

546 lines
20 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4. <title>The source code</title>
  5. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  6. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  7. </head>
  8. <body onload="prettyPrint();">
  9. <pre class="prettyprint lang-js">/*!
  10. * Ext JS Library 3.3.1
  11. * Copyright(c) 2006-2010 Sencha Inc.
  12. * licensing@sencha.com
  13. * http://www.sencha.com/license
  14. */
  15. <div id="cls-Ext.PagingToolbar"></div>/**
  16. * @class Ext.PagingToolbar
  17. * @extends Ext.Toolbar
  18. * <p>As the amount of records increases, the time required for the browser to render
  19. * them increases. Paging is used to reduce the amount of data exchanged with the client.
  20. * Note: if there are more records/rows than can be viewed in the available screen area, vertical
  21. * scrollbars will be added.</p>
  22. * <p>Paging is typically handled on the server side (see exception below). The client sends
  23. * parameters to the server side, which the server needs to interpret and then respond with the
  24. * approprate data.</p>
  25. * <p><b>Ext.PagingToolbar</b> is a specialized toolbar that is bound to a {@link Ext.data.Store}
  26. * and provides automatic paging control. This Component {@link Ext.data.Store#load load}s blocks
  27. * of data into the <tt>{@link #store}</tt> by passing {@link Ext.data.Store#paramNames paramNames} used for
  28. * paging criteria.</p>
  29. * <p>PagingToolbar is typically used as one of the Grid's toolbars:</p>
  30. * <pre><code>
  31. Ext.QuickTips.init(); // to display button quicktips
  32. var myStore = new Ext.data.Store({
  33. reader: new Ext.data.JsonReader({
  34. {@link Ext.data.JsonReader#totalProperty totalProperty}: 'results',
  35. ...
  36. }),
  37. ...
  38. });
  39. var myPageSize = 25; // server script should only send back 25 items at a time
  40. var grid = new Ext.grid.GridPanel({
  41. ...
  42. store: myStore,
  43. bbar: new Ext.PagingToolbar({
  44. {@link #store}: myStore, // grid and PagingToolbar using same store
  45. {@link #displayInfo}: true,
  46. {@link #pageSize}: myPageSize,
  47. {@link #prependButtons}: true,
  48. items: [
  49. 'text 1'
  50. ]
  51. })
  52. });
  53. * </code></pre>
  54. *
  55. * <p>To use paging, pass the paging requirements to the server when the store is first loaded.</p>
  56. * <pre><code>
  57. store.load({
  58. params: {
  59. // specify params for the first page load if using paging
  60. start: 0,
  61. limit: myPageSize,
  62. // other params
  63. foo: 'bar'
  64. }
  65. });
  66. * </code></pre>
  67. *
  68. * <p>If using {@link Ext.data.Store#autoLoad store's autoLoad} configuration:</p>
  69. * <pre><code>
  70. var myStore = new Ext.data.Store({
  71. {@link Ext.data.Store#autoLoad autoLoad}: {params:{start: 0, limit: 25}},
  72. ...
  73. });
  74. * </code></pre>
  75. *
  76. * <p>The packet sent back from the server would have this form:</p>
  77. * <pre><code>
  78. {
  79. "success": true,
  80. "results": 2000,
  81. "rows": [ // <b>*Note:</b> this must be an Array
  82. { "id": 1, "name": "Bill", "occupation": "Gardener" },
  83. { "id": 2, "name": "Ben", "occupation": "Horticulturalist" },
  84. ...
  85. { "id": 25, "name": "Sue", "occupation": "Botanist" }
  86. ]
  87. }
  88. * </code></pre>
  89. * <p><u>Paging with Local Data</u></p>
  90. * <p>Paging can also be accomplished with local data using extensions:</p>
  91. * <div class="mdetail-params"><ul>
  92. * <li><a href="http://extjs.com/forum/showthread.php?t=71532">Ext.ux.data.PagingStore</a></li>
  93. * <li>Paging Memory Proxy (examples/ux/PagingMemoryProxy.js)</li>
  94. * </ul></div>
  95. * @constructor Create a new PagingToolbar
  96. * @param {Object} config The config object
  97. * @xtype paging
  98. */
  99. (function() {
  100. var T = Ext.Toolbar;
  101. Ext.PagingToolbar = Ext.extend(Ext.Toolbar, {
  102. <div id="cfg-Ext.PagingToolbar-store"></div>/**
  103. * @cfg {Ext.data.Store} store
  104. * The {@link Ext.data.Store} the paging toolbar should use as its data source (required).
  105. */
  106. <div id="cfg-Ext.PagingToolbar-displayInfo"></div>/**
  107. * @cfg {Boolean} displayInfo
  108. * <tt>true</tt> to display the displayMsg (defaults to <tt>false</tt>)
  109. */
  110. <div id="cfg-Ext.PagingToolbar-pageSize"></div>/**
  111. * @cfg {Number} pageSize
  112. * The number of records to display per page (defaults to <tt>20</tt>)
  113. */
  114. pageSize : 20,
  115. <div id="cfg-Ext.PagingToolbar-prependButtons"></div>/**
  116. * @cfg {Boolean} prependButtons
  117. * <tt>true</tt> to insert any configured <tt>items</tt> <i>before</i> the paging buttons.
  118. * Defaults to <tt>false</tt>.
  119. */
  120. <div id="cfg-Ext.PagingToolbar-displayMsg"></div>/**
  121. * @cfg {String} displayMsg
  122. * The paging status message to display (defaults to <tt>'Displaying {0} - {1} of {2}'</tt>).
  123. * Note that this string is formatted using the braced numbers <tt>{0}-{2}</tt> as tokens
  124. * that are replaced by the values for start, end and total respectively. These tokens should
  125. * be preserved when overriding this string if showing those values is desired.
  126. */
  127. displayMsg : 'Displaying {0} - {1} of {2}',
  128. <div id="cfg-Ext.PagingToolbar-emptyMsg"></div>/**
  129. * @cfg {String} emptyMsg
  130. * The message to display when no records are found (defaults to 'No data to display')
  131. */
  132. emptyMsg : 'No data to display',
  133. <div id="cfg-Ext.PagingToolbar-beforePageText"></div>/**
  134. * @cfg {String} beforePageText
  135. * The text displayed before the input item (defaults to <tt>'Page'</tt>).
  136. */
  137. beforePageText : 'Page',
  138. <div id="cfg-Ext.PagingToolbar-afterPageText"></div>/**
  139. * @cfg {String} afterPageText
  140. * Customizable piece of the default paging text (defaults to <tt>'of {0}'</tt>). Note that
  141. * this string is formatted using <tt>{0}</tt> as a token that is replaced by the number of
  142. * total pages. This token should be preserved when overriding this string if showing the
  143. * total page count is desired.
  144. */
  145. afterPageText : 'of {0}',
  146. <div id="cfg-Ext.PagingToolbar-firstText"></div>/**
  147. * @cfg {String} firstText
  148. * The quicktip text displayed for the first page button (defaults to <tt>'First Page'</tt>).
  149. * <b>Note</b>: quick tips must be initialized for the quicktip to show.
  150. */
  151. firstText : 'First Page',
  152. <div id="cfg-Ext.PagingToolbar-prevText"></div>/**
  153. * @cfg {String} prevText
  154. * The quicktip text displayed for the previous page button (defaults to <tt>'Previous Page'</tt>).
  155. * <b>Note</b>: quick tips must be initialized for the quicktip to show.
  156. */
  157. prevText : 'Previous Page',
  158. <div id="cfg-Ext.PagingToolbar-nextText"></div>/**
  159. * @cfg {String} nextText
  160. * The quicktip text displayed for the next page button (defaults to <tt>'Next Page'</tt>).
  161. * <b>Note</b>: quick tips must be initialized for the quicktip to show.
  162. */
  163. nextText : 'Next Page',
  164. <div id="cfg-Ext.PagingToolbar-lastText"></div>/**
  165. * @cfg {String} lastText
  166. * The quicktip text displayed for the last page button (defaults to <tt>'Last Page'</tt>).
  167. * <b>Note</b>: quick tips must be initialized for the quicktip to show.
  168. */
  169. lastText : 'Last Page',
  170. <div id="cfg-Ext.PagingToolbar-refreshText"></div>/**
  171. * @cfg {String} refreshText
  172. * The quicktip text displayed for the Refresh button (defaults to <tt>'Refresh'</tt>).
  173. * <b>Note</b>: quick tips must be initialized for the quicktip to show.
  174. */
  175. refreshText : 'Refresh',
  176. <div id="prop-Ext.PagingToolbar-paramNames"></div>/**
  177. * <p><b>Deprecated</b>. <code>paramNames</code> should be set in the <b>data store</b>
  178. * (see {@link Ext.data.Store#paramNames}).</p>
  179. * <br><p>Object mapping of parameter names used for load calls, initially set to:</p>
  180. * <pre>{start: 'start', limit: 'limit'}</pre>
  181. * @type Object
  182. * @property paramNames
  183. * @deprecated
  184. */
  185. <div id="prop-Ext.PagingToolbar-pageSize"></div>/**
  186. * The number of records to display per page. See also <tt>{@link #cursor}</tt>.
  187. * @type Number
  188. * @property pageSize
  189. */
  190. <div id="prop-Ext.PagingToolbar-cursor"></div>/**
  191. * Indicator for the record position. This property might be used to get the active page
  192. * number for example:<pre><code>
  193. * // t is reference to the paging toolbar instance
  194. * var activePage = Math.ceil((t.cursor + t.pageSize) / t.pageSize);
  195. * </code></pre>
  196. * @type Number
  197. * @property cursor
  198. */
  199. initComponent : function(){
  200. var pagingItems = [this.first = new T.Button({
  201. tooltip: this.firstText,
  202. overflowText: this.firstText,
  203. iconCls: 'x-tbar-page-first',
  204. disabled: true,
  205. handler: this.moveFirst,
  206. scope: this
  207. }), this.prev = new T.Button({
  208. tooltip: this.prevText,
  209. overflowText: this.prevText,
  210. iconCls: 'x-tbar-page-prev',
  211. disabled: true,
  212. handler: this.movePrevious,
  213. scope: this
  214. }), '-', this.beforePageText,
  215. this.inputItem = new Ext.form.NumberField({
  216. cls: 'x-tbar-page-number',
  217. allowDecimals: false,
  218. allowNegative: false,
  219. enableKeyEvents: true,
  220. selectOnFocus: true,
  221. submitValue: false,
  222. listeners: {
  223. scope: this,
  224. keydown: this.onPagingKeyDown,
  225. blur: this.onPagingBlur
  226. }
  227. }), this.afterTextItem = new T.TextItem({
  228. text: String.format(this.afterPageText, 1)
  229. }), '-', this.next = new T.Button({
  230. tooltip: this.nextText,
  231. overflowText: this.nextText,
  232. iconCls: 'x-tbar-page-next',
  233. disabled: true,
  234. handler: this.moveNext,
  235. scope: this
  236. }), this.last = new T.Button({
  237. tooltip: this.lastText,
  238. overflowText: this.lastText,
  239. iconCls: 'x-tbar-page-last',
  240. disabled: true,
  241. handler: this.moveLast,
  242. scope: this
  243. }), '-', this.refresh = new T.Button({
  244. tooltip: this.refreshText,
  245. overflowText: this.refreshText,
  246. iconCls: 'x-tbar-loading',
  247. handler: this.doRefresh,
  248. scope: this
  249. })];
  250. var userItems = this.items || this.buttons || [];
  251. if (this.prependButtons) {
  252. this.items = userItems.concat(pagingItems);
  253. }else{
  254. this.items = pagingItems.concat(userItems);
  255. }
  256. delete this.buttons;
  257. if(this.displayInfo){
  258. this.items.push('->');
  259. this.items.push(this.displayItem = new T.TextItem({}));
  260. }
  261. Ext.PagingToolbar.superclass.initComponent.call(this);
  262. this.addEvents(
  263. <div id="event-Ext.PagingToolbar-change"></div>/**
  264. * @event change
  265. * Fires after the active page has been changed.
  266. * @param {Ext.PagingToolbar} this
  267. * @param {Object} pageData An object that has these properties:<ul>
  268. * <li><code>total</code> : Number <div class="sub-desc">The total number of records in the dataset as
  269. * returned by the server</div></li>
  270. * <li><code>activePage</code> : Number <div class="sub-desc">The current page number</div></li>
  271. * <li><code>pages</code> : Number <div class="sub-desc">The total number of pages (calculated from
  272. * the total number of records in the dataset as returned by the server and the current {@link #pageSize})</div></li>
  273. * </ul>
  274. */
  275. 'change',
  276. <div id="event-Ext.PagingToolbar-beforechange"></div>/**
  277. * @event beforechange
  278. * Fires just before the active page is changed.
  279. * Return false to prevent the active page from being changed.
  280. * @param {Ext.PagingToolbar} this
  281. * @param {Object} params An object hash of the parameters which the PagingToolbar will send when
  282. * loading the required page. This will contain:<ul>
  283. * <li><code>start</code> : Number <div class="sub-desc">The starting row number for the next page of records to
  284. * be retrieved from the server</div></li>
  285. * <li><code>limit</code> : Number <div class="sub-desc">The number of records to be retrieved from the server</div></li>
  286. * </ul>
  287. * <p>(note: the names of the <b>start</b> and <b>limit</b> properties are determined
  288. * by the store's {@link Ext.data.Store#paramNames paramNames} property.)</p>
  289. * <p>Parameters may be added as required in the event handler.</p>
  290. */
  291. 'beforechange'
  292. );
  293. this.on('afterlayout', this.onFirstLayout, this, {single: true});
  294. this.cursor = 0;
  295. this.bindStore(this.store, true);
  296. },
  297. // private
  298. onFirstLayout : function(){
  299. if(this.dsLoaded){
  300. this.onLoad.apply(this, this.dsLoaded);
  301. }
  302. },
  303. // private
  304. updateInfo : function(){
  305. if(this.displayItem){
  306. var count = this.store.getCount();
  307. var msg = count == 0 ?
  308. this.emptyMsg :
  309. String.format(
  310. this.displayMsg,
  311. this.cursor+1, this.cursor+count, this.store.getTotalCount()
  312. );
  313. this.displayItem.setText(msg);
  314. }
  315. },
  316. // private
  317. onLoad : function(store, r, o){
  318. if(!this.rendered){
  319. this.dsLoaded = [store, r, o];
  320. return;
  321. }
  322. var p = this.getParams();
  323. this.cursor = (o.params && o.params[p.start]) ? o.params[p.start] : 0;
  324. var d = this.getPageData(), ap = d.activePage, ps = d.pages;
  325. this.afterTextItem.setText(String.format(this.afterPageText, d.pages));
  326. this.inputItem.setValue(ap);
  327. this.first.setDisabled(ap == 1);
  328. this.prev.setDisabled(ap == 1);
  329. this.next.setDisabled(ap == ps);
  330. this.last.setDisabled(ap == ps);
  331. this.refresh.enable();
  332. this.updateInfo();
  333. this.fireEvent('change', this, d);
  334. },
  335. // private
  336. getPageData : function(){
  337. var total = this.store.getTotalCount();
  338. return {
  339. total : total,
  340. activePage : Math.ceil((this.cursor+this.pageSize)/this.pageSize),
  341. pages : total < this.pageSize ? 1 : Math.ceil(total/this.pageSize)
  342. };
  343. },
  344. <div id="method-Ext.PagingToolbar-changePage"></div>/**
  345. * Change the active page
  346. * @param {Integer} page The page to display
  347. */
  348. changePage : function(page){
  349. this.doLoad(((page-1) * this.pageSize).constrain(0, this.store.getTotalCount()));
  350. },
  351. // private
  352. onLoadError : function(){
  353. if(!this.rendered){
  354. return;
  355. }
  356. this.refresh.enable();
  357. },
  358. // private
  359. readPage : function(d){
  360. var v = this.inputItem.getValue(), pageNum;
  361. if (!v || isNaN(pageNum = parseInt(v, 10))) {
  362. this.inputItem.setValue(d.activePage);
  363. return false;
  364. }
  365. return pageNum;
  366. },
  367. onPagingFocus : function(){
  368. this.inputItem.select();
  369. },
  370. //private
  371. onPagingBlur : function(e){
  372. this.inputItem.setValue(this.getPageData().activePage);
  373. },
  374. // private
  375. onPagingKeyDown : function(field, e){
  376. var k = e.getKey(), d = this.getPageData(), pageNum;
  377. if (k == e.RETURN) {
  378. e.stopEvent();
  379. pageNum = this.readPage(d);
  380. if(pageNum !== false){
  381. pageNum = Math.min(Math.max(1, pageNum), d.pages) - 1;
  382. this.doLoad(pageNum * this.pageSize);
  383. }
  384. }else if (k == e.HOME || k == e.END){
  385. e.stopEvent();
  386. pageNum = k == e.HOME ? 1 : d.pages;
  387. field.setValue(pageNum);
  388. }else if (k == e.UP || k == e.PAGEUP || k == e.DOWN || k == e.PAGEDOWN){
  389. e.stopEvent();
  390. if((pageNum = this.readPage(d))){
  391. var increment = e.shiftKey ? 10 : 1;
  392. if(k == e.DOWN || k == e.PAGEDOWN){
  393. increment *= -1;
  394. }
  395. pageNum += increment;
  396. if(pageNum >= 1 & pageNum <= d.pages){
  397. field.setValue(pageNum);
  398. }
  399. }
  400. }
  401. },
  402. // private
  403. getParams : function(){
  404. //retain backwards compat, allow params on the toolbar itself, if they exist.
  405. return this.paramNames || this.store.paramNames;
  406. },
  407. // private
  408. beforeLoad : function(){
  409. if(this.rendered && this.refresh){
  410. this.refresh.disable();
  411. }
  412. },
  413. // private
  414. doLoad : function(start){
  415. var o = {}, pn = this.getParams();
  416. o[pn.start] = start;
  417. o[pn.limit] = this.pageSize;
  418. if(this.fireEvent('beforechange', this, o) !== false){
  419. this.store.load({params:o});
  420. }
  421. },
  422. <div id="method-Ext.PagingToolbar-moveFirst"></div>/**
  423. * Move to the first page, has the same effect as clicking the 'first' button.
  424. */
  425. moveFirst : function(){
  426. this.doLoad(0);
  427. },
  428. <div id="method-Ext.PagingToolbar-movePrevious"></div>/**
  429. * Move to the previous page, has the same effect as clicking the 'previous' button.
  430. */
  431. movePrevious : function(){
  432. this.doLoad(Math.max(0, this.cursor-this.pageSize));
  433. },
  434. <div id="method-Ext.PagingToolbar-moveNext"></div>/**
  435. * Move to the next page, has the same effect as clicking the 'next' button.
  436. */
  437. moveNext : function(){
  438. this.doLoad(this.cursor+this.pageSize);
  439. },
  440. <div id="method-Ext.PagingToolbar-moveLast"></div>/**
  441. * Move to the last page, has the same effect as clicking the 'last' button.
  442. */
  443. moveLast : function(){
  444. var total = this.store.getTotalCount(),
  445. extra = total % this.pageSize;
  446. this.doLoad(extra ? (total - extra) : total - this.pageSize);
  447. },
  448. <div id="method-Ext.PagingToolbar-doRefresh"></div>/**
  449. * Refresh the current page, has the same effect as clicking the 'refresh' button.
  450. */
  451. doRefresh : function(){
  452. this.doLoad(this.cursor);
  453. },
  454. <div id="method-Ext.PagingToolbar-bindStore"></div>/**
  455. * Binds the paging toolbar to the specified {@link Ext.data.Store}
  456. * @param {Store} store The store to bind to this toolbar
  457. * @param {Boolean} initial (Optional) true to not remove listeners
  458. */
  459. bindStore : function(store, initial){
  460. var doLoad;
  461. if(!initial && this.store){
  462. if(store !== this.store && this.store.autoDestroy){
  463. this.store.destroy();
  464. }else{
  465. this.store.un('beforeload', this.beforeLoad, this);
  466. this.store.un('load', this.onLoad, this);
  467. this.store.un('exception', this.onLoadError, this);
  468. }
  469. if(!store){
  470. this.store = null;
  471. }
  472. }
  473. if(store){
  474. store = Ext.StoreMgr.lookup(store);
  475. store.on({
  476. scope: this,
  477. beforeload: this.beforeLoad,
  478. load: this.onLoad,
  479. exception: this.onLoadError
  480. });
  481. doLoad = true;
  482. }
  483. this.store = store;
  484. if(doLoad){
  485. this.onLoad(store, null, {});
  486. }
  487. },
  488. <div id="method-Ext.PagingToolbar-unbind"></div>/**
  489. * Unbinds the paging toolbar from the specified {@link Ext.data.Store} <b>(deprecated)</b>
  490. * @param {Ext.data.Store} store The data store to unbind
  491. */
  492. unbind : function(store){
  493. this.bindStore(null);
  494. },
  495. <div id="method-Ext.PagingToolbar-bind"></div>/**
  496. * Binds the paging toolbar to the specified {@link Ext.data.Store} <b>(deprecated)</b>
  497. * @param {Ext.data.Store} store The data store to bind
  498. */
  499. bind : function(store){
  500. this.bindStore(store);
  501. },
  502. // private
  503. onDestroy : function(){
  504. this.bindStore(null);
  505. Ext.PagingToolbar.superclass.onDestroy.call(this);
  506. }
  507. });
  508. })();
  509. Ext.reg('paging', Ext.PagingToolbar);</pre>
  510. </body>
  511. </html>