Environment.js 62 KB

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