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类似。(仅前端脚本可用)