123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- /**
- * From-To textfield
- * @author yingp
- */
- /*Ext.define('erp.view.core.form.FtField', {
- extend: 'Ext.Component',
- mixins: {
- labelable: 'Ext.form.Labelable',
- field: 'Ext.form.field.Field'
- },
- alias: 'widget.erpFtField',
- fieldSubTpl: [
- '<input id="{id}_from" type="{type}" onkeydown="keydown(' + "'{name}'"
- + ')" onkeyup="keydown(' + "'{name}'" + ')" onchange="keydown(' + "'{name}'" + ')" ',
- '<tpl if="name">name="{name}_from" </tpl>',
- '<tpl if="size">size="{size}" </tpl>',
- '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
- 'class="{fieldCls} {typeCls}" autocomplete="off" />',
- '->',
- '<input id="{id}_to" type="{type}" onkeydown="keydown(' + "'{name}'"
- + ')" onkeyup="keydown(' + "'{name}'" + ')" onchange="keydown(' + "'{name}'" + ')" ',
- '<tpl if="name">name="{name}_to" </tpl>',
- '<tpl if="size">size="{size}" </tpl>',
- '<tpl if="tabIdx">tabIndex="{tabIdx}" </tpl>',
- 'class="{typeCls}" autocomplete="off" />',
- '<span id="ft" style="color:#8EAECE;">From()To()</span>',
- {
- compiled: true,
- disableFormats: true
- }
- ],
- inputType: 'text',
- invalidText : 'The value in this field is invalid',
- fieldCls : Ext.baseCSSPrefix + 'form-field',
- focusCls : Ext.baseCSSPrefix + 'form-focus',
- dirtyCls : Ext.baseCSSPrefix + 'form-dirty',
- checkChangeEvents: Ext.isIE && (!document.documentMode || document.documentMode < 9) ?
- ['change', 'propertychange'] :
- ['change', 'input', 'textInput', 'keyup', 'dragdrop'],
- checkChangeBuffer: 50,
- componentLayout: 'field',
- readOnly : false,
- readOnlyCls: Ext.baseCSSPrefix + 'form-readonly',
- validateOnBlur: true,
- hasFocus : false,
- baseCls: Ext.baseCSSPrefix + 'field',
- maskOnDisable: false,
- initComponent : function() {
- var me = this;
- me.callParent();
- me.subTplData = me.subTplData || {};
- me.addEvents(
- 'focus',
- 'blur',
- 'specialkey'
- );
- me.initLabelable();
- me.initField();
- if (!me.name) {
- me.name = me.getInputId();
- }
- },
- getInputId: function() {
- return this.inputId || (this.inputId = Ext.id());
- },
- getSubTplData: function() {
- var me = this,
- type = me.inputType,
- inputId = me.getInputId();
- return Ext.applyIf(me.subTplData, {
- id: inputId,
- cmpId: me.id,
- name: me.name || inputId,
- type: type,
- size: me.size || 20,
- cls: me.cls,
- fieldCls: me.fieldCls,
- tabIdx: me.tabIndex,
- typeCls: Ext.baseCSSPrefix + 'form-' + (type === 'password' ? 'text' : type)
- });
- },
- afterRender: function() {
- this.callParent();
-
- if (this.inputEl) {
- this.inputEl.selectable();
- }
- },
- getSubTplMarkup: function() {
- return this.getTpl('fieldSubTpl').apply(this.getSubTplData());
- },
- initRenderTpl: function() {
- var me = this;
- if (!me.hasOwnProperty('renderTpl')) {
- me.renderTpl = me.getTpl('labelableRenderTpl');
- }
- return me.callParent();
- },
- initRenderData: function() {
- return Ext.applyIf(this.callParent(), this.getLabelableRenderData());
- },
- setFieldStyle: function(style) {
- var me = this,
- inputEl = me.inputEl;
- if (inputEl) {
- inputEl.applyStyles(style);
- }
- me.fieldStyle = style;
- },
- onRender : function() {
- var me = this,
- fieldStyle = me.fieldStyle;
- me.onLabelableRender();
- me.addChildEls({ name: 'inputEl', id: me.getInputId() });
- me.callParent(arguments);
- me.setRawValue(me.rawValue);
- if (me.readOnly) {
- me.setReadOnly(true);
- }
- if (me.disabled) {
- me.disable();
- }
- if (fieldStyle) {
- me.setFieldStyle(fieldStyle);
- }
- me.renderActiveError();
- },
- initAria: function() {
- var me = this;
- me.callParent();
- me.getActionEl().dom.setAttribute('aria-describedby', Ext.id(me.errorEl));
- },
- getFocusEl: function() {
- return this.inputEl;
- },
- isFileUpload: function() {
- return this.inputType === 'file';
- },
- extractFileInput: function() {
- var me = this,
- fileInput = me.isFileUpload() ? me.inputEl.dom : null,
- clone;
- if (fileInput) {
- clone = fileInput.cloneNode(true);
- fileInput.parentNode.replaceChild(clone, fileInput);
- me.inputEl = Ext.get(clone);
- }
- return fileInput;
- },
- getSubmitData: function() {
- var me = this,
- data = null,
- val;
- if (!me.disabled && me.submitValue && !me.isFileUpload()) {
- val = me.getSubmitValue();
- if (val !== null) {
- data = {};
- data[me.getName()] = val;
- }
- }
- return data;
- },
- getSubmitValue: function() {
- return this.processRawValue(this.getRawValue());
- },
- getRawValue: function() {
- var me = this,
- v = (me.inputEl ? me.inputEl.getValue() : Ext.value(me.rawValue, ''));
- me.rawValue = v;
- return v;
- },
- setRawValue: function(value) {
- var me = this;
- value = Ext.value(value, '');
- me.rawValue = value;
- if (me.inputEl) {
- me.inputEl.dom.value = value;
- }
- return value;
- },
- valueToRaw: function(value) {
- return '' + Ext.value(value, '');
- },
- rawToValue: function(rawValue) {
- return rawValue;
- },
- processRawValue: function(value) {
- return value;
- },
- getValue: function() {
- var me = this,
- val = me.rawToValue(me.processRawValue(me.getRawValue()));
- var from = document.getElementsByName(me.id + '_from')[0].value;
- var to = document.getElementsByName(me.id + '_to')[0].value;
- if(from.length > me.maxLength){
- document.getElementsByName(me.id + '_from')[0].value = from .substring(0, me.maxLength);showError('maxLength:' + me.maxLength);
- from = from .substring(0, me.maxLength);showError('maxLength:' + me.maxLength);
- }
- if(to.length > me.maxLength){
- to = to .substring(0, me.maxLength);showError('maxLength:' + me.maxLength);
- }
- from = from == null || from == '' ? to : from;
- to = to == null || to == '' ? from : to;
- val = val == null || val == '' ? 'BETWEEN ' + from + ' AND ' + to : val;
- me.value = val;
- document.getElementById('ft').innerHTML = 'From (' + from + ') To (' + to + ")";
- return val;
- },
- setValue: function(value) {
- var me = this;
- me.setRawValue(me.valueToRaw(value));
- return me.mixins.field.setValue.call(me, value);
- },
- onDisable: function() {
- var me = this,
- inputEl = me.inputEl;
- me.callParent();
- if (inputEl) {
- inputEl.dom.disabled = true;
- }
- },
- onEnable: function() {
- var me = this,
- inputEl = me.inputEl;
- me.callParent();
- if (inputEl) {
- inputEl.dom.disabled = false;
- }
- },
- setReadOnly: function(readOnly) {
- var me = this,
- inputEl = me.inputEl;
- if (inputEl) {
- inputEl.dom.readOnly = readOnly;
- inputEl.dom.setAttribute('aria-readonly', readOnly);
- }
- me[readOnly ? 'addCls' : 'removeCls'](me.readOnlyCls);
- me.readOnly = readOnly;
- },
- fireKey: function(e){
- if(e.isSpecialKey()){
- this.fireEvent('specialkey', this, Ext.create('Ext.EventObjectImpl', e));
- }
- },
- initEvents : function(){
- var me = this,
- inputEl = me.inputEl,
- onChangeTask,
- onChangeEvent;
- if (inputEl) {
- me.mon(inputEl, Ext.EventManager.getKeyEvent(), me.fireKey, me);
- me.mon(inputEl, 'focus', me.onFocus, me);
- me.mon(inputEl, 'blur', me.onBlur, me, me.inEditor ? {buffer:10} : null);
- onChangeTask = Ext.create('Ext.util.DelayedTask', me.checkChange, me);
- me.onChangeEvent = onChangeEvent = function() {
- onChangeTask.delay(me.checkChangeBuffer);
- };
- Ext.each(me.checkChangeEvents, function(eventName) {
- if (eventName === 'propertychange') {
- me.usesPropertychange = true;
- }
- me.mon(inputEl, eventName, onChangeEvent);
- }, me);
- }
- me.callParent();
- },
- doComponentLayout: function() {
- var me = this,
- inputEl = me.inputEl,
- usesPropertychange = me.usesPropertychange,
- ename = 'propertychange',
- onChangeEvent = me.onChangeEvent;
- if (usesPropertychange) {
- me.mun(inputEl, ename, onChangeEvent);
- }
- me.callParent(arguments);
- if (usesPropertychange) {
- me.mon(inputEl, ename, onChangeEvent);
- }
- },
- preFocus: Ext.emptyFn,
- onFocus: function() {
- var me = this,
- focusCls = me.focusCls,
- inputEl = me.inputEl;
- me.preFocus();
- if (focusCls && inputEl) {
- inputEl.addCls(focusCls);
- }
- if (!me.hasFocus) {
- me.hasFocus = true;
- me.componentLayout.onFocus();
- me.fireEvent('focus', me);
- }
- },
- beforeBlur : Ext.emptyFn,
- onBlur : function(){
- var me = this,
- focusCls = me.focusCls,
- inputEl = me.inputEl;
- if (me.destroying) {
- return;
- }
- me.beforeBlur();
- if (focusCls && inputEl) {
- inputEl.removeCls(focusCls);
- }
- if (me.validateOnBlur) {
- me.validate();
- }
- me.hasFocus = false;
- me.fireEvent('blur', me);
- me.postBlur();
- },
- postBlur : Ext.emptyFn,
- onDirtyChange: function(isDirty) {
- this[isDirty ? 'addCls' : 'removeCls'](this.dirtyCls);
- },
- isValid : function() {
- var me = this;
- return me.disabled || me.validateValue(me.processRawValue(me.getRawValue()));
- },
- validateValue: function(value) {
- var me = this,
- errors = me.getErrors(value),
- isValid = Ext.isEmpty(errors);
- if (!me.preventMark) {
- if (isValid) {
- me.clearInvalid();
- } else {
- me.markInvalid(errors);
- }
- }
- return isValid;
- },
- markInvalid : function(errors) {
- var me = this,
- oldMsg = me.getActiveError();
- me.setActiveErrors(Ext.Array.from(errors));
- if (oldMsg !== me.getActiveError()) {
- me.doComponentLayout();
- }
- },
- clearInvalid : function() {
- var me = this,
- hadError = me.hasActiveError();
- me.unsetActiveError();
- if (hadError) {
- me.doComponentLayout();
- }
- },
- renderActiveError: function() {
- var me = this,
- hasError = me.hasActiveError();
- if (me.inputEl) {
- me.inputEl[hasError ? 'addCls' : 'removeCls'](me.invalidCls + '-field');
- }
- me.mixins.labelable.renderActiveError.call(me);
- },
- getActionEl: function() {
- return this.inputEl || this.el;
- }
- });
- function keydown(name){
- Ext.getCmp(name).value = Ext.getCmp(name).getValue();
- }*/
- Ext.define('erp.view.core.form.TextAreaSelectField', {
- extend: 'Ext.form.field.TextArea',
- alias: 'widget.erpTextAreaSelectField',
- value: " 1=1 ",
- items: [],
- listeners:{
- change: function(field){
- var text = field.rawValue;
- var codes = text.split(/\n/);
- for(var i=0; i<codes.length; i++){
- if(codes[i] == ''){
- codes.splice(i,1);
- }
-
- }
-
-
- if(codes.length>0){
- field.value = " IN (";
- }
- for(var i=0, len=codes.length; i<len; i++){
-
- if (i != len-1){
- field.value += " '"+codes[i]+"', ";
-
- } else {
- field.value += " '"+codes[i]+"') ";
-
- }
-
- }
-
- }
- },
- initComponent : function(){
- this.callParent(arguments);
- var me = this;
- // me.insert(0, {
- // xtype: 'textareafield',
- // id: me.name + '_tas',
- // name: me.name + '_tas',
- // columnWidth: 1,
- // fieldStyle: me.fieldStyle,
- // listeners: {
- // change: function(){
- // var from = Ext.getCmp(me.name + '_from').value;
- // var to = Ext.getCmp(me.name + '_to').value;
- // from = from == null || from == '' ? to == null || to == '' ? '' : to : from;
- // to = to == null || to == '' ? from == null || from == '' ? '' : from : to;
- // me.value = "BETWEEN '" + from + "' AND '" + to + "'";
- // }
- // }
- // });
- }
- });
|