if (!mwf.xscript || !mwf.xscript.pageenvironment) { mwf.xscript = mwf.xscript || {}; mwf.xscript.pageenvironment = function (ev) { var _data = ev.data; var _form = ev.form; var _forms = ev.forms; this.apptype = "portal"; this.library = common; //this.library.version = "4.0"; //data var getjsondata = function (jdata) { return new mwf.xscript.jsondata(jdata, function (data, key, _self) { var p = { "getkey": function () { return key; }, "getparent": function () { return _self; } }; while (p && !_forms[p.getkey()]) p = p.getparent(); var k = (p) ? p.getkey() : ""; if (k) if (_forms[k]) if (_forms[k].resetdata) _forms[k].resetdata(); //if (p) if (p.getkey()) if (_forms[p.getkey()]) _forms[p.getkey()].resetdata(); }); }; this.setdata = function (data) { this.data = getjsondata(data); this.data.save = function (callback) { var formdata = { "data": data, "sectionlist": _form.getsectionlist() }; form.workaction.savedata(function (json) { if (callback) callback(); }.bind(this), null, work.id, jdata); } }; this.setdata(_data); //workcontext this.workcontext = { "gettask": function () { return ev.task; }, "getwork": function () { return ev.work || ev.workcompleted; }, "getactivity": function () { return ev.activity; }, "gettasklist": function () { return ev.tasklist; }, "getcontrol": function () { return ev.control; }, "getworkloglist": function () { return ev.workloglist; }, "getattachmentlist": function () { return ev.attachmentlist; }, "getroutelist": function () { return (ev.task) ? ev.task.routenamelist : null; }, "getinquiredroutelist": function () { return null; }, "settitle": function (title) { //if (!this.workaction){ // mwf.require("mwf.xscript.actions.workactions", null, false); // this.workaction = new mwf.xscript.actions.workactions(); //} //this.workaction.settitle(ev.work.id, {"title": title}); } }; var _redefineworkproperties = function (work) { if (work) { work.creatorpersondn = work.creatorperson; work.creatorunitdn = work.creatorunit; work.creatorunitdnlist = work.creatorunitlist; work.creatoridentitydn = work.creatoridentity; var o = { "creatorperson": { "get": function () { return this.creatorpersondn.substring(0, this.creatorpersondn.indexof("@")); } }, "creatorunit": { "get": function () { return this.creatorunitdn.substring(0, this.creatorunitdn.indexof("@")); } }, "creatordepartment": { "get": function () { return this.creatorunitdn.substring(0, this.creatorunitdn.indexof("@")); } }, "creatoridentity": { "get": function () { return this.creatoridentitydn.substring(0, this.creatoridentitydn.indexof("@")); } }, "creatorunitlist": { "get": function () { var v = []; this.creatorunitdnlist.each(function (dn) { v.push(dn.substring(0, dn.indexof("@"))) }); return v; } }, "creatorcompany": { "get": function () { return this.creatorunitlist[0] } } }; mwf.defineproperties(work, o); } return work; }; var _redefinetaskproperties = function (task) { if (task) { task.persondn = task.person; task.unitdn = task.unit; task.unitdnlist = task.unitlist; task.identitydn = task.identity; var o = { "person": { "get": function () { return this.persondn.substring(0, this.persondn.indexof("@")); } }, "unit": { "get": function () { return this.unitdn.substring(0, this.unitdn.indexof("@")); } }, "department": { "get": function () { return this.unitdn.substring(0, this.unitdn.indexof("@")); } }, "identity": { "get": function () { return this.identitydn.substring(0, this.identitydn.indexof("@")); } }, "unitlist": { "get": function () { var v = []; this.unitdnlist.each(function (dn) { v.push(dn.substring(0, dn.indexof("@"))) }); return v; } }, "company": { "get": function () { return this.unitlist[0]; } } }; mwf.defineproperties(task, o); } return task; }; _redefineworkproperties(this.workcontext.getwork()); _redefinetaskproperties(_redefineworkproperties(this.workcontext.gettask())); //dict this.dict = mwf.xscript.createdict(_form.json.application, "portal"); //org var orgactions = null; var getorgactions = function () { if (!orgactions) { mwf.require("mwf.xscript.actions.unitactions", null, false); orgactions = new mwf.xscript.actions.unitactions(); } }; var getnameflag = function (name) { var t = typeof(name); if (t === "array") { var v = []; name.each(function (id) { v.push((typeof(id) === "object") ? (id.distinguishedname || id.id || id.unique || id.name) : id); }); return v; } else { return [(t === "object") ? (name.distinguishedname || name.id || name.unique || name.name) : name]; } }; this.org = { //群组*************** //获取群组--返回群组的对象数组 getgroup: function (name, async) { getorgactions(); var data = {"grouplist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listgroup(data, cb, null, !!async); return (!!async) ? promise : v; // var v = null; // orgactions.listgroup(data, function(json){v = json.data;}, null, false); // return (v && v.length===1) ? v[0] : v; }, //查询下级群组--返回群组的对象数组 //nested 布尔 true嵌套下级;false直接下级;默认false; listsubgroup: function (name, nested, async) { getorgactions(); var data = {"grouplist": getnameflag(name)}; var v = null; // var cb = ((async && o2.typeof(async)=="function") ? (async.isag ? async : async.ag()) : null) || function(json){ // v = json.data; // return v; // }.ag().catch(function(json){ return json; }); var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise; if (nested) { promise = orgactions.listsubgroupnested(data, cb, null, !!async); } else { promise = orgactions.listsubgroupdirect(data, cb, null, !!async); } return (!!async) ? promise : v; // var v = null; // if (nested){ // orgactions.listsubgroupnested(data, function(json){v = json.data;}, null, false); // }else{ // orgactions.listsubgroupdirect(data, function(json){v = json.data;}, null, false); // } // return v; }, //查询上级群组--返回群组的对象数组 //nested 布尔 true嵌套上级;false直接上级;默认false; listsupgroup: function (name, nested, async) { getorgactions(); var data = {"grouplist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise if (nested) { var promise = orgactions.listsupgroupnested(data, cb, null, !!async); } else { var promise = orgactions.listsupgroupdirect(data, cb, null, !!async); } return (!!async) ? promise : v; // var v = null; // if (nested){ // orgactions.listsupgroupnested(data, function(json){v = json.data;}, null, false); // }else{ // orgactions.listsupgroupdirect(data, function(json){v = json.data;}, null, false); // } // return v; }, //人员所在群组(嵌套)--返回群组的对象数组 listgroupwithperson: function (name, async) { getorgactions(); var data = {"personlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listgroupwithperson(data, cb, null, !!async); return (!!async) ? promise : v; // var v = null; // orgactions.listgroupwithperson(data, function(json){v = json.data;}, null, false); // return v; }, //身份所在群组(嵌套)--返回群组的对象数组 listgroupwithidentity:function(identity, async){ getorgactions(); var data = {"identitylist": getnameflag(identity)}; var v = null; var cb = function(json){ v = json.data; if (async && o2.typeof(async)=="function") return async(v); return v; }; var promise = orgactions.listgroupwithidentity(data, cb, null, !!async); return (!!async) ? promise : v; }, //群组是否拥有角色--返回true, false grouphasrole: function (name, role, async) { getorgactions(); nameflag = (typeof(name) === "object") ? (name.distinguishedname || name.id || name.unique || name.name) : name; var data = {"group": nameflag, "rolelist": getnameflag(role)}; var v = false; var cb = function (json) { v = json.data.value; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.grouphasrole(data, cb, null, !!async); return (!!async) ? promise : v; // var v = false; // orgactions.grouphasrole(data, function(json){v = json.data.value;}, null, false); // return v; }, //角色*************** //获取角色--返回角色的对象数组 getrole: function (name, async) { getorgactions(); var data = {"rolelist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listrole(data, cb, null, !!async); return (!!async) ? promise : v; // var v = null; // orgactions.listrole(data, function(json){v = json.data;}, null, false); // return (v && v.length===1) ? v[0] : v; }, //人员所有角色(嵌套)--返回角色的对象数组 listrolewithperson: function (name, async) { getorgactions(); var data = {"personlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listrolewithperson(data, cb, null, !!async); return (!!async) ? promise : v; // var v = null; // orgactions.listrolewithperson(data, function(json){v = json.data;}, null, false); // return v; }, //人员*************** //人员是否拥有角色--返回true, false personhasrole: function (name, role, async) { getorgactions(); nameflag = (typeof(name) === "object") ? (name.distinguishedname || name.id || name.unique || name.name) : name; var data = {"person": nameflag, "rolelist": getnameflag(role)}; var v = false; var cb = function (json) { v = json.data.value; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.personhasrole(data, cb, null, !!async); return (!!async) ? promise : v; // var v = false; // orgactions.personhasrole(data, function(json){v = json.data.value;}, null, false); // return v; }, //获取人员,附带身份,身份所在的组织,个人所在群组,个人拥有角色. getpersondata: function(name, async){ getorgactions(); var v = null; var cb = function(json){ v = json.data; if (async && o2.typeof(async)=="function") return async(v); return v; }; var promise = orgactions.getperson(null, cb, null, !!async, {"flag": name}); return (!!async) ? promise : v; }, //获取人员--返回人员的对象数组 getperson: function (name, async, findcn) { getorgactions(); var data = {"personlist": getnameflag(name)}; if( o2.typeof(findcn) === "boolean"){ data.usenamefind = findcn; } var v = null; var cb = function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listperson(data, cb, null, !!async); return (!!async) ? promise : v; // var v = null; // orgactions.listperson(data, function(json){v = json.data;}, null, false); // return (v && v.length===1) ? v[0] : v; }, //查询下级人员--返回人员的对象数组 //nested 布尔 true嵌套下级;false直接下级;默认false; listsubperson: function (name, nested, async) { getorgactions(); var data = {"personlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise; if (nested) { promise = orgactions.listpersonsubnested(data, cb, null, !!async); } else { promise = orgactions.listpersonsubdirect(data, cb, null, !!async); } return (!!async) ? promise : v; }, //查询上级人员--返回人员的对象数组 //nested 布尔 true嵌套上级;false直接上级;默认false; listsupperson: function (name, nested, async) { getorgactions(); var data = {"personlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise; if (nested) { promise = orgactions.listpersonsupnested(data, cb, null, !!async); } else { promise = orgactions.listpersonsupdirect(data, cb, null, !!async); } return (!!async) ? promise : v; }, //获取群组的所有人员--返回人员的对象数组 listpersonwithgroup: function (name, async) { getorgactions(); var data = {"grouplist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listpersonwithgroup(data, cb, null, !!async); return (!!async) ? promise : v; }, //获取角色的所有人员--返回人员的对象数组 listpersonwithrole: function (name, async) { getorgactions(); var data = {"rolelist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise promise = orgactions.listpersonwithrole(data, cb, null, !!async); return (!!async) ? promise : v; }, //获取身份的所有人员--返回人员的对象数组 listpersonwithidentity: function (name, async) { getorgactions(); var data = {"identitylist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listpersonwithidentity(data, cb, null, !!async); return (!!async) ? promise : v; }, //获取身份的所有人员--返回人员的对象数组或人员对象 getpersonwithidentity: function (name, async) { getorgactions(); var data = {"identitylist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listpersonwithidentity(data, cb, null, !!async); return (!!async) ? promise : v; }, //查询组织成员的人员--返回人员的对象数组 //nested 布尔 true嵌套的所有成员;false直接成员;默认false; listpersonwithunit: function (name, nested, async) { getorgactions(); var data = {"unitlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise; if (nested) { promise = orgactions.listpersonwithunitnested(data, cb, null, !!async); } else { promise = orgactions.listpersonwithunitdirect(data, cb, null, !!async); } return (!!async) ? promise : v; }, //根据属性查询人员--返回人员的对象数组 //name string 属性名 //value string 属性值 listpersonwithattribute: function (name, value, async) { getorgactions(); var data = {"name": name, "attribute": value}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listpersonwithattribute(data, cb, null, !!async); return (!!async) ? promise : v; }, //根据属性查询人员--返回人员的全称数组 //name string 属性名 //value string 属性值 listpersonnamewithattribute: function (name, value, async) { getorgactions(); var data = {"name": name, "attribute": value}; var v = null; var cb = function (json) { v = json.data.personlist; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listpersonwithattributevalue(data, cb, null, !!async); return (!!async) ? promise : v; }, //人员属性************ //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个) appendpersonattribute: function (person, attr, values, success, failure, async) { getorgactions(); var personflag = (typeof(person) === "object") ? (person.distinguishedname || person.id || person.unique || person.name) : person; var data = {"attributelist": values, "name": attr, "person": personflag}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.appendpersonattribute(data, cb, null, !!async); return (!!async) ? promise : v; // var cb = function(json){ // if (success) return success(json); // }.ag().catch(function(xhr, text, error){ // if (failure) return failure(xhr, text, error); // }); // // orgactions.appendpersonattribute(data, cb, null, !!async); }, //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个) setpersonattribute: function (person, attr, values, success, failure, async) { getorgactions(); var personflag = (typeof(person) === "object") ? (person.distinguishedname || person.id || person.unique || person.name) : person; var data = {"attributelist": values, "name": attr, "person": personflag}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.setpersonattribute(data, cb, null, !!async); return (!!async) ? promise : v; // var cb = function(json){ // if (success) return success(json); // }.ag().catch(function(xhr, text, error){ // if (failure) return failure(xhr, text, error); // }); // // orgactions.setpersonattribute(data, cb, null, !!async); }, //获取人员属性值 getpersonattribute: function (person, attr, async) { getorgactions(); var personflag = (typeof(person) === "object") ? (person.distinguishedname || person.id || person.unique || person.name) : person; var data = {"name": attr, "person": personflag}; var v = null; var cb = function (json) { v = json.data.attributelist; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.getpersonattribute(data, cb, null, !!async); return (!!async) ? promise : v; }, //列出人员所有属性的名称 listpersonattributename: function (name, async) { getorgactions(); var data = {"personlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data.namelist; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listpersonattributename(data, cb, null, !!async); return (!!async) ? promise : v; }, //列出人员的所有属性 listpersonallattribute: function (name, async) { getorgactions(); var data = {"personlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listpersonallattribute(data, cb, null, !!async); return (!!async) ? promise : v; }, //身份********** //获取身份 getidentity: function (name, async) { getorgactions(); var data = {"identitylist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listidentity(data, cb, null, !!async); return (!!async) ? promise : v; }, //列出人员的身份 listidentitywithperson: function (name, async, findcn) { getorgactions(); var data = {"personlist": getnameflag(name)}; if( o2.typeof(findcn) === "boolean"){ data.usenamefind = findcn; } var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listidentitywithperson(data, cb, null, !!async); return (!!async) ? promise : v; }, //查询组织成员身份--返回身份的对象数组 //nested 布尔 true嵌套的所有成员;false直接成员;默认false; listidentitywithunit: function (name, nested, async) { getorgactions(); var data = {"unitlist": getnameflag(name)}; var v = null; // var cb = function(json){ // v = json.data; // if (async && o2.typeof(async)=="function") return async(v); // return v; // }.ag().catch(function(json){ return json; }); var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var method = (nested) ? "listidentitywithunitnested" : "listidentitywithunitdirect"; var promise = orgactions[method](data, cb, null, !!async); promise.name = "org"; // // if (nested){ // orgactions.listidentitywithunitnested(data, cb, null, !!async); // }else{ // orgactions.listidentitywithunitdirect(data, cb, null, !!async); // } return (!!async) ? promise : v; }, //组织********** //获取组织 getunit: function (name, async, findcn) { getorgactions(); var data = {"unitlist": getnameflag(name)}; if( o2.typeof(findcn) === "boolean"){ data.usenamefind = findcn; } var v = null; var cb = function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listunit(data, cb, null, !!async); return (!!async) ? promise : v; }, //查询组织的下级--返回组织的对象数组 //nested 布尔 true嵌套下级;false直接下级;默认false; listsubunit: function (name, nested, async) { getorgactions(); var data = {"unitlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise; if (nested) { promise = orgactions.listunitsubnested(data, cb, null, !!async); } else { promise = orgactions.listunitsubdirect(data, cb, null, !!async); } return (!!async) ? promise : v; }, //查询组织的上级--返回组织的对象数组 //nested 布尔 true嵌套上级;false直接上级;默认false; //async 布尔 true异步请求 listsupunit: function (name, nested, async) { getorgactions(); var data = {"unitlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise; if (nested) { promise = orgactions.listunitsupnested(data, cb, null, !!async); } else { promise = orgactions.listunitsupdirect(data, cb, null, !!async); } return (!!async) ? promise : v; // if (callback){ // if (nested){ // orgactions.listunitsupnested(data, function(json){v = json.data; o2.runcallback(callback, "success", [v], this);}); // }else{ // orgactions.listunitsupdirect(data, function(json){v = json.data; o2.runcallback(callback, "success", [v], this);}); // } // }else{ // var v = null; // if (nested){ // orgactions.listunitsupnested(data, function(json){v = json.data;}, null, false); // }else{ // orgactions.listunitsupdirect(data, function(json){v = json.data;}, null, false); // } // return v; // } }, //根据个人身份获取组织 //flag 数字 表示获取第几层的组织 // 字符串 表示获取指定类型的组织 // 空 表示获取直接所在的组织 getunitbyidentity: function (name, flag, async) { getorgactions(); var getunitmethod = "current"; var v; if (flag) { if (typeof(flag) === "string") getunitmethod = "type"; if (typeof(flag) === "number") getunitmethod = "level"; } var cb; var promise; switch (getunitmethod) { case "current": var data = {"identitylist": getnameflag(name)}; // var cb = ((async && o2.typeof(async)=="function") ? (async.isag ? async : async.ag()) : null) || function(json){ // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v; // }.ag().catch(function(json){ return json; }); cb = function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v; if (async && o2.typeof(async) == "function") return async(v); return v; }; promise = orgactions.listunitwithidentity(data, cb, null, !!async); break; case "type": var data = { "identity": (typeof(name) === "object") ? (name.distinguishedname || name.id || name.unique || name.name) : name, "type": flag }; cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; // var cb = ((async && o2.typeof(async)=="function") ? (async.isag ? async : async.ag()) : null) || function(json){ // v = json.data; return v; // }.ag().catch(function(json){ return json; }); promise = orgactions.getunitwithidentityandtype(data, cb, null, !!async); break; case "level": var data = { "identity": (typeof(name) === "object") ? (name.distinguishedname || name.id || name.unique || name.name) : name, "level": flag }; cb = function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v; if (async && o2.typeof(async) == "function") return async(v); return v; }; // var cb = ((async && o2.typeof(async)=="function") ? (async.isag ? async : async.ag()) : null) || function(json){ // v = json.data; return v; // }.ag().catch(function(json){ return json; }); promise = orgactions.getunitwithidentityandlevel(data, cb, null, !!async); break; } return (!!async) ? promise : v; }, //列出身份所在组织的所有上级组织 listallsupunitwithidentity: function (name, async) { getorgactions(); var data = {"identitylist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listunitsupnestedwithidentity(data, cb, null, !!async); return (!!async) ? promise : v; }, //获取人员所在的所有组织 listunitwithperson: function (name, async) { getorgactions(); var data = {"personlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listunitwithperson(data, cb, null, !!async); return (!!async) ? promise : v; }, //列出人员所在组织的所有上级组织 listallsupunitwithperson: function (name, async) { getorgactions(); var data = {"personlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listunitsupnestedwithperson(data, cb, null, !!async); return (!!async) ? promise : v; }, //根据组织属性,获取所有符合的组织 listunitwithattribute: function (name, attribute, async) { getorgactions(); var data = {"name": name, "attribute": attribute}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; promise = orgactions.listunitwithattribute(data, cb, null, !!async); return (!!async) ? promise : v; }, //根据组织职务,获取所有符合的组织 listunitwithduty: function (name, id, async) { getorgactions(); var data = { "name": name, "identity": (typeof(id) === "object") ? (id.distinguishedname || id.id || id.unique || id.name) : id }; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listunitwithduty(data, cb, null, !!async); return (!!async) ? promise : v; }, //组织职务*********** //获取指定的组织职务的身份 getduty: function (duty, id, async) { getorgactions(); var data = { "name": duty, "unit": (typeof(id) === "object") ? (id.distinguishedname || id.id || id.unique || id.name) : id }; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.getduty(data, cb, null, !!async); return (!!async) ? promise : v; }, //获取身份的所有职务名称 listdutynamewithidentity: function (name, async) { getorgactions(); var data = {"identitylist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data.namelist; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listdutynamewithidentity(data, cb, null, !!async); return (!!async) ? promise : v; }, //获取组织的所有职务名称 listdutynamewithunit: function (name, async) { getorgactions(); var data = {"unitlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data.namelist; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listdutynamewithunit(data, cb, null, !!async); return (!!async) ? promise : v; }, //获取组织的所有职务 listunitallduty: function (name, async) { getorgactions(); var data = {"unitlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listunitallduty(data, cb, null, !!async); return (!!async) ? promise : v; }, //列出顶层组织 listtopunit: function (async) { var action = mwf.actions.get("x_organization_assemble_control"); var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = action.listtopunit(cb, null, !!async); return (!!async) ? promise : v; }, //组织属性************** //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个) appendunitattribute: function (unit, attr, values, success, failure, async) { getorgactions(); var unitflag = (typeof(unit) === "object") ? (unit.distinguishedname || unit.id || unit.unique || unit.name) : unit; var data = {"attributelist": values, "name": attr, "unit": unitflag}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.appendunitattribute(data, cb, null, !!async); return (!!async) ? promise : v; // var cb = function(json){ // if (success) return success(json); // }.ag().catch(function(xhr, text, error){ // if (failure) return failure(xhr, text, error); // }); // // orgactions.appendpersonattribute(data, cb, null, !!async); // orgactions.appendunitattribute(data, function(json){ // if (json.data.value){ // if (success) success(); // }else{ // if (failure) failure(null, "", "append values failed"); // } // }, function(xhr, text, error){ // if (failure) failure(xhr, text, error); // }, false); }, //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个) setunitattribute: function (unit, attr, values, success, failure, async) { getorgactions(); var unitflag = (typeof(unit) === "object") ? (unit.distinguishedname || unit.id || unit.unique || unit.name) : unit; var data = {"attributelist": values, "name": attr, "unit": unitflag}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.setunitattribute(data, cb, null, !!async); return (!!async) ? promise : v; // var cb = function(json){ // if (success) return success(json); // }.ag().catch(function(xhr, text, error){ // if (failure) return failure(xhr, text, error); // }); // orgactions.setunitattribute(data, cb, null, !!async); // orgactions.setunitattribute(data, function(json){ // if (json.data.value){ // if (success) success(); // }else{ // if (failure) failure(null, "", "append values failed"); // } // }, function(xhr, text, error){ // if (failure) failure(xhr, text, error); // }, false); }, //获取组织属性值 getunitattribute: function (unit, attr, async) { getorgactions(); var unitflag = (typeof(unit) === "object") ? (unit.distinguishedname || unit.id || unit.unique || unit.name) : unit; var data = {"name": attr, "unit": unitflag}; var v = null; var cb = function (json) { v = json.data.attributelist; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.getunitattribute(data, cb, null, !!async); return (!!async) ? promise : v; }, //列出组织所有属性的名称 listunitattributename: function (name, async) { getorgactions(); var data = {"unitlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data.namelist; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listunitattributename(data, cb, null, !!async); return (!!async) ? promise : v; }, //列出组织的所有属性 listunitallattribute: function (name, async) { getorgactions(); var data = {"unitlist": getnameflag(name)}; var v = null; var cb = function (json) { v = json.data; if (async && o2.typeof(async) == "function") return async(v); return v; }; var promise = orgactions.listunitallattribute(data, cb, null, !!async); return (!!async) ? promise : v; } }; this.action = (function () { var actions = []; return function (root, json) { var action = actions[root] || (actions[root] = new mwf.xdesktop.actions.restactions("", root, "")); action.getactions = function (callback) { if (!this.actions) this.actions = {}; object.merge(this.actions, json); if (callback) callback(); }; this.invoke = function (option) { action.invoke(option) } } })(); // this.service = { // "jaxwsclient": {}, // "jaxrsclient": {} // }; var lookupaction = null; var getlookupaction = function (callback) { if (!lookupaction) { mwf.require("mwf.xdesktop.actions.restactions", function () { lookupaction = new mwf.xdesktop.actions.restactions("", "x_processplatform_assemble_surface", ""); lookupaction.getactions = function (actioncallback) { this.actions = { //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"}, //"getview": {"uri": "/jaxrs/view/{id}/design"} "lookup": { "uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method": "put" }, "getview": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"} }; if (actioncallback) actioncallback(); } if (callback) callback(); }); } else { if (callback) callback(); } }; this.view = { "lookup": function (view, callback, async) { var filterlist = {"filterlist": (view.filter || null)}; return mwf.actions.load("x_query_assemble_surface").viewaction.executewithquery(view.view, view.application, filterlist, function (json) { var data = { "grid": json.data.grid || json.data.groupgrid, "groupgrid": json.data.groupgrid }; if (callback) callback(data); return data; }, null, async); }, "lookupv1": function (view, callback) { getlookupaction(function () { lookupaction.invoke({ "name": "lookup", "async": true, "parameter": {"view": view.view, "application": view.application}, "success": function (json) { var data = { "grid": json.data.grid, "groupgrid": json.data.groupgrid }; if (callback) callback(data); }.bind(this) }); }.bind(this)); }, "select": function (view, callback, options) { if (view.view) { var viewjson = { "application": view.application || _form.json.application, "viewname": view.view || "", "istitle": (view.istitle === false) ? "no" : "yes", "select": (view.ismulti === false) ? "single" : "multi", "filter": view.filter }; if (!options) options = {}; options.width = view.width; options.height = view.height; options.title = view.caption; var width = options.width || "700"; var height = options.height || "400"; if (layout.mobile) { var size = document.body.getsize(); width = size.x; height = size.y; options.style = "viewmobile"; } width = width.toint(); height = height.toint(); var size = _form.app.content.getsize(); var x = (size.x - width) / 2; var y = (size.y - height) / 2; if (x < 0) x = 0; if (y < 0) y = 0; if (layout.mobile) { x = 20; y = 0; } var _self = this; mwf.require("mwf.xdesktop.dialog", function () { var dlg = new mwf.xdesktop.dialog({ "title": options.title || "select view", "style": options.style || "view", "top": y, "left": x - 20, "fromtop": y, "fromleft": x - 20, "width": width, "height": height, "html": "", "masknode": _form.app.content, "container": _form.app.content, "buttonlist": [ { "text": mwf.lp.process.button.ok, "action": function () { //if (callback) callback(_self.view.selecteditems); if (callback) callback(_self.view.getdata()); this.close(); } }, { "text": mwf.lp.process.button.cancel, "action": function () { this.close(); } } ] }); dlg.show(); if (layout.mobile) { var backaction = dlg.node.getelement(".mwf_dialod_action_back"); var okaction = dlg.node.getelement(".mwf_dialod_action_ok"); if (backaction) backaction.addevent("click", function (e) { dlg.close(); }.bind(this)); if (okaction) okaction.addevent("click", function (e) { //if (callback) callback(this.view.selecteditems); if (callback) callback(this.view.getdata()); dlg.close(); }.bind(this)); } mwf.xdesktop.requireapp("query.query", "viewer", function () { this.view = new mwf.xapplication.query.query.viewer(dlg.content.getfirst(), viewjson, {"style": "select"}, _form.app, _form.macro); }.bind(this)); }.bind(this)); } } }; this.statement = { execute: function (obj, callback, async) { if( obj.format ){ return this._execute(obj, callback, async, obj.format); }else{ if( this.needcheckformat(obj) ){ var result; var p = mwf.actions.load("x_query_assemble_surface").statementaction.getformat(obj.name, function(json){ result = this._execute(obj, callback, async, json.data.format); return result; }.bind(this), null, async); return result || p; }else{ return this._execute(obj, callback, async, ""); } } }, needcheckformat: function(s){ if( s.format )return false; if( typeof(s.parameter) === "object" ){ for( var p in s.parameter ){ if( typeof( s.parameter[p] ) === "date" )return true; } } if( typeof(s.filter) === "array" ){ for( var i=0; i< s.filter.length; i ){ var ftype = s.filter[i].formattype; if( ["datetimevalue", "datetimevalue", "datevalue", "timevalue"].contains( ftype ) )return true; } } return false; }, _execute: function(statement, callback, async, format){ var parameter = this.parseparameter(statement.parameter, format); var filterlist = this.parsefilter(statement.filter, parameter, format); var obj = { "filterlist": filterlist, "parameter" : parameter }; return mwf.actions.load("x_query_assemble_surface").statementaction.executev2( statement.name, statement.mode || "data", statement.page || 1, statement.pagesize || 20, obj, function (json) { if (callback) callback(json); return json; }, null, async); }, parsefilter: function (filter, parameter, format) { if (typeof(filter) !== "array") return []; if( !parameter )parameter = {}; var filterlist = []; (filter || []).each(function (d) { if( !d.logic )d.logic = "and"; //var parametername = d.path.replace(/\./g, "_"); var pname = d.path.replace(/\./g, "_"); var parametername = pname; var suffix = 1; while( parameter[parametername] ){ parametername = pname "_" suffix; suffix ; } var value = d.value; if (d.comparison === "like" || d.comparison === "notlike") { if (value.substr(0, 1) !== "%") value = "%" value; if (value.substr(value.length - 1, 1) !== "%") value = value "%"; parameter[parametername] = value; //"%" value "%"; } else { if( ["sql", "sqlscript"].contains(format) ) { if (d.formattype === "numbervalue") { value = parsefloat(value); } }else{ if (d.formattype === "datetimevalue" || d.formattype === "datetimevalue") { value = "{ts '" value "'}" } else if (d.formattype === "datevalue") { value = "{d '" value "'}" } else if (d.formattype === "timevalue") { value = "{t '" value "'}" } else if (d.formattype === "numbervalue") { value = parsefloat(value); } } parameter[parametername] = value; } d.value = parametername; filterlist.push(d); }.bind(this)); return filterlist; }, parseparameter : function( obj, format ){ if( typeof(obj) !== "object" )return {}; var parameter = {}; //传入的参数 for( var p in obj ){ var value = obj[p]; if( typeof( value ) === "date" ){ if( ["sql", "sqlscript"].contains(format) ){ value = value.format("db"); }else{ value = "{ts '" value.format("db") "'}" } } parameter[ p ] = value; } return parameter; }, "select": function (statement, callback, options) { if (statement.name) { // var parameter = this.parseparameter(statement.parameter); // var filterlist = this.parsefilter(statement.filter, parameter); var statementjson = { "statementid": statement.name || "", "istitle": (statement.istitle === false) ? "no" : "yes", "select": (statement.ismulti === false) ? "single" : "multi", "filter": statement.filter, "parameter": statement.parameter }; if (!options) options = {}; options.width = statement.width; options.height = statement.height; options.title = statement.caption; var width = options.width || "700"; var height = options.height || "400"; if (layout.mobile) { var size = document.body.getsize(); width = size.x; height = size.y; options.style = "viewmobile"; } width = width.toint(); height = height.toint(); var size = _form.app.content.getsize(); var x = (size.x - width) / 2; var y = (size.y - height) / 2; if (x < 0) x = 0; if (y < 0) y = 0; if (layout.mobile) { x = 20; y = 0; } var _self = this; mwf.require("mwf.xdesktop.dialog", function () { var dlg = new mwf.xdesktop.dialog({ "title": options.title || "select statement view", "style": options.style || "view", "top": y, "left": x - 20, "fromtop": y, "fromleft": x - 20, "width": width, "height": height, "html": "", "masknode": _form.app.content, "container": _form.app.content, "buttonlist": [ { "text": mwf.lp.process.button.ok, "action": function () { //if (callback) callback(_self.view.selecteditems); if (callback) callback(_self.statement.getdata()); this.close(); } }, { "text": mwf.lp.process.button.cancel, "action": function () { this.close(); } } ] }); dlg.show(); if (layout.mobile) { var backaction = dlg.node.getelement(".mwf_dialod_action_back"); var okaction = dlg.node.getelement(".mwf_dialod_action_ok"); if (backaction) backaction.addevent("click", function (e) { dlg.close(); }.bind(this)); if (okaction) okaction.addevent("click", function (e) { //if (callback) callback(this.view.selecteditems); if (callback) callback(this.statement.getdata()); dlg.close(); }.bind(this)); } mwf.xdesktop.requireapp("query.query", "statement", function () { this.statement = new mwf.xapplication.query.query.statement(dlg.content.getfirst(), statementjson, {"style": "select"}, _form.app, _form.macro); }.bind(this)); }.bind(this)); } } }; this.importer = { "upload": function (options, callback, async) { mwf.xdesktop.requireapp("query.query", "importer", function () { var importer = new mwf.xapplication.query.query.importer(_form.app.content, options, {}, _form.app, _form.macro); importer.addevent("afterimport", function (data) { if(callback)callback(data); }); importer.load(); }.bind(this)); }, "downloadtemplate": function (options, filename, callback) { mwf.xdesktop.requireapp("query.query", "importer", function () { var importer = new mwf.xapplication.query.query.importer(_form.app.content, options, {}, _form.app, _form.macro); importer.downloadtemplate(filename, callback); }.bind(this)); } }; //include 引用脚本 //optionsorname : { // type : "", 默认为portal, 可以为 portal process cms // application : "", 门户/流程/cms的名称/别名/id, 默认为当前应用 // name : "" // 脚本名称/别名/id //} //或者name: "" // 脚本名称/别名/id // if( !window.includedscripts ){ // var includedscripts = window.includedscripts = []; // }else{ // var includedscripts = window.includedscripts; // } var includedscripts = []; var _includesingle = function (optionsorname, callback, async) { var options = optionsorname; if (typeof(options) == "string") { options = {name: options}; } var name = options.name; var type; if( options.type === "service" ){ type = options.type; }else{ type = (options.type && options.application) ? options.type : "portal"; } var application = options.application || _form.json.application; var key = type "-" application "-" name; if( type === "service" ){ key = type "-" name; } if (includedscripts.indexof(key) > -1) { if (callback) callback.apply(this); return; } //if (includedscripts.indexof( name )> -1){ // if (callback) callback.apply(this); // return; //} if (( options.enableanonymous || options.anonymous ) && type === "cms") { o2.actions.load("x_cms_assemble_control").scriptanonymousaction.getwithappwithname(application, name, function (json) { if (json.data) { includedscripts.push(key); //名称、别名、id (json.data.importedlist || []).each(function (flag) { includedscripts.push(type "-" json.data.appid "-" flag); if (json.data.appname) includedscripts.push(type "-" json.data.appname "-" flag); if (json.data.appalias) includedscripts.push(type "-" json.data.appalias "-" flag); }); includedscripts = includedscripts.concat(json.data.importedlist || []); mwf.cmsmacro.exec(json.data.text, this); if (callback) callback.apply(this); } else { if (callback) callback.apply(this); } }.bind(this), null, false); } else { var scriptaction; switch (type) { case "portal" : if (this.scriptactionportal) { scriptaction = this.scriptactionportal; } else { mwf.require("mwf.xscript.actions.portalscriptactions", null, false); scriptaction = this.scriptactionportal = new mwf.xscript.actions.portalscriptactions(); } break; case "process" : if (this.scriptactionprocess) { scriptaction = this.scriptactionprocess; } else { mwf.require("mwf.xscript.actions.scriptactions", null, false); scriptaction = this.scriptactionprocess = new mwf.xscript.actions.scriptactions(); } break; case "cms" : if (this.scriptactioncms) { scriptaction = this.scriptactioncms; } else { mwf.require("mwf.xscript.actions.cmsscriptactions", null, false); scriptaction = this.scriptactioncms = new mwf.xscript.actions.cmsscriptactions(); } break; case "service" : if (this.scriptactionservice) { scriptaction = this.scriptactionservice; } else { mwf.require("mwf.xscript.actions.servicescriptactions", null, false); scriptaction = this.scriptactionservice = new mwf.xscript.actions.servicescriptactions(); } break; } var successcallback = function (json) { if (json.data) { includedscripts.push(key); //名称、别名、id json.data.importedlist.each(function (flag) { if (type === "portal") { includedscripts.push(type "-" json.data.portal "-" flag); if (json.data.portalname) includedscripts.push(type "-" json.data.portalname "-" flag); if (json.data.portalalias) includedscripts.push(type "-" json.data.portalalias "-" flag); } else if (type === "cms") { includedscripts.push(type "-" json.data.appid "-" flag); if (json.data.appname) includedscripts.push(type "-" json.data.appname "-" flag); if (json.data.appalias) includedscripts.push(type "-" json.data.appalias "-" flag); } else if (type === "process") { includedscripts.push(type "-" json.data.application "-" flag); if (json.data.appname) includedscripts.push(type "-" json.data.appname "-" flag); if (json.data.appalias) includedscripts.push(type "-" json.data.appalias "-" flag); }else if (type === "service") { includedscripts.push(type "-" flag); } }); includedscripts = includedscripts.concat(json.data.importedlist); mwf.macro.exec(json.data.text, this); if (callback) callback.apply(this); } else { if (callback) callback.apply(this); } }.bind(this); if( type === "service" ){ scriptaction.getscriptbyname(name, includedscripts, successcallback, null, !!async); }else{ scriptaction.getscriptbyname(application, name, includedscripts, successcallback, null, !!async); } } }; this.include = function (optionsorname, callback, async) { if (o2.typeof(optionsorname) == "array") { if (!!async) { var count = optionsorname.length; var loaded = 0; optionsorname.each(function (option) { _includesingle.apply(this, [option, function () { loaded ; if (loaded >= count) if (callback) callback.apply(this); }.bind(this), true]); }.bind(this)); } else { optionsorname.each(function (option) { _includesingle.apply(this, [option]); }.bind(this)); if (callback) callback.apply(this); } } else { _includesingle.apply(this, [optionsorname, callback, async]) } }; this.define = function (name, fun, overwrite) { var over = true; if (overwrite === false) over = false; var o = {}; o[name] = {"value": fun, "configurable": over}; mwf.defineproperties(this, o); }.bind(this); //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载, //可在调用前执行 var resolve = this.wait(); //在异步调用结束后 执行 resolve.cb(); //目前只有表单的queryload事件支持此方法。 this.wait = function () { resolve = {}; var setresolve = function (callback) { resolve.cb = callback; }.bind(this); this.target.event_resolve = setresolve; return resolve; }; //和this.wait配合使用, //如果没有异步,则resolve.cb方法不存在, //所以在回调中中使用this.goon();使表单继续加载 this.goon = function () { this.target.event_resolve = null; }; //仅前台对象----------------------------------------- //form /** * page对象可在门户页面中可用。它的很多方法与form类似。(仅前端脚本可用)
* @module page * @o2cn 门户页面 * @o2category web * @o2range {portal} * @o2ordernumber 50 * @o2syntax * //您可以在门户表单中,通过this来获取page对象,如下: * var page = this.page; */ this.page = this.form = { /** 跳转到当前门户的指定页面。(仅门户页面脚本可用) * @method topage * @static * @param {string} name - 要跳转的页面名称 * @param {object} [par] - 要传入被打开页面的数据。在被打开的页面可以用this.page.parameters获取 * @param {boolean} [nohis] - 页面跳转的时候,不往history里增加历史状态,默认为false * @o2syntax * //跳转到当前门户的指定页面。 * this.page.topage( name, par, nohis ); * @example * this.page.topage("列表页面", {"key": "发文列表"});//打开“列表页面”,并传入一个json数据。 * * //在列表页面中,通过this.page.parameters获取传入的数据。 * var key = this.page.parameters.key; //key="发文列表" */ "topage": function (name, par, nohis) { _form.app.topage(name, par, nohis); }, /** 跳转到指定门户页面。(仅门户页面脚本可用) * @method toportal * @static * @param {string} portal - 要跳转的门户名称。 * @param {string} [page] - 要打开的门户的页面名称。为空则打开指定门户的默认游戏厅捕鱼达人首页。 * @param {string} [par] - 在被打开的页面可以用this.page.parameters获取。 * @o2syntax * this.page.toportal( portal, page, par ); * @example * this.page.toportal("公文门户", "列表页面", {"key": "发文列表"});//打开“公文门户”的“列表页面”,并传入一个json数据。 * * //在列表页面中,通过this.page.parameters获取传入的数据。 * var key = this.page.parameters.key; //key="发文列表" */ "toportal": function (portal, page, par) { _form.app.toportal(portal, page, par); }, /**获取当前页面的基本信息 * @method getinfor * @static * @see module:form.getinfor */ "getinfor": function () { return ev.pageinfor; }, "infor": ev.pageinfor, /**获取打开当前页面的component对象。 * @method getapp * @static * @see module:form.getapp */ "getapp": function () { return _form.app; }, "app": _form.app, /**获取page对应的dom对象。 * @method node * @static * @see module:form.node */ "node": function () { return _form.node; }, //"readonly": _form.options.readonly, /**获取页面元素对象。 * @method get * @static * @see module:form.get */ "get": function(name,subformname ){ if( !_form.all )return null; if( subformname ){ if( _form.all[subformname "_" name] )return _form.all[subformname "_" name]; return _form.all[name]; }else{ return _form.all[name]; } // return (_form.all) ? _form.all[name] : null; }, /**获取指定部件元素对象。
* @method getwidgetmodule * @static * @param {string} widgetid - 在游戏厅捕鱼达人主页面嵌入部件时用的标识。 * @param {string} fieldid - 部件内组件标识。 * @return {formcomponent} 请查看本文档的classes导航下的formcomponents。 * @see module:form.get * @o2syntax * this.page.getwidgetmodule( widgetid, fieldid ); * @example * * 1、设计了一个部件,包含一个设计元素subject。
* 2、在游戏厅捕鱼达人主页面里两次嵌入1步骤创建的部件,一个标识是widget_1, widget_2。 * * var module = this.page.getwidgetmodule( "widget_1", "subject"); //部件widget_1的subject组件 * var data2 = this.page.getwidgetmodule( "widget_2", "subject").getdata(); //部件widget_2的subject组件的值 */ "getwidgetmodule": function (widget, modulename) { if (!_form.widgetmodules || !_form.widgetmodules[widget]) return null; var module = _form.widgetmodules[widget][modulename]; return module || null; }, /**获取页面中可输入的字段元素对象 * @method getfield * @static * @see module:form.getfield */ "getfield": function (name) { return _forms[name]; }, "getaction": function () { return _form.workaction }, "getdesktop": function () { return _form.app.desktop }, "getdata": function () { return new mwf.xscript.jsondata(_form.getdata()); }, //"save": function(callback){_form.savework(callback);}, /**关闭当前页面 * @method close * @static * @see module:form.close */ "close": function () { _form.closework(); }, "print": function (application, form) { _form.printwork(application, form); }, /**弹出一个确认框 * @method confirm * @static * @see module:form.confirm */ "confirm": function (type, title, text, width, height, ok, cancel, callback, mask, style) { // var p = mwf.getcenter({"x": width, "y": height}); // e = {"event": {"clientx": p.x,"x": p.x,"clienty": p.y,"y": p.y}}; // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style); if ((arguments.length <= 1) || o2.typeof(arguments[1]) === "string") { var p = mwf.getcenter({"x": width, "y": height}); e = {"event": {"clientx": p.x, "x": p.x, "clienty": p.y, "y": p.y}}; _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style); } else { e = (arguments.length > 1) ? arguments[1] : null; title = (arguments.length > 2) ? arguments[2] : null; text = (arguments.length > 3) ? arguments[3] : null; width = (arguments.length > 4) ? arguments[4] : null; height = (arguments.length > 5) ? arguments[5] : null; ok = (arguments.length > 6) ? arguments[6] : null; cancel = (arguments.length > 7) ? arguments[7] : null; callback = (arguments.length > 8) ? arguments[8] : null; mask = (arguments.length > 9) ? arguments[9] : null; style = (arguments.length > 10) ? arguments[10] : null; _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style); } }, /**显示一个带关闭按钮的信息框 * @method alert * @static * @see module:form.alert */ "alert": function (type, title, text, width, height) { _form.alert(type, title, text, width, height); }, /**显示一个信息框 * @method notice * @static * @see module:form.notice */ "notice": function (content, type, target, where, offset, option) { _form.notice(content, type, target, where, offset, option); }, /**打开一个对话框 * @method dialog * @static * @see module:form.dialog */ "dialog": function ( options ) { return _form.dialog( options ); }, /**打开人员组织选择界面 * @method selectorg * @static * @see module:form.selectorg */ "selectorg": function ( container, options, delayload) { if( !container )container = _form.app.content; return new mwf.o2selector(container, options, delayload); }, /**给页面添加事件。 * @method addevent * @static * @see module:form.addevent */ "addevent": function (e, f) { _form.addevent(e, f); }, "openwindow": function (form, app) { _form.openwindow(form, app); }, /**打开一个在流转或已完成的流程实例 * @method openwork * @static * @see module:form.openwork */ "openwork": function (id, completedid, title, options) { var op = options || {}; op.workid = id; op.workcompletedid = completedid; op.doctitle = title; op.appid = "process.work" (op.workid || op.workcompletedid); return layout.desktop.openapplication(this.event, "process.work", op); }, /**使用流程的jobid打开工作 * @method openjob * @static * @see module:form.openjob */ "openjob": function (id, choice, options, callback) { var workdata = null, handel; o2.actions.get("x_processplatform_assemble_surface").listworkbyjob(id, function(json){ if (json.data) workdata = json.data; }.bind(this), null, false); if( !layout.inbrowser && o2.typeof(callback) === "function" ){ if( !options )options = {}; var queryload = options.onqueryload; options.onqueryload = function () { if( o2.typeof(queryload) === "function" )queryload.call(this); callback(this); } } runcallback = function ( handel ) { if( o2.typeof(callback) === "function" ) { if (layout.inbrowser) { callback(handel); } else if (options && options.appid) { if (layout.desktop && layout.desktop.apps && layout.desktop.apps[options.appid]) { callback(layout.desktop.apps[options.appid], true); }else{ callback(handel, false); } }else{ callback(handel, false); } } }; if (workdata){ var len = workdata.worklist.length workdata.workcompletedlist.length; if (len){ if (len>1 && choice){ var node = new element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node); workdata.worklist.each(function(work){ var worknode = new element("div", { "styles": { "background": "#ffffff", "border-radius": "10px", "clear": "both", "margin-bottom": "10px", "height": "40px", "padding": "10px 10px" } }).inject(node); var html = "" "" "" o2.lp.widget.open "" work.title "" ""; worknode.set("html", html); var action = worknode.getelement(".mwfaction"); action.store("work", work); action.addevent("click", function(e){ var work = e.target.retrieve("work"); if (work){ handel = this.openwork(work.id, null, work.title, options); runcallback( handel ); } dlg.close(); }.bind(this)); }.bind(this)); workdata.workcompletedlist.each(function(work){ var worknode = new element("div", { "styles": { "background": "#ffffff", "border-radius": "10px", "clear": "both", "margin-bottom": "10px", "height": "40px", "padding": "10px 10px" } }).inject(node); var html = "" "" work.activityname "" "" work.activityarrivedtime "" "" (work.manualtaskidentitytext || "") "" "" o2.lp.widget.open "" work.title "" "
" o2.lp.widget.workcompleted "" "" work.completedtime ""; worknode.set("html", html); var action = worknode.getelement(".mwfaction"); action.store("work", work); action.addevent("click", function(e){ var work = e.target.retrieve("work"); if (work){ handel = this.openwork(null, work.id, work.title, options); runcallback( handel ); } dlg.close(); }.bind(this)); }.bind(this)); var height = node.getsize().y 20; if (height>600) height = 600; var dlg = o2.dl.open({ "title": o2.lp.widget.choicework, "style" : "user", "isresize": false, "content": node, "buttonlist": [ { "type" : "cancel", "text": o2.lp.widget.close, "action": function(){dlg.close();} } ] }); }else{ if (workdata.worklist.length){ var work = workdata.worklist[0]; handel = this.openwork(work.id, null, work.title, options); runcallback( handel ); return handel; }else{ var work = workdata.workcompletedlist[0]; handel = this.openwork(null, work.id, work.title, options); runcallback( handel ); return handel; } } }else{ runcallback(new error("can't open this job", { cause: workdata })); } }else{ runcallback(new error("can't open this job", { cause: workdata })); } }, /**打开一个内容管理文档 * @method opendocument * @static * @see module:form.opendocument */ "opendocument": function (id, title, options) { var op = options || {}; op.documentid = id; op.doctitle = title || ""; op.appid = (op.appid) || ("cms.document" id); if( op.onpostpublish ){ op.postpublish = op.onpostpublish; delete op.onpostpublish; } if( op.onafterpublish ){ op.afterpublish = op.onafterpublish; delete op.onafterpublish; } if( op.onaftersave ){ op.aftersave = op.onaftersave; delete op.onaftersave; } if( op.onbeforeclose ){ op.beforeclose = op.onbeforeclose; delete op.onbeforeclose; } if( op.onpostdelete ){ op.postdelete = op.onpostdelete; delete op.onpostdelete; } return layout.desktop.openapplication(this.event, "cms.document", op); }, /**打开一个门户页面 * @method openportal * @static * @see module:form.openportal */ "openportal": function (name, page, par) { var action = mwf.actions.get("x_portal_assemble_surface"); action.getapplication(name, function (json) { if (json.data) { if (page) { action.getpagebyname(page, json.data.id, function (pagejson) { var pageid = (pagejson.data) ? pagejson.data.id : ""; layout.desktop.openapplication(null, "portal.portal", { "portalid": json.data.id, "pageid": pageid, "parameters": par, "appid": (par && par.appid) || ("portal.portal" json.data.id pageid) }) }); } else { layout.desktop.openapplication(null, "portal.portal", { "portalid": json.data.id, "parameters": par, "appid": (par && par.appid) || ("portal.portal" json.data.id) }) } } }); }, /**打开一个内容管理栏目(应用) * @method opencms * @static * @see module:form.opencms */ "opencms": function (name) { var action = mwf.actions.get("x_cms_assemble_control"); action.getcolumn(name, function (json) { if (json.data) { layout.desktop.openapplication(null, "cms.module", { "columnid": json.data.id, "appid": "cms.module" json.data.id }); } }); }, /**打开一个流程应用 * @method openprocess * @static * @see module:form.openprocess */ "openprocess": function (name) { var action = mwf.actions.get("x_processplatform_assemble_surface"); action.getapplication(name, function (json) { if (json.data) { layout.desktop.openapplication(null, "process.application", { "id": json.data.id, "appid": "process.application" json.data.id }); } }); }, /**打开一个任意一个component应用 * @method openapplication * @static * @see module:form.openapplication */ "openapplication": function (name, options, status) { return layout.desktop.openapplication(null, name, options, status); }, /**创建一个内容管理文档 * @method createdocument * @static * @see module:form.createdocument */ "createdocument": function (columnoroptions, category, data, identity, callback, target, latest, selectcolumnenable, ignoretitle, restricttocolumn) { var column = columnoroptions; var onafterpublish, onpostpublish; if (typeof(columnoroptions) == "object") { column = columnoroptions.column; category = columnoroptions.category; data = columnoroptions.data; identity = columnoroptions.identity; callback = columnoroptions.callback; target = columnoroptions.target; latest = columnoroptions.latest; selectcolumnenable = columnoroptions.selectcolumnenable; ignoretitle = columnoroptions.ignoretitle; restricttocolumn = columnoroptions.restricttocolumn; onafterpublish = columnoroptions.onafterpublish; onpostpublish = columnoroptions.onpostpublish; } // 移动端 app相关的实现 if (layout.mobile) { var options = {}; if (column) { options["column"] = column } if (category) { options["category"] = category } if (window.o2android && window.o2android.postmessage) { var body = { type: "createo2cmsdocument", data: options }; window.o2android.postmessage(json.stringify(body)); return; } else if (window.o2android && window.o2android.createo2cmsdocument){ window.o2android.createo2cmsdocument(json.stringify(options)); return; } else if (window.webkit && window.webkit.messagehandlers && window.webkit.messagehandlers.createo2cmsdocument) { window.webkit.messagehandlers.createo2cmsdocument.postmessage(options); return; } } // 下面是pc端 if (target) { if (layout.app && layout.app.inbrowser) { layout.app.content.empty(); layout.app = null; } } mwf.xdesktop.requireapp("cms.index", "newer", function () { var starter = new mwf.xapplication.cms.index.newer(null, null, _form.app, null, { "documentdata": data, "identity": identity, "ignoretitle": ignoretitle === true, "ignoredrafted": latest === false, "selectcolumnenable": !category || selectcolumnenable === true, "restricttocolumn": restricttocolumn === true || (!!category && selectcolumnenable !== true), "categoryflag": category, //category id or name "columnflag": column, //column id or name, "onstarted": function (documentid, data, windowhandle) { if (callback) callback(documentid, data, windowhandle); }, "onpostpublish": function () { if (onpostpublish) onpostpublish(); }, "onafterpublish": function () { if (onafterpublish) onafterpublish(); } }); starter.load(); }) }, /**启动一个流程实例 * @method startprocess * @static * @see module:form.startprocess */ "startprocess": function (app, process, data, identity, callback, target, latest, aftercreated, skipdraftcheck) { if (arguments.length > 2) { for (var i = 2; i < arguments.length; i ) { if (typeof(arguments[i]) == "boolean") { target = arguments[i]; break; } } } if (target) { if (layout.app && layout.app.inbrowser) { //layout.app.content.empty(); layout.app.$openwithself = true; } } if (!app || !process){ var cmpt = this.getapp(); o2.requireapp([["process.taskcenter", "lp." o2.language], ["process.taskcenter", ""]],"", function(){ var obj = { "lp": o2.xapplication.process.taskcenter.lp, "content": cmpt.content, "addevent": function(type, fun){ cmpt.addevent(type, fun); }, "getaction": function (callback) { if (!this.action) { this.action = o2.actions.get("x_processplatform_assemble_surface"); if (callback) callback(); } else { if (callback) callback(); } }, "desktop": layout.desktop, "refreshall": function(){}, "notice": cmpt.notice, } o2.json.get("../x_component_process_taskcenter/$main/default/css.wcss", function(data){ obj.css = data; }, false); if (!cmpt.processstarter) cmpt.processstarter = new o2.xapplication.process.taskcenter.starter(obj); cmpt.processstarter.load(); }, true, true); return ""; } var action = mwf.actions.get("x_processplatform_assemble_surface").getprocessbyname(process, app, function (json) { if (json.data) { mwf.xdesktop.requireapp("process.taskcenter", "processstarter", function () { var starter = new mwf.xapplication.process.taskcenter.processstarter(json.data, _form.app, { "workdata": data, "identity": identity, "latest": latest, "skipdraftcheck": skipdraftcheck, "onstarted": function (data, title, processname) { var application; if (data.work) { var work = data.work; var options = { "draft": work, "appid": "process.work" (new o2.widget.uuid).tostring(), "desktopreload": false }; if( !layout.inbrowser && aftercreated )options.onpostloadform = aftercreated; application = layout.desktop.openapplication(null, "process.work", options); } else { var currenttask = []; data.each(function (work) { if (work.currenttaskindex != -1) currenttask.push(work.tasklist[work.currenttaskindex].work); }.bind(this)); if (currenttask.length == 1) { var options = {"workid": currenttask[0], "appid": currenttask[0]}; if( !layout.inbrowser && aftercreated )options.onpostloadform = aftercreated; application = layout.desktop.openapplication(null, "process.work", options); } else { } } // var currenttask = []; // data.each(function (work) { // if (work.currenttaskindex != -1) currenttask.push(work.tasklist[work.currenttaskindex].work); // }.bind(this)); // // if (currenttask.length == 1) { // var options = { "workid": currenttask[0], "appid": currenttask[0] }; // layout.desktop.openapplication(null, "process.work", options); // } else { } if (callback) callback(data); if(layout.inbrowser && aftercreated){ aftercreated(application) } }.bind(this) }); starter.load(); }.bind(this)); } }); }, /** * 在打开的页面的任意脚本中,获取传入的参数。 * @member parameters * @static * @return {boolean} 任意数据类型,根据传入的参数决定。 * @o2syntax * var par = this.page.parameters * @example * //打开页面时传入参数: * this.form.openportal(id, "", {"type": "my type"}); * * //在打开的页面的任意脚本中,可以获取parameters: * var par = this.page.parameters; * //par的内容:{"type": "my type"} */ "parameters": _form.options.parameters, /** * 在嵌入部件的时候,可以在游戏厅捕鱼达人主页面上传入参数。通过本方法,可以在对应部件或者部件元素的脚本中获取传入的参数。 * @method getwidgetprameters * @static * @return {object} 任意数据类型,根据传入的参数决定。 * @o2syntax * var par = this.page.getwidgetprameters(); * @example * //在游戏厅捕鱼达人主页面嵌入部件的地方传入参数: * return {"type": "my type"}; * * //在对应部件脚本中,可以获取parameters: * var par = this.page.getwidgetprameters(); * //par的内容:{"type": "my type"} */ "getwidgetprameters": function () { if (!this.target) return null; if (!this.target.widget) return null; if (!this.widgetparameters) return null; var pageid = this.target.widget.json.id; return this.widgetparameters[pageid]; }.bind(this) //"app": _form.app }; this.form.currentroutename = _form.json.currentroutename; this.form.opinion = _form.json.opinion; this.target = ev.target; this.event = ev.event; this.status = ev.status; this.session = layout.desktop.session; this.actions = o2.actions; this.query = function (option) { // options = { // "name": "statementname", // "data": "json data", // "firstresult": 1, // "maxresults": 100, // "success": function(){}, // "error": function(){}, // "async": true or false, default is true // } if (option) { var json = (option.data) || {}; if (option.firstresult) json.firstresult = option.firstresult.toint(); if (option.maxresults) json.maxresults = option.maxresults.toint(); o2.actions.get("x_query_assemble_surface").executestatement(option.name, json, success, error, options.async); } }; this.table = mwf.xscript.createtable(); }; } if (!mwf.xscript.createtable) mwf.xscript.createtable = function(){ return function(name){ this.name = name; this.action = o2.actions.load("x_query_assemble_surface").tableaction; this.listrownext = function(id, count, success, error, async){ return this.action.listrownext(this.name, id, count, success, error, async); }; this.listrowprev = function(id, count, success, error, async){ return this.action.listrowprev(this.name, id, count, success, error, async); }; this.listrowselect = function(where, orderby, size, success, error, async){ return this.action.listrowselect(this.name, {"where": where, "orderby": orderby, "size": size || ""}, success, error, async); }; this.listrowselectwhere = function(where, success, error, async){ return this.action.listrowselectwhere(this.name, where, success, error, async); }; this.rowcountwhere = function(where, success, error, async){ return this.action.rowcountwhere(this.name, where, success, error, async); }; this.deleterow = function(id, success, error, async){ return this.action.rowdelete(this.name, id, success, error, async); }; this.deleteallrow = function(success, error, async){ return this.action.rowdeleteall(this.name, success, error, async); }; this.getrow = function(id, success, error, async){ return this.action.rowget(this.name, id, success, error, async); }; this.insertrow = function(data, success, error, async){ return this.action.rowinsert(this.name, data, success, error, async); }; this.addrow = function(data, success, error, async){ return this.action.rowinsertone(this.name, data, success, error, async); }; this.updaterow = function(id, data, success, error, async){ return this.action.rowupdate(this.name, id, data, success, error, async); }; } }; if (!mwf.xscript.jsondata) { var getarrayjsondata = function (jdata, p, _form) { return new mwf.xscript.jsondata(jdata, function (data, key, _self) { var p = { "getkey": function () { return key; }, "getparent": function () { return _self; } }; while (p && !_form.forms[p.getkey()]) p = p.getparent(); //if (p) if (p.getkey()) if (_forms[p.getkey()]) _forms[p.getkey()].resetdata(); var k = (p) ? p.getkey() : ""; if (k) if (_form.forms[k]) if (_form.forms[k].resetdata) _form.forms[k].resetdata(); //if(p) if(p.getkey()) if(_forms[p.getkey()]) if(_forms[p.getkey()].render) _forms[p.getkey()].render(); }, "", p, _form); }; mwf.xscript.jsondata = function (data, callback, key, parent, _form) { var getter = function (data, callback, k, _self) { return function () { var t = typeof(data[k]); if (["array", "object"].indexof(t) === -1) { return data[k] } else { if (t === "array") { if (window.proxy){ var arr = new proxy(data[k], { get: function(o, k){ return (o2.typeof(o[k])==="object") ? getarrayjsondata(o[k], _self, _form) : o[k]; }, set: function(o, k, v){ o[k] = v; if (callback) callback(o, k, _self); return true; } }); return arr; }else{ var arr =[]; data[k].foreach(function(d, i){ arr.push((o2.typeof(d)==="object") ? getarrayjsondata(d, _self, _form) : d); }); return arr; } } else { return new mwf.xscript.jsondata(data[k], callback, k, _self, _form); } // var obj = // if (t==="array") obj.constructor = array; // return obj; } //return (["array","object"].indexof(typeof(data[k]))===-1) ? data[k] : new mwf.xscript.jsondata(data[k], callback, k, _self, _form); }; }; var setter = function (data, callback, k, _self) { return function (v) { data[k] = v; //debugger; //this.add(k, v, true); if (callback) callback(data, k, _self); } }; var define = function () { var o = {}; for (var k in data) o[k] = { "configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, k, this]), "set": setter.apply(this, [data, callback, k, this]) }; o["length"] = { "get": function () { return object.keys(data).length; } }; o["some"] = { "get": function () { return data.some; } }; mwf.defineproperties(this, o); var methods = { "getkey": { "value": function () { return key; } }, "getparent": { "value": function () { return parent; } }, "tostring": { "value": function () { return data.tostring(); } }, "setsection": { "value": function (newkey, newvalue) { this.add(newkey, newvalue, true); try { var path = [this.getkey()]; p = this.getparent(); while (p && p.getkey()) { path.unshift(p.getkey()); p = p.getparent(); } if (path.length) _form.sectionlistobj[path.join(".")] = newkey; } catch (e) { } } }, "add": { "value": function (newkey, newvalue, overwrite, noreset) { if( newkey.test(/^\d $/) ){ throw new error("field name '" newkey "' cannot contain only numbers" ); } if (arguments.length < 2 || newkey.indexof("..") === -1) { var flag = true; var type = typeof(data); if (type === "array") { if (arguments.length < 2) { data.push(newkey); newvalue = newkey; newkey = data.length - 1; } else { if (!newkey && newkey !== 0) { data.push(newvalue); newkey = data.length - 1; } else { if (newkey >= data.length) { data.push(newvalue); newkey = data.length - 1; } else { if (overwrite) data[newkey] = newvalue; newvalue = data[newkey]; flag = false; } } } if (flag) { var o = {}; o[newkey] = { "configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newkey, this]), "set": setter.apply(this, [data, callback, newkey, this]) }; mwf.defineproperties(this, o); } if (!noreset) this[newkey] = newvalue; } else if (type === "object") { if (!this.hasownproperty(newkey)) { if (!data[newkey] || overwrite) { data[newkey] = newvalue; } newvalue = data[newkey]; if (flag) { var o = {}; o[newkey] = { "configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newkey, this]), "set": setter.apply(this, [data, callback, newkey, this]) }; mwf.defineproperties(this, o); } if (!noreset) this[newkey] = newvalue; } else { if (!object.getownpropertydescriptor(this, newkey).get){ var o = {}; o[newkey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newkey, this]),"set": setter.apply(this, [data, callback, newkey, this])}; mwf.defineproperties(this, o); } if (overwrite) { data[newkey] = newvalue; if (!noreset) this[newkey] = newvalue; } } } return this[newkey]; } else { var keys = newkey.split(".."); var kk = keys.shift(); var d = this.add(kk, {}, false, true); if (keys.length) return d.add(keys.join(".."), newvalue, overwrite, noreset); return d; } } }, "check": { "value": function (kk, v) { var value = typeof( v ) === "null" ? "" : v; this.add(kk, value, false, true); } }, "del": { "value": function (delkey) { if (!this.hasownproperty(delkey)) return null; // delete data[delkey]; // delete this[delkey]; data[delkey] = ""; this[delkey] = ""; return this; } } }; mwf.defineproperties(this, methods); //this.getkey = function(){ return key; }; //this.getparent = function(){ return parent; }; //this.tostring = function() { return data.tostring();}; //this.add = function(newkey, newvalue, overwrite){ // var flag = true; // var type = typeof(data); // if (!this.hasownproperty(newkey)){ // if (type=="array"){ // if (arguments.length<2){ // data.push(newkey); // newvalue = newkey; // newkey = data.length-1; // }else{ // debugger; // if (!newkey && newkey!=0){ // data.push(newvalue); // newkey = data.length-1; // }else{ // flag == false; // } // } // }else{ // data[newkey] = newvalue; // } // //var valuetype = typeof(newvalue); // //var newvaluedata = newvalue; // //if (valuetype=="object" || valuetype=="array") newvaluedata = new mwf.xscript.jsondata(newvalue, callback, newkey, this); // //if (valuetype=="null") newvaluedata = new mwf.xscript.jsondata({}, callback, newkey, this); // if (flag){ // var o = {}; // o[newkey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newkey, this]),"set": setter.apply(this, [data, callback, newkey, this])}; // mwf.defineproperties(this, o); // } // this[newkey] = newvalue; // }else{ // if (overwrite) this[newkey] = newvalue; // } // // //var valuetype = typeof(newvalue); // //var newvaluedata = newvalue; // //if (valuetype=="object" || valuetype=="array") newvaluedata = new mwf.xscript.jsondata(newvalue, callback, newkey, this); // //if (valuetype=="null") newvaluedata = new mwf.xscript.jsondata({}, callback, newkey, this); // // // //this[newkey] = newvaluedata; // // return this[newkey]; //}; //this.del = function(delkey){ // if (!this.hasownproperty(delkey)) return null; // delete data[newkey]; // delete this[newkey]; // return this; //}; }; var type = typeof(data); if (type === "object" || type === "array") define.apply(this); }; } if( !mwf.xscript.dictloaded )mwf.xscript.dictloaded = {}; if (!mwf.xscript.createdict) { mwf.xscript.adddicttocache = function (options, path, json) { if (!path) path = "root"; if (path.indexof("root") !== 0) path = "root." path; var type = options.apptype || "process"; var enableanonymous = ( options.enableanonymous || options.anonymous ) || false; var appflaglist = []; if (options.application) appflaglist.push(options.application); if (options.appid) appflaglist.push(options.appid); if (options.appname) appflaglist.push(options.appname); if (options.appalias) appflaglist.push(options.appalias); var dictflaglist = []; if (options.id) dictflaglist.push(options.id); if (options.name) dictflaglist.push(options.name); if (options.alias) dictflaglist.push(options.alias); var cache = {}; cache[path] = json; for (var i = 0; i < appflaglist.length; i ) { for (var j = 0; j < dictflaglist.length; j ) { var k = dictflaglist[j] type appflaglist[i] enableanonymous; if (!mwf.xscript.dictloaded[k]) { mwf.xscript.dictloaded[k] = cache; //指向同一个对象 // mwf.xscript.dictloaded[k][path] = json; //指向不同的对象 } else if (i === 0 && j === 0) { mwf.xscript.setdicttocache(k, path, json); var arr = path.split(/\./g); var p; var cache = mwf.xscript.dictloaded[k]; for (var l = 0; l < arr.length; l ) { p = l === 0 ? arr[0] : (p "." arr[l]); if (cache[p]) break; } if (p) { var mathp = p "."; object.keys(cache).each(function (path, idx) { if (path.indexof(mathp) === 0) delete cache[path]; }) } } } } }; mwf.xscript.getmatcheddict = function (key, path) { if (!path) path = "root"; if (path.indexof("root") !== 0) path = "root." path; var arr = path.split(/\./g); if (mwf.xscript.dictloaded[key]) { var dicts = mwf.xscript.dictloaded[key]; var list = array.clone(arr); var p; var dict; for (var i = 0; i < arr.length; i ) { p = i === 0 ? arr[0] : (p "." arr[i]); list.shift(); if (dicts[p]) { dict = dicts[p]; break; } } return { dict: dict, unmatchedpathlist: list } } return { dict: null, unmatchedpathlist: list } }; mwf.xscript.insertdicttocache = function (key, path, json) { var p = path; if( !p )p = "root"; if( p.indexof("root") !== 0 )p = "root." p ; if (mwf.xscript.dictloaded[key]) { var matcheddict = mwf.xscript.getmatcheddict(key, path); var dict = matcheddict.dict; var list = matcheddict.unmatchedpathlist; if (!dict) { mwf.xscript.dictloaded[key][p] = json; }else if( !list || list.length === 0 ){ mwf.xscript.dictloaded[key][p] = json; } else { for (var j = 0; j < list.length - 1; j ) { if (!dict[list[j]]) { dict[list[j]] = {}; } dict = dict[list[j]]; } var lastpath = list[list.length - 1]; if (!dict[lastpath]) { dict[lastpath] = json; } else if (typeof(dict[lastpath]) === "array") { dict[lastpath].push(json); } } } else { mwf.xscript.dictloaded[key] = {}; mwf.xscript.dictloaded[key][p] = json; } }; mwf.xscript.setdicttocache = function (key, path, json) { var p = path; if( !p )p = "root"; if( p.indexof("root") !== 0 )p = "root." p ; if (mwf.xscript.dictloaded[key]) { var matcheddict = mwf.xscript.getmatcheddict(key, path); var dict = matcheddict.dict; var list = matcheddict.unmatchedpathlist; if (!dict) { mwf.xscript.dictloaded[key][p] = json; }else if( !list || list.length === 0 ){ mwf.xscript.dictloaded[key][p] = json; } else { for (var j = 0; j < list.length - 1; j ) { if (!dict[list[j]]) { dict[list[j]] = {}; } dict = dict[list[j]]; } dict[list[list.length - 1]] = json; } } else { mwf.xscript.dictloaded[key] = {}; mwf.xscript.dictloaded[key][p] = json; } }; mwf.xscript.getdictfromcache = function (key, path) { var matcheddict = mwf.xscript.getmatcheddict(key, path); var dict = matcheddict.dict; var list = matcheddict.unmatchedpathlist; if (dict) { for (var j = 0; j < list.length; j ) { dict = dict[list[j]]; if (!dict) return null; } return dict; } return null; }; mwf.xscript.deletedicttocache = function (key, path) { var matcheddict = mwf.xscript.getmatcheddict(key, path); var dict = matcheddict.dict; var list = matcheddict.unmatchedpathlist; if (dict) { for (var j = 0; j < list.length - 1; j ) { dict = dict[list[j]]; if (!dict) return; } if( list.length ){ delete dict[list[list.length - 1]]; } } }; mwf.xscript.createdict = function (application, apptype) { //optionsorname : { // type : "", //默认为process, 可以为 process cms // application : "", //流程/cms的名称/别名/id, 默认为当前应用 // name : "", // 数据字典名称/别名/id // anonymous : false //允许在未登录的情况下读取cms的数据字典, 该参数名也可以是 enableanonymous //} //或者name: "" // 数据字典名称/别名/id return function (optionsorname) { var options = optionsorname; if (typeof(options) == "string") { options = { name: options, type: apptype, application: application }; } var name = this.name = options.name; var type; if( options.type === "service"){ type = options.type; }else{ type = ( options.type && options.application ) ? options.type : "process"; } var applicationid = options.application || application; var enableanonymous = ( options.enableanonymous || options.anonymous ) || false; var opt = { "apptype": type, "name": name, "appid": applicationid, "enableanonymous": enableanonymous }; var key = name type applicationid enableanonymous; // if (!dictloaded[key]) dictloaded[key] = {}; // this.dictdata = dictloaded[key]; //mwf.require("mwf.xscript.actions.dictactions", null, false); var action; if (type === "cms") { action = mwf.actions.get("x_cms_assemble_control"); } else if( type === "portal" ){ action = mwf.actions.get("x_portal_assemble_surface"); }else if( type === "service" ){ key = name type enableanonymous; action = mwf.actions.get("x_program_center"); } else { action = mwf.actions.get("x_processplatform_assemble_surface"); } var encodepath = function (path) { var arr = path.split(/\./g); var ar = arr.map(function (v) { return encodeuricomponent(v); }); return ( type === "portal" || type === "service" ) ? ar.join(".") : ar.join("/"); }; this.get = function (path, success, failure, async, refresh) { var value = null; if (success === true) async = true; if (failure === true) async = true; if (!refresh) { var data = mwf.xscript.getdictfromcache(key, path); if (data) { if (success && o2.typeof(success) == "function") success(data); if (!!async) { return promise.resolve(data); } else { return data; } } } // var cb = function(json){ // value = json.data; // mwf.xscript.adddicttocache(opt, path, value); // if (success && o2.typeof(success)=="function") value = success(json.data); // return value; // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeof(failure)=="function") return failure(xhr, text, error); }); var cb = function (json) { value = json.data; mwf.xscript.adddicttocache(opt, path, value); if (success && o2.typeof(success) == "function") value = success(json.data); return value; }; var promise; if( type === "service" ){ if (path){ var p = encodepath( path ); promise = action.getdictdata(encodeuricomponent(this.name), p, cb, null, !!async, false); }else{ promise = action.getdictroot(this.name, cb, null, !!async, false); } }else{ if (path) { var p = encodepath(path); promise = action[((enableanonymous && type == "cms") ? "getdictdataanonymous" : "getdictdata")](encodeuricomponent(this.name), applicationid, p, cb, null, !!async, false); } else { promise = action[((enableanonymous && type == "cms") ? "getdictrootanonymous" : "getdictroot")](this.name, applicationid, cb, null, !!async, false); } } return (!!async) ? promise : value; // if (path){ // var p = encodepath( path ); // //var p = path.replace(/\./g, "/"); // action[ ( (enableanonymous && type == "cms") ? "getdictdataanonymous" : "getdictdata" ) ](encodeuricomponent(this.name), applicationid, p, function(json){ // value = json.data; // // this.dictdata[path] = value; // mwf.xscript.adddicttocache(opt, path, value); // if (success) success(json.data); // }.bind(this), function(xhr, text, error){ // if (failure) failure(xhr, text, error); // }, !!async); // }else{ // action[ ( (enableanonymous && type == "cms") ? "getdictrootanonymous" : "getdictroot" ) ](this.name, applicationid, function(json){ // value = json.data; // // this.dictdata["root"] = value; // mwf.xscript.adddicttocache(opt, path, value); // if (success) success(json.data); // }.bind(this), function(xhr, text, error){ // if (failure) failure(xhr, text, error); // }, !!async); // } //return value; }; this.set = function (path, value, success, failure) { var p = encodepath(path); //var p = path.replace(/\./g, "/"); var successcallback = function(json){ mwf.xscript.setdicttocache(key, path, value); if (success) return success(json.data); }; var failurecallback = function(xhr, text, error){ if (failure) return failure(xhr, text, error); }; if( type === "service" ){ return action.setdictdata(encodeuricomponent(this.name), p, value, successcallback, failurecallback, false, false); }else{ return action.setdictdata(encodeuricomponent(this.name), applicationid, p, value, successcallback, failurecallback, false, false); } }; this.add = function (path, value, success, failure) { var p = encodepath(path); //var p = path.replace(/\./g, "/"); var successcallback = function(json){ mwf.xscript.insertdicttocache(key, path, value); if (success) return success(json.data); }; var failurecallback = function(xhr, text, error){ if (failure) return failure(xhr, text, error); }; if( type === "service" ) { return action.adddictdata(encodeuricomponent(this.name), p, value, successcallback, failurecallback, false, false); }else{ return action.adddictdata(encodeuricomponent(this.name), applicationid, p, value, successcallback, failurecallback, false, false); } }; this["delete"] = function (path, success, failure) { var p = encodepath(path); //var p = path.replace(/\./g, "/"); var successcallback = function(json){ mwf.xscript.deletedicttocache(key, path); if (success) return success(json.data); }; var failurecallback = function(xhr, text, error){ if (failure) return failure(xhr, text, error); }; if( type === "service" ) { return action.deletedictdata(encodeuricomponent(this.name), p, successcallback, failurecallback, false, false); }else{ return action.deletedictdata(encodeuricomponent(this.name), applicationid, p, successcallback, failurecallback, false, false); } }; this.destory = this["delete"]; } }; }
source