Environment.js 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065
  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. }, "", null, _form);
  22. };
  23. this.setData = function(data){
  24. this.data = getJSONData(data);
  25. this.data.save = function(callback){
  26. _form.saveFormData(callback)
  27. // var formData = {
  28. // "data": data,
  29. // "sectionList": _form.getSectionList()
  30. // };
  31. // _form.workAction.saveSectionData(function(){if (callback) callback();}.bind(this), null, (ev.work.id || ev.workCompleted.id), formData);
  32. }
  33. };
  34. this.setData(_data);
  35. //task
  36. //this.task = ev.task;
  37. //this.task.process = function(routeName, opinion, callback){
  38. // _form.submitWork(routeName, opinion, callback);
  39. //};
  40. //inquiredRouteList
  41. //this.inquiredRouteList = null;
  42. //workContext
  43. this.workContext = {
  44. "getTask": function(){return ev.task || null;},
  45. "getWork": function(){return ev.work || ev.workCompleted;},
  46. "getActivity": function(){return ev.activity || null;},
  47. "getTaskList": function(callback, error){
  48. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  49. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  50. var list;
  51. o2.Actions.get("x_processplatform_assemble_surface").listTaskByWork(ev.work.id, function(json){
  52. list = json.data;
  53. if (cb) cb(list);
  54. }, ecb, !!cb);
  55. return list;
  56. },
  57. "getTaskListByJob": function(callback, error){
  58. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  59. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  60. var list;
  61. o2.Actions.get("x_processplatform_assemble_surface").listTaskByJob(ev.work.job, function(json){
  62. list = json.data;
  63. if (cb) cb(list);
  64. }, ecb, !!cb);
  65. return list;
  66. },
  67. "getReadList": function(callback, error){
  68. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  69. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  70. var list;
  71. o2.Actions.get("x_processplatform_assemble_surface").listReadByWork(ev.work.id, function(json){
  72. list = json.data;
  73. if (cb) cb(list);
  74. }, ecb, !!cb);
  75. return list;
  76. },
  77. "getReadListByJob": function(callback, error){
  78. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  79. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  80. var list;
  81. o2.Actions.get("x_processplatform_assemble_surface").listReadByJob(ev.work.job, function(json){
  82. list = json.data;
  83. if (cb) cb(list);
  84. }, ecb, !!cb);
  85. return list;
  86. },
  87. "getTaskCompletedList": function(callback, error){
  88. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  89. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  90. var list;
  91. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByWork(ev.work.id, function(json){
  92. list = json.data;
  93. if (cb) cb(list);
  94. }, ecb, !!cb);
  95. return list;
  96. },
  97. "getTaskCompletedListByJob": function(callback, error){
  98. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  99. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  100. var list;
  101. o2.Actions.get("x_processplatform_assemble_surface").listTaskCompletedByJob(ev.work.job, function(json){
  102. list = json.data;
  103. if (cb) cb(list);
  104. }, ecb, !!cb);
  105. return list;
  106. },
  107. "getReadCompletedList": function(callback, error){
  108. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  109. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  110. var list;
  111. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByWork(ev.work.id, function(json){
  112. list = json.data;
  113. if (cb) cb(list);
  114. }, ecb, !!cb);
  115. return list;
  116. },
  117. "getReadCompletedListByJob": function(callback, error){
  118. var cb = (callback && o2.typeOf(callback)==="function") ? callback : null;
  119. var ecb = (error && o2.typeOf(error)==="function") ? error : null;
  120. var list;
  121. o2.Actions.get("x_processplatform_assemble_surface").listReadCompletedByJob(ev.work.job, function(json){
  122. list = json.data;
  123. if (cb) cb(list);
  124. }, ecb, !!cb);
  125. return list;
  126. },
  127. "getJobTaskList": this.getTaskListByJob,
  128. "getJobReadList": this.getReadListByJob,
  129. "getJobTaskCompletedList": this.getTaskCompletedListByJob,
  130. "getJobReadCompletedList": this.getReadCompletedListByJob,
  131. "getControl": function(){return ev.control;},
  132. "getWorkLogList": function(){return ev.workLogList;},
  133. "getRecordList": function(){return ev.recordList;},
  134. "getAttachmentList": function(){return ev.attachmentList;},
  135. "getRouteList": function(){return (ev.task) ? ev.task.routeNameList: null;},
  136. "getInquiredRouteList": function(){return null;},
  137. "setTitle": function(title){
  138. if (!this.workAction){
  139. MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  140. this.workAction = new MWF.xScript.Actions.WorkActions();
  141. }
  142. this.workAction.setTitle(ev.work.id, {"title": title});
  143. }
  144. };
  145. this.workContent = this.workContext;
  146. var _redefineWorkProperties = function(work){
  147. if (work){
  148. work.creatorPersonDn = work.creatorPerson ||"";
  149. work.creatorUnitDn = work.creatorUnit ||"";
  150. work.creatorUnitDnList = work.creatorUnitList ||"";
  151. work.creatorIdentityDn = work.creatorIdentity ||"";
  152. var o = {
  153. "creatorPerson": {"get": function(){return this.creatorPersonDn.substring(0, this.creatorPersonDn.indexOf("@"));}},
  154. "creatorUnit": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  155. "creatorDepartment": {"get": function(){return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));}},
  156. "creatorIdentity": {"get": function(){return this.creatorIdentityDn.substring(0, this.creatorIdentityDn.indexOf("@"));}},
  157. // "creatorUnitList": {
  158. // "get": function(){
  159. // var v = [];
  160. // this.creatorUnitDnList.each(function(dn){
  161. // v.push(dn.substring(0, dn.indexOf("@")))
  162. // });
  163. // return v;
  164. // }
  165. // },
  166. "creatorCompany": {"get": function(){
  167. if (this.creatorUnitLevel){
  168. var level = this.creatorUnitLevel.split("/");
  169. return level[0];
  170. }else{
  171. return this.creatorUnitDn.substring(0, this.creatorUnitDn.indexOf("@"));
  172. }
  173. }}
  174. };
  175. MWF.defineProperties(work, o);
  176. }
  177. return work;
  178. };
  179. var _redefineTaskProperties = function(task){
  180. if (task){
  181. task.personDn = task.person || "";
  182. task.unitDn = task.unit || "";
  183. task.unitDnList = task.unitList || "";
  184. task.identityDn = task.identity || "";
  185. var o = {
  186. "person": {"get": function(){return this.personDn.substring(0, this.personDn.indexOf("@"));}},
  187. "unit": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  188. "department": {"get": function(){return this.unitDn.substring(0, this.unitDn.indexOf("@"));}},
  189. "identity": {"get": function(){return this.identityDn.substring(0, this.identityDn.indexOf("@"));}},
  190. // "unitList": {
  191. // "get": function(){
  192. // var v = [];
  193. // this.unitDnList.each(function(dn){
  194. // v.push(dn.substring(0, dn.indexOf("@")))
  195. // });
  196. // return v;
  197. // }
  198. // },
  199. "company": {"get": function(){return this.unitList[0];}}
  200. };
  201. MWF.defineProperties(task, o);
  202. }
  203. return task;
  204. };
  205. _redefineWorkProperties(this.workContext.getWork());
  206. _redefineTaskProperties(_redefineWorkProperties(this.workContext.getTask()));
  207. //dict
  208. this.Dict = MWF.xScript.createDict(_form.json.application);
  209. //unit
  210. var orgActions = null;
  211. var getOrgActions = function(){
  212. // if (!orgActions){
  213. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  214. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  215. // }
  216. if (!orgActions){
  217. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  218. orgActions = new MWF.xScript.Actions.UnitActions();
  219. }
  220. };
  221. var getNameFlag = function(name){
  222. var t = typeOf(name);
  223. if (t==="array"){
  224. var v = [];
  225. name.each(function(id){
  226. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  227. });
  228. return v;
  229. }else{
  230. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  231. }
  232. };
  233. this.org = {
  234. //群组***************
  235. //获取群组--返回群组的对象数组
  236. getGroup: function(name){
  237. getOrgActions();
  238. var data = {"groupList": getNameFlag(name)};
  239. var v = null;
  240. orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  241. return (v && v.length===1) ? v[0] : v;
  242. },
  243. //查询下级群组--返回群组的对象数组
  244. //nested 布尔 true嵌套下级;false直接下级;默认false;
  245. listSubGroup: function(name, nested){
  246. getOrgActions();
  247. var data = {"groupList": getNameFlag(name)};
  248. var v = null;
  249. if (nested){
  250. orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  251. }else{
  252. orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  253. }
  254. return v;
  255. },
  256. //查询上级群组--返回群组的对象数组
  257. //nested 布尔 true嵌套上级;false直接上级;默认false;
  258. listSupGroup:function(name, nested){
  259. getOrgActions();
  260. var data = {"groupList": getNameFlag(name)};
  261. var v = null;
  262. if (nested){
  263. orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  264. }else{
  265. orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  266. }
  267. return v;
  268. },
  269. //人员所在群组(嵌套)--返回群组的对象数组
  270. listGroupWithPerson:function(name){
  271. getOrgActions();
  272. var data = {"personList": getNameFlag(name)};
  273. var v = null;
  274. orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  275. return v;
  276. },
  277. //群组是否拥有角色--返回true, false
  278. groupHasRole: function(name, role){
  279. getOrgActions();
  280. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  281. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  282. var v = false;
  283. orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  284. return v;
  285. },
  286. //角色***************
  287. //获取角色--返回角色的对象数组
  288. getRole: function(name){
  289. getOrgActions();
  290. var data = {"roleList": getNameFlag(name)};
  291. var v = null;
  292. orgActions.listRole(data, function(json){v = json.data;}, null, false);
  293. return (v && v.length===1) ? v[0] : v;
  294. },
  295. //人员所有角色(嵌套)--返回角色的对象数组
  296. listRoleWithPerson:function(name){
  297. getOrgActions();
  298. var data = {"personList": getNameFlag(name)};
  299. var v = null;
  300. orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  301. return v;
  302. },
  303. //人员***************
  304. //人员是否拥有角色--返回true, false
  305. personHasRole: function(name, role){
  306. getOrgActions();
  307. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  308. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  309. var v = false;
  310. orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  311. return v;
  312. },
  313. //获取人员--返回人员的对象数组
  314. getPerson: function(name){
  315. getOrgActions();
  316. var data = {"personList": getNameFlag(name)};
  317. var v = null;
  318. orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  319. return (v && v.length===1) ? v[0] : v;;
  320. },
  321. //查询下级人员--返回人员的对象数组
  322. //nested 布尔 true嵌套下级;false直接下级;默认false;
  323. listSubPerson: function(name, nested){
  324. getOrgActions();
  325. var data = {"personList": getNameFlag(name)};
  326. var v = null;
  327. if (nested){
  328. orgActions.listPersonSubNested(data, function(json){v = json.data;}, null, false);
  329. }else{
  330. orgActions.listPersonSubDirect(data, function(json){v = json.data;}, null, false);
  331. }
  332. return v;
  333. },
  334. //查询上级人员--返回人员的对象数组
  335. //nested 布尔 true嵌套上级;false直接上级;默认false;
  336. listSupPerson: function(name, nested){
  337. getOrgActions();
  338. var data = {"personList": getNameFlag(name)};
  339. var v = null;
  340. if (nested){
  341. orgActions.listPersonSupNested(data, function(json){v = json.data;}, null, false);
  342. }else{
  343. orgActions.listPersonSupDirect(data, function(json){v = json.data;}, null, false);
  344. }
  345. return v;
  346. },
  347. //获取群组的所有人员--返回人员的对象数组
  348. listPersonWithGroup: function(name){
  349. getOrgActions();
  350. var data = {"groupList": getNameFlag(name)};
  351. var v = null;
  352. orgActions.listPersonWithGroup(data, function(json){v = json.data;}, null, false);
  353. return v;
  354. },
  355. //获取角色的所有人员--返回人员的对象数组
  356. listPersonWithRole: function(name){
  357. getOrgActions();
  358. var data = {"roleList": getNameFlag(name)};
  359. var v = null;
  360. orgActions.listPersonWithRole(data, function(json){v = json.data;}, null, false);
  361. return v;
  362. },
  363. //获取身份的所有人员--返回人员的对象数组
  364. listPersonWithIdentity: function(name){
  365. getOrgActions();
  366. var data = {"identityList": getNameFlag(name)};
  367. var v = null;
  368. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  369. return v;
  370. },
  371. //获取身份的所有人员--返回人员的对象数组或人员对象
  372. getPersonWithIdentity: function(name){
  373. getOrgActions();
  374. var data = {"identityList": getNameFlag(name)};
  375. var v = null;
  376. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  377. return (v && v.length===1) ? v[0] : v;
  378. },
  379. //查询组织成员的人员--返回人员的对象数组
  380. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  381. listPersonWithUnit: function(name, nested){
  382. getOrgActions();
  383. var data = {"unitList": getNameFlag(name)};
  384. var v = null;
  385. if (nested){
  386. orgActions.listPersonWithUnitNested(data, function(json){v = json.data;}, null, false);
  387. }else{
  388. orgActions.listPersonWithUnitDirect(data, function(json){v = json.data;}, null, false);
  389. }
  390. return v;
  391. },
  392. //根据属性查询人员--返回人员的对象数组
  393. //name string 属性名
  394. //value string 属性值
  395. listPersonWithAttribute: function(name, value){
  396. getOrgActions();
  397. var data = {"name": name, "attribute": value};
  398. var v = null;
  399. orgActions.listPersonWithAttribute(data, function(json){v = json.data;}, null, false);
  400. return v;
  401. },
  402. //根据属性查询人员--返回人员的全称数组
  403. //name string 属性名
  404. //value string 属性值
  405. listPersonNameWithAttribute: function(name, value){
  406. getOrgActions();
  407. var data = {"name": name, "attribute": value};
  408. var v = null;
  409. orgActions.listPersonWithAttributeValue(data, function(json){v = json.data.personList;}, null, false);
  410. return v;
  411. },
  412. //人员属性************
  413. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  414. appendPersonAttribute: function(person, attr, values, success, failure){
  415. getOrgActions();
  416. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  417. var data = {"attributeList":values,"name":attr,"person":personFlag};
  418. orgActions.appendPersonAttribute(data, function(json){
  419. if (json.data.value){
  420. if (success) success();
  421. }else{
  422. if (failure) failure(null, "", "append values failed");
  423. }
  424. }, function(xhr, text, error){
  425. if (failure) failure(xhr, text, error);
  426. }, false);
  427. },
  428. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  429. setPersonAttribute: function(person, attr, values, success, failure){
  430. getOrgActions();
  431. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  432. var data = {"attributeList":values,"name":attr,"person":personFlag};
  433. orgActions.setPersonAttribute(data, function(json){
  434. if (json.data.value){
  435. if (success) success();
  436. }else{
  437. if (failure) failure(null, "", "append values failed");
  438. }
  439. }, function(xhr, text, error){
  440. if (failure) failure(xhr, text, error);
  441. }, false);
  442. },
  443. //获取人员属性值
  444. getPersonAttribute: function(person, attr){
  445. getOrgActions();
  446. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  447. var data = {"name":attr,"person":personFlag};
  448. var v = null;
  449. orgActions.getPersonAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  450. return v;
  451. },
  452. //列出人员所有属性的名称
  453. listPersonAttributeName: function(name){
  454. getOrgActions();
  455. var data = {"personList":getNameFlag(name)};
  456. var v = null;
  457. orgActions.listPersonAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  458. return v;
  459. },
  460. //列出人员的所有属性
  461. listPersonAllAttribute: function(name){
  462. getOrgActions();
  463. var data = {"personList":getNameFlag(name)};
  464. var v = null;
  465. orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  466. return v;
  467. },
  468. //身份**********
  469. //获取身份
  470. getIdentity: function(name){
  471. getOrgActions();
  472. var data = {"identityList":getNameFlag(name)};
  473. var v = null;
  474. orgActions.listIdentity(data, function(json){v = json.data;}, null, false);
  475. return (v && v.length===1) ? v[0] : v;
  476. },
  477. //列出人员的身份
  478. listIdentityWithPerson: function(name){
  479. getOrgActions();
  480. var data = {"personList":getNameFlag(name)};
  481. var v = null;
  482. orgActions.listIdentityWithPerson(data, function(json){v = json.data;}, null, false);
  483. return v;
  484. },
  485. //查询组织成员身份--返回身份的对象数组
  486. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  487. listIdentityWithUnit: function(name, nested){
  488. getOrgActions();
  489. var data = {"unitList": getNameFlag(name)};
  490. var v = null;
  491. if (nested){
  492. orgActions.listIdentityWithUnitNested(data, function(json){v = json.data;}, null, false);
  493. }else{
  494. orgActions.listIdentityWithUnitDirect(data, function(json){v = json.data;}, null, false);
  495. }
  496. return v;
  497. },
  498. //组织**********
  499. //获取组织
  500. getUnit: function(name){
  501. getOrgActions();
  502. var data = {"unitList":getNameFlag(name)};
  503. var v = null;
  504. orgActions.listUnit(data, function(json){v = json.data;}, null, false);
  505. return (v && v.length===1) ? v[0] : v;
  506. },
  507. //查询组织的下级--返回组织的对象数组
  508. //nested 布尔 true嵌套下级;false直接下级;默认false;
  509. listSubUnit: function(name, nested){
  510. getOrgActions();
  511. var data = {"unitList": getNameFlag(name)};
  512. var v = null;
  513. if (nested){
  514. orgActions.listUnitSubNested(data, function(json){v = json.data;}, null, false);
  515. }else{
  516. orgActions.listUnitSubDirect(data, function(json){v = json.data;}, null, false);
  517. }
  518. return v;
  519. },
  520. //查询组织的上级--返回组织的对象数组
  521. //nested 布尔 true嵌套上级;false直接上级;默认false;
  522. listSupUnit: function(name, nested){
  523. getOrgActions();
  524. var data = {"unitList": getNameFlag(name)};
  525. var v = null;
  526. if (nested){
  527. orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  528. }else{
  529. orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  530. }
  531. return v;
  532. },
  533. //根据个人身份获取组织
  534. //flag 数字 表示获取第几层的组织
  535. // 字符串 表示获取指定类型的组织
  536. // 空 表示获取直接所在的组织
  537. getUnitByIdentity: function(name, flag){
  538. getOrgActions();
  539. var getUnitMethod = "current";
  540. var v;
  541. if (flag){
  542. if (typeOf(flag)==="string") getUnitMethod = "type";
  543. if (typeOf(flag)==="number") getUnitMethod = "level";
  544. }
  545. switch (getUnitMethod){
  546. case "current":
  547. var data = {"identityList":getNameFlag(name)};
  548. orgActions.listUnitWithIdentity(data, function(json){ v = json.data; v=(v&&v.length===1) ? v[0] : v }, null, false);
  549. break;
  550. case "type":
  551. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  552. orgActions.getUnitWithIdentityAndType(data, function(json){ v = json.data; }, null, false);
  553. break;
  554. case "level":
  555. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  556. orgActions.getUnitWithIdentityAndLevel(data, function(json){ v = json.data; }, null, false);
  557. break;
  558. }
  559. return v;
  560. },
  561. //列出身份所在组织的所有上级组织
  562. listAllSupUnitWithIdentity: function(name){
  563. getOrgActions();
  564. var data = {"identityList":getNameFlag(name)};
  565. var v = null;
  566. orgActions.listUnitSupNestedWithIdentity(data, function(json){v = json.data;}, null, false);
  567. return v;
  568. },
  569. //获取人员所在的所有组织
  570. listUnitWithPerson: function(name){
  571. getOrgActions();
  572. var data = {"personList":getNameFlag(name)};
  573. var v = null;
  574. orgActions.listUnitWithPerson(data, function(json){v = json.data;}, null, false);
  575. return v;
  576. },
  577. //列出人员所在组织的所有上级组织
  578. listAllSupUnitWithPerson: function(name){
  579. getOrgActions();
  580. var data = {"personList":getNameFlag(name)};
  581. var v = null;
  582. orgActions.listUnitSupNestedWithPerson(data, function(json){v = json.data;}, null, false);
  583. return v;
  584. },
  585. //根据组织属性,获取所有符合的组织
  586. listUnitWithAttribute: function(name, attribute){
  587. getOrgActions();
  588. var data = {"name":name,"attribute":attribute};
  589. var v = null;
  590. orgActions.listUnitWithAttribute(data, function(json){v = json.data;}, null, false);
  591. return v;
  592. },
  593. //根据组织职务,获取所有符合的组织
  594. listUnitWithDuty: function(name, id){
  595. getOrgActions();
  596. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  597. var v = null;
  598. orgActions.listUnitWithDuty(data, function(json){v = json.data;}, null, false);
  599. return v;
  600. },
  601. //组织职务***********
  602. //获取指定的组织职务的身份
  603. getDuty: function(duty, id){
  604. getOrgActions();
  605. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  606. var v = null;
  607. orgActions.getDuty(data, function(json){v = json.data;}, null, false);
  608. return v;
  609. },
  610. //获取身份的所有职务名称
  611. listDutyNameWithIdentity: function(name){
  612. getOrgActions();
  613. var data = {"identityList":getNameFlag(name)};
  614. var v = null;
  615. orgActions.listDutyNameWithIdentity(data, function(json){v = json.data.nameList;}, null, false);
  616. return v;
  617. },
  618. //获取组织的所有职务名称
  619. listDutyNameWithUnit: function(name){
  620. getOrgActions();
  621. var data = {"unitList":getNameFlag(name)};
  622. var v = null;
  623. orgActions.listDutyNameWithUnit(data, function(json){v = json.data.nameList;}, null, false);
  624. return v;
  625. },
  626. //获取组织的所有职务
  627. listUnitAllDuty: function(name){
  628. getOrgActions();
  629. var data = {"unitList":getNameFlag(name)};
  630. var v = null;
  631. orgActions.listUnitAllDuty(data, function(json){v = json.data;}, null, false);
  632. return v;
  633. },
  634. //列出顶层组织
  635. listTopUnit: function(){
  636. var action = MWF.Actions.get("x_organization_assemble_control");
  637. var v = null;
  638. action.listTopUnit(function(json){
  639. v = json.data;
  640. }, null, false);
  641. return v;
  642. },
  643. //组织属性**************
  644. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  645. appendUnitAttribute: function(unit, attr, values, success, failure){
  646. getOrgActions();
  647. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  648. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  649. orgActions.appendUnitAttribute(data, function(json){
  650. if (json.data.value){
  651. if (success) success();
  652. }else{
  653. if (failure) failure(null, "", "append values failed");
  654. }
  655. }, function(xhr, text, error){
  656. if (failure) failure(xhr, text, error);
  657. }, false);
  658. },
  659. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  660. setUnitAttribute: function(unit, attr, values, success, failure){
  661. getOrgActions();
  662. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  663. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  664. orgActions.setUnitAttribute(data, function(json){
  665. if (json.data.value){
  666. if (success) success();
  667. }else{
  668. if (failure) failure(null, "", "append values failed");
  669. }
  670. }, function(xhr, text, error){
  671. if (failure) failure(xhr, text, error);
  672. }, false);
  673. },
  674. //获取组织属性值
  675. getUnitAttribute: function(unit, attr){
  676. getOrgActions();
  677. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  678. var data = {"name":attr,"unit":unitFlag};
  679. var v = null;
  680. orgActions.getUnitAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  681. return v;
  682. },
  683. //列出组织所有属性的名称
  684. listUnitAttributeName: function(name){
  685. getOrgActions();
  686. var data = {"unitList":getNameFlag(name)};
  687. var v = null;
  688. orgActions.listUnitAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  689. return v;
  690. },
  691. //列出组织的所有属性
  692. listUnitAllAttribute: function(name){
  693. getOrgActions();
  694. var data = {"unitList":getNameFlag(name)};
  695. var v = null;
  696. orgActions.listUnitAllAttribute(data, function(json){v = json.data;}, null, false);
  697. return v;
  698. }
  699. };
  700. this.Action = (function(){
  701. var actions = [];
  702. return function(root, json){
  703. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  704. action.getActions = function(callback){
  705. if (!this.actions) this.actions = {};
  706. Object.merge(this.actions, json);
  707. if (callback) callback();
  708. };
  709. this.invoke = function(option){
  710. action.invoke(option)
  711. }
  712. }
  713. })();
  714. this.service = {
  715. "jaxwsClient":{},
  716. "jaxrsClient":{}
  717. };
  718. var lookupAction = null;
  719. var getLookupAction = function(callback){
  720. if (!lookupAction){
  721. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  722. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  723. lookupAction.getActions = function(actionCallback){
  724. this.actions = {
  725. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  726. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  727. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  728. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  729. };
  730. if (actionCallback) actionCallback();
  731. };
  732. if (callback) callback();
  733. });
  734. }else{
  735. if (callback) callback();
  736. }
  737. };
  738. this.view = {
  739. "lookup": function(view, callback, async){
  740. var filterList = {"filterList": (view.filter || null)};
  741. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  742. var data = {
  743. "grid": json.data.grid || json.data.groupGrid,
  744. "groupGrid": json.data.groupGrid
  745. };
  746. if (callback) callback(data);
  747. }, null, async);
  748. },
  749. "lookupV1": function(view, callback){
  750. getLookupAction(function(){
  751. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  752. var data = {
  753. "grid": json.data.grid,
  754. "groupGrid": json.data.groupGrid
  755. };
  756. if (callback) callback(data);
  757. }.bind(this)});
  758. }.bind(this));
  759. },
  760. "select": function(view, callback, options){
  761. if (view.view){
  762. var viewJson = {
  763. "application": view.application || _form.json.application,
  764. "viewName": view.view || "",
  765. "isTitle": (view.isTitle===false) ? "no" : "yes",
  766. "select": (view.isMulti===false) ? "single" : "multi",
  767. "filter": view.filter
  768. };
  769. if (!options) options = {};
  770. options.width = view.width;
  771. options.height = view.height;
  772. options.title = view.caption;
  773. var width = options.width || "700";
  774. var height = options.height || "400";
  775. if (layout.mobile){
  776. var size = document.body.getSize();
  777. width = size.x;
  778. height = size.y;
  779. options.style = "viewmobile";
  780. }
  781. width = width.toInt();
  782. height = height.toInt();
  783. var size = _form.app.content.getSize();
  784. var x = (size.x-width)/2;
  785. var y = (size.y-height)/2;
  786. if (x<0) x = 0;
  787. if (y<0) y = 0;
  788. if (layout.mobile){
  789. x = 20;
  790. y = 0;
  791. }
  792. var _self = this;
  793. MWF.require("MWF.xDesktop.Dialog", function(){
  794. var dlg = new MWF.xDesktop.Dialog({
  795. "title": options.title || "select view",
  796. "style": options.style || "view",
  797. "top": y,
  798. "left": x-20,
  799. "fromTop":y,
  800. "fromLeft": x-20,
  801. "width": width,
  802. "height": height,
  803. "html": "<div style='height: 100%;'></div>",
  804. "maskNode": _form.app.content,
  805. "container": _form.app.content,
  806. "buttonList": [
  807. {
  808. "text": MWF.LP.process.button.ok,
  809. "action": function(){
  810. //if (callback) callback(_self.view.selectedItems);
  811. if (callback) callback(_self.view.getData());
  812. this.close();
  813. }
  814. },
  815. {
  816. "text": MWF.LP.process.button.cancel,
  817. "action": function(){this.close();}
  818. }
  819. ]
  820. });
  821. dlg.show();
  822. if (layout.mobile){
  823. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  824. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  825. if (backAction) backAction.addEvent("click", function(e){
  826. dlg.close();
  827. }.bind(this));
  828. if (okAction) okAction.addEvent("click", function(e){
  829. //if (callback) callback(this.view.selectedItems);
  830. if (callback) callback(this.view.getData());
  831. dlg.close();
  832. }.bind(this));
  833. }
  834. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  835. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  836. }.bind(this));
  837. }.bind(this));
  838. }
  839. }
  840. };
  841. this.statement = {
  842. "execute": function (statement, callback, async) {
  843. var parameter = this.parseParameter(statement.parameter);
  844. var filterList = this.parseFilter(statement.filter, parameter);
  845. var obj = {
  846. "filterList": filterList,
  847. "parameter" : parameter
  848. };
  849. MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  850. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  851. function (json) {
  852. if (callback) callback(json);
  853. }, null, async);
  854. },
  855. parseFilter : function( filter, parameter ){
  856. if( typeOf(filter) !== "array" )return [];
  857. var filterList = [];
  858. ( filter || [] ).each( function (d) {
  859. var parameterName = d.path.replace(/\./g, "_");
  860. var value = d.value;
  861. if( d.comparison === "like" || d.comparison === "notLike" ){
  862. if( value.substr(0, 1) !== "%" )value = "%"+value;
  863. if( value.substr(value.length-1,1) !== "%" )value = value+"%";
  864. parameter[ parameterName ] = value; //"%"+value+"%";
  865. }else{
  866. if( d.formatType === "dateTimeValue" || d.formatType === "datetimeValue"){
  867. value = "{ts '"+value+"'}"
  868. }else if( d.formatType === "dateValue" ){
  869. value = "{d '"+value+"'}"
  870. }else if( d.formatType === "timeValue" ){
  871. value = "{t '"+value+"'}"
  872. }
  873. parameter[ parameterName ] = value;
  874. }
  875. d.value = parameterName;
  876. filterList.push( d );
  877. }.bind(this));
  878. return filterList;
  879. },
  880. parseParameter : function( obj ){
  881. if( typeOf(obj) !== "object" )return {};
  882. var parameter = {};
  883. //传入的参数
  884. for( var p in obj ){
  885. var value = obj[p];
  886. if( typeOf( value ) === "date" ){
  887. value = "{ts '"+value.format("db")+"'}"
  888. }
  889. parameter[ p ] = value;
  890. }
  891. return parameter;
  892. },
  893. "select": function (statement, callback, options) {
  894. if (statement.name) {
  895. // var parameter = this.parseParameter(statement.parameter);
  896. // var filterList = this.parseFilter(statement.filter, parameter);
  897. var statementJson = {
  898. "statementId": statement.name || "",
  899. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  900. "select": (statement.isMulti === false) ? "single" : "multi",
  901. "filter": statement.filter,
  902. "parameter": statement.parameter
  903. };
  904. if (!options) options = {};
  905. options.width = statement.width;
  906. options.height = statement.height;
  907. options.title = statement.caption;
  908. var width = options.width || "700";
  909. var height = options.height || "400";
  910. if (layout.mobile) {
  911. var size = document.body.getSize();
  912. width = size.x;
  913. height = size.y;
  914. options.style = "viewmobile";
  915. }
  916. width = width.toInt();
  917. height = height.toInt();
  918. var size = _form.app.content.getSize();
  919. var x = (size.x - width) / 2;
  920. var y = (size.y - height) / 2;
  921. if (x < 0) x = 0;
  922. if (y < 0) y = 0;
  923. if (layout.mobile) {
  924. x = 20;
  925. y = 0;
  926. }
  927. var _self = this;
  928. MWF.require("MWF.xDesktop.Dialog", function () {
  929. var dlg = new MWF.xDesktop.Dialog({
  930. "title": options.title || "select statement view",
  931. "style": options.style || "view",
  932. "top": y,
  933. "left": x - 20,
  934. "fromTop": y,
  935. "fromLeft": x - 20,
  936. "width": width,
  937. "height": height,
  938. "html": "<div style='height: 100%;'></div>",
  939. "maskNode": _form.app.content,
  940. "container": _form.app.content,
  941. "buttonList": [
  942. {
  943. "text": MWF.LP.process.button.ok,
  944. "action": function () {
  945. //if (callback) callback(_self.view.selectedItems);
  946. if (callback) callback(_self.statement.getData());
  947. this.close();
  948. }
  949. },
  950. {
  951. "text": MWF.LP.process.button.cancel,
  952. "action": function () { this.close(); }
  953. }
  954. ]
  955. });
  956. dlg.show();
  957. if (layout.mobile) {
  958. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  959. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  960. if (backAction) backAction.addEvent("click", function (e) {
  961. dlg.close();
  962. }.bind(this));
  963. if (okAction) okAction.addEvent("click", function (e) {
  964. //if (callback) callback(this.view.selectedItems);
  965. if (callback) callback(this.statement.getData());
  966. dlg.close();
  967. }.bind(this));
  968. }
  969. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  970. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
  971. }.bind(this));
  972. }.bind(this));
  973. }
  974. }
  975. };
  976. //include 引用脚本
  977. //optionsOrName : {
  978. // type : "", 默认为process, 可以为 portal process cms
  979. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  980. // name : "" // 脚本名称/别名/id
  981. //}
  982. //或者name: "" // 脚本名称/别名/id
  983. // if( !window.includedScripts ){
  984. // var includedScripts = window.includedScripts = [];
  985. // }else{
  986. // var includedScripts = window.includedScripts;
  987. // }
  988. var includedScripts = [];
  989. var _includeSingle = function( optionsOrName , callback, async){
  990. var options = optionsOrName;
  991. if( typeOf( options ) == "string" ){
  992. options = { name : options };
  993. }
  994. var name = options.name;
  995. var type = ( options.type && options.application ) ? options.type : "process";
  996. var application = options.application || _form.json.application;
  997. var key = type +"-" + application + "-" + name;
  998. if (includedScripts.indexOf( key )> -1){
  999. if (callback) callback.apply(this);
  1000. return;
  1001. }
  1002. //if (includedScripts.indexOf( name )> -1){
  1003. // if (callback) callback.apply(this);
  1004. // return;
  1005. //}
  1006. var scriptAction;
  1007. switch ( type ){
  1008. case "portal" :
  1009. if( this.scriptActionPortal ){
  1010. scriptAction = this.scriptActionPortal;
  1011. }else{
  1012. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  1013. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  1014. }
  1015. break;
  1016. case "process" :
  1017. if( this.scriptActionProcess ){
  1018. scriptAction = this.scriptActionProcess;
  1019. }else{
  1020. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1021. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1022. }
  1023. break;
  1024. case "cms" :
  1025. if( this.scriptActionCMS ){
  1026. scriptAction = this.scriptActionCMS;
  1027. }else{
  1028. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1029. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1030. }
  1031. break;
  1032. }
  1033. debugger;
  1034. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  1035. if (json.data){
  1036. includedScripts.push( key );
  1037. //名称、别名、id
  1038. json.data.importedList.each( function ( flag ) {
  1039. if( type === "portal" ){
  1040. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  1041. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  1042. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  1043. }else if( type === "cms" ){
  1044. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  1045. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1046. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1047. }else if( type === "process" ){
  1048. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  1049. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1050. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1051. }
  1052. });
  1053. includedScripts = includedScripts.concat(json.data.importedList);
  1054. MWF.Macro.exec(json.data.text, this);
  1055. if (callback) callback.apply(this);
  1056. }else{
  1057. if (callback) callback.apply(this);
  1058. }
  1059. }.bind(this), null, !!async);
  1060. }
  1061. this.include = function( optionsOrName , callback, async){
  1062. if (o2.typeOf(optionsOrName)=="array"){
  1063. if (!!async){
  1064. var count = optionsOrName.length;
  1065. var loaded = 0;
  1066. optionsOrName.each(function(option){
  1067. _includeSingle.apply(this, [option, function(){
  1068. loaded++;
  1069. if (loaded>=count) if (callback) callback.apply(this);;
  1070. }.bind(this), true]);
  1071. }.bind(this));
  1072. }else{
  1073. optionsOrName.each(function(option){
  1074. _includeSingle.apply(this, [option]);
  1075. if (callback) callback.apply(this);
  1076. }.bind(this));
  1077. }
  1078. }else{
  1079. _includeSingle.apply(this, [optionsOrName , callback, async])
  1080. }
  1081. };
  1082. this.define = function(name, fun, overwrite){
  1083. var over = true;
  1084. if (overwrite===false) over = false;
  1085. var o = {};
  1086. o[name] = {"value": fun, "configurable": over};
  1087. MWF.defineProperties(this, o);
  1088. }.bind(this);
  1089. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1090. //可在调用前执行 var resolve = this.wait();
  1091. //在异步调用结束后 执行 resolve.cb();
  1092. //目前只有表单的queryload事件支持此方法。
  1093. this.wait = function(){
  1094. resolve = {};
  1095. var setResolve = function(callback){
  1096. resolve.cb = callback;
  1097. }.bind(this);
  1098. this.target.event_resolve = setResolve;
  1099. return resolve;
  1100. }
  1101. //和this.wait配合使用,
  1102. //如果没有异步,则resolve.cb方法不存在,
  1103. //所以在回调中中使用this.goon();使表单继续加载
  1104. this.goon = function(){
  1105. this.target.event_resolve = null;
  1106. }
  1107. //仅前台对象-----------------------------------------
  1108. //form
  1109. this.page = this.form = {
  1110. "getInfor": function(){return ev.formInfor;},
  1111. "infor": ev.formInfor,
  1112. "getApp": function(){return _form.app;},
  1113. "app": _form.app,
  1114. "node": function(){return _form.node;},
  1115. "readonly": _form.options.readonly,
  1116. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  1117. "getField": function(name){return _forms[name];},
  1118. "getAction": function(){return _form.workAction},
  1119. "getDesktop": function(){return _form.app.desktop},
  1120. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  1121. "save": function(callback, silent){_form.saveWork(callback, silent); },
  1122. "close": function(){_form.closeWork();},
  1123. "verify": function(){
  1124. return !(!_form.formCustomValidation("", "") || !_form.formValidation("", ""));
  1125. },
  1126. "process": function(option){
  1127. var op = _form.getOpinion();
  1128. var mds = op.medias;
  1129. if (option){
  1130. _form.submitWork(option.routeName, option.opinion, mds, option.callback,
  1131. option.processor, null, option.appendTaskIdentityList, option.processorOrgList, option.callbackBeforeSave );
  1132. }else{
  1133. _form.processWork();
  1134. }
  1135. },
  1136. "reset": function(option){
  1137. if (!option){
  1138. if (_form.businessData.control["allowReset"]) _form.resetWork();
  1139. }else{
  1140. _form.resetWorkToPeson(option.names, option.opinion, option.keep, option.success, option.failure);
  1141. }
  1142. },
  1143. "retract": function(option){
  1144. if (!option){
  1145. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  1146. }else{
  1147. _form.doRetractWork(option.success, option.failure);
  1148. }
  1149. },
  1150. "addSplit": function(option){
  1151. if (!option){
  1152. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  1153. }else{
  1154. _form.addSplitWork(option.value, option.success, option.failure);
  1155. }
  1156. },
  1157. "rollback": function(option){
  1158. if (!option){
  1159. if (_form.businessData.control["allowRollback"]) _form.rollback();
  1160. }else{
  1161. _form.doRollbackActionInvoke(option.log, option.flow, option.success, option.failure);
  1162. }
  1163. },
  1164. "print": function(application, form){
  1165. if (arguments.length){
  1166. var app = (arguments.length>1) ? arguments[0] : null;
  1167. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1168. _form.printWork(app, formName);
  1169. }else{
  1170. _form.printWork();
  1171. }
  1172. },
  1173. "deleteWork": function(option){
  1174. if (!option){
  1175. if (_form.businessData.control["allowDelete"]) _form.deleteWork();
  1176. }else{
  1177. _form.doDeleteWork(option.success, option.failure);
  1178. }
  1179. },
  1180. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  1181. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  1182. var p = MWF.getCenter({"x": width, "y": height});
  1183. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1184. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1185. }else{
  1186. e = (arguments.length>1) ? arguments[1] : null;
  1187. title = (arguments.length>2) ? arguments[2] : null;
  1188. text = (arguments.length>3) ? arguments[3] : null;
  1189. width = (arguments.length>4) ? arguments[4] : null;
  1190. height = (arguments.length>5) ? arguments[5] : null;
  1191. ok = (arguments.length>6) ? arguments[6] : null;
  1192. cancel = (arguments.length>7) ? arguments[7] : null;
  1193. callback = (arguments.length>8) ? arguments[8] : null;
  1194. mask = (arguments.length>9) ? arguments[9] : null;
  1195. style = (arguments.length>10) ? arguments[10] : null;
  1196. // var p = MWF.getCenter({"x": width, "y": height});
  1197. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1198. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1199. }
  1200. },
  1201. "alert": function(type, title, text, width, height){
  1202. _form.alert(type, title, text, width, height);
  1203. },
  1204. "notice": function(content, type, target, where, offset, option){
  1205. _form.notice(content, type, target, where, offset, option);
  1206. },
  1207. "addEvent": function(e, f){_form.addEvent(e, f);},
  1208. "openWindow": function(application, form){
  1209. if (arguments.length){
  1210. var app = (arguments.length>1) ? arguments[0] : null;
  1211. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1212. _form.openWindow(formName, app);
  1213. }else{
  1214. _form.openWindow();
  1215. }
  1216. },
  1217. "openWork": function(id, completedId, title, options){
  1218. var op = options || {};
  1219. op.workId = id;
  1220. op.workCompletedId = completedId;
  1221. op.docTitle = title;
  1222. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1223. return layout.desktop.openApplication(this.event, "process.Work", op);
  1224. },
  1225. "openJob": function(id, choice, options){
  1226. var workData = null;
  1227. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1228. if (json.data) workData = json.data;
  1229. }.bind(this), null, false);
  1230. if (workData){
  1231. var len = workData.workList.length + workData.workCompletedList.length;
  1232. if (len){
  1233. if (len>1 && choice){
  1234. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1235. workData.workList.each(function(work){
  1236. var workNode = new Element("div", {
  1237. "styles": {
  1238. "background": "#ffffff",
  1239. "border-radius": "10px",
  1240. "clear": "both",
  1241. "margin-bottom": "10px",
  1242. "height": "40px",
  1243. "padding": "10px 10px"
  1244. }
  1245. }).inject(node);
  1246. var html = "<div style='height: 40px; width: 40px; float: left; background: url(../x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
  1247. "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
  1248. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1249. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1250. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1251. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1252. workNode.set("html", html);
  1253. var action = workNode.getElement(".MWFAction");
  1254. action.store("work", work);
  1255. action.addEvent("click", function(e){
  1256. var work = e.target.retrieve("work");
  1257. if (work) this.openWork(work.id, null, work.title, options);
  1258. dlg.close();
  1259. }.bind(this));
  1260. }.bind(this));
  1261. workData.workCompletedList.each(function(work){
  1262. var workNode = new Element("div", {
  1263. "styles": {
  1264. "background": "#ffffff",
  1265. "border-radius": "10px",
  1266. "clear": "both",
  1267. "margin-bottom": "10px",
  1268. "height": "40px",
  1269. "padding": "10px 10px"
  1270. }
  1271. }).inject(node);
  1272. var html = "<div style='height: 40px; width: 40px; float: left; background: url(../x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
  1273. "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
  1274. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1275. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1276. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1277. workNode.set("html", html);
  1278. var action = workNode.getElement(".MWFAction");
  1279. action.store("work", work);
  1280. action.addEvent("click", function(e){
  1281. var work = e.target.retrieve("work");
  1282. if (work) this.openWork(null, work.id, work.title, options);
  1283. dlg.close();
  1284. }.bind(this));
  1285. }.bind(this));
  1286. var height = node.getSize().y+20;
  1287. if (height>600) height = 600;
  1288. var dlg = o2.DL.open({
  1289. "title": o2.LP.widget.choiceWork,
  1290. "style" : "user",
  1291. "isResize": false,
  1292. "content": node,
  1293. "buttonList": [
  1294. {
  1295. "type" : "cancel",
  1296. "text": o2.LP.widget.close,
  1297. "action": function(){dlg.close();}
  1298. }
  1299. ]
  1300. });
  1301. }else{
  1302. if (workData.workList.length){
  1303. var work = workData.workList[0];
  1304. return this.openWork(work.id, null, work.title, options);
  1305. }else{
  1306. var work = workData.workCompletedList[0];
  1307. return this.openWork(null, work.id, work.title, options);
  1308. }
  1309. }
  1310. }
  1311. }
  1312. // var op = options || {};
  1313. // op.workId = id;
  1314. // op.workCompletedId = completedId;
  1315. // op.docTitle = title;
  1316. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1317. // layout.desktop.openApplication(this.event, "process.Work", op);
  1318. },
  1319. "openDocument": function(id, title, options){
  1320. var op = options || {};
  1321. op.documentId = id;
  1322. op.docTitle = title;
  1323. layout.desktop.openApplication(this.event, "cms.Document", op);
  1324. },
  1325. "openPortal": function(name, page, par){
  1326. var action = MWF.Actions.get("x_portal_assemble_surface");
  1327. action.getApplication(name, function(json){
  1328. if (json.data){
  1329. if (page){
  1330. action.getPageByName(page, json.data.id, function(pageJson){
  1331. layout.desktop.openApplication(null, "portal.Portal", {
  1332. "portalId": json.data.id,
  1333. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1334. "parameters": par,
  1335. "appId": "portal.Portal"+json.data.id
  1336. })
  1337. });
  1338. }else{
  1339. layout.desktop.openApplication(null, "portal.Portal", {
  1340. "portalId": json.data.id,
  1341. "parameters": par,
  1342. "appId": "portal.Portal"+json.data.id
  1343. })
  1344. }
  1345. }
  1346. });
  1347. },
  1348. "openCMS": function(name){
  1349. var action = MWF.Actions.get("x_cms_assemble_control");
  1350. action.getColumn(name, function(json){
  1351. if (json.data){
  1352. layout.desktop.openApplication(null, "cms.Module", {
  1353. "columnId": json.data.id,
  1354. "appId": "cms.Module"+json.data.id
  1355. });
  1356. }
  1357. });
  1358. },
  1359. "openProcess": function(name){
  1360. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1361. action.getApplication(name, function(json){
  1362. if (json.data){
  1363. layout.desktop.openApplication(null, "process.Application", {
  1364. "id": json.data.id,
  1365. "appId": "process.Application"+json.data.id
  1366. });
  1367. }
  1368. });
  1369. },
  1370. "openApplication":function(name, options){
  1371. layout.desktop.openApplication(null, name, options);
  1372. },
  1373. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1374. var column = columnOrOptions;
  1375. var onAfterPublish, onPostPublish;
  1376. if (typeOf(columnOrOptions) == "object") {
  1377. column = columnOrOptions.column;
  1378. category = columnOrOptions.category;
  1379. data = columnOrOptions.data;
  1380. identity = columnOrOptions.identity;
  1381. callback = columnOrOptions.callback;
  1382. target = columnOrOptions.target;
  1383. latest = columnOrOptions.latest;
  1384. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1385. ignoreTitle = columnOrOptions.ignoreTitle;
  1386. onAfterPublish = columnOrOptions.onAfterPublish;
  1387. onPostPublish = columnOrOptions.onPostPublish;
  1388. }
  1389. if (target) {
  1390. if (layout.app && layout.app.inBrowser) {
  1391. layout.app.content.empty();
  1392. layout.app = null;
  1393. }
  1394. }
  1395. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1396. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1397. "documentData": data,
  1398. "identity": identity,
  1399. "ignoreTitle": ignoreTitle === true,
  1400. "ignoreDrafted": latest === false,
  1401. "selectColumnEnable": !category || selectColumnEnable === true,
  1402. "restrictToColumn": !!category && selectColumnEnable !== true,
  1403. "categoryFlag": category, //category id or name
  1404. "columnFlag": column, //column id or name,
  1405. "onStarted": function (documentId, data) {
  1406. if (callback) callback();
  1407. },
  1408. "onPostPublish": function () {
  1409. if(onPostPublish)onPostPublish();
  1410. },
  1411. "onAfterPublish": function () {
  1412. if(onAfterPublish)onAfterPublish();
  1413. }
  1414. });
  1415. starter.load();
  1416. })
  1417. },
  1418. "startProcess": function(app, process, data, identity, callback, target, latest){
  1419. if (arguments.length>2){
  1420. for (var i=2; i<arguments.length; i++){
  1421. if (typeOf(arguments[i])=="boolean"){
  1422. target = arguments[i];
  1423. break;
  1424. }
  1425. }
  1426. }
  1427. if (target){
  1428. if (layout.app && layout.app.inBrowser){
  1429. //layout.app.content.empty();
  1430. layout.app.$openWithSelf = true;
  1431. }
  1432. }
  1433. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1434. if (json.data){
  1435. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1436. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1437. "workData": data,
  1438. "identity": identity,
  1439. "latest": latest,
  1440. "onStarted": function(data, title, processName){
  1441. if (data.work){
  1442. var work = data.work;
  1443. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1444. layout.desktop.openApplication(null, "process.Work", options);
  1445. }else{
  1446. var currentTask = [];
  1447. data.each(function(work){
  1448. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1449. }.bind(this));
  1450. if (currentTask.length==1){
  1451. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1452. layout.desktop.openApplication(null, "process.Work", options);
  1453. }else{}
  1454. }
  1455. if (callback) callback(data);
  1456. }.bind(this)
  1457. });
  1458. starter.load();
  1459. }.bind(this));
  1460. }
  1461. });
  1462. }
  1463. };
  1464. this.form.currentRouteName = _form.json.currentRouteName;
  1465. this.form.opinion = _form.json.opinion;
  1466. this.target = ev.target;
  1467. this.event = ev.event;
  1468. this.status = ev.status;
  1469. this.session = layout.desktop.session;
  1470. this.Actions = o2.Actions;
  1471. this.query = function(option){
  1472. // options = {
  1473. // "name": "statementName",
  1474. // "data": "json data",
  1475. // "firstResult": 1,
  1476. // "maxResults": 100,
  1477. // "success": function(){},
  1478. // "error": function(){},
  1479. // "async": true or false, default is true
  1480. // }
  1481. if (option){
  1482. var json = (option.data) || {};
  1483. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1484. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1485. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1486. }
  1487. }
  1488. this.Table = MWF.xScript.createTable();
  1489. };
  1490. MWF.xScript.createTable = function(){
  1491. return function(name){
  1492. this.name = name;
  1493. this.action = o2.Actions.get("x_query_assemble_surface");
  1494. this.listRowNext = function(id, count, success, error, async){
  1495. this.action.listRowNext(this.name, id, count, success, error, async);
  1496. };
  1497. this.listRowPrev = function(id, count, success, error, async){
  1498. this.action.listRowPrev(this.name, id, count, success, error, async);
  1499. };
  1500. this.listRowPrev = function(id, count, success, error, async){
  1501. this.action.listRowPrev(this.name, id, count, success, error, async);
  1502. };
  1503. this.listRowSelectWhere = function(where, success, error, async){
  1504. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1505. };
  1506. this.listRowCountWhere = function(where, success, error, async){
  1507. this.action.listRowCountWhere(this.name, where, success, error, async);
  1508. };
  1509. this.deleteRow = function(id, success, error, async){
  1510. this.action.deleteRow(this.name, id, success, error, async);
  1511. };
  1512. this.deleteAllRow = function(success, error, async){
  1513. this.action.deleteAllRow(this.name, success, error, async);
  1514. };
  1515. this.getRow = function(id, success, error, async){
  1516. this.action.getRow(this.name, id, success, error, async);
  1517. };
  1518. this.insertRow = function(data, success, error, async){
  1519. this.action.insertRow(this.name, data, success, error, async);
  1520. };
  1521. this.updateRow = function(id, data, success, error, async){
  1522. this.action.updateRow(this.name, id, data, success, error, async);
  1523. };
  1524. }
  1525. };
  1526. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  1527. var getter = function(data, callback, k, _self){
  1528. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  1529. };
  1530. var setter = function(data, callback, k, _self){
  1531. return function(v){
  1532. data[k] = v;
  1533. //debugger;
  1534. //this.add(k, v, true);
  1535. if (callback) callback(data, k, _self);
  1536. }
  1537. };
  1538. var define = function(){
  1539. var o = {};
  1540. 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])};
  1541. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1542. MWF.defineProperties(this, o);
  1543. var methods = {
  1544. "getKey": {"value": function(){ return key; }},
  1545. "getParent": {"value": function(){ return parent; }},
  1546. "toString": {"value": function() { return data.toString();}},
  1547. "setSection": {"value": function(newKey, newValue){
  1548. this.add(newKey, newValue, true);
  1549. try {
  1550. var path = [this.getKey()];
  1551. p = this.getParent();
  1552. while (p && p.getKey()){
  1553. path.unshift(p.getKey());
  1554. p = p.getParent();
  1555. }
  1556. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  1557. }catch(e){
  1558. debugger;
  1559. }
  1560. }},
  1561. "add": {"value": function(newKey, newValue, overwrite){
  1562. var flag = true;
  1563. var type = typeOf(data);
  1564. if (type==="array"){
  1565. if (arguments.length<2){
  1566. data.push(newKey);
  1567. newValue = newKey;
  1568. newKey = data.length-1;
  1569. }else{
  1570. if (!newKey && newKey!==0){
  1571. data.push(newValue);
  1572. newKey = data.length-1;
  1573. }else{
  1574. flag = false;
  1575. }
  1576. }
  1577. if (flag){
  1578. var o = {};
  1579. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1580. MWF.defineProperties(this, o);
  1581. }
  1582. this[newKey] = newValue;
  1583. }else if (type==="object"){
  1584. if (!this.hasOwnProperty(newKey)){
  1585. data[newKey] = newValue;
  1586. if (flag){
  1587. var o = {};
  1588. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1589. MWF.defineProperties(this, o);
  1590. }
  1591. this[newKey] = newValue;
  1592. }else{
  1593. if (overwrite) this[newKey] = newValue;
  1594. }
  1595. }
  1596. return this[newKey];
  1597. }},
  1598. "del": {"value": function(delKey){
  1599. if (!this.hasOwnProperty(delKey)) return null;
  1600. delete data[delKey];
  1601. delete this[delKey];
  1602. return this;
  1603. }}
  1604. };
  1605. MWF.defineProperties(this, methods);
  1606. //this.getKey = function(){ return key; };
  1607. //this.getParent = function(){ return parent; };
  1608. //this.toString = function() { return data.toString();};
  1609. //this.add = function(newKey, newValue, overwrite){
  1610. // var flag = true;
  1611. // var type = typeOf(data);
  1612. // if (!this.hasOwnProperty(newKey)){
  1613. // if (type=="array"){
  1614. // if (arguments.length<2){
  1615. // data.push(newKey);
  1616. // newValue = newKey;
  1617. // newKey = data.length-1;
  1618. // }else{
  1619. // debugger;
  1620. // if (!newKey && newKey!=0){
  1621. // data.push(newValue);
  1622. // newKey = data.length-1;
  1623. // }else{
  1624. // flag == false;
  1625. // }
  1626. // }
  1627. // }else{
  1628. // data[newKey] = newValue;
  1629. // }
  1630. // //var valueType = typeOf(newValue);
  1631. // //var newValueData = newValue;
  1632. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1633. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1634. // if (flag){
  1635. // var o = {};
  1636. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1637. // MWF.defineProperties(this, o);
  1638. // }
  1639. // this[newKey] = newValue;
  1640. // }else{
  1641. // if (overwrite) this[newKey] = newValue;
  1642. // }
  1643. //
  1644. // //var valueType = typeOf(newValue);
  1645. // //var newValueData = newValue;
  1646. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1647. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1648. // //
  1649. // //this[newKey] = newValueData;
  1650. //
  1651. // return this[newKey];
  1652. //};
  1653. //this.del = function(delKey){
  1654. // if (!this.hasOwnProperty(delKey)) return null;
  1655. // delete data[newKey];
  1656. // delete this[newKey];
  1657. // return this;
  1658. //};
  1659. };
  1660. var type = typeOf(data);
  1661. if (type==="object" || type==="array") define.apply(this);
  1662. };
  1663. //MWF.xScript.createDict = function(application){
  1664. // return function(name){
  1665. // var applicationId = application;
  1666. // this.name = name;
  1667. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1668. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1669. //
  1670. // this.get = function(path, success, failure){
  1671. // debugger;
  1672. // var value = null;
  1673. // if (path){
  1674. // var arr = path.split(/\./g);
  1675. // var ar = arr.map(function(v){
  1676. // return encodeURIComponent(v);
  1677. // });
  1678. // //var p = path.replace(/\./g, "/");
  1679. // var p = ar.join("/");
  1680. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1681. // value = json.data;
  1682. // if (success) success(json.data);
  1683. // }, function(xhr, text, error){
  1684. // if (failure) failure(xhr, text, error);
  1685. // }, false);
  1686. // }else{
  1687. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  1688. // value = json.data;
  1689. // if (success) success(json.data);
  1690. // }, function(xhr, text, error){
  1691. // if (failure) failure(xhr, text, error);
  1692. // }, false);
  1693. // }
  1694. //
  1695. // return value;
  1696. // };
  1697. //
  1698. // this.set = function(path, value, success, failure){
  1699. // var p = path.replace(/\./g, "/");
  1700. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1701. // if (success) success(json.data);
  1702. // }, function(xhr, text, error){
  1703. // if (failure) failure(xhr, text, error);
  1704. // });
  1705. // };
  1706. // this.add = function(path, value, success, failure){
  1707. // var p = path.replace(/\./g, "/");
  1708. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1709. // if (success) success(json.data);
  1710. // }, function(xhr, text, error){
  1711. // if (failure) failure(xhr, text, error);
  1712. // });
  1713. // };
  1714. // this["delete"] = function(path, success, failure){
  1715. // var p = path.replace(/\./g, "/");
  1716. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1717. // if (success) success(json.data);
  1718. // }, function(xhr, text, error){
  1719. // if (failure) failure(xhr, text, error);
  1720. // });
  1721. // };
  1722. // this.destory = this["delete"];
  1723. // }
  1724. //};
  1725. // var dictLoaded = {};
  1726. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  1727. MWF.xScript.addDictToCache = function ( options, path, json ) {
  1728. if( !path )path = "root";
  1729. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1730. var type = options.appType || "process";
  1731. var enableAnonymous = options.enableAnonymous || false;
  1732. var appFlagList = [];
  1733. if( options.application )appFlagList.push( options.application );
  1734. if( options.appId )appFlagList.push( options.appId );
  1735. if( options.appName )appFlagList.push( options.appName );
  1736. if( options.appAlias )appFlagList.push( options.appAlias );
  1737. var dictFlagList = [];
  1738. if( options.id )dictFlagList.push( options.id );
  1739. if( options.name )dictFlagList.push( options.name );
  1740. if( options.alias )dictFlagList.push( options.alias );
  1741. var cache = {};
  1742. cache[path] = json;
  1743. for( var i=0; i<appFlagList.length; i++ ){
  1744. for( var j=0; j<dictFlagList.length; j++ ){
  1745. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  1746. if( !MWF.xScript.dictLoaded[k] ){
  1747. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  1748. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  1749. }else if( i===0 && j===0 ){
  1750. MWF.xScript.setDictToCache( k, path ,json );
  1751. var arr = path.split(/\./g);
  1752. var p;
  1753. var cache = MWF.xScript.dictLoaded[k];
  1754. for( var l=0 ; l<arr.length; l++ ){
  1755. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  1756. if( cache[ p ] )break;
  1757. }
  1758. if( p ){
  1759. var mathP = p+".";
  1760. Object.keys( cache ).each( function( path, idx){
  1761. if( path.indexOf( mathP ) === 0 )delete cache[path];
  1762. })
  1763. }
  1764. }
  1765. }
  1766. }
  1767. };
  1768. MWF.xScript.getMatchedDict = function(key, path){
  1769. if( !path )path = "root";
  1770. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1771. var arr = path.split(/\./g);
  1772. if( MWF.xScript.dictLoaded[key] ){
  1773. var dicts = MWF.xScript.dictLoaded[key];
  1774. var list = Array.clone(arr);
  1775. var p;
  1776. var dict;
  1777. for( var i=0 ; i<arr.length; i++ ){
  1778. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  1779. list.shift();
  1780. if( dicts[ p ] ){
  1781. dict = dicts[ p ];
  1782. break;
  1783. }
  1784. }
  1785. return {
  1786. dict : dict,
  1787. unmatchedPathList : list
  1788. }
  1789. }
  1790. return {
  1791. dict : null,
  1792. unmatchedPathList : list
  1793. }
  1794. };
  1795. MWF.xScript.insertDictToCache = function(key, path, json){
  1796. if( MWF.xScript.dictLoaded[key] ){
  1797. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1798. var dict = matchedDict.dict;
  1799. var list = matchedDict.unmatchedPathList;
  1800. if( !dict ){
  1801. MWF.xScript.dictLoaded[key][path] = json;
  1802. }else{
  1803. for( var j=0; j<list.length-1; j++ ){
  1804. if( !dict[ list[j] ] ){
  1805. dict[ list[j] ] = {};
  1806. }
  1807. dict = dict[ list[j] ];
  1808. }
  1809. var lastPath = list[list.length-1];
  1810. if( !dict[lastPath] ){
  1811. dict[lastPath] = json;
  1812. }else if( typeOf( dict[lastPath] ) === "array" ){
  1813. dict[lastPath].push( json );
  1814. }
  1815. }
  1816. }else{
  1817. MWF.xScript.dictLoaded[key] = {};
  1818. MWF.xScript.dictLoaded[key][path] = json;
  1819. }
  1820. };
  1821. MWF.xScript.setDictToCache = function(key, path, json){
  1822. if( MWF.xScript.dictLoaded[key] ){
  1823. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1824. var dict = matchedDict.dict;
  1825. var list = matchedDict.unmatchedPathList;
  1826. if( !dict ){
  1827. MWF.xScript.dictLoaded[key][path] = json;
  1828. }else{
  1829. for( var j=0; j<list.length-1; j++ ){
  1830. if( !dict[ list[j] ] ){
  1831. dict[ list[j] ] = {};
  1832. }
  1833. dict = dict[ list[j] ];
  1834. }
  1835. dict[list[list.length-1]] = json;
  1836. }
  1837. }else{
  1838. MWF.xScript.dictLoaded[key] = {};
  1839. MWF.xScript.dictLoaded[key][path] = json;
  1840. }
  1841. };
  1842. MWF.xScript.getDictFromCache = function( key, path ){
  1843. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1844. var dict = matchedDict.dict;
  1845. var list = matchedDict.unmatchedPathList;
  1846. if( dict ){
  1847. for( var j=0; j<list.length; j++ ){
  1848. dict = dict[ list[j] ];
  1849. if( !dict )return null;
  1850. }
  1851. return dict;
  1852. }
  1853. return null;
  1854. };
  1855. MWF.xScript.deleteDictToCache = function(key, path){
  1856. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1857. var dict = matchedDict.dict;
  1858. var list = matchedDict.unmatchedPathList;
  1859. if( dict){
  1860. for( var j=0; j<list.length-1; j++ ){
  1861. dict = dict[ list[j] ];
  1862. if( !dict )return;
  1863. }
  1864. delete dict[list[list.length-1]];
  1865. }
  1866. };
  1867. MWF.xScript.createDict = function(application){
  1868. //optionsOrName : {
  1869. // type : "", //默认为process, 可以为 process cms
  1870. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1871. // name : "", // 数据字典名称/别名/id
  1872. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1873. //}
  1874. //或者name: "" // 数据字典名称/别名/id
  1875. return function(optionsOrName){
  1876. var options = optionsOrName;
  1877. if( typeOf( options ) == "string" ){
  1878. options = { name : options };
  1879. }
  1880. var name = this.name = options.name;
  1881. var type = ( options.type && options.application ) ? options.type : "process";
  1882. var applicationId = options.application || application;
  1883. var enableAnonymous = options.enableAnonymous || false;
  1884. var opt = {
  1885. "appType" : type,
  1886. "name" : name,
  1887. "appId" : applicationId,
  1888. "enableAnonymous" : enableAnonymous
  1889. };
  1890. var key = name+type+applicationId+enableAnonymous;
  1891. // if (!dictLoaded[key]) dictLoaded[key] = {};
  1892. // this.dictData = dictLoaded[key];
  1893. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1894. if( type == "cms" ){
  1895. var action = MWF.Actions.get("x_cms_assemble_control");
  1896. }else{
  1897. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1898. }
  1899. var encodePath = function( path ){
  1900. var arr = path.split(/\./g);
  1901. var ar = arr.map(function(v){
  1902. return encodeURIComponent(v);
  1903. });
  1904. return ar.join("/");
  1905. };
  1906. this.get = function(path, success, failure, async, refresh){
  1907. var value = null;
  1908. if (!refresh ){
  1909. var data = MWF.xScript.getDictFromCache( key, path );
  1910. if( data ){
  1911. if (success) success( data );
  1912. return data;
  1913. }
  1914. }
  1915. if (path){
  1916. var p = encodePath( path );
  1917. //var p = path.replace(/\./g, "/");
  1918. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1919. value = json.data;
  1920. // this.dictData[path] = value;
  1921. MWF.xScript.addDictToCache(opt, path, value);
  1922. if (success) success(json.data);
  1923. }.bind(this), function(xhr, text, error){
  1924. if (failure) failure(xhr, text, error);
  1925. }, !!async, false);
  1926. }else{
  1927. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1928. value = json.data;
  1929. // this.dictData["root"] = value;
  1930. MWF.xScript.addDictToCache(opt, path, value);
  1931. if (success) success(json.data);
  1932. }.bind(this), function(xhr, text, error){
  1933. if (failure) failure(xhr, text, error);
  1934. }, !!async);
  1935. }
  1936. return value;
  1937. };
  1938. this.set = function(path, value, success, failure){
  1939. var p = encodePath( path );
  1940. //var p = path.replace(/\./g, "/");
  1941. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1942. MWF.xScript.setDictToCache(key, path, value);
  1943. if (success) success(json.data);
  1944. }, function(xhr, text, error){
  1945. if (failure) failure(xhr, text, error);
  1946. }, false, false);
  1947. };
  1948. this.add = function(path, value, success, failure){
  1949. var p = encodePath( path );
  1950. //var p = path.replace(/\./g, "/");
  1951. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1952. MWF.xScript.insertDictToCache(key, path, value);
  1953. if (success) success(json.data);
  1954. }, function(xhr, text, error){
  1955. if (failure) failure(xhr, text, error);
  1956. }, false, false);
  1957. };
  1958. this["delete"] = function(path, success, failure){
  1959. var p = encodePath( path );
  1960. //var p = path.replace(/\./g, "/");
  1961. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1962. MWF.xScript.deleteDictToCache(key, path);
  1963. if (success) success(json.data);
  1964. }, function(xhr, text, error){
  1965. if (failure) failure(xhr, text, error);
  1966. }, false, false);
  1967. };
  1968. this.destory = this["delete"];
  1969. }
  1970. };