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

source

mwf.xdesktop.requireapp("process.xform", "$selector", null, false);
mwf.require("mwf.widget.uuid", null, false);
/** @class calendar 多选按钮组件。
 * @o2cn 多选按钮
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var field = this.form.get("fieldid"); //获取组件对象
 * //方法2
 * var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等
 * @extends mwf.xapplication.process.xform.$selector
 * @o2category formcomponents
 * @o2range {process|cms|portal}
 * @hideconstructor
 */
mwf.xapplication.process.xform.checkbox = mwf.appcheckbox =  new class(
    /** @lends mwf.xapplication.process.xform.checkbox# */
    {
        implements: [events],
        extends: mwf.app$selector,
        /**
         * 组件加载后触发。如果选项加载为异步,则异步处理完成后触发此事件
         * @event mwf.xapplication.process.xform.checkbox#load
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 值改变时触发。可以通过this.event获取修改后的选择项(dom对象)。
         * @event mwf.xapplication.process.xform.checkbox#change
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        loaddescription: function(){},
        _loadnode: function(){
            if (this.isreadonly()){
                this._loadnoderead();
            }else{
                this._loadnodeedit();
            }
        },
        _loadmergereadcontentnode: function( contentnode, data ){
            this._showvalue(contentnode, data.data)
        },
        _loadmergeeditnodebydefault: function(){
            var data = this.getsortedsectiondata();
            var businessdata = [];
            data.each(function(d){
                businessdata = businessdata.concat( d.data || [] );
            });
            this._setbusinessdata( businessdata );
            this._loadnode();
        },
        _loadnoderead: function(){
            this.node.empty();
            this.node.set({
                "nodeid": this.json.id,
                "mwftype": this.json.type
            });
            var value = this.getvalue();
            this._showvalue(this.node, value)
        },
        __showvalue: function(node, value, optionitems){
            if( !value )return;
            var texts = [];
            optionitems.each(function(item){
                var tmps = item.split("|");
                var t = tmps[0];
                var v = tmps[1] || t;
                if (value.indexof(v)!=-1){
                    texts.push(t);
                }
            });
            if( !this.isnumber(this.json.countperline) ) {
                if( this.json.newline ){
                    texts.each(function(t){
                        new element("div", { "text": t }).inject(node)
                    }.bind(this))
                }else{
                    node.set("text", texts.join(", "));
                }
            }else{
                var div;
                var countperline = this.json.countperline.toint();
                if( countperline === 0 ){
                    div = new element("div", {"style":"display:inline-block;"}).inject( node );
                    div.set("text", texts.join(", "));
                }else{
                    var textsperline = [];
                    texts.each(function(t, i){
                        if( i % countperline === 0){ //如果需要换行了
                            if( div && textsperline.length )div.set("text", textsperline.join(",")  ",");
                            textsperline = [];
                            div = new element("div").inject( node );
                        }
                        textsperline.push( t );
                    }.bind(this));
                    if( div && textsperline.length )div.set("text", textsperline.join(","));
                }
            }
        },
        _resetnodeedit: function(){
            var div = new element("div");
            div.set(this.json.properties);
            div.inject(this.node, "after");
            this.node.destroy();
            this.node = div;
        },
        _loadnodeedit: function(){
            //this.container = new element("select");
            if (!this.json.preprocessing) this._resetnodeedit();
            this.node.set({
                "id": this.json.id,
                "mwftype": this.json.type,
                "styles": {
                    "display": "inline"
                }
            });
            if( this.json.newline )this.node.setstyle("display", "block");
            this.setoptions();
        },
        _loaddomevents: function(){
        },
        _loadevents: function(){
            object.each(this.json.events, function(e, key){
                if (e.code){
                    if (this.options.moduleevents.indexof(key)!=-1){
                        this.addevent(key, function(event){
                            return this.form.macro.fire(e.code, this, event);
                        }.bind(this));
                    }else{
                        //this.node.addevent(key, function(event){
                        //    return this.form.macro.fire(e.code, this, event);
                        //}.bind(this));
                    }
                }
            }.bind(this));
        },
        addmoduleevent: function(key, fun){
            if (this.options.moduleevents.indexof(key)!==-1){
                this.addevent(key, function(event){
                    return (fun) ? fun(this, event) : null;
                }.bind(this));
            }else{
                var inputs = this.node.getelements("input");
                inputs.each(function(input){
                    input.addevent(key, function(event){
                        return (fun) ? fun(this, event) : null;
                    }.bind(this));
                }.bind(this));
            }
        },
        isnumber : function( d ){
            return parseint(d).tostring() !== "nan";
        },
        _setoptions: function(optionitems){
            var p = o2.promiseall(optionitems).then(function(radiovalues){
                this.moduleselectag = null;
                if (!radiovalues) radiovalues = [];
                var node;
                if (o2.typeof(radiovalues)==="array"){
                    var flag = (new mwf.widget.uuid).tostring();
                    radiovalues.each(function(item, i){
                        var tmps = item.split("|");
                        var text = tmps[0];
                        var value = tmps[1] || text;
                        if( !this.isnumber(this.json.countperline) ) {
                            if( this.json.newline ){
                                node = new element("div").inject(this.node);
                            }else{
                                node = this.node;
                            }
                        }else{
                            var countperline = this.json.countperline.toint();
                            if( countperline === 0 ){
                                if(i===0)node = new element("div", {"style":"display:inline-block;"}).inject(this.node);
                            }else if( i % countperline === 0){
                                node = new element("div").inject(this.node);
                            }
                        }
                        var radio = new element("input", {
                            "type": "checkbox",
                            "name": ((this.json.properties) ? this.json.properties.name : null) || flag this.json.id,
                            "value": value,
                            "showtext": text,
                            "styles": this.json.buttonstyles
                        }).inject(node);
                        //radio.appendtext(text, "after");
                        var textnode = new element( "span", {
                            "text" : text,
                            "styles" : { "cursor" : "default" }
                        }).inject(node);
                        textnode.addevent("click", function( ev ){
                            if( this.radio.get("disabled") === true || this.radio.get("disabled") === "true" )return;
                            this.radio.checked = ! this.radio.checked;
                            this.radio.fireevent("change", [this.radio]);
                            this.radio.fireevent("click");
                        }.bind( {radio : radio} ) );
                        radio.addevent("click", function(){
                            this.validationmode();
                            if (this.validation()) {
                                var v = this.getinputdata("change");
                                this._setbusinessdata(v || []);
                                //this._setenvironmentdata(v || []);
                                //this._setbusinessdata(this.getinputdata("change") || []);
                                this.fireevent("change", [radio]);
                            }
                        }.bind(this));
                        object.each(this.json.events, function(e, key){
                            if (e.code){
                                if (this.options.moduleevents.indexof(key)!=-1){
                                }else{
                                    radio.addevent(key, function(event){
                                        return this.form.macro.fire(e.code, this, event);
                                    }.bind(this));
                                }
                            }
                        }.bind(this));
                    }.bind(this));
                }
            }.bind(this), function(){});
            this.moduleselectag = p;
            if (p) p.then(function(){
                this.moduleselectag = null;
            }.bind(this), function(){
                this.moduleselectag = null;
            }.bind(this));
        },
        _setvalue: function(value, m, firechange){
            var mothed = m || "__setvalue";
            if (!!value){
                var p = o2.promiseall(value).then(function(v){
                    //if (o2.typeof(v)=="array") v = v[0];
                    if (this.moduleselectag){
                        this.modulevalueag = this.moduleselectag;
                        this.moduleselectag.then(function(){
                            this[mothed](v, firechange);
                            return v;
                        }.bind(this), function(){});
                    }else{
                        this[mothed](v, firechange)
                    }
                    return v;
                }.bind(this), function(){});
                this.modulevalueag = p;
                if (this.modulevalueag) this.modulevalueag.then(function(){
                    this.modulevalueag = null;
                }.bind(this), function(){
                    this.modulevalueag = null;
                }.bind(this));
            }else{
                this[mothed](value, firechange);
            }
            // this.modulevalueag = o2.ag.all(value).then(function(v){
            //     if (this.moduleselectag){
            //         this.modulevalueag = this.moduleselectag;
            //         this.moduleselectag.then(function(){
            //             this.modulevalueag = null;
            //             this.__setvalue(v);
            //         }.bind(this));
            //     }else{
            //         this.modulevalueag = null;
            //         this.__setvalue(v);
            //     }
            //     return v;
            // }.bind(this));
            //
            // if (this.modulevalueag) this.modulevalueag.then(function(){
            //     this.modulevalueag = "";
            // }.bind(this));
        },
        __setvalue: function(value){
            this.modulevalueag = null;
            this._setbusinessdata(value);
            if (this.isreadonly()){
                this._loadnoderead();
            }else{
                var radios = this.node.getelements("input");
                for (var i=0; idata.value){
                            this.notvalidationmode(data.prompt);
                            return false;
                        }
                        break;
                    case "lt":
                        if (v -1 ? options.textlist[ idx ] : "") ;
                });
                return arr.join(", ");
            });
        },
        setexceldata: function(d, type){
            var arr = this.stringtoarray(d);
            this.exceldata = arr;
            if( type === "value" ){
                this.setdata(arr, true);
            }else{
                var options = this.getoptionsobj();
                this.moduleexcelag = promise.resolve(options).then(function (opts) {
                    arr.each( function( a, i ){
                        var idx = opts.textlist.indexof( a );
                        arr[ i ] = idx > -1 ? opts.valuelist[ idx ] : null;
                    });
                    arr.clean();
                    var value = arr.length === 1  ? arr[0] : arr;
                    this.setdata(value, true);
                    this.moduleexcelag = null;
                }.bind(this));
            }
        },
        validationconfigitemexcel: function(data){
            if (data.status==="all"){
                var n = this.getinputdata();
                if( typeof(n)==="array" && n.length === 0 )n = "";
                var ed = typeof( this.exceldata ) === "null" ? [] : this.exceldata;
                if( typeof(ed)==="array" && ed.length === 0 )ed = "";
                var v, ev;
                if(data.valuetype==="value"){
                    v = n;
                    ev = ed;
                }else{
                    v = n.length;
                    ev = ed.length || 0;
                }
                switch (data.operateor){
                    case "isnull":
                        if (!v)return !ev ? data.prompt : "不在选项中";
                        break;
                    case "notnull":
                        if (v)return data.prompt;
                        break;
                    case "gt":
                        if (v>data.value)return data.prompt;
                        break;
                    case "lt":
                        if (v
网站地图