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

source

mwf.require("mwf.widget.common", null, false);
/** @classdesc $module 组件类,此类为所有组件的父类。
 * @class
 * @o2category formcomponents
 * @hideconstructor
 * */
mwf.xapplication.process.xform.$module = mwf.app$module =  new class(
    /** @lends mwf.xapplication.process.xform.$module# */
    {
    implements: [events],
    options: {
        /**
         * 组件加载前触发。queryload执行的时候,当前组件没有在form里注册,通过this.form.get("fieldid")不能获取到当前组件,需要用this.target获取。
         * @event mwf.xapplication.process.xform.$module#queryload
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 组件加载后触发.
         * @event mwf.xapplication.process.xform.$module#postload
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        /**
         * 组件加载后触发.
         * @event mwf.xapplication.process.xform.$module#load
         * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
         */
        "moduleevents": ["load", "queryload", "postload"]
    },
    initialize: function(node, json, form, options){
        /**
         * @summary 组件的节点,mootools封装过的dom对象,可以直接使用原生的js和moootools方法访问和操作该对象。
         * @see https://mootools.net/core/docs/1.6.0/element/element
         * @member {element}
         * @example
         *  //可以在脚本中获取该组件
         * var field = this.form.get("fieldid"); //获取组件对象
         * field.node.setstyle("font-size","12px"); //给节点设置样式
         */
        this.node = $(node);
        this.node.store("module", this);
        /**
         * @summary 组件的配置信息,比如id,类型,是否只读等等。可以在组件的queryload事件里修改该配置来对组件做一些改变。
         * @member {jsonobject}
         * @example
         *  //可以在脚本中获取该组件
         * var json = this.form.get("fieldid").json; //获取组件对象
         * var id = json.id; //获取组件的id
         * var type = json.type; //获取组件的类型,如textfield 为文本输入组件,select为下拉组件
         *
         * //在组件queryload事件里设置组件只读。
         * //当前组件的queryload事件运行时还没有在form里注册,通过this.form.get("fieldid")不能获取到当前组件,需要用this.target获取。
         * var json = this.target.json;
         * json.isreadonly = true; //设置组件为只读。
         */
        this.json = json;
        /**
         * @summary 组件的所在表单对象.
         * @member {mwf.xapplication.process.xform.form}
         * @example
         * var form = this.form.get("fieldid").form; //获取组件所在表单对象
         * var container = form.container; //获取表单容器
         */
        this.form = form;
        /**
         * 当前组件在数据表格或者数据模板中时,可以通过此属性获取所在行(条目)对象.
         * @member {mwf.xapplication.process.xform.datatemplate.line|mwf.xapplication.process.xform.datatablepc.line|mwf.xapplication.process.xform.datatablemobile.line}
         * @example
         * //获取当前组件所在数据模板/数据表格的行(条目)对象
         * var line = this.target.parentline;
         * //获取当前字段所在行下标
         * var index = line.getindex();
         * //获取当前字段所在条目的subject字段的值
         * var data = line.getmodule("subject").getdata();
         * //设置当前字段所在条目的subject字段的值
         * line.getmodule("subject").setdata("test1");
         */
        this.parentline = null;
    },
    /**
     * @summary 根据组件的校验设置进行校验。
     *  @param {string} [routename] - 可选,路由名称.
     *  @example
     *  if( !this.form.get('fieldid').validate() ){
     *      return false;
     *  }
     *  @return {boolean} 是否通过校验
     */
    validate: function (routename, opinion) {
        if( this.validationmode )this.validationmode();
        if( this.validation ){
            return this.validation(routename, opinion);
        }else{
            return true;
        }
    },
    validation: function (routename, opinion) {
        if (!this.isreadonly()){
            if (this.getinputdata){
                this._setbusinessdata(this.getinputdata("change"));
            }
            if (this.validationformat){
                if (!this.validationformat()) return false;
            }
            if (!this.validationconfig(routename, opinion)) return false;
            if (!this.json.validation) return true;
            if (!this.json.validation.code) return true;
            this.currentroutename = routename;
            var flag = this.form.macro.exec(this.json.validation.code, this);
            this.currentroutename = "";
            if (!flag) flag = mwf.xapplication.process.xform.lp.notvalidation;
            if (flag.tostring() !== "true") {
                this.notvalidationmode(flag);
                return false;
            }
        }
        return true;
    },
    savevalidation: function () {
        return true;
    },
    /**
     * 当前组件在数据源组件中时,可以通过此方法获取所在的上级数据源/子数据源/子数项组件.
     * @param {string} [type] 需要获取的类型,"source"为表示数据源,"subsource"表示子数据源,"subsourceitem"表示子数据项组件。
     * 如果该参数省略,则获取离当前组件最近的上述组件。
     * @return {source|subsource|subsourceitem}。
     * @example
     * var source = this.target.getsource(); //获取当前组件的所在子上级数据源/子数据源/子数项组件.
     * var data = source.data; //获取数据
     *
     * var source = this.form.get("fieldid").getsource("source"); //获取数据源组件
     * var data = source.data; //获取数据
     */
    getsource: function( type ){
        if( type ){
            var parent = this.node.getparent();
            while(parent && parent.get("mwftype")!= type ){
                parent = parent.getparent();
            }
            return (parent) ? parent.retrieve("module") : null;
        }else{
            return this._getsource();
        }
    },
    _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;
    },
    /**
     * 获取当前组件所在的祖先组件.
     * @param {string} [type] 需要获取的组件类型。
     * 如果该参数省略,则获取离当前组件最近的祖先组件。type有效值如下:
     * 
form- 表单
*
common- 通用组件
*
datatable- 数据表格
*
datatableline- 数据表格行
*
datatemplate- 数据模板
*
datatemplateline- 数据模板行
*
div- 容器组件
*
elcommon- element通用组件
*
elcontainer- element容器组件
*
subform- 子表单
*
source- 数据源组件
*
subsource- 子数据源
*
subsourceitem- 子数据项组件
*
tab- 分页组件
*
tabpage- 分页组件的某个分页
*
table- 表格
*
tabletd- 单元格
*
widget- 部件
* @param {function} [validatefunction] 进一步校验,参数为获取到匹配到类型的组件,返回false继续往上取对应类型的组件,返回true返回该组件。 * @return {mwf.xapplication.process.xform.$module}。 * @example * var module = this.target.getparentmodule(); //获取最近的祖先。 * * var datatemplateline = this.target.getparentmodule("datatemplateline"); //获取当前组件所在的数据模板行. * * var module = this.target.getparentmodule(null, function(module){ * return module.json.id === "div_1"; * }); //获取当前组件id为div_1的父组件。 */ getparentmodule: function( type, validatefunction ){ var lctype = ( type || "" ).tolowercase(); if( lctype === "form" )return this.form; var module, vm; var parent; if( ["datatableline","datatemplateline", "tabpage", "tab", "widget", "table"].contains( lctype ) ){ parent = this.node; }else{ parent = this.node.getparent(); } while(parent) { module = null; vm = null; var mwftype = parent.get("mwftype"); if( mwftype ){ module = parent.retrieve("module"); if( module ){ switch (lctype) { case "": vm = module; break; case "table": if( module.table )vm = module.table; break; case "widget": if( module.widget )vm = module.widget; break; case "tab": if( module.tab )vm = module.tab; break; case "tabpage": if( module.page && module.tab )vm = module.page; break; case "datatableline": if( module.parentline && module.parentdatatable )vm = module.parentline; break; case "datatemplateline": if( module.parentline && module.parentdatatemplate )vm = module.parentline; break; case "subsourceitem": if( mwftype.tolowercase() === "subsourceitem" )vm = module; break; case "tabletd": if( module.json.type === "table$td" )vm = module; break; default: if( module.json.type.tolowercase() === lctype )vm = module; break; } } if( vm ){ if( !validatefunction ){ return vm; }else if( validatefunction && validatefunction.call(this.form.macro, vm) ){ return vm; } } parent = parent.getparent(); }else{ parent = parent.getparent(); } } return null; }, isreadonly : function(){ return !!(this.readonly || this.json.isreadonly || this.form.json.isreadonly || this.issectionmergeread()); }, isallsectionshow: function(){ return this.json.showallsection && this.json.section === "yes" && this.issectiondata(); }, issectionmergeread: function(){ return this.json.sectionmerge === "read" && this.json.section !== "yes" && this.issectiondata() }, issectionmergeedit: function(){ return this.json.sectionmerge === "edit" && this.json.section !== "yes" && this.issectiondata() }, issectiondata: function(){ //数据是否经过区段处理 var data = this.getbusinessdatabyid(); return o2.typeof( data ) === "object"; }, getsortedsectiondata: function(){ //获取合并排序后的数据 var data = this.getbusinessdatabyid(); var array = []; for( var key in data ){ array.push({ sectionkey: key, key: key, data: data[key] }) } if( this.json.sectionmergesortscript && this.json.sectionmergesortscript.code){ array.sort( function(a, b){ this.form.macro.environment.event = { "a": a, "b": b }; var flag = this.form.macro.exec(this.json.sectionmergesortscript.code, this); this.form.macro.environment.event = null; return flag; }.bind(this)) } return array; }, //区段合并的区段值 _getmergesectionkey: function( data ){ switch (this.json.sectionkey){ case "person": return layout.desktop.session.user.id; case "unit": return (this.form.businessdata.task) ? this.form.businessdata.task.unit : ""; case "activity": return (this.form.businessdata.work) ? this.form.businessdata.work.activity : ""; case "splitvalue": return (this.form.businessdata.work) ? this.form.businessdata.work.splitvalue : ""; case "script": var d; if( this.json.sectionkeyscript && this.json.sectionkeyscript.code){ this.form.macro.environment.event = data; d = this.form.macro.exec(this.json.sectionkeyscript.code, this); this.form.macro.environment.event = null; }else{ d = ""; } return d; default: return ""; } }, getsectionkeywithmerge: function(data, callback){ switch (this.json.sectionkey) { case "person": if( !this.form.sectionkeypersonmap )this.form.sectionkeypersonmap = {}; if( this.form.sectionkeypersonmap[data.key] ){ callback(this.form.sectionkeypersonmap[data.key]); return; } //只获取一次。把callback存起来,等异步调用完成后一次性执行callback if( !this.form.sectionkeycallbackmap )this.form.sectionkeycallbackmap = {}; var map = this.form.sectionkeycallbackmap; if( !map[ data.key ] )map[ data.key ] = []; if( !map[ data.key ].length ){ promise.resolve( o2.actions.load("x_organization_assemble_express").personaction.listobject({ "personlist": [data.key] })).then(function(json){ var key = json.data.length ? json.data[0].name : data.key; this.form.sectionkeypersonmap[data.key] = key; while( map[ data.key ].length ){ map[ data.key ].shift()( key ); } }.bind(this)); } map[ data.key ].push( callback ); break; case "unit": callback( data.key.split("@")[0] ); break; case "activity": case "splitvalue": callback( data.key ); break; case "script": var d; if( this.json.sectionkeyscript && this.json.sectionkeyscript.code){ this.form.macro.environment.event = data; d = this.form.macro.exec(this.json.sectionkeyscript.code, this); this.form.macro.environment.event = null; }else{ d = ""; } callback( d ); break; } }, _loadmergereadnode: function(keephtml, position) { if (!keephtml) { this.node.empty(); this.node.set({ "nodeid": this.json.id, "mwftype": this.json.type }); } switch (this.json.mergetyperead) { case "htmlscript": this._loadmergereadnodebyhtml(); break; case "datascript": this._loadmergereadnodebydata(); break; default: this._loadmergereadnodebydefault(position); break; } }, _loadmergereadnodebyhtml: function(){ if (this.json.sectionmergereadhtmlscript && this.json.sectionmergereadhtmlscript.code) { var html = this.form.macro.exec(this.json.sectionmergereadhtmlscript.code, this); this.node.set("html", html); } }, _loadmergereadnodebydata: function(){ if (this.json.sectionmergereaddatascript && this.json.sectionmergereaddatascript.code) { var data = this.form.macro.exec(this.json.sectionmergereaddatascript.code, this); } }, _loadmergereadnodebydefault: function( position ){ var data = this.getsortedsectiondata(); var sectionnodestyles = this._parsestyles(this.json.sectionnodestyles); var sectionkeystyles = this._parsestyles(this.json.sectionkeystyles); var sectioncontentstyles = this._parsestyles(this.json.sectioncontentstyles); data.each(function(d){ var node = new element("div.mwf_sectionnode", { styles : sectionnodestyles }).inject(this.node, position || "bottom"); if( this.json.showsectionkey ){ var keynode = new element("div.mwf_sectionkey", { styles : sectionkeystyles }).inject(node); this.getsectionkeywithmerge( d, function (key) { if( o2.typeof(key) === "string" ){ keynode.set("text", key (this.json.keycontentseparator || "")); }else{ promise.resolve(key).then(function (k) { keynode.set("text", k (this.json.keycontentseparator || "")); }.bind(this)) } }.bind(this)); } var contentnode = new element("div.mwf_sectioncontent", { styles : sectioncontentstyles }).inject(node); this._loadmergereadcontentnode( contentnode, d ) }.bind(this)) }, _loadmergereadcontentnode: function( contentnode, data ){ contentnode.set("text", data.data) }, _loadmergeeditnode: function(){ if( this.json.mergetypeedit === "script" ){ this._loadmergeeditnodebyscript(); }else{ this._loadmergeeditnodebydefault(); } }, _loadmergeeditnodebyscript: function(){ if (this.json.sectionmergeeditscript && this.json.sectionmergeeditscript.code) { var data = this.form.macro.exec(this.json.sectionmergeeditscript.code, this); this._setbusinessdata( data ); this._loadnode(); } }, _loadmergeeditnodebydefault: function(){ var data = this.getsortedsectiondata(); data = data.map(function(d){ return d.data; }); this._setbusinessdata( data.join("") ); this._loadnode(); }, /** * @summary 隐藏组件. * @example * this.form.get("fieldid").hide(); //隐藏组件 */ hide: function(){ var dsp = this.node.getstyle("display"); if (dsp!=="none") this.node.store("mwf_display", dsp); this.node.setstyle("display", "none"); if (this.iconnode) this.iconnode.setstyle("display", "none"); }, /** * @summary 显示组件. * @example * this.form.get("fieldid").show(); //显示组件 */ show: function(){ var dsp = this.node.retrieve("mwf_display", dsp); this.node.setstyle("display", dsp); if (this.iconnode) this.iconnode.setstyle("display", "block"); }, load: function(){ this._loadmoduleevents(); if (this.fireevent("queryload")){ this._queryloaded(); this._loaduserinterface(); this._loadstyles(); this._loaddomevents(); //this._loadevents(); this._afterloaded(); this.fireevent("postload"); if( this.moduleselectag && typeof(this.moduleselectag.then) === "function" ){ this.moduleselectag.then(function () { this.fireevent("load"); this.isloaded = true; }.bind(this)) }else{ this.fireevent("load"); this.isloaded = true; } } }, _loaduserinterface: function(){ // this.node = this.node; }, _loadstyles: function(){ if (this.json.styles){ this.node.setstyles( this._parsestyles(this.json.styles) ); } // if (this.json.styles) object.each(this.json.styles, function(value, key){ // if ((value.indexof("x_processplatform_assemble_surface")!=-1 || value.indexof("x_portal_assemble_surface")!=-1 || value.indexof("x_cms_assemble_control")!=-1)){ // var host1 = mwf.actions.gethost("x_processplatform_assemble_surface"); // var host2 = mwf.actions.gethost("x_portal_assemble_surface"); // var host3 = mwf.actions.gethost("x_cms_assemble_control"); // if (value.indexof("/x_processplatform_assemble_surface")!==-1){ // value = value.replace("/x_processplatform_assemble_surface", host1 "/x_processplatform_assemble_surface"); // }else if (value.indexof("x_processplatform_assemble_surface")!==-1){ // value = value.replace("x_processplatform_assemble_surface", host1 "/x_processplatform_assemble_surface"); // } // if (value.indexof("/x_portal_assemble_surface")!==-1){ // value = value.replace("/x_portal_assemble_surface", host2 "/x_portal_assemble_surface"); // }else if (value.indexof("x_portal_assemble_surface")!==-1){ // value = value.replace("x_portal_assemble_surface", host2 "/x_portal_assemble_surface"); // } // if (value.indexof("/x_cms_assemble_control")!==-1){ // value = value.replace("/x_cms_assemble_control", host3 "/x_cms_assemble_control"); // }else if (value.indexof("x_cms_assemble_control")!==-1){ // value = value.replace("x_cms_assemble_control", host3 "/x_cms_assemble_control"); // } // value = o2.filter; // } // this.node.setstyle(key, value); // }.bind(this)); }, _parsestyles: function( styles ){ var s = {}; object.each(styles || {}, function(value, key){ if ((value.indexof("x_processplatform_assemble_surface")!=-1 || value.indexof("x_portal_assemble_surface")!=-1 || value.indexof("x_cms_assemble_control")!=-1)){ var host1 = mwf.actions.gethost("x_processplatform_assemble_surface"); var host2 = mwf.actions.gethost("x_portal_assemble_surface"); var host3 = mwf.actions.gethost("x_cms_assemble_control"); if (value.indexof("/x_processplatform_assemble_surface")!==-1){ value = value.replace("/x_processplatform_assemble_surface", host1 "/x_processplatform_assemble_surface"); }else if (value.indexof("x_processplatform_assemble_surface")!==-1){ value = value.replace("x_processplatform_assemble_surface", host1 "/x_processplatform_assemble_surface"); } if (value.indexof("/x_portal_assemble_surface")!==-1){ value = value.replace("/x_portal_assemble_surface", host2 "/x_portal_assemble_surface"); }else if (value.indexof("x_portal_assemble_surface")!==-1){ value = value.replace("x_portal_assemble_surface", host2 "/x_portal_assemble_surface"); } if (value.indexof("/x_cms_assemble_control")!==-1){ value = value.replace("/x_cms_assemble_control", host3 "/x_cms_assemble_control"); }else if (value.indexof("x_cms_assemble_control")!==-1){ value = value.replace("x_cms_assemble_control", host3 "/x_cms_assemble_control"); } value = o2.filter; } s[key] = value; }.bind(this)); return s; }, _loadmoduleevents : 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)); } } }.bind(this)); }, _loaddomevents: function(){ object.each(this.json.events, function(e, key){ if (e.code){ if (this.options.moduleevents.indexof(key)===-1){ this.node.addevent(key, function(event){ return this.form.macro.fire(e.code, this, event); }.bind(this)); } } }.bind(this)); }, _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{ this.node.addevent(key, function(event){ return (fun) ? fun(this, event) : null; }.bind(this)); } }, _getbusinessdata: function(id){ var v; if (this.json.section=="yes"){ v = this._getbusinesssectiondata(id); }else { if (this.json.type==="opinion"){ v = this._getbusinesssectiondatabyperson(id); }else{ // return this.form.businessdata.data[this.json.id] || ""; var value = this.getbusinessdatabyid(null, id); return (o2.typeof(value)!=="null") ? value : ""; //return this.getbusinessdatabyid() || ""; } } //if (o2.typeof(v)==="string") v = o2.dtxt(v); return v; }, _getbusinesssectiondata: function(id){ switch (this.json.sectionby){ case "person": return this._getbusinesssectiondatabyperson(id); case "unit": return this._getbusinesssectiondatabyunit(id); case "activity": return this._getbusinesssectiondatabyactivity(id); case "splitvalue": return this._getbusinesssectiondatabysplitvalue(id); case "script": return this._getbusinesssectiondatabyscript(((this.json.sectionbyscript) ? this.json.sectionbyscript.code : ""), id); default: // return this.form.businessdata.data[this.json.id] || ""; return this.getbusinessdatabyid(null, id) || ""; } }, _getbusinesssectiondatabyperson: function(id){ this.form.sectionlistobj[id||this.json.id] = layout.desktop.session.user.id; // var dataobj = this.form.businessdata.data[this.json.id]; var dataobj = this.getbusinessdatabyid(null, id); return (dataobj) ? (dataobj[layout.desktop.session.user.id] || "") : ""; }, _getbusinesssectiondatabyunit: function(id){ this.form.sectionlistobj[id || this.json.id] = ""; // var dataobj = this.form.businessdata.data[this.json.id]; var dataobj = this.getbusinessdatabyid(null, id); if (!dataobj) return ""; var key = (this.form.businessdata.task) ? this.form.businessdata.task.unit : ""; if (key) this.form.sectionlistobj[id||this.json.id] = key; return (key) ? (dataobj[key] || "") : ""; }, _getbusinesssectiondatabyactivity: function(id){ this.form.sectionlistobj[id||this.json.id] = ""; // var dataobj = this.form.businessdata.data[this.json.id]; var dataobj = this.getbusinessdatabyid(null, id); if (!dataobj) return ""; var key = (this.form.businessdata.work) ? this.form.businessdata.work.activity : ""; if (key) this.form.sectionlistobj[id||this.json.id] = key; return (key) ? (dataobj[key] || "") : ""; }, _getbusinesssectiondatabysplitvalue: function(id){ this.form.sectionlistobj[id||this.json.id] = ""; // var dataobj = this.form.businessdata.data[this.json.id]; var dataobj = this.getbusinessdatabyid(null, id); if (!dataobj) return ""; var key = (this.form.businessdata.work) ? this.form.businessdata.work.splitvalue : ""; if (key) this.form.sectionlistobj[id||this.json.id] = key; return (key) ? (dataobj[key] || "") : ""; }, _getbusinesssectiondatabyscript: function(code, id){ this.form.sectionlistobj[id||this.json.id] = ""; // var dataobj = this.form.businessdata.data[this.json.id]; var dataobj = this.getbusinessdatabyid(null, id); if (!dataobj) return ""; var key = this.form.macro.exec(code, this); if (key) this.form.sectionlistobj[id||this.json.id] = key; return (key) ? (dataobj[key] || "") : ""; }, _setenvironmentdata: function(v){ if (this.json.section=="yes"){ this._setenvironmentsectiondata(v); }else { if (this.json.type==="opinion"){ this._setenvironmentsectiondatabyperson(v); }else{ this.setenvironmentdatabyid(v); } } }, _setenvironmentsectiondata: function(v){ switch (this.json.sectionby){ case "person": var key = layout.desktop.session.user.id; this._setenvironmentsectiondatabykey(key, v); break; case "unit": var key = (this.form.businessdata.task) ? this.form.businessdata.task.unit : ""; this._setenvironmentsectiondatabykey(key, v); break; case "activity": var key = (this.form.businessdata.work) ? this.form.businessdata.work.activity : ""; this._setenvironmentsectiondatabykey(key, v); break; case "splitvalue": var key = (this.form.businessdata.work) ? this.form.businessdata.work.splitvalue : ""; this._setenvironmentsectiondatabykey(key, v); break; case "script": var key = this.form.macro.exec(this.json.sectionbyscript.code, this); this._setenvironmentsectiondatabykey(key, v); break; default: this.setenvironmentdatabyid(v); } }, _setenvironmentsectiondatabykey: function(key, v){ if (key){ var evdata = this.getbusinessdatabyid(this.form.macro.environment.data); var evdata; if (!evdata){ evdata = this.setenvironmentdatabyid({}); } if (!evdata.hasownproperty(key)){ evdata.add(key, v); }else{ evdata[key] = v; } } }, setenvironmentdatabyid: function(v){ //对id类似于 xx..0..xx 的字段进行拆分 var evdata = this.form.macro.environment.data; if(this.json.id.indexof("..") < 1){ if (!evdata.hasownproperty(this.json.id)){ evdata.add(this.json.id, v); }else{ evdata[this.json.id] = v; } }else{ var idlist = this.json.id.split(".."); idlist = idlist.map( function(d){ return d.test(/^\d $/) ? d.toint() : d; }); //var data = this.form.businessdata.data; var lastindex = idlist.length - 1; for(var i=0; i<=lastindex; i ){ var id = idlist[i]; if( !id && id !== 0 )return; if( i === lastindex ){ if (!evdata.hasownproperty(id)){ evdata.add(id, v); }else{ evdata[id] = v; } }else{ var nexid = idlist[i 1]; if(o2.typeof(nexid) === "number"){ //下一个id是数字 if( !evdata[id] && o2.typeof(evdata[id]) !== "array" ){ evdata.add(id, []); } if( nexid > evdata[id].length ){ //超过了最大下标,丢弃 return; } }else{ //下一个id是字符串 if( !evdata[id] || o2.typeof(evdata[id]) !== "object"){ evdata.add(id, {}); } } evdata = evdata[id]; } } } return evdata; }, _setbusinessdata: function(v, id){ //if (o2.typeof(v)==="string") v = o2.txt(v); if (this.json.section=="yes"){ this._setbusinesssectiondata(v, id); }else { if (this.json.type==="opinion"){ this._setbusinesssectiondatabyperson(v, id); }else{ this.setbusinessdatabyid(v, id); if (this.json.istitle) this.form.businessdata.data.$work.title = v; } } }, _setbusinesssectiondata: function(v, id){ switch (this.json.sectionby){ case "person": this._setbusinesssectiondatabyperson(v, id); break; case "unit": this._setbusinesssectiondatabyunit(v, id); break; case "activity": this._setbusinesssectiondatabyactivity(v, id); break; case "splitvalue": this._setbusinesssectiondatabysplitvalue(v, id); break; case "script": this._setbusinesssectiondatabyscript(this.json.sectionbyscript.code, v, id); break; default: this.setbusinessdatabyid(v, id); } }, _setbusinesssectiondatabyperson: function(v, id){ var key = layout.desktop.session.user.id; this._setbusinesssectiondatabykey(key, v, id); }, _setbusinesssectiondatabyunit: function(v, id){ var key = (this.form.businessdata.task) ? this.form.businessdata.task.unit : ""; this._setbusinesssectiondatabykey(key, v, id); }, _setbusinesssectiondatabyactivity: function(v, id){ var key = (this.form.businessdata.work) ? this.form.businessdata.work.activity : ""; this._setbusinesssectiondatabykey(key, v, id); }, _setbusinesssectiondatabysplitvalue: function(v, id){ var key = (this.form.businessdata.work) ? this.form.businessdata.work.splitvalue : ""; this._setbusinesssectiondatabykey(key, v, id); }, _setbusinesssectiondatabyscript: function(code, v, id){ var key = this.form.macro.exec(code, this); this._setbusinesssectiondatabykey(key, v, id); }, _setbusinesssectiondatabykey: function(key, v, id){ if (key){ var dataobj = this.getbusinessdatabyid(null, id); var evdata; if (!dataobj){ dataobj = {}; evdata = this.setbusinessdatabyid(dataobj, id); } dataobj[key] = v; if (evdata) evdata.check(key, v); } }, getbusinessdatabyid: function(d, id){ var data = d || this.form.businessdata.data; var thisid = id || this.json.id; //对id类似于 xx..0..xx 的字段进行拆分 if(thisid.indexof("..") < 1){ return data[thisid]; }else{ var idlist = thisid.split(".."); idlist = idlist.map( function(d){ return d.test(/^\d $/) ? d.toint() : d; }); var lastindex = idlist.length - 1; for(var i=0; i<=lastindex; i ){ var id = idlist[i]; if( !id && id !== 0 )return null; if( ["object","array"].contains(o2.typeof(data)) ){ if( i === lastindex ){ return data[id]; }else{ data = data[id]; } }else{ return null; } } } }, _checkevdata: function(evdata, id, v){ switch (o2.typeof(evdata)){ case "array": break; default: evdata.check(id, v); } }, setbusinessdatabyid: function(v, id){ //对id类似于 xx..0..xx 的字段进行拆分 var evdata = this.form.macro.environment.data; var data = this.form.businessdata.data; var thisid = id || this.json.id; if(thisid.indexof("..") < 1){ data[thisid] = v; this._checkevdata(evdata, thisid, v); //this.form.businessdata.data[this.json.id] = v; }else{ var idlist = thisid.split(".."); idlist = idlist.map( function(d){ return d.test(/^\d $/) ? d.toint() : d; }); //var data = this.form.businessdata.data; var lastindex = idlist.length - 1; for(var i=0; i<=lastindex; i ){ var id = idlist[i]; if( !id && id !== 0 )return; if( i === lastindex ){ data[id] = v; //evdata.check(id, v); this._checkevdata(evdata, id, v); }else{ var nexid = idlist[i 1]; if(o2.typeof(nexid) === "number"){ //下一个id是数字 if( !data[id] && o2.typeof(data[id]) !== "array" ){ data[id] = []; //evdata.check(id, []); this._checkevdata(evdata, id, []); } if( nexid > data[id].length ){ //超过了最大下标,丢弃 return; } }else{ //下一个id是字符串 if( !data[id] || o2.typeof(data[id]) !== "object"){ data[id] = {}; //evdata.check(id, {}); this._checkevdata(evdata, id, {}); } } data = data[id]; evdata = evdata[id]; } } } return evdata; }, _queryloaded: function(){}, _afterloaded: function(){}, setvalue: function(){ }, focus: function(){ this.node.focus(); }, _getmodulebypath: function( path ){ /* 注: 系统的数据中允许多层路径,id上通过..来区分层次: 1、单层或者是最外层,填"fieldid",表示表单上的直接组件。 2、如果有多层数据模板,"./fieldid"表示和当前组件id同层次的组件,"../fieldid"表示和上一层组件同层次的组件,以此类推。 3、如果有多层数据模板,也可通过"datatemplateid.*.datatemplateid2.*.fieldid"来表示全层次路径。datatemplateid表示第一层数据模板的id,datatemplateid2表示第二层的id。 */ if(!path)return; var idlist = this.json.id.split(".."); if( path.contains("*") ){ //允许path中包含*,替代当前path的层次 var paths = path.split("."); for( var i=0; i level*2 ){ for( var i=0; i 0)idlist_copy.pop(); } path = idlist_copy.join("..") ".." lastname; }else{ idlist_copy[idlist_copy.length-1] = lastname; path = idlist_copy.join("..") } } return this.form.all[path]; } });
网站地图