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

source

mwf.xdesktop.requireapp("process.xform", "div", null, false);
/** @class source 数据源组件。
 * @o2cn 数据源
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var source = this.form.get("fieldid"); //获取数据源组件
 * //方法2
 * var source = this.target; //在组件本身的脚本中获取
 * @extends mwf.xapplication.process.xform.div
 * @o2category formcomponents
 * @o2range {portal}
 * @hideconstructor
 */
mwf.xapplication.process.xform.source = mwf.appsource =  new class(
    /** @lends mwf.xapplication.process.xform.source# */
    {
	extends: mwf.appdiv,
    options: {
        /**
         * 加载数据后执行,但这时还未加载下属组件,可以可以使用this.target.data获取数据进行修改。
         * @event mwf.xapplication.process.xform.source#postloaddata
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 加载数据、下属组件后执行。
         * @event mwf.xapplication.process.xform.source#loaddata
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        "moduleevents": ["queryload","postload","load", "postloaddata", "loaddata"]
    },
	_loaduserinterface: function(){
        this.data = null;
        if (this.json.path){
            if (this.json.sourcetype=="o2"){
                if (this.json.path) this._geto2source();
            }
        }
	},
    _geto2address: function(){
        try {
            this.json.service = json.parse(this.json.contextroot);
        }catch(e){
            this.json.service = {"root": this.json.contextroot, "action":"", "method": "", "url": ""};
        }
        var addressobj = layout.serviceaddresslist[this.json.service.root];
        if (addressobj){
            this.address = layout.config.app_protocol "//" addressobj.host (addressobj.port==80 ? "" : ":" addressobj.port) addressobj.context;
        }else{
            var host = layout.desktop.centerserver.host || window.location.hostname;
            var port = layout.desktop.centerserver.port;
            this.address = layout.config.app_protocol "//" host (port=="80" ? "" : ":" port) "/" this.json.service.root;
        }
    },
    //_getconfigparameters: function(){
    //
    //    return pars;
    //},
    _geto2uri: function(){
        //var uri = this.json.path || this.json.selectpath;
        var uri = this.json.path;
        var pars = {};
        if (this.json.parameters){
            object.each(this.json.parameters, function(v, key){
                if (uri.indexof("{" key "}")!=-1){
                    var reg = new regexp("{" key "}", "g");
                    uri = uri.replace(reg, encodeuricomponent((v && v.code) ? (this.form.macro.exec(v.code, this) || "") : v));
                }else{
                    pars[key] = v;
                }
            }.bind(this));
        }
        var data = null;
        if (this.json.requestbody){
            if (this.json.requestbody.code){
                data = this.form.macro.exec(this.json.requestbody.code, this)
            }
        }
        if (this.json.httpmethod=="get" || this.json.httpmethod=="options" || this.json.httpmethod=="head" || this.json.httpmethod=="delete"){
            var tag = "?";
            if (uri.indexof("?")!=-1) tag = "&";
            object.each(pars, function(v, k){
                var value = (v && v.code) ? (this.form.macro.exec(v.code, this) || "") : v;
                uri = uri tag k "=" value;
            }.bind(this));
        }else{
            object.each(pars, function(v, k){
                if (!data) data = {};
                var value = (v && v.code) ? (this.form.macro.exec(v.code, this) || "") : v;
                data[k] = value;
            }.bind(this));
        }
        this.body = data;
        this.uri = this.address uri;
    },
    _geto2source: function(){
        this._geto2address();
        this._geto2uri();
        this._invoke(function(){
            this._loadsub(this.node);
            this.fireevent("loaddata");
        }.bind(this));
    },
    _invoke: function(callback){
        mwf.restful(this.json.httpmethod, this.uri, json.encode(this.body), function(json){
            /**
             * @summary 该属性获取当前数据源的数据,当数据源加载完成后才有值。
             * @member {array|object|string|number|boolean|null}
             * @example
             * var field = this.form.get("fieldid").data; //获取数据源数据
             */
            this.data = json;
            this.fireevent("postloaddata");
            if (callback) callback();
        }.bind(this), true, true);
    },
    setbody: function(data){
        this.body = data;
    },
    /**
     * @summary 替换全部的url参数,但不刷新组件
     * @param {object} url参数
     * @example
     * //如,原来的组件url参数为:
     * { "page" : 1, "count" : 10  }
     *
     * this.form.get("fieldid").setparameters({"id":"662ede34-4e21-428a-9c3b-f1bf14d15650"});
     *
     * //执行后变为
     * {"id":"662ede34-4e21-428a-9c3b-f1bf14d15650"}
     */
    setparameters: function(json){
        this.json.parameters = json;
        this._geto2address();
        this._geto2uri();
    },
    /**
     * @summary 新增url参数,但不刷新组件。如果该参数key已经存在,则覆盖
     * @param {object} url参数
     * @example
     * * //如,原来的组件url参数为:
     * { "page" : 1, "count" : 10  }
     *
     * this.form.get("fieldid").addparameters({
     *  "page" : 2,
     *  "id":"662ede34-4e21-428a-9c3b-f1bf14d15650"
     *  });
     *
     * //执行后变为
     * {
     *  "page" : 2,
     *  "count" : 10
     *  "id":"662ede34-4e21-428a-9c3b-f1bf14d15650"
     *  }
     */
    addparameters: function(json){
        if (!this.json.parameters) this.json.parameters={};
        object.each(json, function(v, k){
            this.json.parameters[k] = v;
        }.bind(this));
        this._geto2address();
        this._geto2uri();
    },
    /**
     * @summary 重新加载组件。会触发loaddata事件
     * @param {boolean} notinit - false表示不重新初始化子数据源和数据文本,true表示重新初始化,默认为false
     * @param {function} callback 加载完成后的回调
     * @example
     * this.form.get("fieldid").reload(); //重新加载组件
     */
    reload: function(notinit, callback){
	    this._geto2uri();
        this._invoke(function(){
            this._loadsub(this.node, notinit);
            this.fireevent("loaddata");
            if (callback) callback();
        }.bind(this));
    },
    _loadsub: function(dom, notinit){
        var subdom = dom.getfirst();
        var module = null;
        while (subdom){
            module = null;
            module = subdom.retrieve("module", null);
            if (module){
                if (module._loadjsondata) module._loadjsondata(notinit);
            }else{
                this._loadsub(subdom);
            }
            //var type = subdom.get("mwftype");
            //if (type){
            //    if (type=="sourcetext"){
            //        module = subdom.retrieve("module");
            //        module._loaddata();
            //    }else if (type=="subsource"){
            //        module = subdom.retrieve("module");
            //        module._loaddata();
            //    }else{
            //        this._loadsub(subdom);
            //    }
            //}else{
            //   this._loadsub(subdom);
            //}
            subdom = subdom.getnext();
        }
    }
}); 
网站地图