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.

415 lines
16 KiB

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