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.

478 lines
17 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.PropertyRecord"></div>/**
  16. * @class Ext.grid.PropertyRecord
  17. * A specific {@link Ext.data.Record} type that represents a name/value pair and is made to work with the
  18. * {@link Ext.grid.PropertyGrid}. Typically, PropertyRecords do not need to be created directly as they can be
  19. * created implicitly by simply using the appropriate data configs either via the {@link Ext.grid.PropertyGrid#source}
  20. * config property or by calling {@link Ext.grid.PropertyGrid#setSource}. However, if the need arises, these records
  21. * can also be created explicitly as shwon below. Example usage:
  22. * <pre><code>
  23. var rec = new Ext.grid.PropertyRecord({
  24. name: 'Birthday',
  25. value: new Date(Date.parse('05/26/1972'))
  26. });
  27. // Add record to an already populated grid
  28. grid.store.addSorted(rec);
  29. </code></pre>
  30. * @constructor
  31. * @param {Object} config A data object in the format: {name: [name], value: [value]}. The specified value's type
  32. * will be read automatically by the grid to determine the type of editor to use when displaying it.
  33. */
  34. Ext.grid.PropertyRecord = Ext.data.Record.create([
  35. {name:'name',type:'string'}, 'value'
  36. ]);
  37. <div id="cls-Ext.grid.PropertyStore"></div>/**
  38. * @class Ext.grid.PropertyStore
  39. * @extends Ext.util.Observable
  40. * A custom wrapper for the {@link Ext.grid.PropertyGrid}'s {@link Ext.data.Store}. This class handles the mapping
  41. * between the custom data source objects supported by the grid and the {@link Ext.grid.PropertyRecord} format
  42. * required for compatibility with the underlying store. Generally this class should not need to be used directly --
  43. * the grid's data should be accessed from the underlying store via the {@link #store} property.
  44. * @constructor
  45. * @param {Ext.grid.Grid} grid The grid this store will be bound to
  46. * @param {Object} source The source data config object
  47. */
  48. Ext.grid.PropertyStore = Ext.extend(Ext.util.Observable, {
  49. constructor : function(grid, source){
  50. this.grid = grid;
  51. this.store = new Ext.data.Store({
  52. recordType : Ext.grid.PropertyRecord
  53. });
  54. this.store.on('update', this.onUpdate, this);
  55. if(source){
  56. this.setSource(source);
  57. }
  58. Ext.grid.PropertyStore.superclass.constructor.call(this);
  59. },
  60. // protected - should only be called by the grid. Use grid.setSource instead.
  61. setSource : function(o){
  62. this.source = o;
  63. this.store.removeAll();
  64. var data = [];
  65. for(var k in o){
  66. if(this.isEditableValue(o[k])){
  67. data.push(new Ext.grid.PropertyRecord({name: k, value: o[k]}, k));
  68. }
  69. }
  70. this.store.loadRecords({records: data}, {}, true);
  71. },
  72. // private
  73. onUpdate : function(ds, record, type){
  74. if(type == Ext.data.Record.EDIT){
  75. var v = record.data.value;
  76. var oldValue = record.modified.value;
  77. if(this.grid.fireEvent('beforepropertychange', this.source, record.id, v, oldValue) !== false){
  78. this.source[record.id] = v;
  79. record.commit();
  80. this.grid.fireEvent('propertychange', this.source, record.id, v, oldValue);
  81. }else{
  82. record.reject();
  83. }
  84. }
  85. },
  86. // private
  87. getProperty : function(row){
  88. return this.store.getAt(row);
  89. },
  90. // private
  91. isEditableValue: function(val){
  92. return Ext.isPrimitive(val) || Ext.isDate(val);
  93. },
  94. // private
  95. setValue : function(prop, value, create){
  96. var r = this.getRec(prop);
  97. if(r){
  98. r.set('value', value);
  99. this.source[prop] = value;
  100. }else if(create){
  101. // only create if specified.
  102. this.source[prop] = value;
  103. r = new Ext.grid.PropertyRecord({name: prop, value: value}, prop);
  104. this.store.add(r);
  105. }
  106. },
  107. // private
  108. remove : function(prop){
  109. var r = this.getRec(prop);
  110. if(r){
  111. this.store.remove(r);
  112. delete this.source[prop];
  113. }
  114. },
  115. // private
  116. getRec : function(prop){
  117. return this.store.getById(prop);
  118. },
  119. // protected - should only be called by the grid. Use grid.getSource instead.
  120. getSource : function(){
  121. return this.source;
  122. }
  123. });
  124. <div id="cls-Ext.grid.PropertyColumnModel"></div>/**
  125. * @class Ext.grid.PropertyColumnModel
  126. * @extends Ext.grid.ColumnModel
  127. * A custom column model for the {@link Ext.grid.PropertyGrid}. Generally it should not need to be used directly.
  128. * @constructor
  129. * @param {Ext.grid.Grid} grid The grid this store will be bound to
  130. * @param {Object} source The source data config object
  131. */
  132. Ext.grid.PropertyColumnModel = Ext.extend(Ext.grid.ColumnModel, {
  133. // private - strings used for locale support
  134. nameText : 'Name',
  135. valueText : 'Value',
  136. dateFormat : 'm/j/Y',
  137. trueText: 'true',
  138. falseText: 'false',
  139. constructor : function(grid, store){
  140. var g = Ext.grid,
  141. f = Ext.form;
  142. this.grid = grid;
  143. g.PropertyColumnModel.superclass.constructor.call(this, [
  144. {header: this.nameText, width:50, sortable: true, dataIndex:'name', id: 'name', menuDisabled:true},
  145. {header: this.valueText, width:50, resizable:false, dataIndex: 'value', id: 'value', menuDisabled:true}
  146. ]);
  147. this.store = store;
  148. var bfield = new f.Field({
  149. autoCreate: {tag: 'select', children: [
  150. {tag: 'option', value: 'true', html: this.trueText},
  151. {tag: 'option', value: 'false', html: this.falseText}
  152. ]},
  153. getValue : function(){
  154. return this.el.dom.value == 'true';
  155. }
  156. });
  157. this.editors = {
  158. 'date' : new g.GridEditor(new f.DateField({selectOnFocus:true})),
  159. 'string' : new g.GridEditor(new f.TextField({selectOnFocus:true})),
  160. 'number' : new g.GridEditor(new f.NumberField({selectOnFocus:true, style:'text-align:left;'})),
  161. 'boolean' : new g.GridEditor(bfield, {
  162. autoSize: 'both'
  163. })
  164. };
  165. this.renderCellDelegate = this.renderCell.createDelegate(this);
  166. this.renderPropDelegate = this.renderProp.createDelegate(this);
  167. },
  168. // private
  169. renderDate : function(dateVal){
  170. return dateVal.dateFormat(this.dateFormat);
  171. },
  172. // private
  173. renderBool : function(bVal){
  174. return this[bVal ? 'trueText' : 'falseText'];
  175. },
  176. // private
  177. isCellEditable : function(colIndex, rowIndex){
  178. return colIndex == 1;
  179. },
  180. // private
  181. getRenderer : function(col){
  182. return col == 1 ?
  183. this.renderCellDelegate : this.renderPropDelegate;
  184. },
  185. // private
  186. renderProp : function(v){
  187. return this.getPropertyName(v);
  188. },
  189. // private
  190. renderCell : function(val, meta, rec){
  191. var renderer = this.grid.customRenderers[rec.get('name')];
  192. if(renderer){
  193. return renderer.apply(this, arguments);
  194. }
  195. var rv = val;
  196. if(Ext.isDate(val)){
  197. rv = this.renderDate(val);
  198. }else if(typeof val == 'boolean'){
  199. rv = this.renderBool(val);
  200. }
  201. return Ext.util.Format.htmlEncode(rv);
  202. },
  203. // private
  204. getPropertyName : function(name){
  205. var pn = this.grid.propertyNames;
  206. return pn && pn[name] ? pn[name] : name;
  207. },
  208. // private
  209. getCellEditor : function(colIndex, rowIndex){
  210. var p = this.store.getProperty(rowIndex),
  211. n = p.data.name,
  212. val = p.data.value;
  213. if(this.grid.customEditors[n]){
  214. return this.grid.customEditors[n];
  215. }
  216. if(Ext.isDate(val)){
  217. return this.editors.date;
  218. }else if(typeof val == 'number'){
  219. return this.editors.number;
  220. }else if(typeof val == 'boolean'){
  221. return this.editors['boolean'];
  222. }else{
  223. return this.editors.string;
  224. }
  225. },
  226. // inherit docs
  227. destroy : function(){
  228. Ext.grid.PropertyColumnModel.superclass.destroy.call(this);
  229. this.destroyEditors(this.editors);
  230. this.destroyEditors(this.grid.customEditors);
  231. },
  232. destroyEditors: function(editors){
  233. for(var ed in editors){
  234. Ext.destroy(editors[ed]);
  235. }
  236. }
  237. });
  238. <div id="cls-Ext.grid.PropertyGrid"></div>/**
  239. * @class Ext.grid.PropertyGrid
  240. * @extends Ext.grid.EditorGridPanel
  241. * A specialized grid implementation intended to mimic the traditional property grid as typically seen in
  242. * development IDEs. Each row in the grid represents a property of some object, and the data is stored
  243. * as a set of name/value pairs in {@link Ext.grid.PropertyRecord}s. Example usage:
  244. * <pre><code>
  245. var grid = new Ext.grid.PropertyGrid({
  246. title: 'Properties Grid',
  247. autoHeight: true,
  248. width: 300,
  249. renderTo: 'grid-ct',
  250. source: {
  251. "(name)": "My Object",
  252. "Created": new Date(Date.parse('10/15/2006')),
  253. "Available": false,
  254. "Version": .01,
  255. "Description": "A test object"
  256. }
  257. });
  258. </code></pre>
  259. * @constructor
  260. * @param {Object} config The grid config object
  261. */
  262. Ext.grid.PropertyGrid = Ext.extend(Ext.grid.EditorGridPanel, {
  263. <div id="cfg-Ext.grid.PropertyGrid-propertyNames"></div>/**
  264. * @cfg {Object} propertyNames An object containing property name/display name pairs.
  265. * If specified, the display name will be shown in the name column instead of the property name.
  266. */
  267. <div id="cfg-Ext.grid.PropertyGrid-source"></div>/**
  268. * @cfg {Object} source A data object to use as the data source of the grid (see {@link #setSource} for details).
  269. */
  270. <div id="cfg-Ext.grid.PropertyGrid-customEditors"></div>/**
  271. * @cfg {Object} customEditors An object containing name/value pairs of custom editor type definitions that allow
  272. * the grid to support additional types of editable fields. By default, the grid supports strongly-typed editing
  273. * of strings, dates, numbers and booleans using built-in form editors, but any custom type can be supported and
  274. * associated with a custom input control by specifying a custom editor. The name of the editor
  275. * type should correspond with the name of the property that will use the editor. Example usage:
  276. * <pre><code>
  277. var grid = new Ext.grid.PropertyGrid({
  278. ...
  279. customEditors: {
  280. 'Start Time': new Ext.grid.GridEditor(new Ext.form.TimeField({selectOnFocus:true}))
  281. },
  282. source: {
  283. 'Start Time': '10:00 AM'
  284. }
  285. });
  286. </code></pre>
  287. */
  288. <div id="cfg-Ext.grid.PropertyGrid-source"></div>/**
  289. * @cfg {Object} source A data object to use as the data source of the grid (see {@link #setSource} for details).
  290. */
  291. <div id="cfg-Ext.grid.PropertyGrid-customRenderers"></div>/**
  292. * @cfg {Object} customRenderers An object containing name/value pairs of custom renderer type definitions that allow
  293. * the grid to support custom rendering of fields. By default, the grid supports strongly-typed rendering
  294. * of strings, dates, numbers and booleans using built-in form editors, but any custom type can be supported and
  295. * associated with the type of the value. The name of the renderer type should correspond with the name of the property
  296. * that it will render. Example usage:
  297. * <pre><code>
  298. var grid = new Ext.grid.PropertyGrid({
  299. ...
  300. customRenderers: {
  301. Available: function(v){
  302. if(v){
  303. return '<span style="color: green;">Yes</span>';
  304. }else{
  305. return '<span style="color: red;">No</span>';
  306. }
  307. }
  308. },
  309. source: {
  310. Available: true
  311. }
  312. });
  313. </code></pre>
  314. */
  315. // private config overrides
  316. enableColumnMove:false,
  317. stripeRows:false,
  318. trackMouseOver: false,
  319. clicksToEdit:1,
  320. enableHdMenu : false,
  321. viewConfig : {
  322. forceFit:true
  323. },
  324. // private
  325. initComponent : function(){
  326. this.customRenderers = this.customRenderers || {};
  327. this.customEditors = this.customEditors || {};
  328. this.lastEditRow = null;
  329. var store = new Ext.grid.PropertyStore(this);
  330. this.propStore = store;
  331. var cm = new Ext.grid.PropertyColumnModel(this, store);
  332. store.store.sort('name', 'ASC');
  333. this.addEvents(
  334. <div id="event-Ext.grid.PropertyGrid-beforepropertychange"></div>/**
  335. * @event beforepropertychange
  336. * Fires before a property value changes. Handlers can return false to cancel the property change
  337. * (this will internally call {@link Ext.data.Record#reject} on the property's record).
  338. * @param {Object} source The source data object for the grid (corresponds to the same object passed in
  339. * as the {@link #source} config property).
  340. * @param {String} recordId The record's id in the data store
  341. * @param {Mixed} value The current edited property value
  342. * @param {Mixed} oldValue The original property value prior to editing
  343. */
  344. 'beforepropertychange',
  345. <div id="event-Ext.grid.PropertyGrid-propertychange"></div>/**
  346. * @event propertychange
  347. * Fires after a property value has changed.
  348. * @param {Object} source The source data object for the grid (corresponds to the same object passed in
  349. * as the {@link #source} config property).
  350. * @param {String} recordId The record's id in the data store
  351. * @param {Mixed} value The current edited property value
  352. * @param {Mixed} oldValue The original property value prior to editing
  353. */
  354. 'propertychange'
  355. );
  356. this.cm = cm;
  357. this.ds = store.store;
  358. Ext.grid.PropertyGrid.superclass.initComponent.call(this);
  359. this.mon(this.selModel, 'beforecellselect', function(sm, rowIndex, colIndex){
  360. if(colIndex === 0){
  361. this.startEditing.defer(200, this, [rowIndex, 1]);
  362. return false;
  363. }
  364. }, this);
  365. },
  366. // private
  367. onRender : function(){
  368. Ext.grid.PropertyGrid.superclass.onRender.apply(this, arguments);
  369. this.getGridEl().addClass('x-props-grid');
  370. },
  371. // private
  372. afterRender: function(){
  373. Ext.grid.PropertyGrid.superclass.afterRender.apply(this, arguments);
  374. if(this.source){
  375. this.setSource(this.source);
  376. }
  377. },
  378. <div id="method-Ext.grid.PropertyGrid-setSource"></div>/**
  379. * Sets the source data object containing the property data. The data object can contain one or more name/value
  380. * pairs representing all of the properties of an object to display in the grid, and this data will automatically
  381. * be loaded into the grid's {@link #store}. The values should be supplied in the proper data type if needed,
  382. * otherwise string type will be assumed. If the grid already contains data, this method will replace any
  383. * existing data. See also the {@link #source} config value. Example usage:
  384. * <pre><code>
  385. grid.setSource({
  386. "(name)": "My Object",
  387. "Created": new Date(Date.parse('10/15/2006')), // date type
  388. "Available": false, // boolean type
  389. "Version": .01, // decimal type
  390. "Description": "A test object"
  391. });
  392. </code></pre>
  393. * @param {Object} source The data object
  394. */
  395. setSource : function(source){
  396. this.propStore.setSource(source);
  397. },
  398. <div id="method-Ext.grid.PropertyGrid-getSource"></div>/**
  399. * Gets the source data object containing the property data. See {@link #setSource} for details regarding the
  400. * format of the data object.
  401. * @return {Object} The data object
  402. */
  403. getSource : function(){
  404. return this.propStore.getSource();
  405. },
  406. <div id="method-Ext.grid.PropertyGrid-setProperty"></div>/**
  407. * Sets the value of a property.
  408. * @param {String} prop The name of the property to set
  409. * @param {Mixed} value The value to test
  410. * @param {Boolean} create (Optional) True to create the property if it doesn't already exist. Defaults to <tt>false</tt>.
  411. */
  412. setProperty : function(prop, value, create){
  413. this.propStore.setValue(prop, value, create);
  414. },
  415. <div id="method-Ext.grid.PropertyGrid-removeProperty"></div>/**
  416. * Removes a property from the grid.
  417. * @param {String} prop The name of the property to remove
  418. */
  419. removeProperty : function(prop){
  420. this.propStore.remove(prop);
  421. }
  422. <div id="cfg-Ext.grid.PropertyGrid-null"></div>/**
  423. * @cfg store
  424. * @hide
  425. */
  426. <div id="cfg-Ext.grid.PropertyGrid-null"></div>/**
  427. * @cfg colModel
  428. * @hide
  429. */
  430. <div id="cfg-Ext.grid.PropertyGrid-null"></div>/**
  431. * @cfg cm
  432. * @hide
  433. */
  434. <div id="cfg-Ext.grid.PropertyGrid-null"></div>/**
  435. * @cfg columns
  436. * @hide
  437. */
  438. });
  439. Ext.reg("propertygrid", Ext.grid.PropertyGrid);
  440. </pre>
  441. </body>
  442. </html>