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

source

mwf.xdesktop.requireapp("process.xform", "$module", null, false);
//common.ajaxmodule.load("jsontemplate", null, false);
/** @class subsource 子数据源。
 * @o2cn 子数据源
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var subsource = this.form.get("fieldid"); //获取组件
 * //方法2
 * var subsource = this.target; //在组件本身的脚本中获取
 * @extends mwf.xapplication.process.xform.$module
 * @o2category formcomponents
 * @o2range {portal}
 * @hideconstructor
 */
mwf.xapplication.process.xform.subsource = mwf.appsubsource =  new class(
    /** @lends mwf.xapplication.process.xform.subsource# */
{
    extends: mwf.app$module,
    options: {
        /**
         * 加载数据后执行,但这时还未加载下属组件,可以可以使用this.target.data获取数据进行修改。
         * @event mwf.xapplication.process.xform.subsource#postloaddata
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 加载数据、下属组件后执行。
         * @event mwf.xapplication.process.xform.subsource#loaddata
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        "moduleevents": ["queryload","postload","load", "postloaddata", "loaddata"]
    },
    load: function(){
        /**
         * @ignore
         * @member parentline
         * @memberof mwf.xapplication.process.xform.subsource#
         */
        this._loadmoduleevents();
        this._queryloaded();
        this._loaduserinterface();
        //this._loadstyles();
        //this._loadevents();
        // this._loaddomevents();
        this._afterloaded();
    },
    _loaduserinterface: function(){
        this.loopnodes = [];
        this.subsourceitems = [];
        var node = new element("div").inject(this.node, "before");
        this.node.inject(node);
        this.loopnode = this.node.dispose();
        this.node = node;
        var id = node.get("id");
        node.set("id", "");
        this.node.set({
            "id": id,
            "mwftype": node.get("mwftype")
        });
        this.node.store("module", this);
        this._loadjsondata();
    },
    _getsource: function(){
        var parent = this.node.getparent();
        while(parent && (parent.get("mwftype")!="source" && parent.get("mwftype")!="subsource" && parent.get("mwftype")!="subsourceitem")) parent = parent.getparent();
        return (parent) ? parent.retrieve("module") : null;
    },
    _getsourcedata: function(sourcedata){
        var data = sourcedata;
        if (this.json.jsonpath!="."){
            var paths = this.json.jsonpath.split(".");
            paths.each(function(p){
                data = data[p];
            }.bind(this));
        }
        /**
         * @summary 该属性获取当前子数据源的数据,当所在上级数据源加载完成后才有值。
         * @member {array|object|string|number|boolean|null}
         * @example
         * var field = this.form.get("fieldid").data; //获取子数据源数据
         */
        this.data = data;
    },
    _loopsub: function(dom, i){
        var _self = this;
        var modulenodes = this.form._getmodulenodes(dom);
        modulenodes.each(function(node){
            var json = this.form._getdomjson(node);
            var subjson = object.clone(json);
            subjson.id = subjson.id "_" i;
            node.set("id", subjson.id);
            var module = this.form._loadmodule(subjson, node, function(){
                if( _self.widget )this.widget = _self.widget;
            }, true);
            //this.modules.push(module);
        }.bind(this));
    },
    _loopdata: function(){
        var _self = this;
        this.data.each(function(d, i){
            var node = this.loopnode.clone(true, true);
            node.inject(this.node);
            var json = object.clone(this.json);
            json.id = json.id "_" i;
            json.type = "subsourceitem";
            node.set({
                "id": json.id,
                "mwftype": "subsourceitem"
            });
            var module = this.form._loadmodule(json, node, function(){
                if( _self.widget )this.widget = _self.widget;
                this.data = d;
                this.position = i;
            }, true);
            this.subsourceitems.push(module);
            this.loopnodes.push(node);
            this._loopsub(node, i);
        }.bind(this));
    },
    _initsubsource: function(){
        if (this.loopnode){
            var modulenodes = this.form._getmodulenodes(this.node);
            modulenodes.each(function(node){
                var module = node.retrieve("module");
                if (module){
                    if (module.json.type=="subsource"){
                        module._initsubsource();
                    }else{
                        mwf.release(module);
                    }
                }
            }.bind(this));
            this.node.empty();
        }
        this.loopnodes = [];
        this.subsourceitems = [];
    },
    _loadjsondata: function(notinit){
        if (!notinit) this._initsubsource();
        this.source = this._getsource();
        if (this.source){
            if (this.source.data){
                this._getsourcedata(this.source.data);
                this.fireevent("postloaddata");
                if (typeof(this.data)!=="array") this.data = [this.data];
                if (typeof(this.data)=="array"){
                    this._loopdata();
                    this.fireevent("loaddata");
                }else{
                    var _self = this;
                    this.form._loadmodules(this.node, function () {
                        if( _self.widget )this.widget = _self.widget;
                    }, true);
                }
                //this.tmpdiv = new element("div");
                //var html = "{loop:" this.json.jsonpath "}" this.node.outerhtml "{/loop:" this.json.jsonpath "}";
                ////this.template = new template();
                ////var loophtml = this.template.substitute("{" this.json.jsonpath "}", this.source.data);
                //this.node.set("text", this.text);
            }
        }
    }
});
mwf.xapplication.process.xform.subsourceitem = mwf.appsubsourceitem =  new class({
    extends: mwf.app$module,
    _loaduserinterface: function(){
        this.loopnodes = [];
        this.subsourceitems = [];
    }
});
网站地图