6d840fb1b4d77e38f37d419060b3811e6372ba38.svn-base 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Ext JS Library 2.0 Copyright(c) 2006-2007, Ext JS, LLC. licensing@extjs.com
  3. *
  4. * http://extjs.com/license
  5. */
  6. Ext.Editor = function(B, A) {
  7. this.field = B;
  8. Ext.Editor.superclass.constructor.call(this, A)
  9. };
  10. Ext.extend(Ext.Editor, Ext.Component, {
  11. value : "",
  12. alignment : "c-c?",
  13. shadow : "frame",
  14. constrain : false,
  15. swallowKeys : true,
  16. completeOnEnter : false,
  17. cancelOnEsc : false,
  18. updateEl : false,
  19. initComponent : function() {
  20. Ext.Editor.superclass.initComponent.call(this);
  21. this.addEvents("beforestartedit", "startedit", "beforecomplete",
  22. "complete", "specialkey")
  23. },
  24. onRender : function(B, A) {
  25. this.el = new Ext.Layer({
  26. shadow : this.shadow,
  27. cls : "x-editor",
  28. parentEl : B,
  29. shim : this.shim,
  30. shadowOffset : 4,
  31. id : this.id,
  32. constrain : this.constrain
  33. });
  34. this.el.setStyle("overflow", Ext.isGecko ? "auto" : "hidden");
  35. if (this.field.msgTarget != "title") {
  36. this.field.msgTarget = "qtip"
  37. }
  38. this.field.render(this.el);
  39. if (Ext.isGecko) {
  40. this.field.el.dom.setAttribute("autocomplete", "off")
  41. }
  42. this.field.on("specialkey", this.onSpecialKey, this);
  43. if (this.swallowKeys) {
  44. this.field.el.swallowEvent(["keydown", "keypress"])
  45. }
  46. this.field.show();
  47. this.field.on("blur", this.onBlur, this);
  48. if (this.field.grow) {
  49. this.field.on("autosize", this.el.sync, this.el, {
  50. delay : 1
  51. })
  52. }
  53. },
  54. onSpecialKey : function(B, A) {
  55. if (this.completeOnEnter && A.getKey() == A.ENTER) {
  56. A.stopEvent();
  57. this.completeEdit()
  58. } else {
  59. if (this.cancelOnEsc && A.getKey() == A.ESC) {
  60. this.cancelEdit()
  61. } else {
  62. this.fireEvent("specialkey", B, A)
  63. }
  64. }
  65. },
  66. startEdit : function(B, C) {
  67. if (this.editing) {
  68. this.completeEdit()
  69. }
  70. this.boundEl = Ext.get(B);
  71. var A = C !== undefined ? C : this.boundEl.dom.innerHTML;
  72. if (!this.rendered) {
  73. this.render(this.parentEl || document.body)
  74. }
  75. if (this.fireEvent("beforestartedit", this, this.boundEl, A) === false) {
  76. return
  77. }
  78. this.startValue = A;
  79. this.field.setValue(A);
  80. if (this.autoSize) {
  81. var D = this.boundEl.getSize();
  82. switch (this.autoSize) {
  83. case "width" :
  84. this.setSize(D.width, "");
  85. break;
  86. case "height" :
  87. this.setSize("", D.height);
  88. break;
  89. default :
  90. this.setSize(D.width, D.height)
  91. }
  92. }
  93. this.el.alignTo(this.boundEl, this.alignment);
  94. this.editing = true;
  95. this.show()
  96. },
  97. setSize : function(A, B) {
  98. this.field.setSize(A, B);
  99. if (this.el) {
  100. this.el.sync()
  101. }
  102. },
  103. realign : function() {
  104. this.el.alignTo(this.boundEl, this.alignment)
  105. },
  106. completeEdit : function(A) {
  107. if (!this.editing) {
  108. return
  109. }
  110. var B = this.getValue();
  111. if (this.revertInvalid !== false && !this.field.isValid()) {
  112. B = this.startValue;
  113. this.cancelEdit(true)
  114. }
  115. if (String(B) === String(this.startValue) && this.ignoreNoChange) {
  116. this.editing = false;
  117. this.hide();
  118. return
  119. }
  120. if (this.fireEvent("beforecomplete", this, B, this.startValue) !== false) {
  121. this.editing = false;
  122. if (this.updateEl && this.boundEl) {
  123. this.boundEl.update(B)
  124. }
  125. if (A !== true) {
  126. this.hide()
  127. }
  128. this.fireEvent("complete", this, B, this.startValue)
  129. }
  130. },
  131. onShow : function() {
  132. this.el.show();
  133. if (this.hideEl !== false) {
  134. this.boundEl.hide()
  135. }
  136. this.field.show();
  137. if (Ext.isIE && !this.fixIEFocus) {
  138. this.fixIEFocus = true;
  139. this.deferredFocus.defer(50, this)
  140. } else {
  141. this.field.focus()
  142. }
  143. this.fireEvent("startedit", this.boundEl, this.startValue)
  144. },
  145. deferredFocus : function() {
  146. if (this.editing) {
  147. this.field.focus()
  148. }
  149. },
  150. cancelEdit : function(A) {
  151. if (this.editing) {
  152. this.setValue(this.startValue);
  153. if (A !== true) {
  154. this.hide()
  155. }
  156. }
  157. },
  158. onBlur : function() {
  159. if (this.allowBlur !== true && this.editing) {
  160. this.completeEdit()
  161. }
  162. },
  163. onHide : function() {
  164. if (this.editing) {
  165. this.completeEdit();
  166. return
  167. }
  168. this.field.blur();
  169. if (this.field.collapse) {
  170. this.field.collapse()
  171. }
  172. this.el.hide();
  173. if (this.hideEl !== false) {
  174. this.boundEl.show()
  175. }
  176. },
  177. setValue : function(A) {
  178. this.field.setValue(A)
  179. },
  180. getValue : function() {
  181. return this.field.getValue()
  182. },
  183. beforeDestroy : function() {
  184. this.field.destroy();
  185. this.field = null
  186. }
  187. });
  188. Ext.reg("editor", Ext.Editor);