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.

295 lines
10 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.CellSelectionModel"></div>/**
  16. * @class Ext.grid.CellSelectionModel
  17. * @extends Ext.grid.AbstractSelectionModel
  18. * This class provides the basic implementation for <i>single</i> <b>cell</b> selection in a grid.
  19. * The object stored as the selection contains the following properties:
  20. * <div class="mdetail-params"><ul>
  21. * <li><b>cell</b> : see {@link #getSelectedCell}
  22. * <li><b>record</b> : Ext.data.record The {@link Ext.data.Record Record}
  23. * which provides the data for the row containing the selection</li>
  24. * </ul></div>
  25. * @constructor
  26. * @param {Object} config The object containing the configuration of this model.
  27. */
  28. Ext.grid.CellSelectionModel = Ext.extend(Ext.grid.AbstractSelectionModel, {
  29. constructor : function(config){
  30. Ext.apply(this, config);
  31. this.selection = null;
  32. this.addEvents(
  33. <div id="event-Ext.grid.CellSelectionModel-beforecellselect"></div>/**
  34. * @event beforecellselect
  35. * Fires before a cell is selected, return false to cancel the selection.
  36. * @param {SelectionModel} this
  37. * @param {Number} rowIndex The selected row index
  38. * @param {Number} colIndex The selected cell index
  39. */
  40. "beforecellselect",
  41. <div id="event-Ext.grid.CellSelectionModel-cellselect"></div>/**
  42. * @event cellselect
  43. * Fires when a cell is selected.
  44. * @param {SelectionModel} this
  45. * @param {Number} rowIndex The selected row index
  46. * @param {Number} colIndex The selected cell index
  47. */
  48. "cellselect",
  49. <div id="event-Ext.grid.CellSelectionModel-selectionchange"></div>/**
  50. * @event selectionchange
  51. * Fires when the active selection changes.
  52. * @param {SelectionModel} this
  53. * @param {Object} selection null for no selection or an object with two properties
  54. * <div class="mdetail-params"><ul>
  55. * <li><b>cell</b> : see {@link #getSelectedCell}
  56. * <li><b>record</b> : Ext.data.record<p class="sub-desc">The {@link Ext.data.Record Record}
  57. * which provides the data for the row containing the selection</p></li>
  58. * </ul></div>
  59. */
  60. "selectionchange"
  61. );
  62. Ext.grid.CellSelectionModel.superclass.constructor.call(this);
  63. },
  64. /** @ignore */
  65. initEvents : function(){
  66. this.grid.on('cellmousedown', this.handleMouseDown, this);
  67. this.grid.on(Ext.EventManager.getKeyEvent(), this.handleKeyDown, this);
  68. this.grid.getView().on({
  69. scope: this,
  70. refresh: this.onViewChange,
  71. rowupdated: this.onRowUpdated,
  72. beforerowremoved: this.clearSelections,
  73. beforerowsinserted: this.clearSelections
  74. });
  75. if(this.grid.isEditor){
  76. this.grid.on('beforeedit', this.beforeEdit, this);
  77. }
  78. },
  79. //private
  80. beforeEdit : function(e){
  81. this.select(e.row, e.column, false, true, e.record);
  82. },
  83. //private
  84. onRowUpdated : function(v, index, r){
  85. if(this.selection && this.selection.record == r){
  86. v.onCellSelect(index, this.selection.cell[1]);
  87. }
  88. },
  89. //private
  90. onViewChange : function(){
  91. this.clearSelections(true);
  92. },
  93. <div id="method-Ext.grid.CellSelectionModel-getSelectedCell"></div>/**
  94. * Returns an array containing the row and column indexes of the currently selected cell
  95. * (e.g., [0, 0]), or null if none selected. The array has elements:
  96. * <div class="mdetail-params"><ul>
  97. * <li><b>rowIndex</b> : Number<p class="sub-desc">The index of the selected row</p></li>
  98. * <li><b>cellIndex</b> : Number<p class="sub-desc">The index of the selected cell.
  99. * Due to possible column reordering, the cellIndex should <b>not</b> be used as an
  100. * index into the Record's data. Instead, use the cellIndex to determine the <i>name</i>
  101. * of the selected cell and use the field name to retrieve the data value from the record:<pre><code>
  102. // get name
  103. var fieldName = grid.getColumnModel().getDataIndex(cellIndex);
  104. // get data value based on name
  105. var data = record.get(fieldName);
  106. * </code></pre></p></li>
  107. * </ul></div>
  108. * @return {Array} An array containing the row and column indexes of the selected cell, or null if none selected.
  109. */
  110. getSelectedCell : function(){
  111. return this.selection ? this.selection.cell : null;
  112. },
  113. <div id="method-Ext.grid.CellSelectionModel-clearSelections"></div>/**
  114. * If anything is selected, clears all selections and fires the selectionchange event.
  115. * @param {Boolean} preventNotify <tt>true</tt> to prevent the gridview from
  116. * being notified about the change.
  117. */
  118. clearSelections : function(preventNotify){
  119. var s = this.selection;
  120. if(s){
  121. if(preventNotify !== true){
  122. this.grid.view.onCellDeselect(s.cell[0], s.cell[1]);
  123. }
  124. this.selection = null;
  125. this.fireEvent("selectionchange", this, null);
  126. }
  127. },
  128. <div id="method-Ext.grid.CellSelectionModel-hasSelection"></div>/**
  129. * Returns <tt>true</tt> if there is a selection.
  130. * @return {Boolean}
  131. */
  132. hasSelection : function(){
  133. return this.selection ? true : false;
  134. },
  135. /** @ignore */
  136. handleMouseDown : function(g, row, cell, e){
  137. if(e.button !== 0 || this.isLocked()){
  138. return;
  139. }
  140. this.select(row, cell);
  141. },
  142. <div id="method-Ext.grid.CellSelectionModel-select"></div>/**
  143. * Selects a cell. Before selecting a cell, fires the
  144. * {@link #beforecellselect} event. If this check is satisfied the cell
  145. * will be selected and followed up by firing the {@link #cellselect} and
  146. * {@link #selectionchange} events.
  147. * @param {Number} rowIndex The index of the row to select
  148. * @param {Number} colIndex The index of the column to select
  149. * @param {Boolean} preventViewNotify (optional) Specify <tt>true</tt> to
  150. * prevent notifying the view (disables updating the selected appearance)
  151. * @param {Boolean} preventFocus (optional) Whether to prevent the cell at
  152. * the specified rowIndex / colIndex from being focused.
  153. * @param {Ext.data.Record} r (optional) The record to select
  154. */
  155. select : function(rowIndex, colIndex, preventViewNotify, preventFocus, /*internal*/ r){
  156. if(this.fireEvent("beforecellselect", this, rowIndex, colIndex) !== false){
  157. this.clearSelections();
  158. r = r || this.grid.store.getAt(rowIndex);
  159. this.selection = {
  160. record : r,
  161. cell : [rowIndex, colIndex]
  162. };
  163. if(!preventViewNotify){
  164. var v = this.grid.getView();
  165. v.onCellSelect(rowIndex, colIndex);
  166. if(preventFocus !== true){
  167. v.focusCell(rowIndex, colIndex);
  168. }
  169. }
  170. this.fireEvent("cellselect", this, rowIndex, colIndex);
  171. this.fireEvent("selectionchange", this, this.selection);
  172. }
  173. },
  174. //private
  175. isSelectable : function(rowIndex, colIndex, cm){
  176. return !cm.isHidden(colIndex);
  177. },
  178. // private
  179. onEditorKey: function(field, e){
  180. if(e.getKey() == e.TAB){
  181. this.handleKeyDown(e);
  182. }
  183. },
  184. /** @ignore */
  185. handleKeyDown : function(e){
  186. if(!e.isNavKeyPress()){
  187. return;
  188. }
  189. var k = e.getKey(),
  190. g = this.grid,
  191. s = this.selection,
  192. sm = this,
  193. walk = function(row, col, step){
  194. return g.walkCells(
  195. row,
  196. col,
  197. step,
  198. g.isEditor && g.editing ? sm.acceptsNav : sm.isSelectable, // *** handle tabbing while editorgrid is in edit mode
  199. sm
  200. );
  201. },
  202. cell, newCell, r, c, ae;
  203. switch(k){
  204. case e.ESC:
  205. case e.PAGE_UP:
  206. case e.PAGE_DOWN:
  207. // do nothing
  208. break;
  209. default:
  210. // *** call e.stopEvent() only for non ESC, PAGE UP/DOWN KEYS
  211. e.stopEvent();
  212. break;
  213. }
  214. if(!s){
  215. cell = walk(0, 0, 1); // *** use private walk() function defined above
  216. if(cell){
  217. this.select(cell[0], cell[1]);
  218. }
  219. return;
  220. }
  221. cell = s.cell; // currently selected cell
  222. r = cell[0]; // current row
  223. c = cell[1]; // current column
  224. switch(k){
  225. case e.TAB:
  226. if(e.shiftKey){
  227. newCell = walk(r, c - 1, -1);
  228. }else{
  229. newCell = walk(r, c + 1, 1);
  230. }
  231. break;
  232. case e.DOWN:
  233. newCell = walk(r + 1, c, 1);
  234. break;
  235. case e.UP:
  236. newCell = walk(r - 1, c, -1);
  237. break;
  238. case e.RIGHT:
  239. newCell = walk(r, c + 1, 1);
  240. break;
  241. case e.LEFT:
  242. newCell = walk(r, c - 1, -1);
  243. break;
  244. case e.ENTER:
  245. if (g.isEditor && !g.editing) {
  246. g.startEditing(r, c);
  247. return;
  248. }
  249. break;
  250. }
  251. if(newCell){
  252. // *** reassign r & c variables to newly-selected cell's row and column
  253. r = newCell[0];
  254. c = newCell[1];
  255. this.select(r, c); // *** highlight newly-selected cell and update selection
  256. if(g.isEditor && g.editing){ // *** handle tabbing while editorgrid is in edit mode
  257. ae = g.activeEditor;
  258. if(ae && ae.field.triggerBlur){
  259. // *** if activeEditor is a TriggerField, explicitly call its triggerBlur() method
  260. ae.field.triggerBlur();
  261. }
  262. g.startEditing(r, c);
  263. }
  264. }
  265. },
  266. acceptsNav : function(row, col, cm){
  267. return !cm.isHidden(col) && cm.isCellEditable(col, row);
  268. }
  269. });</pre>
  270. </body>
  271. </html>