form-debug.js

来自「php绿色服务器,让大家试用greenamp」· JavaScript 代码 · 共 2,414 行 · 第 1/5 页

JS
2,414
字号
        activeAction : null,        waitMsgTarget : undefined,        initEl : function(el){        this.el = Ext.get(el);        this.id = this.el.id || Ext.id();        this.el.on('submit', this.onSubmit, this);        this.el.addClass('x-form');    },        onSubmit : function(e){        e.stopEvent();    },        isValid : function(){        var valid = true;        this.items.each(function(f){           if(!f.validate()){               valid = false;           }        });        return valid;    },        doAction : function(action, options){        if(typeof action == 'string'){            action = new Ext.form.Action.ACTION_TYPES[action](this, options);        }        if(this.fireEvent('beforeaction', this, action) !== false){            this.beforeAction(action);            action.run.defer(100, action);        }    },        submit : function(options){        this.doAction('submit', options);    },        load : function(options){        this.doAction('load', options);    },        updateRecord : function(record){        record.beginEdit();        var fs = record.fields;        fs.each(function(f){            var field = this.findField(f.name);            if(field){                record.set(f.name, field.getValue());            }        }, this);        record.endEdit();    },        beforeAction : function(action){        var o = action.options;        if(o.waitMsg){            if(this.waitMsgTarget === true){                this.el.mask(o.waitMsg, 'x-mask-loading');            }else if(this.waitMsgTarget){                this.waitMsgTarget = Ext.get(this.waitMsgTarget);                this.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');            }else{                Ext.MessageBox.wait(o.waitMsg, o.waitTitle || this.waitTitle || 'Please Wait...');            }        }    },        afterAction : function(action, success){        this.activeAction = null;        var o = action.options;        if(o.waitMsg){            if(this.waitMsgTarget === true){                this.el.unmask();            }else if(this.waitMsgTarget){                this.waitMsgTarget.unmask();            }else{                Ext.MessageBox.updateProgress(1);                Ext.MessageBox.hide();            }        }        if(success){            if(o.reset){                this.reset();            }            Ext.callback(o.success, o.scope, [this, action]);            this.fireEvent('actioncomplete', this, action);        }else{            Ext.callback(o.failure, o.scope, [this, action]);            this.fireEvent('actionfailed', this, action);        }    },        findField : function(id){        var field = this.items.get(id);        if(!field){            this.items.each(function(f){                if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){                    field = f;                    return false;                }            });        }        return field || null;    },        markInvalid : function(errors){        if(errors instanceof Array){            for(var i = 0, len = errors.length; i < len; i++){                var fieldError = errors[i];                var f = this.findField(fieldError.id);                if(f){                    f.markInvalid(fieldError.msg);                }            }        }else{            var field, id;            for(id in errors){                if(typeof errors[id] != 'function' && (field = this.findField(id))){                    field.markInvalid(errors[id]);                }            }        }    },        setValues : function(values){        if(values instanceof Array){             for(var i = 0, len = values.length; i < len; i++){                var v = values[i];                var f = this.findField(v.id);                if(f){                    f.setValue(v.value);                }            }        }else{             var field, id;            for(id in values){                if(typeof values[id] != 'function' && (field = this.findField(id))){                    field.setValue(values[id]);                }            }        }    },        getValues : function(asString){        var fs = Ext.lib.Ajax.serializeForm(this.el.dom);        if(asString === true){            return fs;        }        return Ext.urlDecode(fs);    },        clearInvalid : function(){        this.items.each(function(f){           f.clearInvalid();        });    },        reset : function(){        this.items.each(function(f){            f.reset();        });    },        add : function(){        this.items.addAll(Array.prototype.slice.call(arguments, 0));    },        remove : function(field){        this.items.remove(field);    },        render : function(){        this.items.each(function(f){            if(f.isFormField && !f.rendered && document.getElementById(f.id)){                 f.applyTo(f.id);            }        });    },        applyToFields : function(o){        this.items.each(function(f){           Ext.apply(f, o);        });    },        applyIfToFields : function(o){        this.items.each(function(f){           Ext.applyIf(f, o);        });    }});Ext.BasicForm = Ext.form.BasicForm;Ext.form.Form = function(config){    Ext.form.Form.superclass.constructor.call(this, null, config);    this.url = this.url || this.action;    if(!this.root){        this.root = new Ext.form.Layout(Ext.applyIf({            id: Ext.id()        }, config));    }    this.active = this.root;        this.buttons = [];    this.addEvents({                clientvalidation: true    });};Ext.extend(Ext.form.Form, Ext.form.BasicForm, {                buttonAlign:'center',        minButtonWidth:75,        labelAlign:'left',        monitorValid : false,        monitorPoll : 200,        column : function(c){        var col = new Ext.form.Column(c);        this.start(col);        if(arguments.length > 1){             this.add.apply(this, Array.prototype.slice.call(arguments, 1));            this.end();        }        return col;    },        fieldset : function(c){        var fs = new Ext.form.FieldSet(c);        this.start(fs);        if(arguments.length > 1){             this.add.apply(this, Array.prototype.slice.call(arguments, 1));            this.end();        }        return fs;    },        container : function(c){        var l = new Ext.form.Layout(c);        this.start(l);        if(arguments.length > 1){             this.add.apply(this, Array.prototype.slice.call(arguments, 1));            this.end();        }        return l;    },        start : function(c){                Ext.applyIf(c, {'labelAlign': this.active.labelAlign, 'labelWidth': this.active.labelWidth, 'itemCls': this.active.itemCls});        this.active.stack.push(c);        c.ownerCt = this.active;        this.active = c;        return this;    },        end : function(){        if(this.active == this.root){            return this;        }        this.active = this.active.ownerCt;        return this;    },        add : function(){        this.active.stack.push.apply(this.active.stack, arguments);        var r = [];        for(var i = 0, a = arguments, len = a.length; i < len; i++) {            if(a[i].isFormField){                r.push(a[i]);            }        }        if(r.length > 0){            Ext.form.Form.superclass.add.apply(this, r);        }        return this;    },        render : function(ct){        ct = Ext.get(ct);        var o = this.autoCreate || {            tag: 'form',            method : this.method || 'POST',            id : this.id || Ext.id()        };        this.initEl(ct.createChild(o));        this.root.render(this.el);        this.items.each(function(f){            f.render('x-form-el-'+f.id);        });        if(this.buttons.length > 0){                        var tb = this.el.createChild({cls:'x-form-btns-ct', cn: {                cls:"x-form-btns x-form-btns-"+this.buttonAlign,                html:'<table cellspacing="0"><tbody><tr></tr></tbody></table><div class="x-clear"></div>'            }}, null, true);            var tr = tb.getElementsByTagName('tr')[0];            for(var i = 0, len = this.buttons.length; i < len; i++) {                var b = this.buttons[i];                var td = document.createElement('td');                td.className = 'x-form-btn-td';                b.render(tr.appendChild(td));            }        }        if(this.monitorValid){             this.startMonitoring();        }        return this;    },        addButton : function(config, handler, scope){        var bc = {            handler: handler,            scope: scope,            minWidth: this.minButtonWidth,            hideParent:true        };        if(typeof config == "string"){            bc.text = config;        }else{            Ext.apply(bc, config);        }        var btn = new Ext.Button(null, bc);        this.buttons.push(btn);        return btn;    },        startMonitoring : function(){        if(!this.bound){            this.bound = true;            Ext.TaskMgr.start({                run : this.bindHandler,                interval : this.monitorPoll || 200,                scope: this            });        }    },        stopMonitoring : function(){        this.bound = false;    },        bindHandler : function(){        if(!this.bound){            return false;         }        var valid = true;        this.items.each(function(f){            if(!f.isValid(true)){                valid = false;                return false;            }        });        for(var i = 0, len = this.buttons.length; i < len; i++){            var btn = this.buttons[i];            if(btn.formBind === true && btn.disabled === valid){                btn.setDisabled(!valid);            }        }        this.fireEvent('clientvalidation', this, valid);    }});Ext.Form = Ext.form.Form;Ext.form.Action = function(form, options){    this.form = form;    this.options = options || {};};Ext.form.Action.CLIENT_INVALID = 'client';Ext.form.Action.SERVER_INVALID = 'server';Ext.form.Action.CONNECT_FAILURE = 'connect';Ext.form.Action.LOAD_FAILURE = 'load';Ext.form.Action.prototype = {    type : 'default',    failureType : undefined,    response : undefined,    result : undefined,        run : function(options){    },        success : function(response){    },        handleResponse : function(response){    },        failure : function(response){        this.response = response;        this.failureType = Ext.form.Action.CONNECT_FAILURE;        this.form.afterAction(this, false);    },    processResponse : function(response){        this.response = response;        if(!response.responseText){            return true;        }        this.result = this.handleResponse(response);        return this.result;    },        getUrl : function(appendParams){        var url = this.options.url || this.form.url || this.form.el.dom.action;        if(appendParams){            var p = this.getParams();            if(p){                url += (url.indexOf('?') != -1 ? '&' : '?') + p;            }        }        return url;    },    getMethod : function(){        return (this.options.method || this.form.method || this.form.el.dom.method || 'POST').toUpperCase();    },    getParams : function(){        var bp = this.form.baseParams;        var p = this.options.params;        if(p){            if(typeof p == "object"){                p = Ext.urlEncode(Ext.applyIf(p, bp));            }else if(typeof p == 'string' && bp){                p += '&' + Ext.urlEncode(bp);            }        }else if(bp){            p = Ext.urlEncode(bp);        }        return p;    },    createCallback : function(){        return {            success: this.success,            failure: this.failure,         

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?