Environment.js 66 KB

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