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.

411 lines
15 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.Editor"></div>/**
  16. * @class Ext.Editor
  17. * @extends Ext.Component
  18. * A base editor field that handles displaying/hiding on demand and has some built-in sizing and event handling logic.
  19. * @constructor
  20. * Create a new Editor
  21. * @param {Object} config The config object
  22. * @xtype editor
  23. */
  24. Ext.Editor = function(field, config){
  25. if(field.field){
  26. this.field = Ext.create(field.field, 'textfield');
  27. config = Ext.apply({}, field); // copy so we don't disturb original config
  28. delete config.field;
  29. }else{
  30. this.field = field;
  31. }
  32. Ext.Editor.superclass.constructor.call(this, config);
  33. };
  34. Ext.extend(Ext.Editor, Ext.Component, {
  35. <div id="cfg-Ext.Editor-field"></div>/**
  36. * @cfg {Ext.form.Field} field
  37. * The Field object (or descendant) or config object for field
  38. */
  39. <div id="cfg-Ext.Editor-allowBlur"></div>/**
  40. * @cfg {Boolean} allowBlur
  41. * True to {@link #completeEdit complete the editing process} if in edit mode when the
  42. * field is blurred. Defaults to <tt>true</tt>.
  43. */
  44. allowBlur: true,
  45. <div id="cfg-Ext.Editor-autoSize"></div>/**
  46. * @cfg {Boolean/String} autoSize
  47. * True for the editor to automatically adopt the size of the underlying field, "width" to adopt the width only,
  48. * or "height" to adopt the height only, "none" to always use the field dimensions. (defaults to false)
  49. */
  50. <div id="cfg-Ext.Editor-revertInvalid"></div>/**
  51. * @cfg {Boolean} revertInvalid
  52. * True to automatically revert the field value and cancel the edit when the user completes an edit and the field
  53. * validation fails (defaults to true)
  54. */
  55. <div id="cfg-Ext.Editor-ignoreNoChange"></div>/**
  56. * @cfg {Boolean} ignoreNoChange
  57. * True to skip the edit completion process (no save, no events fired) if the user completes an edit and
  58. * the value has not changed (defaults to false). Applies only to string values - edits for other data types
  59. * will never be ignored.
  60. */
  61. <div id="cfg-Ext.Editor-hideEl"></div>/**
  62. * @cfg {Boolean} hideEl
  63. * False to keep the bound element visible while the editor is displayed (defaults to true)
  64. */
  65. <div id="cfg-Ext.Editor-value"></div>/**
  66. * @cfg {Mixed} value
  67. * The data value of the underlying field (defaults to "")
  68. */
  69. value : "",
  70. <div id="cfg-Ext.Editor-alignment"></div>/**
  71. * @cfg {String} alignment
  72. * The position to align to (see {@link Ext.Element#alignTo} for more details, defaults to "c-c?").
  73. */
  74. alignment: "c-c?",
  75. <div id="cfg-Ext.Editor-offsets"></div>/**
  76. * @cfg {Array} offsets
  77. * The offsets to use when aligning (see {@link Ext.Element#alignTo} for more details. Defaults to <tt>[0, 0]</tt>.
  78. */
  79. offsets: [0, 0],
  80. <div id="cfg-Ext.Editor-shadow"></div>/**
  81. * @cfg {Boolean/String} shadow "sides" for sides/bottom only, "frame" for 4-way shadow, and "drop"
  82. * for bottom-right shadow (defaults to "frame")
  83. */
  84. shadow : "frame",
  85. <div id="cfg-Ext.Editor-constrain"></div>/**
  86. * @cfg {Boolean} constrain True to constrain the editor to the viewport
  87. */
  88. constrain : false,
  89. <div id="cfg-Ext.Editor-swallowKeys"></div>/**
  90. * @cfg {Boolean} swallowKeys Handle the keydown/keypress events so they don't propagate (defaults to true)
  91. */
  92. swallowKeys : true,
  93. <div id="cfg-Ext.Editor-completeOnEnter"></div>/**
  94. * @cfg {Boolean} completeOnEnter True to complete the edit when the enter key is pressed. Defaults to <tt>true</tt>.
  95. */
  96. completeOnEnter : true,
  97. <div id="cfg-Ext.Editor-cancelOnEsc"></div>/**
  98. * @cfg {Boolean} cancelOnEsc True to cancel the edit when the escape key is pressed. Defaults to <tt>true</tt>.
  99. */
  100. cancelOnEsc : true,
  101. <div id="cfg-Ext.Editor-updateEl"></div>/**
  102. * @cfg {Boolean} updateEl True to update the innerHTML of the bound element when the update completes (defaults to false)
  103. */
  104. updateEl : false,
  105. initComponent : function(){
  106. Ext.Editor.superclass.initComponent.call(this);
  107. this.addEvents(
  108. <div id="event-Ext.Editor-beforestartedit"></div>/**
  109. * @event beforestartedit
  110. * Fires when editing is initiated, but before the value changes. Editing can be canceled by returning
  111. * false from the handler of this event.
  112. * @param {Editor} this
  113. * @param {Ext.Element} boundEl The underlying element bound to this editor
  114. * @param {Mixed} value The field value being set
  115. */
  116. "beforestartedit",
  117. <div id="event-Ext.Editor-startedit"></div>/**
  118. * @event startedit
  119. * Fires when this editor is displayed
  120. * @param {Ext.Element} boundEl The underlying element bound to this editor
  121. * @param {Mixed} value The starting field value
  122. */
  123. "startedit",
  124. <div id="event-Ext.Editor-beforecomplete"></div>/**
  125. * @event beforecomplete
  126. * Fires after a change has been made to the field, but before the change is reflected in the underlying
  127. * field. Saving the change to the field can be canceled by returning false from the handler of this event.
  128. * Note that if the value has not changed and ignoreNoChange = true, the editing will still end but this
  129. * event will not fire since no edit actually occurred.
  130. * @param {Editor} this
  131. * @param {Mixed} value The current field value
  132. * @param {Mixed} startValue The original field value
  133. */
  134. "beforecomplete",
  135. <div id="event-Ext.Editor-complete"></div>/**
  136. * @event complete
  137. * Fires after editing is complete and any changed value has been written to the underlying field.
  138. * @param {Editor} this
  139. * @param {Mixed} value The current field value
  140. * @param {Mixed} startValue The original field value
  141. */
  142. "complete",
  143. <div id="event-Ext.Editor-canceledit"></div>/**
  144. * @event canceledit
  145. * Fires after editing has been canceled and the editor's value has been reset.
  146. * @param {Editor} this
  147. * @param {Mixed} value The user-entered field value that was discarded
  148. * @param {Mixed} startValue The original field value that was set back into the editor after cancel
  149. */
  150. "canceledit",
  151. <div id="event-Ext.Editor-specialkey"></div>/**
  152. * @event specialkey
  153. * Fires when any key related to navigation (arrows, tab, enter, esc, etc.) is pressed. You can check
  154. * {@link Ext.EventObject#getKey} to determine which key was pressed.
  155. * @param {Ext.form.Field} this
  156. * @param {Ext.EventObject} e The event object
  157. */
  158. "specialkey"
  159. );
  160. },
  161. // private
  162. onRender : function(ct, position){
  163. this.el = new Ext.Layer({
  164. shadow: this.shadow,
  165. cls: "x-editor",
  166. parentEl : ct,
  167. shim : this.shim,
  168. shadowOffset: this.shadowOffset || 4,
  169. id: this.id,
  170. constrain: this.constrain
  171. });
  172. if(this.zIndex){
  173. this.el.setZIndex(this.zIndex);
  174. }
  175. this.el.setStyle("overflow", Ext.isGecko ? "auto" : "hidden");
  176. if(this.field.msgTarget != 'title'){
  177. this.field.msgTarget = 'qtip';
  178. }
  179. this.field.inEditor = true;
  180. this.mon(this.field, {
  181. scope: this,
  182. blur: this.onBlur,
  183. specialkey: this.onSpecialKey
  184. });
  185. if(this.field.grow){
  186. this.mon(this.field, "autosize", this.el.sync, this.el, {delay:1});
  187. }
  188. this.field.render(this.el).show();
  189. this.field.getEl().dom.name = '';
  190. if(this.swallowKeys){
  191. this.field.el.swallowEvent([
  192. 'keypress', // *** Opera
  193. 'keydown' // *** all other browsers
  194. ]);
  195. }
  196. },
  197. // private
  198. onSpecialKey : function(field, e){
  199. var key = e.getKey(),
  200. complete = this.completeOnEnter && key == e.ENTER,
  201. cancel = this.cancelOnEsc && key == e.ESC;
  202. if(complete || cancel){
  203. e.stopEvent();
  204. if(complete){
  205. this.completeEdit();
  206. }else{
  207. this.cancelEdit();
  208. }
  209. if(field.triggerBlur){
  210. field.triggerBlur();
  211. }
  212. }
  213. this.fireEvent('specialkey', field, e);
  214. },
  215. <div id="method-Ext.Editor-startEdit"></div>/**
  216. * Starts the editing process and shows the editor.
  217. * @param {Mixed} el The element to edit
  218. * @param {String} value (optional) A value to initialize the editor with. If a value is not provided, it defaults
  219. * to the innerHTML of el.
  220. */
  221. startEdit : function(el, value){
  222. if(this.editing){
  223. this.completeEdit();
  224. }
  225. this.boundEl = Ext.get(el);
  226. var v = value !== undefined ? value : this.boundEl.dom.innerHTML;
  227. if(!this.rendered){
  228. this.render(this.parentEl || document.body);
  229. }
  230. if(this.fireEvent("beforestartedit", this, this.boundEl, v) !== false){
  231. this.startValue = v;
  232. this.field.reset();
  233. this.field.setValue(v);
  234. this.realign(true);
  235. this.editing = true;
  236. this.show();
  237. }
  238. },
  239. // private
  240. doAutoSize : function(){
  241. if(this.autoSize){
  242. var sz = this.boundEl.getSize(),
  243. fs = this.field.getSize();
  244. switch(this.autoSize){
  245. case "width":
  246. this.setSize(sz.width, fs.height);
  247. break;
  248. case "height":
  249. this.setSize(fs.width, sz.height);
  250. break;
  251. case "none":
  252. this.setSize(fs.width, fs.height);
  253. break;
  254. default:
  255. this.setSize(sz.width, sz.height);
  256. }
  257. }
  258. },
  259. <div id="method-Ext.Editor-setSize"></div>/**
  260. * Sets the height and width of this editor.
  261. * @param {Number} width The new width
  262. * @param {Number} height The new height
  263. */
  264. setSize : function(w, h){
  265. delete this.field.lastSize;
  266. this.field.setSize(w, h);
  267. if(this.el){
  268. // IE7 in strict mode doesn't size properly.
  269. if(Ext.isGecko2 || Ext.isOpera || (Ext.isIE7 && Ext.isStrict)){
  270. // prevent layer scrollbars
  271. this.el.setSize(w, h);
  272. }
  273. this.el.sync();
  274. }
  275. },
  276. <div id="method-Ext.Editor-realign"></div>/**
  277. * Realigns the editor to the bound field based on the current alignment config value.
  278. * @param {Boolean} autoSize (optional) True to size the field to the dimensions of the bound element.
  279. */
  280. realign : function(autoSize){
  281. if(autoSize === true){
  282. this.doAutoSize();
  283. }
  284. this.el.alignTo(this.boundEl, this.alignment, this.offsets);
  285. },
  286. <div id="method-Ext.Editor-completeEdit"></div>/**
  287. * Ends the editing process, persists the changed value to the underlying field, and hides the editor.
  288. * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after edit (defaults to false)
  289. */
  290. completeEdit : function(remainVisible){
  291. if(!this.editing){
  292. return;
  293. }
  294. // Assert combo values first
  295. if (this.field.assertValue) {
  296. this.field.assertValue();
  297. }
  298. var v = this.getValue();
  299. if(!this.field.isValid()){
  300. if(this.revertInvalid !== false){
  301. this.cancelEdit(remainVisible);
  302. }
  303. return;
  304. }
  305. if(String(v) === String(this.startValue) && this.ignoreNoChange){
  306. this.hideEdit(remainVisible);
  307. return;
  308. }
  309. if(this.fireEvent("beforecomplete", this, v, this.startValue) !== false){
  310. v = this.getValue();
  311. if(this.updateEl && this.boundEl){
  312. this.boundEl.update(v);
  313. }
  314. this.hideEdit(remainVisible);
  315. this.fireEvent("complete", this, v, this.startValue);
  316. }
  317. },
  318. // private
  319. onShow : function(){
  320. this.el.show();
  321. if(this.hideEl !== false){
  322. this.boundEl.hide();
  323. }
  324. this.field.show().focus(false, true);
  325. this.fireEvent("startedit", this.boundEl, this.startValue);
  326. },
  327. <div id="method-Ext.Editor-cancelEdit"></div>/**
  328. * Cancels the editing process and hides the editor without persisting any changes. The field value will be
  329. * reverted to the original starting value.
  330. * @param {Boolean} remainVisible Override the default behavior and keep the editor visible after
  331. * cancel (defaults to false)
  332. */
  333. cancelEdit : function(remainVisible){
  334. if(this.editing){
  335. var v = this.getValue();
  336. this.setValue(this.startValue);
  337. this.hideEdit(remainVisible);
  338. this.fireEvent("canceledit", this, v, this.startValue);
  339. }
  340. },
  341. // private
  342. hideEdit: function(remainVisible){
  343. if(remainVisible !== true){
  344. this.editing = false;
  345. this.hide();
  346. }
  347. },
  348. // private
  349. onBlur : function(){
  350. // selectSameEditor flag allows the same editor to be started without onBlur firing on itself
  351. if(this.allowBlur === true && this.editing && this.selectSameEditor !== true){
  352. this.completeEdit();
  353. }
  354. },
  355. // private
  356. onHide : function(){
  357. if(this.editing){
  358. this.completeEdit();
  359. return;
  360. }
  361. this.field.blur();
  362. if(this.field.collapse){
  363. this.field.collapse();
  364. }
  365. this.el.hide();
  366. if(this.hideEl !== false){
  367. this.boundEl.show();
  368. }
  369. },
  370. <div id="method-Ext.Editor-setValue"></div>/**
  371. * Sets the data value of the editor
  372. * @param {Mixed} value Any valid value supported by the underlying field
  373. */
  374. setValue : function(v){
  375. this.field.setValue(v);
  376. },
  377. <div id="method-Ext.Editor-getValue"></div>/**
  378. * Gets the data value of the editor
  379. * @return {Mixed} The data value
  380. */
  381. getValue : function(){
  382. return this.field.getValue();
  383. },
  384. beforeDestroy : function(){
  385. Ext.destroyMembers(this, 'field');
  386. delete this.parentEl;
  387. delete this.boundEl;
  388. }
  389. });
  390. Ext.reg('editor', Ext.Editor);
  391. </pre>
  392. </body>
  393. </html>