o2oa api: x-游戏厅捕鱼达人

source

//mwf.require("mwf.widget.pinyin", null, false);
mwf.xdesktop.requireapp("process.xform", "combox", null, false);
/** @class address 地址选择组件。
 * @o2cn 地址选择
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var address = this.form.get("name"); //获取组件
 * //方法2
 * var address = this.target; //组件本身的事件和脚本中获取
 * @extends mwf.xapplication.process.xform.combox
 * @o2category formcomponents
 * @o2range {process|cms}
 * @hideconstructor
 */
mwf.xapplication.process.xform.address = mwf.appaddress =  new class(
    /** @lends mwf.xapplication.process.xform.address# */
    {
	implements: [events],
	extends: mwf.appcombox,
    options: {
        "moduleevents": ["load", "queryload", "postload", "commitinput", "change"]
    },
    initialize: function(node, json, form){
        this.node = $(node);
        this.node.store("module", this);
        this.json = json;
        this.form = form;
        this.field = true;
        this.fieldmoduleloaded = false;
    },
    _loadnode: function(){
        if (this.isreadonly()){
            this._loadnoderead();
        }else{
            this._loadnodeedit();
        }
    },
    _loadnoderead: function(){
        this.node.empty();
        this.node.set({
            "nodeid": this.json.id,
            "mwftype": this.json.type
        });
        this.loadval();
        //new element("select").inject(this.node);
    },
    _loadnodeedit: function(){
        this.node.empty();
        mwf.require(["mwf.widget.combox","mwf.widget.pinyin"], function(){
            this.combox = new mwf.widget.combox({
                "style": this.form.json.addressstyle ? this.form.json.addressstyle.style : "blue",
                "positionx": this.form.json.addressstyle ? this.form.json.addressstyle.positionx : "left",
                "onlyselect": true,
                "count": 4,
                "focuslist": true,
                "oncommitinput": function(){
                    this.fireevent("commitinput");
                }.bind(this),
                "onchange": function(e, oldvalues){
                    var thisvalues = this.combox.values.map(function(v){ return v.data || v.value});
                    if ((oldvalues && (oldvalues.join() !== thisvalues.join()))){
                        while (this.combox.values.length-1>e.index){
                            this.combox.deleteitem(this.combox.values[this.combox.values.length-1])
                        }
                        this.fireevent("change");
                    }
                }.bind(this),
                "optionsmethod": this._searchoptions.bind(this)
            });
            this.combox.intoedit = function(e){
                if (this.options.count){
                    if (this.values.length>=this.options.count){
                        // if (this.input) this.input.noblur = true;
                        if (this.input) this.input.node.hide();
                        // this.getlast().edit();
                        return false;
                    }
                }
                if (!this.input){
                    this.input = new mwf.widget.combox.input(this, this, "");
                    this.input.node.inject(this.node);
                    this.input.node.setstyle("width", "1px");
                }
                this.input.node.show();
                this.input.setinputnodestyles();
                //this.input.node.set("value", "111");
                this.input.node.focus();
                this.input.setinputposition();
                if (this.options.focuslist) this.input.searchitems();
            }
        }.bind(this), false);
        this.combox.inject(this.node);
        this.node.set({
            "id": this.json.id,
            "mwftype": this.json.type
        });
        this.combox.addevent("change", function(){
            this.validationmode();
            if (this.validation()){
                var v = this.getinputdata("change");
                this._setbusinessdata(v);
                //this._setenvironmentdata(v);
            }
        }.bind(this));
        this.loadval();
    },
    _searchoptions: function(value, callback, comboxvalueobject){
        value = value.tolowercase();
        var i;
        if( comboxvalueobject ){
            i = comboxvalueobject.index;
        }else{
            i = (this.combox.edititem) ? this.combox.edititem.getitemposition() : this.combox.values.length;
        }
        if(this.json.selectrange==="province"){
            if( i > 0 ){
                if (callback) callback([]);
                return;
            }
        }else if(this.json.selectrange==="city"){
            if( i > 1 ){
                if (callback) callback([]);
                return;
            }
        }
        switch (i) {
            case 0: //省
                o2.actions.get("x_general_assemble_control").listprovince(function(json){
                    var list = [];
                    json.data.each(function(text){
                        var k = text.name;
                        var keyword = k mwf.widget.pinyin.topy(k).tolowercase() mwf.widget.pinyin.topyfirst(k).tolowercase();
                        if (value){
                            //if (keyword.indexof(value)!==-1)
                                list.push({"text": k, "value": k});
                        }else{
                            list.push({"text": k, "value": k});
                        }
                    }.bind(this));
                    // if (list.length) if (callback) callback(list);
                    if (callback) callback(list);
                }.bind(this));
                // mwf.ud.getpublicdata("addr_province", function(json){
                //     var list = [];
                //     json.each(function(text){
                //         var keyword = text mwf.widget.pinyin.topy(text).tolowercase() mwf.widget.pinyin.topyfirst(text).tolowercase();
                //         if (value){
                //             if (keyword.indexof(value)!==-1) list.push({"text": text, "value": text});
                //         }else{
                //             list.push({"text": text, "value": text});
                //         }
                //
                //     }.bind(this));
                //     if (list.length) if (callback) callback(list);
                // });
                break;
            case 1: //市
                var item = this.combox.getfirst();
                o2.actions.get("x_general_assemble_control").listcity(item.data || item.value, function(json){
                    var list = [];
                    json.data.each(function(text){
                        var k = text.name;
                        var keyword = k mwf.widget.pinyin.topy(k).tolowercase() mwf.widget.pinyin.topyfirst(k).tolowercase();
                        if (value){
                            //if (keyword.indexof(value)!==-1)
                                list.push({"text": k, "value": k});
                        }else{
                            list.push({"text": k, "value": k});
                        }
                    }.bind(this));
                    // if (list.length) if (callback) callback(list);
                    if (callback) callback(list);
                }.bind(this));
                // mwf.ud.getpublicdata("addr_city_" item.data, function(json){
                //     var list = [];
                //     json.each(function(text){
                //         var keyword = text mwf.widget.pinyin.topy(text).tolowercase() mwf.widget.pinyin.topyfirst(text).tolowercase();
                //         if (value){
                //             if (keyword.indexof(value)!==-1) list.push({"text": text, "value": text});
                //         }else{
                //             list.push({"text": text, "value": text});
                //         }
                //     }.bind(this));
                //     if (list.length) if (callback) callback(list);
                // });
                break;
            case 2: //区
                var f = this.combox.getfirst();
                var p = f.data || f.value;
                var item = this.combox.getfirst().getnextitem();
                o2.actions.get("x_general_assemble_control").listdistrict(p, item.data||item.value, function(json){
                    var list = [];
                    json.data.each(function(text){
                        var k = text.name;
                        var keyword = k mwf.widget.pinyin.topy(k).tolowercase() mwf.widget.pinyin.topyfirst(k).tolowercase();
                        if (value){
                            //if (keyword.indexof(value)!==-1)
                                list.push({"text": k, "value": k});
                        }else{
                            list.push({"text": k, "value": k});
                        }
                    }.bind(this));
                    if (list.length) if (callback) callback(list);
                }.bind(this));
                // mwf.ud.getpublicdata("addr_district_" item.data, function(json){
                //     var list = [];
                //     json.each(function(text){
                //         var keyword = text mwf.widget.pinyin.topy(text).tolowercase() mwf.widget.pinyin.topyfirst(text).tolowercase();
                //         if (value){
                //             if (keyword.indexof(value)!==-1) list.push({"text": text, "value": text});
                //         }else{
                //             list.push({"text": text, "value": text});
                //         }
                //     }.bind(this));
                //     if (list.length) if (callback) callback(list);
                // });
                break;
            default:
                if (callback) callback([]);
        }
    }
}); 
网站地图