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.

337 lines
13 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.grid.EditorGridPanel"></div>/**
  16. * @class Ext.grid.EditorGridPanel
  17. * @extends Ext.grid.GridPanel
  18. * <p>This class extends the {@link Ext.grid.GridPanel GridPanel Class} to provide cell editing
  19. * on selected {@link Ext.grid.Column columns}. The editable columns are specified by providing
  20. * an {@link Ext.grid.ColumnModel#editor editor} in the {@link Ext.grid.Column column configuration}.</p>
  21. * <p>Editability of columns may be controlled programatically by inserting an implementation
  22. * of {@link Ext.grid.ColumnModel#isCellEditable isCellEditable} into the
  23. * {@link Ext.grid.ColumnModel ColumnModel}.</p>
  24. * <p>Editing is performed on the value of the <i>field</i> specified by the column's
  25. * <tt>{@link Ext.grid.ColumnModel#dataIndex dataIndex}</tt> in the backing {@link Ext.data.Store Store}
  26. * (so if you are using a {@link Ext.grid.ColumnModel#setRenderer renderer} in order to display
  27. * transformed data, this must be accounted for).</p>
  28. * <p>If a value-to-description mapping is used to render a column, then a {@link Ext.form.Field#ComboBox ComboBox}
  29. * which uses the same {@link Ext.form.Field#valueField value}-to-{@link Ext.form.Field#displayFieldField description}
  30. * mapping would be an appropriate editor.</p>
  31. * If there is a more complex mismatch between the visible data in the grid, and the editable data in
  32. * the {@link Edt.data.Store Store}, then code to transform the data both before and after editing can be
  33. * injected using the {@link #beforeedit} and {@link #afteredit} events.
  34. * @constructor
  35. * @param {Object} config The config object
  36. * @xtype editorgrid
  37. */
  38. Ext.grid.EditorGridPanel = Ext.extend(Ext.grid.GridPanel, {
  39. <div id="cfg-Ext.grid.EditorGridPanel-clicksToEdit"></div>/**
  40. * @cfg {Number} clicksToEdit
  41. * <p>The number of clicks on a cell required to display the cell's editor (defaults to 2).</p>
  42. * <p>Setting this option to 'auto' means that mousedown <i>on the selected cell</i> starts
  43. * editing that cell.</p>
  44. */
  45. clicksToEdit: 2,
  46. <div id="cfg-Ext.grid.EditorGridPanel-forceValidation"></div>/**
  47. * @cfg {Boolean} forceValidation
  48. * True to force validation even if the value is unmodified (defaults to false)
  49. */
  50. forceValidation: false,
  51. // private
  52. isEditor : true,
  53. // private
  54. detectEdit: false,
  55. <div id="cfg-Ext.grid.EditorGridPanel-autoEncode"></div>/**
  56. * @cfg {Boolean} autoEncode
  57. * True to automatically HTML encode and decode values pre and post edit (defaults to false)
  58. */
  59. autoEncode : false,
  60. <div id="cfg-Ext.grid.EditorGridPanel-trackMouseOver"></div>/**
  61. * @cfg {Boolean} trackMouseOver @hide
  62. */
  63. // private
  64. trackMouseOver: false, // causes very odd FF errors
  65. // private
  66. initComponent : function(){
  67. Ext.grid.EditorGridPanel.superclass.initComponent.call(this);
  68. if(!this.selModel){
  69. <div id="cfg-Ext.grid.EditorGridPanel-selModel"></div>/**
  70. * @cfg {Object} selModel Any subclass of AbstractSelectionModel that will provide the selection model for
  71. * the grid (defaults to {@link Ext.grid.CellSelectionModel} if not specified).
  72. */
  73. this.selModel = new Ext.grid.CellSelectionModel();
  74. }
  75. this.activeEditor = null;
  76. this.addEvents(
  77. <div id="event-Ext.grid.EditorGridPanel-beforeedit"></div>/**
  78. * @event beforeedit
  79. * Fires before cell editing is triggered. The edit event object has the following properties <br />
  80. * <ul style="padding:5px;padding-left:16px;">
  81. * <li>grid - This grid</li>
  82. * <li>record - The record being edited</li>
  83. * <li>field - The field name being edited</li>
  84. * <li>value - The value for the field being edited.</li>
  85. * <li>row - The grid row index</li>
  86. * <li>column - The grid column index</li>
  87. * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
  88. * </ul>
  89. * @param {Object} e An edit event (see above for description)
  90. */
  91. "beforeedit",
  92. <div id="event-Ext.grid.EditorGridPanel-afteredit"></div>/**
  93. * @event afteredit
  94. * Fires after a cell is edited. The edit event object has the following properties <br />
  95. * <ul style="padding:5px;padding-left:16px;">
  96. * <li>grid - This grid</li>
  97. * <li>record - The record being edited</li>
  98. * <li>field - The field name being edited</li>
  99. * <li>value - The value being set</li>
  100. * <li>originalValue - The original value for the field, before the edit.</li>
  101. * <li>row - The grid row index</li>
  102. * <li>column - The grid column index</li>
  103. * </ul>
  104. *
  105. * <pre><code>
  106. grid.on('afteredit', afterEdit, this );
  107. function afterEdit(e) {
  108. // execute an XHR to send/commit data to the server, in callback do (if successful):
  109. e.record.commit();
  110. };
  111. * </code></pre>
  112. * @param {Object} e An edit event (see above for description)
  113. */
  114. "afteredit",
  115. <div id="event-Ext.grid.EditorGridPanel-validateedit"></div>/**
  116. * @event validateedit
  117. * Fires after a cell is edited, but before the value is set in the record. Return false
  118. * to cancel the change. The edit event object has the following properties <br />
  119. * <ul style="padding:5px;padding-left:16px;">
  120. * <li>grid - This grid</li>
  121. * <li>record - The record being edited</li>
  122. * <li>field - The field name being edited</li>
  123. * <li>value - The value being set</li>
  124. * <li>originalValue - The original value for the field, before the edit.</li>
  125. * <li>row - The grid row index</li>
  126. * <li>column - The grid column index</li>
  127. * <li>cancel - Set this to true to cancel the edit or return false from your handler.</li>
  128. * </ul>
  129. * Usage example showing how to remove the red triangle (dirty record indicator) from some
  130. * records (not all). By observing the grid's validateedit event, it can be cancelled if
  131. * the edit occurs on a targeted row (for example) and then setting the field's new value
  132. * in the Record directly:
  133. * <pre><code>
  134. grid.on('validateedit', function(e) {
  135. var myTargetRow = 6;
  136. if (e.row == myTargetRow) {
  137. e.cancel = true;
  138. e.record.data[e.field] = e.value;
  139. }
  140. });
  141. * </code></pre>
  142. * @param {Object} e An edit event (see above for description)
  143. */
  144. "validateedit"
  145. );
  146. },
  147. // private
  148. initEvents : function(){
  149. Ext.grid.EditorGridPanel.superclass.initEvents.call(this);
  150. this.getGridEl().on('mousewheel', this.stopEditing.createDelegate(this, [true]), this);
  151. this.on('columnresize', this.stopEditing, this, [true]);
  152. if(this.clicksToEdit == 1){
  153. this.on("cellclick", this.onCellDblClick, this);
  154. }else {
  155. var view = this.getView();
  156. if(this.clicksToEdit == 'auto' && view.mainBody){
  157. view.mainBody.on('mousedown', this.onAutoEditClick, this);
  158. }
  159. this.on('celldblclick', this.onCellDblClick, this);
  160. }
  161. },
  162. onResize : function(){
  163. Ext.grid.EditorGridPanel.superclass.onResize.apply(this, arguments);
  164. var ae = this.activeEditor;
  165. if(this.editing && ae){
  166. ae.realign(true);
  167. }
  168. },
  169. // private
  170. onCellDblClick : function(g, row, col){
  171. this.startEditing(row, col);
  172. },
  173. // private
  174. onAutoEditClick : function(e, t){
  175. if(e.button !== 0){
  176. return;
  177. }
  178. var row = this.view.findRowIndex(t),
  179. col = this.view.findCellIndex(t);
  180. if(row !== false && col !== false){
  181. this.stopEditing();
  182. if(this.selModel.getSelectedCell){ // cell sm
  183. var sc = this.selModel.getSelectedCell();
  184. if(sc && sc[0] === row && sc[1] === col){
  185. this.startEditing(row, col);
  186. }
  187. }else{
  188. if(this.selModel.isSelected(row)){
  189. this.startEditing(row, col);
  190. }
  191. }
  192. }
  193. },
  194. // private
  195. onEditComplete : function(ed, value, startValue){
  196. this.editing = false;
  197. this.lastActiveEditor = this.activeEditor;
  198. this.activeEditor = null;
  199. var r = ed.record,
  200. field = this.colModel.getDataIndex(ed.col);
  201. value = this.postEditValue(value, startValue, r, field);
  202. if(this.forceValidation === true || String(value) !== String(startValue)){
  203. var e = {
  204. grid: this,
  205. record: r,
  206. field: field,
  207. originalValue: startValue,
  208. value: value,
  209. row: ed.row,
  210. column: ed.col,
  211. cancel:false
  212. };
  213. if(this.fireEvent("validateedit", e) !== false && !e.cancel && String(value) !== String(startValue)){
  214. r.set(field, e.value);
  215. delete e.cancel;
  216. this.fireEvent("afteredit", e);
  217. }
  218. }
  219. this.view.focusCell(ed.row, ed.col);
  220. },
  221. <div id="method-Ext.grid.EditorGridPanel-startEditing"></div>/**
  222. * Starts editing the specified for the specified row/column
  223. * @param {Number} rowIndex
  224. * @param {Number} colIndex
  225. */
  226. startEditing : function(row, col){
  227. this.stopEditing();
  228. if(this.colModel.isCellEditable(col, row)){
  229. this.view.ensureVisible(row, col, true);
  230. var r = this.store.getAt(row),
  231. field = this.colModel.getDataIndex(col),
  232. e = {
  233. grid: this,
  234. record: r,
  235. field: field,
  236. value: r.data[field],
  237. row: row,
  238. column: col,
  239. cancel:false
  240. };
  241. if(this.fireEvent("beforeedit", e) !== false && !e.cancel){
  242. this.editing = true;
  243. var ed = this.colModel.getCellEditor(col, row);
  244. if(!ed){
  245. return;
  246. }
  247. if(!ed.rendered){
  248. ed.parentEl = this.view.getEditorParent(ed);
  249. ed.on({
  250. scope: this,
  251. render: {
  252. fn: function(c){
  253. c.field.focus(false, true);
  254. },
  255. single: true,
  256. scope: this
  257. },
  258. specialkey: function(field, e){
  259. this.getSelectionModel().onEditorKey(field, e);
  260. },
  261. complete: this.onEditComplete,
  262. canceledit: this.stopEditing.createDelegate(this, [true])
  263. });
  264. }
  265. Ext.apply(ed, {
  266. row : row,
  267. col : col,
  268. record : r
  269. });
  270. this.lastEdit = {
  271. row: row,
  272. col: col
  273. };
  274. this.activeEditor = ed;
  275. // Set the selectSameEditor flag if we are reusing the same editor again and
  276. // need to prevent the editor from firing onBlur on itself.
  277. ed.selectSameEditor = (this.activeEditor == this.lastActiveEditor);
  278. var v = this.preEditValue(r, field);
  279. ed.startEdit(this.view.getCell(row, col).firstChild, Ext.isDefined(v) ? v : '');
  280. // Clear the selectSameEditor flag
  281. (function(){
  282. delete ed.selectSameEditor;
  283. }).defer(50);
  284. }
  285. }
  286. },
  287. // private
  288. preEditValue : function(r, field){
  289. var value = r.data[field];
  290. return this.autoEncode && Ext.isString(value) ? Ext.util.Format.htmlDecode(value) : value;
  291. },
  292. // private
  293. postEditValue : function(value, originalValue, r, field){
  294. return this.autoEncode && Ext.isString(value) ? Ext.util.Format.htmlEncode(value) : value;
  295. },
  296. <div id="method-Ext.grid.EditorGridPanel-stopEditing"></div>/**
  297. * Stops any active editing
  298. * @param {Boolean} cancel (optional) True to cancel any changes
  299. */
  300. stopEditing : function(cancel){
  301. if(this.editing){
  302. // Store the lastActiveEditor to check if it is changing
  303. var ae = this.lastActiveEditor = this.activeEditor;
  304. if(ae){
  305. ae[cancel === true ? 'cancelEdit' : 'completeEdit']();
  306. this.view.focusCell(ae.row, ae.col);
  307. }
  308. this.activeEditor = null;
  309. }
  310. this.editing = false;
  311. }
  312. });
  313. Ext.reg('editorgrid', Ext.grid.EditorGridPanel);</pre>
  314. </body>
  315. </html>