Web UI for ARGUS server
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.

551 lines
19 KiB

6 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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.grid.RowSelectionModel"></div>/**
  16. * @class Ext.grid.RowSelectionModel
  17. * @extends Ext.grid.AbstractSelectionModel
  18. * The default SelectionModel used by {@link Ext.grid.GridPanel}.
  19. * It supports multiple selections and keyboard selection/navigation. The objects stored
  20. * as selections and returned by {@link #getSelected}, and {@link #getSelections} are
  21. * the {@link Ext.data.Record Record}s which provide the data for the selected rows.
  22. * @constructor
  23. * @param {Object} config
  24. */
  25. Ext.grid.RowSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
  26. <div id="cfg-Ext.grid.RowSelectionModel-singleSelect"></div>/**
  27. * @cfg {Boolean} singleSelect
  28. * <tt>true</tt> to allow selection of only one row at a time (defaults to <tt>false</tt>
  29. * allowing multiple selections)
  30. */
  31. singleSelect : false,
  32. constructor : function(config){
  33. Ext.apply(this, config);
  34. this.selections = new Ext.util.MixedCollection(false, function(o){
  35. return o.id;
  36. });
  37. this.last = false;
  38. this.lastActive = false;
  39. this.addEvents(
  40. <div id="event-Ext.grid.RowSelectionModel-selectionchange"></div>/**
  41. * @event selectionchange
  42. * Fires when the selection changes
  43. * @param {SelectionModel} this
  44. */
  45. 'selectionchange',
  46. <div id="event-Ext.grid.RowSelectionModel-beforerowselect"></div>/**
  47. * @event beforerowselect
  48. * Fires before a row is selected, return false to cancel the selection.
  49. * @param {SelectionModel} this
  50. * @param {Number} rowIndex The index to be selected
  51. * @param {Boolean} keepExisting False if other selections will be cleared
  52. * @param {Record} record The record to be selected
  53. */
  54. 'beforerowselect',
  55. <div id="event-Ext.grid.RowSelectionModel-rowselect"></div>/**
  56. * @event rowselect
  57. * Fires when a row is selected.
  58. * @param {SelectionModel} this
  59. * @param {Number} rowIndex The selected index
  60. * @param {Ext.data.Record} r The selected record
  61. */
  62. 'rowselect',
  63. <div id="event-Ext.grid.RowSelectionModel-rowdeselect"></div>/**
  64. * @event rowdeselect
  65. * Fires when a row is deselected. To prevent deselection
  66. * {@link Ext.grid.AbstractSelectionModel#lock lock the selections}.
  67. * @param {SelectionModel} this
  68. * @param {Number} rowIndex
  69. * @param {Record} record
  70. */
  71. 'rowdeselect'
  72. );
  73. Ext.grid.RowSelectionModel.superclass.constructor.call(this);
  74. },
  75. <div id="cfg-Ext.grid.RowSelectionModel-moveEditorOnEnter"></div>/**
  76. * @cfg {Boolean} moveEditorOnEnter
  77. * <tt>false</tt> to turn off moving the editor to the next row down when the enter key is pressed
  78. * or the next row up when shift + enter keys are pressed.
  79. */
  80. // private
  81. initEvents : function(){
  82. if(!this.grid.enableDragDrop && !this.grid.enableDrag){
  83. this.grid.on('rowmousedown', this.handleMouseDown, this);
  84. }
  85. this.rowNav = new Ext.KeyNav(this.grid.getGridEl(), {
  86. up: this.onKeyPress,
  87. down: this.onKeyPress,
  88. scope: this
  89. });
  90. this.grid.getView().on({
  91. scope: this,
  92. refresh: this.onRefresh,
  93. rowupdated: this.onRowUpdated,
  94. rowremoved: this.onRemove
  95. });
  96. },
  97. onKeyPress : function(e, name){
  98. var up = name == 'up',
  99. method = up ? 'selectPrevious' : 'selectNext',
  100. add = up ? -1 : 1,
  101. last;
  102. if(!e.shiftKey || this.singleSelect){
  103. this[method](false);
  104. }else if(this.last !== false && this.lastActive !== false){
  105. last = this.last;
  106. this.selectRange(this.last, this.lastActive + add);
  107. this.grid.getView().focusRow(this.lastActive);
  108. if(last !== false){
  109. this.last = last;
  110. }
  111. }else{
  112. this.selectFirstRow();
  113. }
  114. },
  115. // private
  116. onRefresh : function(){
  117. var ds = this.grid.store,
  118. s = this.getSelections(),
  119. i = 0,
  120. len = s.length,
  121. index, r;
  122. this.silent = true;
  123. this.clearSelections(true);
  124. for(; i < len; i++){
  125. r = s[i];
  126. if((index = ds.indexOfId(r.id)) != -1){
  127. this.selectRow(index, true);
  128. }
  129. }
  130. if(s.length != this.selections.getCount()){
  131. this.fireEvent('selectionchange', this);
  132. }
  133. this.silent = false;
  134. },
  135. // private
  136. onRemove : function(v, index, r){
  137. if(this.selections.remove(r) !== false){
  138. this.fireEvent('selectionchange', this);
  139. }
  140. },
  141. // private
  142. onRowUpdated : function(v, index, r){
  143. if(this.isSelected(r)){
  144. v.onRowSelect(index);
  145. }
  146. },
  147. <div id="method-Ext.grid.RowSelectionModel-selectRecords"></div>/**
  148. * Select records.
  149. * @param {Array} records The records to select
  150. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  151. */
  152. selectRecords : function(records, keepExisting){
  153. if(!keepExisting){
  154. this.clearSelections();
  155. }
  156. var ds = this.grid.store,
  157. i = 0,
  158. len = records.length;
  159. for(; i < len; i++){
  160. this.selectRow(ds.indexOf(records[i]), true);
  161. }
  162. },
  163. <div id="method-Ext.grid.RowSelectionModel-getCount"></div>/**
  164. * Gets the number of selected rows.
  165. * @return {Number}
  166. */
  167. getCount : function(){
  168. return this.selections.length;
  169. },
  170. <div id="method-Ext.grid.RowSelectionModel-selectFirstRow"></div>/**
  171. * Selects the first row in the grid.
  172. */
  173. selectFirstRow : function(){
  174. this.selectRow(0);
  175. },
  176. <div id="method-Ext.grid.RowSelectionModel-selectLastRow"></div>/**
  177. * Select the last row.
  178. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  179. */
  180. selectLastRow : function(keepExisting){
  181. this.selectRow(this.grid.store.getCount() - 1, keepExisting);
  182. },
  183. <div id="method-Ext.grid.RowSelectionModel-selectNext"></div>/**
  184. * Selects the row immediately following the last selected row.
  185. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  186. * @return {Boolean} <tt>true</tt> if there is a next row, else <tt>false</tt>
  187. */
  188. selectNext : function(keepExisting){
  189. if(this.hasNext()){
  190. this.selectRow(this.last+1, keepExisting);
  191. this.grid.getView().focusRow(this.last);
  192. return true;
  193. }
  194. return false;
  195. },
  196. <div id="method-Ext.grid.RowSelectionModel-selectPrevious"></div>/**
  197. * Selects the row that precedes the last selected row.
  198. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  199. * @return {Boolean} <tt>true</tt> if there is a previous row, else <tt>false</tt>
  200. */
  201. selectPrevious : function(keepExisting){
  202. if(this.hasPrevious()){
  203. this.selectRow(this.last-1, keepExisting);
  204. this.grid.getView().focusRow(this.last);
  205. return true;
  206. }
  207. return false;
  208. },
  209. <div id="method-Ext.grid.RowSelectionModel-hasNext"></div>/**
  210. * Returns true if there is a next record to select
  211. * @return {Boolean}
  212. */
  213. hasNext : function(){
  214. return this.last !== false && (this.last+1) < this.grid.store.getCount();
  215. },
  216. <div id="method-Ext.grid.RowSelectionModel-hasPrevious"></div>/**
  217. * Returns true if there is a previous record to select
  218. * @return {Boolean}
  219. */
  220. hasPrevious : function(){
  221. return !!this.last;
  222. },
  223. <div id="method-Ext.grid.RowSelectionModel-getSelections"></div>/**
  224. * Returns the selected records
  225. * @return {Array} Array of selected records
  226. */
  227. getSelections : function(){
  228. return [].concat(this.selections.items);
  229. },
  230. <div id="method-Ext.grid.RowSelectionModel-getSelected"></div>/**
  231. * Returns the first selected record.
  232. * @return {Record}
  233. */
  234. getSelected : function(){
  235. return this.selections.itemAt(0);
  236. },
  237. <div id="method-Ext.grid.RowSelectionModel-each"></div>/**
  238. * Calls the passed function with each selection. If the function returns
  239. * <tt>false</tt>, iteration is stopped and this function returns
  240. * <tt>false</tt>. Otherwise it returns <tt>true</tt>.
  241. * @param {Function} fn The function to call upon each iteration. It is passed the selected {@link Ext.data.Record Record}.
  242. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this RowSelectionModel.
  243. * @return {Boolean} true if all selections were iterated
  244. */
  245. each : function(fn, scope){
  246. var s = this.getSelections(),
  247. i = 0,
  248. len = s.length;
  249. for(; i < len; i++){
  250. if(fn.call(scope || this, s[i], i) === false){
  251. return false;
  252. }
  253. }
  254. return true;
  255. },
  256. <div id="method-Ext.grid.RowSelectionModel-clearSelections"></div>/**
  257. * Clears all selections if the selection model
  258. * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
  259. * @param {Boolean} fast (optional) <tt>true</tt> to bypass the
  260. * conditional checks and events described in {@link #deselectRow}.
  261. */
  262. clearSelections : function(fast){
  263. if(this.isLocked()){
  264. return;
  265. }
  266. if(fast !== true){
  267. var ds = this.grid.store,
  268. s = this.selections;
  269. s.each(function(r){
  270. this.deselectRow(ds.indexOfId(r.id));
  271. }, this);
  272. s.clear();
  273. }else{
  274. this.selections.clear();
  275. }
  276. this.last = false;
  277. },
  278. <div id="method-Ext.grid.RowSelectionModel-selectAll"></div>/**
  279. * Selects all rows if the selection model
  280. * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
  281. */
  282. selectAll : function(){
  283. if(this.isLocked()){
  284. return;
  285. }
  286. this.selections.clear();
  287. for(var i = 0, len = this.grid.store.getCount(); i < len; i++){
  288. this.selectRow(i, true);
  289. }
  290. },
  291. <div id="method-Ext.grid.RowSelectionModel-hasSelection"></div>/**
  292. * Returns <tt>true</tt> if there is a selection.
  293. * @return {Boolean}
  294. */
  295. hasSelection : function(){
  296. return this.selections.length > 0;
  297. },
  298. <div id="method-Ext.grid.RowSelectionModel-isSelected"></div>/**
  299. * Returns <tt>true</tt> if the specified row is selected.
  300. * @param {Number/Record} index The record or index of the record to check
  301. * @return {Boolean}
  302. */
  303. isSelected : function(index){
  304. var r = Ext.isNumber(index) ? this.grid.store.getAt(index) : index;
  305. return (r && this.selections.key(r.id) ? true : false);
  306. },
  307. <div id="method-Ext.grid.RowSelectionModel-isIdSelected"></div>/**
  308. * Returns <tt>true</tt> if the specified record id is selected.
  309. * @param {String} id The id of record to check
  310. * @return {Boolean}
  311. */
  312. isIdSelected : function(id){
  313. return (this.selections.key(id) ? true : false);
  314. },
  315. // private
  316. handleMouseDown : function(g, rowIndex, e){
  317. if(e.button !== 0 || this.isLocked()){
  318. return;
  319. }
  320. var view = this.grid.getView();
  321. if(e.shiftKey && !this.singleSelect && this.last !== false){
  322. var last = this.last;
  323. this.selectRange(last, rowIndex, e.ctrlKey);
  324. this.last = last; // reset the last
  325. view.focusRow(rowIndex);
  326. }else{
  327. var isSelected = this.isSelected(rowIndex);
  328. if(e.ctrlKey && isSelected){
  329. this.deselectRow(rowIndex);
  330. }else if(!isSelected || this.getCount() > 1){
  331. this.selectRow(rowIndex, e.ctrlKey || e.shiftKey);
  332. view.focusRow(rowIndex);
  333. }
  334. }
  335. },
  336. <div id="method-Ext.grid.RowSelectionModel-selectRows"></div>/**
  337. * Selects multiple rows.
  338. * @param {Array} rows Array of the indexes of the row to select
  339. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep
  340. * existing selections (defaults to <tt>false</tt>)
  341. */
  342. selectRows : function(rows, keepExisting){
  343. if(!keepExisting){
  344. this.clearSelections();
  345. }
  346. for(var i = 0, len = rows.length; i < len; i++){
  347. this.selectRow(rows[i], true);
  348. }
  349. },
  350. <div id="method-Ext.grid.RowSelectionModel-selectRange"></div>/**
  351. * Selects a range of rows if the selection model
  352. * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
  353. * All rows in between startRow and endRow are also selected.
  354. * @param {Number} startRow The index of the first row in the range
  355. * @param {Number} endRow The index of the last row in the range
  356. * @param {Boolean} keepExisting (optional) True to retain existing selections
  357. */
  358. selectRange : function(startRow, endRow, keepExisting){
  359. var i;
  360. if(this.isLocked()){
  361. return;
  362. }
  363. if(!keepExisting){
  364. this.clearSelections();
  365. }
  366. if(startRow <= endRow){
  367. for(i = startRow; i <= endRow; i++){
  368. this.selectRow(i, true);
  369. }
  370. }else{
  371. for(i = startRow; i >= endRow; i--){
  372. this.selectRow(i, true);
  373. }
  374. }
  375. },
  376. <div id="method-Ext.grid.RowSelectionModel-deselectRange"></div>/**
  377. * Deselects a range of rows if the selection model
  378. * {@link Ext.grid.AbstractSelectionModel#isLocked is not locked}.
  379. * All rows in between startRow and endRow are also deselected.
  380. * @param {Number} startRow The index of the first row in the range
  381. * @param {Number} endRow The index of the last row in the range
  382. */
  383. deselectRange : function(startRow, endRow, preventViewNotify){
  384. if(this.isLocked()){
  385. return;
  386. }
  387. for(var i = startRow; i <= endRow; i++){
  388. this.deselectRow(i, preventViewNotify);
  389. }
  390. },
  391. <div id="method-Ext.grid.RowSelectionModel-selectRow"></div>/**
  392. * Selects a row. Before selecting a row, checks if the selection model
  393. * {@link Ext.grid.AbstractSelectionModel#isLocked is locked} and fires the
  394. * {@link #beforerowselect} event. If these checks are satisfied the row
  395. * will be selected and followed up by firing the {@link #rowselect} and
  396. * {@link #selectionchange} events.
  397. * @param {Number} row The index of the row to select
  398. * @param {Boolean} keepExisting (optional) <tt>true</tt> to keep existing selections
  399. * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
  400. * prevent notifying the view (disables updating the selected appearance)
  401. */
  402. selectRow : function(index, keepExisting, preventViewNotify){
  403. if(this.isLocked() || (index < 0 || index >= this.grid.store.getCount()) || (keepExisting && this.isSelected(index))){
  404. return;
  405. }
  406. var r = this.grid.store.getAt(index);
  407. if(r && this.fireEvent('beforerowselect', this, index, keepExisting, r) !== false){
  408. if(!keepExisting || this.singleSelect){
  409. this.clearSelections();
  410. }
  411. this.selections.add(r);
  412. this.last = this.lastActive = index;
  413. if(!preventViewNotify){
  414. this.grid.getView().onRowSelect(index);
  415. }
  416. if(!this.silent){
  417. this.fireEvent('rowselect', this, index, r);
  418. this.fireEvent('selectionchange', this);
  419. }
  420. }
  421. },
  422. <div id="method-Ext.grid.RowSelectionModel-deselectRow"></div>/**
  423. * Deselects a row. Before deselecting a row, checks if the selection model
  424. * {@link Ext.grid.AbstractSelectionModel#isLocked is locked}.
  425. * If this check is satisfied the row will be deselected and followed up by
  426. * firing the {@link #rowdeselect} and {@link #selectionchange} events.
  427. * @param {Number} row The index of the row to deselect
  428. * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
  429. * prevent notifying the view (disables updating the selected appearance)
  430. */
  431. deselectRow : function(index, preventViewNotify){
  432. if(this.isLocked()){
  433. return;
  434. }
  435. if(this.last == index){
  436. this.last = false;
  437. }
  438. if(this.lastActive == index){
  439. this.lastActive = false;
  440. }
  441. var r = this.grid.store.getAt(index);
  442. if(r){
  443. this.selections.remove(r);
  444. if(!preventViewNotify){
  445. this.grid.getView().onRowDeselect(index);
  446. }
  447. this.fireEvent('rowdeselect', this, index, r);
  448. this.fireEvent('selectionchange', this);
  449. }
  450. },
  451. // private
  452. acceptsNav : function(row, col, cm){
  453. return !cm.isHidden(col) && cm.isCellEditable(col, row);
  454. },
  455. // private
  456. onEditorKey : function(field, e){
  457. var k = e.getKey(),
  458. newCell,
  459. g = this.grid,
  460. last = g.lastEdit,
  461. ed = g.activeEditor,
  462. shift = e.shiftKey,
  463. ae, last, r, c;
  464. if(k == e.TAB){
  465. e.stopEvent();
  466. ed.completeEdit();
  467. if(shift){
  468. newCell = g.walkCells(ed.row, ed.col-1, -1, this.acceptsNav, this);
  469. }else{
  470. newCell = g.walkCells(ed.row, ed.col+1, 1, this.acceptsNav, this);
  471. }
  472. }else if(k == e.ENTER){
  473. if(this.moveEditorOnEnter !== false){
  474. if(shift){
  475. newCell = g.walkCells(last.row - 1, last.col, -1, this.acceptsNav, this);
  476. }else{
  477. newCell = g.walkCells(last.row + 1, last.col, 1, this.acceptsNav, this);
  478. }
  479. }
  480. }
  481. if(newCell){
  482. r = newCell[0];
  483. c = newCell[1];
  484. this.onEditorSelect(r, last.row);
  485. if(g.isEditor && g.editing){ // *** handle tabbing while editorgrid is in edit mode
  486. ae = g.activeEditor;
  487. if(ae && ae.field.triggerBlur){
  488. // *** if activeEditor is a TriggerField, explicitly call its triggerBlur() method
  489. ae.field.triggerBlur();
  490. }
  491. }
  492. g.startEditing(r, c);
  493. }
  494. },
  495. onEditorSelect: function(row, lastRow){
  496. if(lastRow != row){
  497. this.selectRow(row); // *** highlight newly-selected cell and update selection
  498. }
  499. },
  500. destroy : function(){
  501. Ext.destroy(this.rowNav);
  502. this.rowNav = null;
  503. Ext.grid.RowSelectionModel.superclass.destroy.call(this);
  504. }
  505. });
  506. </pre>
  507. </body>
  508. </html>