Environment.js 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.Environment = function(ev){
  3. var _data = ev.data;
  4. var _form = ev.form;
  5. var _forms = ev.forms;
  6. this.library = COMMON;
  7. //this.library.version = "4.0";
  8. this.power = {
  9. "isManager": MWF.AC.isProcessManager() || _form.businessData.control.allowReroute,
  10. "isReseter": _form.businessData.control.allowReset,
  11. "isDelete": _form.businessData.control.allowDeleteWork,
  12. "isPront": true,
  13. "isPrint": true
  14. };
  15. //data
  16. var getJSONData = function(jData){
  17. return new MWF.xScript.JSONData(jData, function(data, key, _self){
  18. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  19. while (p && !_forms[p.getKey()]) p = p.getParent();
  20. if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  21. });
  22. };
  23. this.setData = function(data){
  24. this.data = getJSONData(data);
  25. this.data.save = function(callback){
  26. form.workAction.saveData(function(){if (callback) callback();}.bind(this), null, work.id, jData);
  27. }
  28. };
  29. this.setData(_data);
  30. //task
  31. //this.task = ev.task;
  32. //this.task.process = function(routeName, opinion, callback){
  33. // _form.submitWork(routeName, opinion, callback);
  34. //};
  35. //inquiredRouteList
  36. //this.inquiredRouteList = null;
  37. //workContext
  38. this.workContext = {
  39. "getTask": function(){return ev.task || null;},
  40. "getWork": function(){return ev.work || ev.workCompleted;},
  41. "getActivity": function(){return ev.activity || null;},
  42. "getTaskList": function(){return ev.taskList;},
  43. "getReadList": function(){return ev.readList;},
  44. "getTaskCompletedList": function(){
  45. //MWF.Actions.get("")
  46. return ev.taskCompletedList;
  47. },
  48. "getControl": function(){return ev.control;},
  49. "getWorkLogList": function(){return ev.workLogList;},
  50. "getAttachmentList": function(){return ev.attachmentList;},
  51. "getRouteList": function(){return (ev.task) ? ev.task.routeNameList: null;},
  52. "getInquiredRouteList": function(){return null;},
  53. "setTitle": function(title){
  54. if (!this.workAction){
  55. MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  56. this.workAction = new MWF.xScript.Actions.WorkActions();
  57. }
  58. this.workAction.setTitle(ev.work.id, {"title": title});
  59. }
  60. };
  61. this.workContent = this.workContext;
  62. var _redefineWorkProperties = function(work){
  63. if (work){
  64. work.creatorPersonDn = work.creatorPerson ||"";
  65. work.creatorUnitDn = work.creatorUnit ||"";
  66. work.creatorUnitDnList = work.creatorUnitList ||"";
  67. work.creatorIdentityDn = work.creatorIdentity ||"";
  68. var o = {
  69. "creatorPerson": {"get": function(){return this.creatorPersonDn.substring(0, this.creatorPersonDn.indexOf("@"));}},
  70. "creatorUnit": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  71. "creatorDepartment": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  72. "creatorIdentity": {"get": function(){return this.creatorIdentityDn.substring(0, this.creatorIdentityDn.indexOf("@"));}},
  73. // "creatorUnitList": {
  74. // "get": function(){
  75. // var v = [];
  76. // this.creatorUnitDnList.each(function(dn){
  77. // v.push(dn.substring(0, dn.indexOf("@")))
  78. // });
  79. // return v;
  80. // }
  81. // },
  82. "creatorCompany": {"get": function(){
  83. if (this.creatorUnitLevel){
  84. var level = this.creatorUnitLevel.split("/");
  85. return level[0];
  86. }else{
  87. return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));
  88. }
  89. }}
  90. };
  91. MWF.defineProperties(work, o);
  92. }
  93. return work;
  94. };
  95. var _redefineTaskProperties = function(task){
  96. if (task){
  97. task.personDn = task.person || "";
  98. task.unitDn = task.unit || "";
  99. task.unitDnList = task.unitList || "";
  100. task.identityDn = task.identity || "";
  101. var o = {
  102. "person": {"get": function(){return this.personDn.substring(0, this.personDn.indexOf("@"));}},
  103. "unit": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  104. "department": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  105. "identity": {"get": function(){return this.identityDn.substring(0, this.identityDn.indexOf("@"));}},
  106. // "unitList": {
  107. // "get": function(){
  108. // var v = [];
  109. // this.unitDnList.each(function(dn){
  110. // v.push(dn.substring(0, dn.indexOf("@")))
  111. // });
  112. // return v;
  113. // }
  114. // },
  115. "company": {"get": function(){return this.unitList[0];}}
  116. };
  117. MWF.defineProperties(task, o);
  118. }
  119. return task;
  120. };
  121. _redefineWorkProperties(this.workContext.getWork());
  122. _redefineTaskProperties(_redefineWorkProperties(this.workContext.getTask()));
  123. //dict
  124. this.Dict = MWF.xScript.createDict(_form.json.application);
  125. //unit
  126. var orgActions = null;
  127. var getOrgActions = function(){
  128. // if (!orgActions){
  129. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  130. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  131. // }
  132. if (!orgActions){
  133. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  134. orgActions = new MWF.xScript.Actions.UnitActions();
  135. }
  136. };
  137. var getNameFlag = function(name){
  138. var t = typeOf(name);
  139. if (t==="array"){
  140. var v = [];
  141. name.each(function(id){
  142. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  143. });
  144. return v;
  145. }else{
  146. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  147. }
  148. };
  149. this.org = {
  150. //群组***************
  151. //获取群组--返回群组的对象数组
  152. getGroup: function(name){
  153. getOrgActions();
  154. var data = {"groupList": getNameFlag(name)};
  155. var v = null;
  156. orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  157. return (v && v.length===1) ? v[0] : v;
  158. },
  159. //查询下级群组--返回群组的对象数组
  160. //nested 布尔 true嵌套下级;false直接下级;默认false;
  161. listSubGroup: function(name, nested){
  162. getOrgActions();
  163. var data = {"groupList": getNameFlag(name)};
  164. var v = null;
  165. if (nested){
  166. orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  167. }else{
  168. orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  169. }
  170. return v;
  171. },
  172. //查询上级群组--返回群组的对象数组
  173. //nested 布尔 true嵌套上级;false直接上级;默认false;
  174. listSupGroup:function(name, nested){
  175. getOrgActions();
  176. var data = {"groupList": getNameFlag(name)};
  177. var v = null;
  178. if (nested){
  179. orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  180. }else{
  181. orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  182. }
  183. return v;
  184. },
  185. //人员所在群组(嵌套)--返回群组的对象数组
  186. listGroupWithPerson:function(name){
  187. getOrgActions();
  188. var data = {"personList": getNameFlag(name)};
  189. var v = null;
  190. orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  191. return v;
  192. },
  193. //群组是否拥有角色--返回true, false
  194. groupHasRole: function(name, role){
  195. getOrgActions();
  196. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  197. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  198. var v = false;
  199. orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  200. return v;
  201. },
  202. //角色***************
  203. //获取角色--返回角色的对象数组
  204. getRole: function(name){
  205. getOrgActions();
  206. var data = {"roleList": getNameFlag(name)};
  207. var v = null;
  208. orgActions.listRole(data, function(json){v = json.data;}, null, false);
  209. return (v && v.length===1) ? v[0] : v;
  210. },
  211. //人员所有角色(嵌套)--返回角色的对象数组
  212. listRoleWithPerson:function(name){
  213. getOrgActions();
  214. var data = {"personList": getNameFlag(name)};
  215. var v = null;
  216. orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  217. return v;
  218. },
  219. //人员***************
  220. //人员是否拥有角色--返回true, false
  221. personHasRole: function(name, role){
  222. getOrgActions();
  223. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  224. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  225. var v = false;
  226. orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  227. return v;
  228. },
  229. //获取人员--返回人员的对象数组
  230. getPerson: function(name){
  231. getOrgActions();
  232. var data = {"personList": getNameFlag(name)};
  233. var v = null;
  234. orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  235. return (v && v.length===1) ? v[0] : v;;
  236. },
  237. //查询下级人员--返回人员的对象数组
  238. //nested 布尔 true嵌套下级;false直接下级;默认false;
  239. listSubPerson: function(name, nested){
  240. getOrgActions();
  241. var data = {"personList": getNameFlag(name)};
  242. var v = null;
  243. if (nested){
  244. orgActions.listPersonSubNested(data, function(json){v = json.data;}, null, false);
  245. }else{
  246. orgActions.listPersonSubDirect(data, function(json){v = json.data;}, null, false);
  247. }
  248. return v;
  249. },
  250. //查询上级人员--返回人员的对象数组
  251. //nested 布尔 true嵌套上级;false直接上级;默认false;
  252. listSupPerson: function(name, nested){
  253. getOrgActions();
  254. var data = {"personList": getNameFlag(name)};
  255. var v = null;
  256. if (nested){
  257. orgActions.listPersonSupNested(data, function(json){v = json.data;}, null, false);
  258. }else{
  259. orgActions.listPersonSupDirect(data, function(json){v = json.data;}, null, false);
  260. }
  261. return v;
  262. },
  263. //获取群组的所有人员--返回人员的对象数组
  264. listPersonWithGroup: function(name){
  265. getOrgActions();
  266. var data = {"groupList": getNameFlag(name)};
  267. var v = null;
  268. orgActions.listPersonWithGroup(data, function(json){v = json.data;}, null, false);
  269. return v;
  270. },
  271. //获取角色的所有人员--返回人员的对象数组
  272. listPersonWithRole: function(name){
  273. getOrgActions();
  274. var data = {"roleList": getNameFlag(name)};
  275. var v = null;
  276. orgActions.listPersonWithRole(data, function(json){v = json.data;}, null, false);
  277. return v;
  278. },
  279. //获取身份的所有人员--返回人员的对象数组
  280. listPersonWithIdentity: function(name){
  281. getOrgActions();
  282. var data = {"identityList": getNameFlag(name)};
  283. var v = null;
  284. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  285. return v;
  286. },
  287. //获取身份的所有人员--返回人员的对象数组或人员对象
  288. getPersonWithIdentity: function(name){
  289. getOrgActions();
  290. var data = {"identityList": getNameFlag(name)};
  291. var v = null;
  292. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  293. return (v && v.length===1) ? v[0] : v;
  294. },
  295. //查询组织成员的人员--返回人员的对象数组
  296. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  297. listPersonWithUnit: function(name, nested){
  298. getOrgActions();
  299. var data = {"unitList": getNameFlag(name)};
  300. var v = null;
  301. if (nested){
  302. orgActions.listPersonWithUnitNested(data, function(json){v = json.data;}, null, false);
  303. }else{
  304. orgActions.listPersonWithUnitDirect(data, function(json){v = json.data;}, null, false);
  305. }
  306. return v;
  307. },
  308. //人员属性************
  309. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  310. appendPersonAttribute: function(person, attr, values){
  311. getOrgActions();
  312. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  313. var data = {"attributeList":values,"name":attr,"person":personFlag};
  314. orgActions.appendPersonAttribute(data, function(json){
  315. if (json.data.value){
  316. if (success) success();
  317. }else{
  318. if (failure) failure(null, "", "append values failed");
  319. }
  320. }, function(xhr, text, error){
  321. if (failure) failure(xhr, text, error);
  322. }, false);
  323. },
  324. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  325. setPersonAttribute: function(person, attr, values){
  326. getOrgActions();
  327. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  328. var data = {"attributeList":values,"name":attr,"person":personFlag};
  329. orgActions.setPersonAttribute(data, function(json){
  330. if (json.data.value){
  331. if (success) success();
  332. }else{
  333. if (failure) failure(null, "", "append values failed");
  334. }
  335. }, function(xhr, text, error){
  336. if (failure) failure(xhr, text, error);
  337. }, false);
  338. },
  339. //获取人员属性值
  340. getPersonAttribute: function(person, attr){
  341. getOrgActions();
  342. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  343. var data = {"name":attr,"person":personFlag};
  344. var v = null;
  345. orgActions.getPersonAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  346. return v;
  347. },
  348. //列出人员所有属性的名称
  349. listPersonAttributeName: function(name){
  350. getOrgActions();
  351. var data = {"personList":getNameFlag(name)};
  352. var v = null;
  353. orgActions.listPersonAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  354. return v;
  355. },
  356. //列出人员的所有属性
  357. listPersonAllAttribute: function(name){
  358. getOrgActions();
  359. var data = {"personList":getNameFlag(name)};
  360. var v = null;
  361. orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  362. return v;
  363. },
  364. //身份**********
  365. //获取身份
  366. getIdentity: function(name){
  367. getOrgActions();
  368. var data = {"identityList":getNameFlag(name)};
  369. var v = null;
  370. orgActions.listIdentity(data, function(json){v = json.data;}, null, false);
  371. return (v && v.length===1) ? v[0] : v;
  372. },
  373. //列出人员的身份
  374. listIdentityWithPerson: function(name){
  375. getOrgActions();
  376. var data = {"personList":getNameFlag(name)};
  377. var v = null;
  378. orgActions.listIdentityWithPerson(data, function(json){v = json.data;}, null, false);
  379. return v;
  380. },
  381. //查询组织成员身份--返回身份的对象数组
  382. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  383. listIdentityWithUnit: function(name, nested){
  384. getOrgActions();
  385. var data = {"unitList": getNameFlag(name)};
  386. var v = null;
  387. if (nested){
  388. orgActions.listIdentityWithUnitNested(data, function(json){v = json.data;}, null, false);
  389. }else{
  390. orgActions.listIdentityWithUnitDirect(data, function(json){v = json.data;}, null, false);
  391. }
  392. return v;
  393. },
  394. //组织**********
  395. //获取组织
  396. getUnit: function(name){
  397. getOrgActions();
  398. var data = {"unitList":getNameFlag(name)};
  399. var v = null;
  400. orgActions.listUnit(data, function(json){v = json.data;}, null, false);
  401. return (v && v.length===1) ? v[0] : v;
  402. },
  403. //查询组织的下级--返回组织的对象数组
  404. //nested 布尔 true嵌套下级;false直接下级;默认false;
  405. listSubUnit: function(name, nested){
  406. getOrgActions();
  407. var data = {"unitList": getNameFlag(name)};
  408. var v = null;
  409. if (nested){
  410. orgActions.listUnitSubNested(data, function(json){v = json.data;}, null, false);
  411. }else{
  412. orgActions.listUnitSubDirect(data, function(json){v = json.data;}, null, false);
  413. }
  414. return v;
  415. },
  416. //查询组织的上级--返回组织的对象数组
  417. //nested 布尔 true嵌套上级;false直接上级;默认false;
  418. listSupUnit: function(name, nested){
  419. getOrgActions();
  420. var data = {"unitList": getNameFlag(name)};
  421. var v = null;
  422. if (nested){
  423. orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  424. }else{
  425. orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  426. }
  427. return v;
  428. },
  429. //根据个人身份获取组织
  430. //flag 数字 表示获取第几层的组织
  431. // 字符串 表示获取指定类型的组织
  432. // 空 表示获取直接所在的组织
  433. getUnitByIdentity: function(name, flag){
  434. getOrgActions();
  435. var getUnitMethod = "current";
  436. var v;
  437. if (flag){
  438. if (typeOf(flag)==="string") getUnitMethod = "type";
  439. if (typeOf(flag)==="number") getUnitMethod = "level";
  440. }
  441. switch (getUnitMethod){
  442. case "current":
  443. var data = {"identityList":getNameFlag(name)};
  444. orgActions.f(data, function(json){ v = json.data; }, null, false);
  445. break;
  446. case "type":
  447. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  448. orgActions.getUnitWithIdentityAndType(data, function(json){ v = json.data; }, null, false);
  449. break;
  450. case "level":
  451. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  452. orgActions.getUnitWithIdentityAndLevel(data, function(json){ v = json.data; }, null, false);
  453. break;
  454. }
  455. return v;
  456. },
  457. //列出身份所在组织的所有上级组织
  458. listAllSupUnitWithIdentity: function(name){
  459. getOrgActions();
  460. var data = {"identityList":getNameFlag(name)};
  461. var v = null;
  462. orgActions.listUnitSupNestedWithIdentity(data, function(json){v = json.data;}, null, false);
  463. return v;
  464. },
  465. //获取人员所在的所有组织
  466. listUnitWithPerson: function(name){
  467. getOrgActions();
  468. var data = {"personList":getNameFlag(name)};
  469. var v = null;
  470. orgActions.listUnitWithPerson(data, function(json){v = json.data;}, null, false);
  471. return v;
  472. },
  473. //列出人员所在组织的所有上级组织
  474. listAllSupUnitWithPerson: function(name){
  475. getOrgActions();
  476. var data = {"personList":getNameFlag(name)};
  477. var v = null;
  478. orgActions.listUnitSupNestedWithPerson(data, function(json){v = json.data;}, null, false);
  479. return v;
  480. },
  481. //根据组织属性,获取所有符合的组织
  482. listUnitWithAttribute: function(name, attribute){
  483. getOrgActions();
  484. var data = {"name":name,"attribute":attribute};
  485. var v = null;
  486. orgActions.listUnitWithAttribute(data, function(json){v = json.data;}, null, false);
  487. return v;
  488. },
  489. //根据组织职务,获取所有符合的组织
  490. listUnitWithDuty: function(name, id){
  491. getOrgActions();
  492. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  493. var v = null;
  494. orgActions.listUnitWithDuty(data, function(json){v = json.data;}, null, false);
  495. return v;
  496. },
  497. //组织职务***********
  498. //获取指定的组织职务的身份
  499. getDuty: function(duty, id){
  500. getOrgActions();
  501. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  502. var v = null;
  503. orgActions.getDuty(data, function(json){v = json.data;}, null, false);
  504. return v;
  505. },
  506. //获取身份的所有职务名称
  507. listDutyNameWithIdentity: function(name){
  508. getOrgActions();
  509. var data = {"identityList":getNameFlag(name)};
  510. var v = null;
  511. orgActions.listDutyNameWithIdentity(data, function(json){v = json.data.nameList;}, null, false);
  512. return v;
  513. },
  514. //获取组织的所有职务名称
  515. listDutyNameWithUnit: function(name){
  516. getOrgActions();
  517. var data = {"unitList":getNameFlag(name)};
  518. var v = null;
  519. orgActions.listDutyNameWithUnit(data, function(json){v = json.data.nameList;}, null, false);
  520. return v;
  521. },
  522. //获取组织的所有职务
  523. listUnitAllDuty: function(name){
  524. getOrgActions();
  525. var data = {"unitList":getNameFlag(name)};
  526. var v = null;
  527. orgActions.listUnitAllDuty(data, function(json){v = json.data;}, null, false);
  528. return v;
  529. },
  530. //列出顶层组织
  531. listTopUnit: function(){
  532. var action = MWF.Actions.get("x_organization_assemble_control");
  533. var v = null;
  534. action.listTopUnit(function(json){
  535. v = json.data;
  536. }, null, false);
  537. return v;
  538. },
  539. //组织属性**************
  540. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  541. appendUnitAttribute: function(unit, attr, values){
  542. getOrgActions();
  543. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  544. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  545. orgActions.appendUnitAttribute(data, function(json){
  546. if (json.data.value){
  547. if (success) success();
  548. }else{
  549. if (failure) failure(null, "", "append values failed");
  550. }
  551. }, function(xhr, text, error){
  552. if (failure) failure(xhr, text, error);
  553. }, false);
  554. },
  555. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  556. setUnitAttribute: function(unit, attr, values){
  557. getOrgActions();
  558. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  559. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  560. orgActions.setUnitAttribute(data, function(json){
  561. if (json.data.value){
  562. if (success) success();
  563. }else{
  564. if (failure) failure(null, "", "append values failed");
  565. }
  566. }, function(xhr, text, error){
  567. if (failure) failure(xhr, text, error);
  568. }, false);
  569. },
  570. //获取组织属性值
  571. getUnitAttribute: function(unit, attr){
  572. getOrgActions();
  573. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  574. var data = {"name":attr,"unit":unitFlag};
  575. var v = null;
  576. orgActions.getUnitAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  577. return v;
  578. },
  579. //列出组织所有属性的名称
  580. listUnitAttributeName: function(name){
  581. getOrgActions();
  582. var data = {"unitList":getNameFlag(name)};
  583. var v = null;
  584. orgActions.listUnitAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  585. return v;
  586. },
  587. //列出组织的所有属性
  588. listUnitAllAttribute: function(name){
  589. getOrgActions();
  590. var data = {"unitList":getNameFlag(name)};
  591. var v = null;
  592. orgActions.listUnitAllAttribute(data, function(json){v = json.data;}, null, false);
  593. return v;
  594. }
  595. };
  596. this.Action = (function(){
  597. var actions = [];
  598. return function(root, json){
  599. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  600. action.getActions = function(callback){
  601. if (!this.actions) this.actions = {};
  602. Object.merge(this.actions, json);
  603. if (callback) callback();
  604. };
  605. this.invoke = function(option){
  606. action.invoke(option)
  607. }
  608. }
  609. })();
  610. this.service = {
  611. "jaxwsClient":{},
  612. "jaxrsClient":{}
  613. };
  614. var lookupAction = null;
  615. var getLookupAction = function(callback){
  616. if (!lookupAction){
  617. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  618. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  619. lookupAction.getActions = function(actionCallback){
  620. this.actions = {
  621. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  622. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  623. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  624. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  625. };
  626. if (actionCallback) actionCallback();
  627. };
  628. if (callback) callback();
  629. });
  630. }else{
  631. if (callback) callback();
  632. }
  633. };
  634. //this.view = {
  635. // "lookup": function(view, callback){
  636. // getLookupAction(function(){
  637. // lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  638. // var data = {
  639. // "grid": json.data.grid,
  640. // "groupGrid": json.data.groupGrid
  641. // };
  642. // if (callback) callback(data);
  643. // }.bind(this)});
  644. // }.bind(this));
  645. // },
  646. // "select": function(view, callback, options){
  647. // if (view.view){
  648. // var viewJson = {
  649. // "application": view.application || _form.json.application,
  650. // "viewName": view.view || "",
  651. // "isTitle": view.isTitle || "yes",
  652. // "select": view.select || "multi",
  653. // "title": view.title || "Select View"
  654. // };
  655. // if (!options) options = {};
  656. // var width = options.width || "700";
  657. // var height = options.height || "400";
  658. //
  659. // var size;
  660. // if (layout.mobile){
  661. // size = document.body.getSize();
  662. // width = size.x;
  663. // height = size.y;
  664. // options.style = "viewmobile";
  665. // }
  666. // width = width.toInt();
  667. // height = height.toInt();
  668. //
  669. // size = _form.app.content.getSize();
  670. // var x = (size.x-width)/2;
  671. // var y = (size.y-height)/2;
  672. // if (x<0) x = 0;
  673. // if (y<0) y = 0;
  674. // if (layout.mobile){
  675. // x = 20;
  676. // y = 0;
  677. // }
  678. //
  679. // var _self = this;
  680. // MWF.require("MWF.xDesktop.Dialog", function(){
  681. // var dlg = new MWF.xDesktop.Dialog({
  682. // "title": viewJson.title || "select view",
  683. // "style": options.style || "view",
  684. // "top": y,
  685. // "left": x-20,
  686. // "fromTop":y,
  687. // "fromLeft": x-20,
  688. // "width": width,
  689. // "height": height,
  690. // "html": "<div style='height: 100%;'></div>",
  691. // "maskNode": _form.app.content,
  692. // "container": _form.app.content,
  693. // "buttonList": [
  694. // {
  695. // "text": MWF.LP.process.button.ok,
  696. // "action": function(){
  697. // //if (callback) callback(_self.view.selectedItems);
  698. // if (callback) callback(_self.view.getData());
  699. // this.close();
  700. // }
  701. // },
  702. // {
  703. // "text": MWF.LP.process.button.cancel,
  704. // "action": function(){this.close();}
  705. // }
  706. // ]
  707. // });
  708. // dlg.show();
  709. //
  710. // if (layout.mobile){
  711. // var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  712. // var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  713. // if (backAction) backAction.addEvent("click", function(){
  714. // dlg.close();
  715. // }.bind(this));
  716. // if (okAction) okAction.addEvent("click", function(){
  717. // //if (callback) callback(this.view.selectedItems);
  718. // if (callback) callback(this.view.getData());
  719. // dlg.close();
  720. // }.bind(this));
  721. // }
  722. //
  723. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  724. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  725. // }.bind(this));
  726. // }.bind(this));
  727. // }
  728. // }
  729. //};
  730. this.view = {
  731. "lookup": function(view, callback, async){
  732. var filterList = {"filterList": (view.filter || null)};
  733. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  734. var data = {
  735. "grid": json.data.grid || json.data.groupGrid,
  736. "groupGrid": json.data.groupGrid
  737. };
  738. if (callback) callback(data);
  739. }, null, async);
  740. },
  741. "lookupV1": function(view, callback){
  742. getLookupAction(function(){
  743. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  744. var data = {
  745. "grid": json.data.grid,
  746. "groupGrid": json.data.groupGrid
  747. };
  748. if (callback) callback(data);
  749. }.bind(this)});
  750. }.bind(this));
  751. },
  752. "select": function(view, callback, options){
  753. if (view.view){
  754. var viewJson = {
  755. "application": view.application || _form.json.application,
  756. "viewName": view.view || "",
  757. "isTitle": (view.isTitle===false) ? "no" : "yes",
  758. "select": (view.isMulti===false) ? "single" : "multi",
  759. "filter": view.filter
  760. };
  761. if (!options) options = {};
  762. options.width = view.width;
  763. options.height = view.height;
  764. options.title = view.caption;
  765. var width = options.width || "700";
  766. var height = options.height || "400";
  767. if (layout.mobile){
  768. var size = document.body.getSize();
  769. width = size.x;
  770. height = size.y;
  771. options.style = "viewmobile";
  772. }
  773. width = width.toInt();
  774. height = height.toInt();
  775. var size = _form.app.content.getSize();
  776. var x = (size.x-width)/2;
  777. var y = (size.y-height)/2;
  778. if (x<0) x = 0;
  779. if (y<0) y = 0;
  780. if (layout.mobile){
  781. x = 20;
  782. y = 0;
  783. }
  784. var _self = this;
  785. MWF.require("MWF.xDesktop.Dialog", function(){
  786. var dlg = new MWF.xDesktop.Dialog({
  787. "title": options.title || "select view",
  788. "style": options.style || "view",
  789. "top": y,
  790. "left": x-20,
  791. "fromTop":y,
  792. "fromLeft": x-20,
  793. "width": width,
  794. "height": height,
  795. "html": "<div style='height: 100%;'></div>",
  796. "maskNode": _form.app.content,
  797. "container": _form.app.content,
  798. "buttonList": [
  799. {
  800. "text": MWF.LP.process.button.ok,
  801. "action": function(){
  802. //if (callback) callback(_self.view.selectedItems);
  803. if (callback) callback(_self.view.getData());
  804. this.close();
  805. }
  806. },
  807. {
  808. "text": MWF.LP.process.button.cancel,
  809. "action": function(){this.close();}
  810. }
  811. ]
  812. });
  813. dlg.show();
  814. if (layout.mobile){
  815. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  816. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  817. if (backAction) backAction.addEvent("click", function(e){
  818. dlg.close();
  819. }.bind(this));
  820. if (okAction) okAction.addEvent("click", function(e){
  821. //if (callback) callback(this.view.selectedItems);
  822. if (callback) callback(this.view.getData());
  823. dlg.close();
  824. }.bind(this));
  825. }
  826. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  827. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  828. }.bind(this));
  829. }.bind(this));
  830. }
  831. }
  832. };
  833. //include 引用脚本
  834. //optionsOrName : {
  835. // type : "", 默认为process, 可以为 portal process cms
  836. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  837. // name : "" // 脚本名称/别名/id
  838. //}
  839. //或者name: "" // 脚本名称/别名/id
  840. if( !window.includedScripts ){
  841. var includedScripts = window.includedScripts = [];
  842. }else{
  843. var includedScripts = window.includedScripts;
  844. }
  845. this.include = function( optionsOrName , callback ){
  846. var options = optionsOrName;
  847. if( typeOf( options ) == "string" ){
  848. options = { name : options };
  849. }
  850. var name = options.name;
  851. var type = ( options.type && options.application ) ? options.type : "process";
  852. var application = options.application || _form.json.application;
  853. if (includedScripts.indexOf( name )> -1){
  854. if (callback) callback.apply(this);
  855. return;
  856. }
  857. var scriptAction;
  858. switch ( type ){
  859. case "portal" :
  860. if( this.scriptActionPortal ){
  861. scriptAction = this.scriptActionPortal;
  862. }else{
  863. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  864. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  865. }
  866. break;
  867. case "process" :
  868. if( this.scriptActionProcess ){
  869. scriptAction = this.scriptActionProcess;
  870. }else{
  871. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  872. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  873. }
  874. break;
  875. case "cms" :
  876. if( this.scriptActionCMS ){
  877. scriptAction = this.scriptActionCMS;
  878. }else{
  879. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  880. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  881. }
  882. break;
  883. }
  884. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  885. if (json.data){
  886. includedScripts = includedScripts.concat(json.data.importedList);
  887. MWF.Macro.exec(json.data.text, this);
  888. if (callback) callback.apply(this);
  889. }else{
  890. if (callback) callback.apply(this);
  891. }
  892. }.bind(this), null, false);
  893. };
  894. //var includedScripts = [];
  895. //this.include = function(name, callback){
  896. // if (includedScripts.indexOf(name)===-1){
  897. // if (!this.scriptAction){
  898. // MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  899. // this.scriptAction = new MWF.xScript.Actions.ScriptActions();
  900. // }
  901. // this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
  902. // if (json.data){
  903. // includedScripts = includedScripts.concat(json.data.importedList);
  904. // MWF.Macro.exec(json.data.text, this);
  905. // if (callback) callback.apply(this);
  906. // }else{
  907. // if (callback) callback.apply(this);
  908. // }
  909. // }.bind(this), null, false);
  910. // }else{
  911. // if (callback) callback.apply(this);
  912. // }
  913. //}.bind(this);
  914. this.define = function(name, fun, overwrite){
  915. var over = true;
  916. if (overwrite===false) over = false;
  917. var o = {};
  918. o[name] = {"value": fun, "configurable": over};
  919. MWF.defineProperties(this, o);
  920. }.bind(this);
  921. //仅前台对象-----------------------------------------
  922. //form
  923. this.form = {
  924. "getInfor": function(){return ev.formInfor;},
  925. "infor": ev.formInfor,
  926. "getApp": function(){return _form.app;},
  927. "app": _form.app,
  928. "node": function(){return _form.node;},
  929. "readonly": _form.options.readonly,
  930. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  931. "getField": function(name){return _forms[name];},
  932. "getAction": function(){return _form.workAction},
  933. "getDesktop": function(){return _form.app.desktop},
  934. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  935. "save": function(callback){_form.saveWork(callback);},
  936. "close": function(){_form.closeWork();},
  937. "process": function(option){
  938. if (option){
  939. _form.submitWork(option.routeName, option.opinion, null, option.callback);
  940. }else{
  941. _form.processWork();
  942. }
  943. },
  944. "reset": function(option){
  945. if (!option){
  946. if (_form.businessData.control["allowReset"]) _form.resetWork();
  947. }else{
  948. _form.resetWorkToPeson(option.names, option.opinion, opinion.success, opinion.failure);
  949. }
  950. },
  951. "retract": function(option){
  952. if (!option){
  953. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  954. }else{
  955. _form.doRetractWork(opinion.success, opinion.failure);
  956. }
  957. },
  958. "print": function(application, form){
  959. if (arguments.length){
  960. var app = (arguments.length>1) ? arguments[0] : null;
  961. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  962. _form.printWork(app, formName);
  963. }else{
  964. _form.printWork();
  965. }
  966. },
  967. "deleteWork": function(option){
  968. if (!option){
  969. if (_form.businessData.control["allowDeleteWork"]) _form.deleteWork();
  970. }else{
  971. _form.doDeleteWork(opinion.success, opinion.failure);
  972. }
  973. },
  974. "confirm": function(type, title, text, width, height, ok, cancel, callback){
  975. var p = MWF.getCenter({"x": width, "y": height});
  976. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  977. _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  978. },
  979. "notice": function(content, type, target, where){
  980. _form.notice(content, type, target, where);
  981. },
  982. "addEvent": function(e, f){_form.addEvent(e, f);},
  983. "openWindow": function(application, form){
  984. if (arguments.length){
  985. var app = (arguments.length>1) ? arguments[0] : null;
  986. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  987. _form.openWindow(formName, app);
  988. }else{
  989. _form.openWindow();
  990. }
  991. },
  992. "openWork": function(id, completedId, title, options){
  993. var op = options || {};
  994. op.workId = id;
  995. op.workCompletedId = completedId;
  996. op.docTitle = title;
  997. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  998. layout.desktop.openApplication(this.event, "process.Work", op);
  999. },
  1000. "openDocument": function(id, title, options){
  1001. var op = options || {};
  1002. op.documentId = id;
  1003. op.docTitle = title;
  1004. layout.desktop.openApplication(this.event, "cms.Document", op);
  1005. },
  1006. "openPortal": function(name, page, par){
  1007. var action = MWF.Actions.get("x_portal_assemble_surface");
  1008. action.getApplication(name, function(json){
  1009. if (json.data){
  1010. if (page){
  1011. action.getPageByName(page, json.data.id, function(pageJson){
  1012. layout.desktop.openApplication(null, "portal.Portal", {
  1013. "portalId": json.data.id,
  1014. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1015. "parameters": par,
  1016. "appId": "portal.Portal"+json.data.id
  1017. })
  1018. });
  1019. }else{
  1020. layout.desktop.openApplication(null, "portal.Portal", {
  1021. "portalId": json.data.id,
  1022. "parameters": par,
  1023. "appId": "portal.Portal"+json.data.id
  1024. })
  1025. }
  1026. }
  1027. });
  1028. },
  1029. "openCMS": function(name){
  1030. var action = MWF.Actions.get("x_cms_assemble_control");
  1031. action.getColumn(name, function(json){
  1032. if (json.data){
  1033. layout.desktop.openApplication(null, "cms.Module", {
  1034. "columnId": json.data.id,
  1035. "appId": "cms.Module"+json.data.id
  1036. });
  1037. }
  1038. });
  1039. },
  1040. "openProcess": function(name){
  1041. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1042. action.getApplication(name, function(json){
  1043. if (json.data){
  1044. layout.desktop.openApplication(null, "process.Application", {
  1045. "id": json.data.id,
  1046. "appId": "process.Application"+json.data.id
  1047. });
  1048. }
  1049. });
  1050. },
  1051. "openApplication":function(name, options){
  1052. layout.desktop.openApplication(null, name, options);
  1053. },
  1054. "createDocument" : function(columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle){
  1055. var column = columnOrOptions;
  1056. if( typeOf( columnOrOptions ) == "object" ){
  1057. column = columnOrOptions.column;
  1058. category = columnOrOptions.category;
  1059. data = columnOrOptions.data;
  1060. identity = columnOrOptions.identity;
  1061. callback = columnOrOptions.callback;
  1062. target = columnOrOptions.target;
  1063. latest = columnOrOptions.latest;
  1064. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1065. ignoreTitle = columnOrOptions.ignoreTitle;
  1066. }
  1067. if (target){
  1068. if (layout.app && layout.app.inBrowser){
  1069. layout.app.content.empty();
  1070. layout.app = null;
  1071. }
  1072. }
  1073. MWF.xDesktop.requireApp("cms.Index", "Newer", function(){
  1074. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1075. "documentData": data,
  1076. "identity": identity,
  1077. "ignoreTitle" : ignoreTitle === true,
  1078. "ignoreDrafted" : latest === false,
  1079. "selectColumnEnable" : !category || selectColumnEnable === true,
  1080. "restrictToColumn" : !!category && selectColumnEnable !== true,
  1081. "categoryFlag" : category, //category id or name
  1082. "columnFlag" : column, //column id or name,
  1083. "onStarted" : function( documentId, data ){
  1084. if(callback)callback();
  1085. },
  1086. "onPostLoad" : function(){
  1087. },
  1088. "onPostPublish" : function(){
  1089. }
  1090. });
  1091. starter.load();
  1092. })
  1093. },
  1094. "startProcess": function(app, process, data, identity, callback, target, latest){
  1095. if (arguments.length>2){
  1096. for (var i=2; i<arguments.length; i++){
  1097. if (typeOf(arguments[i])=="boolean"){
  1098. target = arguments[i];
  1099. break;
  1100. }
  1101. }
  1102. }
  1103. if (target){
  1104. if (layout.app && layout.app.inBrowser){
  1105. layout.app.content.empty();
  1106. layout.app = null;
  1107. }
  1108. }
  1109. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1110. if (json.data){
  1111. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1112. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1113. "workData": data,
  1114. "identity": identity,
  1115. "latest": latest,
  1116. "onStarted": function(data, title, processName){
  1117. var currentTask = [];
  1118. data.each(function(work){
  1119. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1120. }.bind(this));
  1121. if (currentTask.length==1){
  1122. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1123. layout.desktop.openApplication(null, "process.Work", options);
  1124. }else{}
  1125. if (callback) callback(data);
  1126. }.bind(this)
  1127. });
  1128. starter.load();
  1129. }.bind(this));
  1130. }
  1131. });
  1132. }
  1133. };
  1134. this.form.currentRouteName = _form.json.currentRouteName;
  1135. this.form.opinion = _form.json.opinion;
  1136. this.target = ev.target;
  1137. this.event = ev.event;
  1138. this.status = ev.status;
  1139. this.session = layout.desktop.session;
  1140. this.Actions = o2.Actions;
  1141. };
  1142. MWF.xScript.JSONData = function(data, callback, key, parent){
  1143. var getter = function(data, callback, k, _self){
  1144. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self);};
  1145. };
  1146. var setter = function(data, callback, k, _self){
  1147. return function(v){
  1148. data[k] = v;
  1149. //debugger;
  1150. //this.add(k, v, true);
  1151. if (callback) callback(data, k, _self);
  1152. }
  1153. };
  1154. var define = function(){
  1155. var o = {};
  1156. 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])};
  1157. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1158. MWF.defineProperties(this, o);
  1159. var methods = {
  1160. "getKey": {"value": function(){ return key; }},
  1161. "getParent": {"value": function(){ return parent; }},
  1162. "toString": {"value": function() { return data.toString();}},
  1163. "add": {"value": function(newKey, newValue, overwrite){
  1164. var flag = true;
  1165. var type = typeOf(data);
  1166. if (type==="array"){
  1167. if (arguments.length<2){
  1168. data.push(newKey);
  1169. newValue = newKey;
  1170. newKey = data.length-1;
  1171. }else{
  1172. if (!newKey && newKey!==0){
  1173. data.push(newValue);
  1174. newKey = data.length-1;
  1175. }else{
  1176. flag = false;
  1177. }
  1178. }
  1179. if (flag){
  1180. var o = {};
  1181. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1182. MWF.defineProperties(this, o);
  1183. }
  1184. this[newKey] = newValue;
  1185. }else if (type==="object"){
  1186. if (!this.hasOwnProperty(newKey)){
  1187. data[newKey] = newValue;
  1188. if (flag){
  1189. var o = {};
  1190. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1191. MWF.defineProperties(this, o);
  1192. }
  1193. this[newKey] = newValue;
  1194. }else{
  1195. if (overwrite) this[newKey] = newValue;
  1196. }
  1197. }
  1198. return this[newKey];
  1199. }},
  1200. "del": {"value": function(delKey){
  1201. if (!this.hasOwnProperty(delKey)) return null;
  1202. delete data[delKey];
  1203. delete this[delKey];
  1204. return this;
  1205. }}
  1206. };
  1207. MWF.defineProperties(this, methods);
  1208. //this.getKey = function(){ return key; };
  1209. //this.getParent = function(){ return parent; };
  1210. //this.toString = function() { return data.toString();};
  1211. //this.add = function(newKey, newValue, overwrite){
  1212. // var flag = true;
  1213. // var type = typeOf(data);
  1214. // if (!this.hasOwnProperty(newKey)){
  1215. // if (type=="array"){
  1216. // if (arguments.length<2){
  1217. // data.push(newKey);
  1218. // newValue = newKey;
  1219. // newKey = data.length-1;
  1220. // }else{
  1221. // debugger;
  1222. // if (!newKey && newKey!=0){
  1223. // data.push(newValue);
  1224. // newKey = data.length-1;
  1225. // }else{
  1226. // flag == false;
  1227. // }
  1228. // }
  1229. // }else{
  1230. // data[newKey] = newValue;
  1231. // }
  1232. // //var valueType = typeOf(newValue);
  1233. // //var newValueData = newValue;
  1234. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1235. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1236. // if (flag){
  1237. // var o = {};
  1238. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1239. // MWF.defineProperties(this, o);
  1240. // }
  1241. // this[newKey] = newValue;
  1242. // }else{
  1243. // if (overwrite) this[newKey] = newValue;
  1244. // }
  1245. //
  1246. // //var valueType = typeOf(newValue);
  1247. // //var newValueData = newValue;
  1248. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1249. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1250. // //
  1251. // //this[newKey] = newValueData;
  1252. //
  1253. // return this[newKey];
  1254. //};
  1255. //this.del = function(delKey){
  1256. // if (!this.hasOwnProperty(delKey)) return null;
  1257. // delete data[newKey];
  1258. // delete this[newKey];
  1259. // return this;
  1260. //};
  1261. };
  1262. var type = typeOf(data);
  1263. if (type==="object" || type==="array") define.apply(this);
  1264. };
  1265. //MWF.xScript.createDict = function(application){
  1266. // return function(name){
  1267. // var applicationId = application;
  1268. // this.name = name;
  1269. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1270. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1271. //
  1272. // this.get = function(path, success, failure){
  1273. // debugger;
  1274. // var value = null;
  1275. // if (path){
  1276. // var arr = path.split(/\./g);
  1277. // var ar = arr.map(function(v){
  1278. // return encodeURIComponent(v);
  1279. // });
  1280. // //var p = path.replace(/\./g, "/");
  1281. // var p = ar.join("/");
  1282. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1283. // value = json.data;
  1284. // if (success) success(json.data);
  1285. // }, function(xhr, text, error){
  1286. // if (failure) failure(xhr, text, error);
  1287. // }, false);
  1288. // }else{
  1289. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  1290. // value = json.data;
  1291. // if (success) success(json.data);
  1292. // }, function(xhr, text, error){
  1293. // if (failure) failure(xhr, text, error);
  1294. // }, false);
  1295. // }
  1296. //
  1297. // return value;
  1298. // };
  1299. //
  1300. // this.set = function(path, value, success, failure){
  1301. // var p = path.replace(/\./g, "/");
  1302. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1303. // if (success) success(json.data);
  1304. // }, function(xhr, text, error){
  1305. // if (failure) failure(xhr, text, error);
  1306. // });
  1307. // };
  1308. // this.add = function(path, value, success, failure){
  1309. // var p = path.replace(/\./g, "/");
  1310. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1311. // if (success) success(json.data);
  1312. // }, function(xhr, text, error){
  1313. // if (failure) failure(xhr, text, error);
  1314. // });
  1315. // };
  1316. // this["delete"] = function(path, success, failure){
  1317. // var p = path.replace(/\./g, "/");
  1318. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1319. // if (success) success(json.data);
  1320. // }, function(xhr, text, error){
  1321. // if (failure) failure(xhr, text, error);
  1322. // });
  1323. // };
  1324. // this.destory = this["delete"];
  1325. // }
  1326. //};
  1327. MWF.xScript.createDict = function(application){
  1328. //optionsOrName : {
  1329. // type : "", //默认为process, 可以为 process cms
  1330. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1331. // name : "", // 数据字典名称/别名/id
  1332. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1333. //}
  1334. //或者name: "" // 数据字典名称/别名/id
  1335. return function(optionsOrName){
  1336. var options = optionsOrName;
  1337. if( typeOf( options ) == "string" ){
  1338. options = { name : options };
  1339. }
  1340. var name = this.name = options.name;
  1341. var type = ( options.type && options.application ) ? options.type : "process";
  1342. var applicationId = options.application || application;
  1343. var enableAnonymous = options.enableAnonymous || false;
  1344. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1345. if( type == "cms" ){
  1346. var action = MWF.Actions.get("x_cms_assemble_control");
  1347. }else{
  1348. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1349. }
  1350. var encodePath = function( path ){
  1351. var arr = path.split(/\./g);
  1352. var ar = arr.map(function(v){
  1353. return encodeURIComponent(v);
  1354. });
  1355. return ar.join("/");
  1356. };
  1357. this.get = function(path, success, failure){
  1358. var value = null;
  1359. if (path){
  1360. var p = encodePath( path );
  1361. //var p = path.replace(/\./g, "/");
  1362. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1363. value = json.data;
  1364. if (success) success(json.data);
  1365. }, function(xhr, text, error){
  1366. if (failure) failure(xhr, text, error);
  1367. }, false);
  1368. }else{
  1369. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](encodeURIComponent(this.name), applicationId, function(json){
  1370. value = json.data;
  1371. if (success) success(json.data);
  1372. }, function(xhr, text, error){
  1373. if (failure) failure(xhr, text, error);
  1374. }, false);
  1375. }
  1376. return value;
  1377. };
  1378. this.set = function(path, value, success, failure){
  1379. var p = encodePath( path );
  1380. //var p = path.replace(/\./g, "/");
  1381. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1382. if (success) success(json.data);
  1383. }, function(xhr, text, error){
  1384. if (failure) failure(xhr, text, error);
  1385. });
  1386. };
  1387. this.add = function(path, value, success, failure){
  1388. var p = encodePath( path );
  1389. //var p = path.replace(/\./g, "/");
  1390. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1391. if (success) success(json.data);
  1392. }, function(xhr, text, error){
  1393. if (failure) failure(xhr, text, error);
  1394. });
  1395. };
  1396. this["delete"] = function(path, success, failure){
  1397. var p = encodePath( path );
  1398. //var p = path.replace(/\./g, "/");
  1399. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1400. if (success) success(json.data);
  1401. }, function(xhr, text, error){
  1402. if (failure) failure(xhr, text, error);
  1403. });
  1404. };
  1405. this.destory = this["delete"];
  1406. }
  1407. };