TextAreaSelectField.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. /**
  2. * From-To textfield
  3. * @author yingp
  4. */
  5. /*Ext.define('erp.view.core.form.FtField', {
  6. extend: 'Ext.Component',
  7. mixins: {
  8. labelable: 'Ext.form.Labelable',
  9. field: 'Ext.form.field.Field'
  10. },
  11. alias: 'widget.erpFtField',
  12. fieldSubTpl: [
  13. '<input id="{id}_from" type="{type}" onkeydown="keydown(' + "'{name}'"
  14. + ')" onkeyup="keydown(' + "'{name}'" + ')" onchange="keydown(' + "'{name}'" + ')" ',
  15. '<tpl if="name">name="{name}_from" </tpl>',
  16. '<tpl if="size">size="{size}" </tpl>',
  17. '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
  18. 'class="{fieldCls} {typeCls}" autocomplete="off" />',
  19. '->',
  20. '<input id="{id}_to" type="{type}" onkeydown="keydown(' + "'{name}'"
  21. + ')" onkeyup="keydown(' + "'{name}'" + ')" onchange="keydown(' + "'{name}'" + ')" ',
  22. '<tpl if="name">name="{name}_to" </tpl>',
  23. '<tpl if="size">size="{size}" </tpl>',
  24. '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
  25. 'class="{typeCls}" autocomplete="off" />',
  26. '<span id="ft" style="color:#8EAECE;">From()To()</span>',
  27. {
  28. compiled: true,
  29. disableFormats: true
  30. }
  31. ],
  32. inputType: 'text',
  33. invalidText : 'The value in this field is invalid',
  34. fieldCls : Ext.baseCSSPrefix + 'form-field',
  35. focusCls : Ext.baseCSSPrefix + 'form-focus',
  36. dirtyCls : Ext.baseCSSPrefix + 'form-dirty',
  37. checkChangeEvents: Ext.isIE && (!document.documentMode || document.documentMode < 9) ?
  38. ['change', 'propertychange'] :
  39. ['change', 'input', 'textInput', 'keyup', 'dragdrop'],
  40. checkChangeBuffer: 50,
  41. componentLayout: 'field',
  42. readOnly : false,
  43. readOnlyCls: Ext.baseCSSPrefix + 'form-readonly',
  44. validateOnBlur: true,
  45. hasFocus : false,
  46. baseCls: Ext.baseCSSPrefix + 'field',
  47. maskOnDisable: false,
  48. initComponent : function() {
  49. var me = this;
  50. me.callParent();
  51. me.subTplData = me.subTplData || {};
  52. me.addEvents(
  53. 'focus',
  54. 'blur',
  55. 'specialkey'
  56. );
  57. me.initLabelable();
  58. me.initField();
  59. if (!me.name) {
  60. me.name = me.getInputId();
  61. }
  62. },
  63. getInputId: function() {
  64. return this.inputId || (this.inputId = Ext.id());
  65. },
  66. getSubTplData: function() {
  67. var me = this,
  68. type = me.inputType,
  69. inputId = me.getInputId();
  70. return Ext.applyIf(me.subTplData, {
  71. id: inputId,
  72. cmpId: me.id,
  73. name: me.name || inputId,
  74. type: type,
  75. size: me.size || 20,
  76. cls: me.cls,
  77. fieldCls: me.fieldCls,
  78. tabIdx: me.tabIndex,
  79. typeCls: Ext.baseCSSPrefix + 'form-' + (type === 'password' ? 'text' : type)
  80. });
  81. },
  82. afterRender: function() {
  83. this.callParent();
  84. if (this.inputEl) {
  85. this.inputEl.selectable();
  86. }
  87. },
  88. getSubTplMarkup: function() {
  89. return this.getTpl('fieldSubTpl').apply(this.getSubTplData());
  90. },
  91. initRenderTpl: function() {
  92. var me = this;
  93. if (!me.hasOwnProperty('renderTpl')) {
  94. me.renderTpl = me.getTpl('labelableRenderTpl');
  95. }
  96. return me.callParent();
  97. },
  98. initRenderData: function() {
  99. return Ext.applyIf(this.callParent(), this.getLabelableRenderData());
  100. },
  101. setFieldStyle: function(style) {
  102. var me = this,
  103. inputEl = me.inputEl;
  104. if (inputEl) {
  105. inputEl.applyStyles(style);
  106. }
  107. me.fieldStyle = style;
  108. },
  109. onRender : function() {
  110. var me = this,
  111. fieldStyle = me.fieldStyle;
  112. me.onLabelableRender();
  113. me.addChildEls({ name: 'inputEl', id: me.getInputId() });
  114. me.callParent(arguments);
  115. me.setRawValue(me.rawValue);
  116. if (me.readOnly) {
  117. me.setReadOnly(true);
  118. }
  119. if (me.disabled) {
  120. me.disable();
  121. }
  122. if (fieldStyle) {
  123. me.setFieldStyle(fieldStyle);
  124. }
  125. me.renderActiveError();
  126. },
  127. initAria: function() {
  128. var me = this;
  129. me.callParent();
  130. me.getActionEl().dom.setAttribute('aria-describedby', Ext.id(me.errorEl));
  131. },
  132. getFocusEl: function() {
  133. return this.inputEl;
  134. },
  135. isFileUpload: function() {
  136. return this.inputType === 'file';
  137. },
  138. extractFileInput: function() {
  139. var me = this,
  140. fileInput = me.isFileUpload() ? me.inputEl.dom : null,
  141. clone;
  142. if (fileInput) {
  143. clone = fileInput.cloneNode(true);
  144. fileInput.parentNode.replaceChild(clone, fileInput);
  145. me.inputEl = Ext.get(clone);
  146. }
  147. return fileInput;
  148. },
  149. getSubmitData: function() {
  150. var me = this,
  151. data = null,
  152. val;
  153. if (!me.disabled && me.submitValue && !me.isFileUpload()) {
  154. val = me.getSubmitValue();
  155. if (val !== null) {
  156. data = {};
  157. data[me.getName()] = val;
  158. }
  159. }
  160. return data;
  161. },
  162. getSubmitValue: function() {
  163. return this.processRawValue(this.getRawValue());
  164. },
  165. getRawValue: function() {
  166. var me = this,
  167. v = (me.inputEl ? me.inputEl.getValue() : Ext.value(me.rawValue, ''));
  168. me.rawValue = v;
  169. return v;
  170. },
  171. setRawValue: function(value) {
  172. var me = this;
  173. value = Ext.value(value, '');
  174. me.rawValue = value;
  175. if (me.inputEl) {
  176. me.inputEl.dom.value = value;
  177. }
  178. return value;
  179. },
  180. valueToRaw: function(value) {
  181. return '' + Ext.value(value, '');
  182. },
  183. rawToValue: function(rawValue) {
  184. return rawValue;
  185. },
  186. processRawValue: function(value) {
  187. return value;
  188. },
  189. getValue: function() {
  190. var me = this,
  191. val = me.rawToValue(me.processRawValue(me.getRawValue()));
  192. var from = document.getElementsByName(me.id + '_from')[0].value;
  193. var to = document.getElementsByName(me.id + '_to')[0].value;
  194. if(from.length > me.maxLength){
  195. document.getElementsByName(me.id + '_from')[0].value = from .substring(0, me.maxLength);showError('maxLength:' + me.maxLength);
  196. from = from .substring(0, me.maxLength);showError('maxLength:' + me.maxLength);
  197. }
  198. if(to.length > me.maxLength){
  199. to = to .substring(0, me.maxLength);showError('maxLength:' + me.maxLength);
  200. }
  201. from = from == null || from == '' ? to : from;
  202. to = to == null || to == '' ? from : to;
  203. val = val == null || val == '' ? 'BETWEEN ' + from + ' AND ' + to : val;
  204. me.value = val;
  205. document.getElementById('ft').innerHTML = 'From (' + from + ') To (' + to + ")";
  206. return val;
  207. },
  208. setValue: function(value) {
  209. var me = this;
  210. me.setRawValue(me.valueToRaw(value));
  211. return me.mixins.field.setValue.call(me, value);
  212. },
  213. onDisable: function() {
  214. var me = this,
  215. inputEl = me.inputEl;
  216. me.callParent();
  217. if (inputEl) {
  218. inputEl.dom.disabled = true;
  219. }
  220. },
  221. onEnable: function() {
  222. var me = this,
  223. inputEl = me.inputEl;
  224. me.callParent();
  225. if (inputEl) {
  226. inputEl.dom.disabled = false;
  227. }
  228. },
  229. setReadOnly: function(readOnly) {
  230. var me = this,
  231. inputEl = me.inputEl;
  232. if (inputEl) {
  233. inputEl.dom.readOnly = readOnly;
  234. inputEl.dom.setAttribute('aria-readonly', readOnly);
  235. }
  236. me[readOnly ? 'addCls' : 'removeCls'](me.readOnlyCls);
  237. me.readOnly = readOnly;
  238. },
  239. fireKey: function(e){
  240. if(e.isSpecialKey()){
  241. this.fireEvent('specialkey', this, Ext.create('Ext.EventObjectImpl', e));
  242. }
  243. },
  244. initEvents : function(){
  245. var me = this,
  246. inputEl = me.inputEl,
  247. onChangeTask,
  248. onChangeEvent;
  249. if (inputEl) {
  250. me.mon(inputEl, Ext.EventManager.getKeyEvent(), me.fireKey, me);
  251. me.mon(inputEl, 'focus', me.onFocus, me);
  252. me.mon(inputEl, 'blur', me.onBlur, me, me.inEditor ? {buffer:10} : null);
  253. onChangeTask = Ext.create('Ext.util.DelayedTask', me.checkChange, me);
  254. me.onChangeEvent = onChangeEvent = function() {
  255. onChangeTask.delay(me.checkChangeBuffer);
  256. };
  257. Ext.each(me.checkChangeEvents, function(eventName) {
  258. if (eventName === 'propertychange') {
  259. me.usesPropertychange = true;
  260. }
  261. me.mon(inputEl, eventName, onChangeEvent);
  262. }, me);
  263. }
  264. me.callParent();
  265. },
  266. doComponentLayout: function() {
  267. var me = this,
  268. inputEl = me.inputEl,
  269. usesPropertychange = me.usesPropertychange,
  270. ename = 'propertychange',
  271. onChangeEvent = me.onChangeEvent;
  272. if (usesPropertychange) {
  273. me.mun(inputEl, ename, onChangeEvent);
  274. }
  275. me.callParent(arguments);
  276. if (usesPropertychange) {
  277. me.mon(inputEl, ename, onChangeEvent);
  278. }
  279. },
  280. preFocus: Ext.emptyFn,
  281. onFocus: function() {
  282. var me = this,
  283. focusCls = me.focusCls,
  284. inputEl = me.inputEl;
  285. me.preFocus();
  286. if (focusCls && inputEl) {
  287. inputEl.addCls(focusCls);
  288. }
  289. if (!me.hasFocus) {
  290. me.hasFocus = true;
  291. me.componentLayout.onFocus();
  292. me.fireEvent('focus', me);
  293. }
  294. },
  295. beforeBlur : Ext.emptyFn,
  296. onBlur : function(){
  297. var me = this,
  298. focusCls = me.focusCls,
  299. inputEl = me.inputEl;
  300. if (me.destroying) {
  301. return;
  302. }
  303. me.beforeBlur();
  304. if (focusCls && inputEl) {
  305. inputEl.removeCls(focusCls);
  306. }
  307. if (me.validateOnBlur) {
  308. me.validate();
  309. }
  310. me.hasFocus = false;
  311. me.fireEvent('blur', me);
  312. me.postBlur();
  313. },
  314. postBlur : Ext.emptyFn,
  315. onDirtyChange: function(isDirty) {
  316. this[isDirty ? 'addCls' : 'removeCls'](this.dirtyCls);
  317. },
  318. isValid : function() {
  319. var me = this;
  320. return me.disabled || me.validateValue(me.processRawValue(me.getRawValue()));
  321. },
  322. validateValue: function(value) {
  323. var me = this,
  324. errors = me.getErrors(value),
  325. isValid = Ext.isEmpty(errors);
  326. if (!me.preventMark) {
  327. if (isValid) {
  328. me.clearInvalid();
  329. } else {
  330. me.markInvalid(errors);
  331. }
  332. }
  333. return isValid;
  334. },
  335. markInvalid : function(errors) {
  336. var me = this,
  337. oldMsg = me.getActiveError();
  338. me.setActiveErrors(Ext.Array.from(errors));
  339. if (oldMsg !== me.getActiveError()) {
  340. me.doComponentLayout();
  341. }
  342. },
  343. clearInvalid : function() {
  344. var me = this,
  345. hadError = me.hasActiveError();
  346. me.unsetActiveError();
  347. if (hadError) {
  348. me.doComponentLayout();
  349. }
  350. },
  351. renderActiveError: function() {
  352. var me = this,
  353. hasError = me.hasActiveError();
  354. if (me.inputEl) {
  355. me.inputEl[hasError ? 'addCls' : 'removeCls'](me.invalidCls + '-field');
  356. }
  357. me.mixins.labelable.renderActiveError.call(me);
  358. },
  359. getActionEl: function() {
  360. return this.inputEl || this.el;
  361. }
  362. });
  363. function keydown(name){
  364. Ext.getCmp(name).value = Ext.getCmp(name).getValue();
  365. }*/
  366. Ext.define('erp.view.core.form.TextAreaSelectField', {
  367. extend: 'Ext.form.field.TextArea',
  368. alias: 'widget.erpTextAreaSelectField',
  369. value: " 1=1 ",
  370. items: [],
  371. listeners:{
  372. change: function(field){
  373. var text = field.rawValue;
  374. var codes = text.split(/\n/);
  375. for(var i=0; i<codes.length; i++){
  376. if(codes[i] == ''){
  377. codes.splice(i,1);
  378. }
  379. }
  380. if(codes.length>0){
  381. field.value = " IN (";
  382. }
  383. for(var i=0, len=codes.length; i<len; i++){
  384. if (i != len-1){
  385. field.value += " '"+codes[i]+"', ";
  386. } else {
  387. field.value += " '"+codes[i]+"') ";
  388. }
  389. }
  390. }
  391. },
  392. initComponent : function(){
  393. this.callParent(arguments);
  394. var me = this;
  395. // me.insert(0, {
  396. // xtype: 'textareafield',
  397. // id: me.name + '_tas',
  398. // name: me.name + '_tas',
  399. // columnWidth: 1,
  400. // fieldStyle: me.fieldStyle,
  401. // listeners: {
  402. // change: function(){
  403. // var from = Ext.getCmp(me.name + '_from').value;
  404. // var to = Ext.getCmp(me.name + '_to').value;
  405. // from = from == null || from == '' ? to == null || to == '' ? '' : to : from;
  406. // to = to == null || to == '' ? from == null || from == '' ? '' : from : to;
  407. // me.value = "BETWEEN '" + from + "' AND '" + to + "'";
  408. // }
  409. // }
  410. // });
  411. }
  412. });