Environment.js 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488
  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, async){
  237. getOrgActions();
  238. var data = {"groupList": getNameFlag(name)};
  239. var v = null;
  240. var cb = function(json){
  241. v = json.data;
  242. v = (v && v.length===1) ? v[0] : v
  243. if (async && o2.typeOf(async)=="function") return async(v);
  244. return v;
  245. };
  246. var promise = orgActions.listGroup(data, cb, null, !!async);
  247. return (!!async) ? promise : v;
  248. // var v = null;
  249. // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  250. // return (v && v.length===1) ? v[0] : v;
  251. },
  252. //查询下级群组--返回群组的对象数组
  253. //nested 布尔 true嵌套下级;false直接下级;默认false;
  254. listSubGroup: function(name, nested, async){
  255. getOrgActions();
  256. var data = {"groupList": getNameFlag(name)};
  257. var v = null;
  258. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  259. // v = json.data;
  260. // return v;
  261. // }.ag().catch(function(json){ return json; });
  262. var cb = function(json){
  263. v = json.data;
  264. if (async && o2.typeOf(async)=="function") return async(v);
  265. return v;
  266. };
  267. var promise;
  268. if (nested){
  269. promise = orgActions.listSubGroupNested(data, cb, null, !!async);
  270. }else{
  271. promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
  272. }
  273. return (!!async) ? promise : v;
  274. // var v = null;
  275. // if (nested){
  276. // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  277. // }else{
  278. // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  279. // }
  280. // return v;
  281. },
  282. //查询上级群组--返回群组的对象数组
  283. //nested 布尔 true嵌套上级;false直接上级;默认false;
  284. listSupGroup:function(name, nested, async){
  285. getOrgActions();
  286. var data = {"groupList": getNameFlag(name)};
  287. var v = null;
  288. var cb = function(json){
  289. v = json.data;
  290. if (async && o2.typeOf(async)=="function") return async(v);
  291. return v;
  292. };
  293. var promise
  294. if (nested){
  295. var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
  296. }else{
  297. var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
  298. }
  299. return (!!async) ? promise : v;
  300. // var v = null;
  301. // if (nested){
  302. // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  303. // }else{
  304. // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  305. // }
  306. // return v;
  307. },
  308. //人员所在群组(嵌套)--返回群组的对象数组
  309. listGroupWithPerson:function(name, async){
  310. getOrgActions();
  311. var data = {"personList": getNameFlag(name)};
  312. var v = null;
  313. var cb = function(json){
  314. v = json.data;
  315. if (async && o2.typeOf(async)=="function") return async(v);
  316. return v;
  317. };
  318. var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
  319. return (!!async) ? promise : v;
  320. // var v = null;
  321. // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  322. // return v;
  323. },
  324. //群组是否拥有角色--返回true, false
  325. groupHasRole: function(name, role, async){
  326. getOrgActions();
  327. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  328. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  329. var v = false;
  330. var cb = function(json){
  331. v = json.data.value;
  332. if (async && o2.typeOf(async)=="function") return async(v);
  333. return v;
  334. };
  335. var promise = orgActions.groupHasRole(data, cb, null, !!async);
  336. return (!!async) ? promise : v;
  337. // var v = false;
  338. // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  339. // return v;
  340. },
  341. //角色***************
  342. //获取角色--返回角色的对象数组
  343. getRole: function(name, async){
  344. getOrgActions();
  345. var data = {"roleList": getNameFlag(name)};
  346. var v = null;
  347. var cb = function(json){
  348. v = json.data;
  349. v = (v && v.length===1) ? v[0] : v;
  350. if (async && o2.typeOf(async)=="function") return async(v);
  351. return v;
  352. };
  353. var promise = orgActions.listRole(data, cb, null, !!async);
  354. return (!!async) ? promise : v;
  355. // var v = null;
  356. // orgActions.listRole(data, function(json){v = json.data;}, null, false);
  357. // return (v && v.length===1) ? v[0] : v;
  358. },
  359. //人员所有角色(嵌套)--返回角色的对象数组
  360. listRoleWithPerson:function(name, async){
  361. getOrgActions();
  362. var data = {"personList": getNameFlag(name)};
  363. var v = null;
  364. var cb = function(json){
  365. v = json.data;
  366. if (async && o2.typeOf(async)=="function") return async(v);
  367. return v;
  368. };
  369. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  370. return (!!async) ? promise : v;
  371. // var v = null;
  372. // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  373. // return v;
  374. },
  375. //人员***************
  376. //人员是否拥有角色--返回true, false
  377. personHasRole: function(name, role, async){
  378. getOrgActions();
  379. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  380. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  381. var v = false;
  382. var cb = function(json){
  383. v = json.data.value;
  384. if (async && o2.typeOf(async)=="function") return async(v);
  385. return v;
  386. };
  387. var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
  388. return (!!async) ? promise : v;
  389. // var v = false;
  390. // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  391. // return v;
  392. },
  393. //获取人员--返回人员的对象数组
  394. getPerson: function(name, async){
  395. getOrgActions();
  396. var data = {"personList": getNameFlag(name)};
  397. var v = null;
  398. var cb = function(json){
  399. v = json.data;
  400. v = (v && v.length===1) ? v[0] : v;
  401. if (async && o2.typeOf(async)=="function") return async(v);
  402. return v;
  403. };
  404. var promise = orgActions.listPerson(data, cb, null, !!async);
  405. return (!!async) ? promise : v;
  406. // var v = null;
  407. // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  408. // return (v && v.length===1) ? v[0] : v;
  409. },
  410. //查询下级人员--返回人员的对象数组
  411. //nested 布尔 true嵌套下级;false直接下级;默认false;
  412. listSubPerson: function(name, nested, async){
  413. getOrgActions();
  414. var data = {"personList": getNameFlag(name)};
  415. var v = null;
  416. var cb = function(json){
  417. v = json.data;
  418. if (async && o2.typeOf(async)=="function") return async(v);
  419. return v;
  420. };
  421. var promise;
  422. if (nested){
  423. promise = orgActions.listPersonSubNested(data, cb, null, !!async);
  424. }else{
  425. promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
  426. }
  427. return (!!async) ? promise : v;
  428. },
  429. //查询上级人员--返回人员的对象数组
  430. //nested 布尔 true嵌套上级;false直接上级;默认false;
  431. listSupPerson: function(name, nested, async){
  432. getOrgActions();
  433. var data = {"personList": getNameFlag(name)};
  434. var v = null;
  435. var cb = function(json){
  436. v = json.data;
  437. if (async && o2.typeOf(async)=="function") return async(v);
  438. return v;
  439. };
  440. var promise;
  441. if (nested){
  442. promise = orgActions.listPersonSupNested(data, cb, null, !!async);
  443. }else{
  444. promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
  445. }
  446. return (!!async) ? promise : v;
  447. },
  448. //获取群组的所有人员--返回人员的对象数组
  449. listPersonWithGroup: function(name, async){
  450. getOrgActions();
  451. var data = {"groupList": getNameFlag(name)};
  452. var v = null;
  453. var cb = function(json){
  454. v = json.data;
  455. if (async && o2.typeOf(async)=="function") return async(v);
  456. return v;
  457. };
  458. var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
  459. return (!!async) ? promise : v;
  460. },
  461. //获取角色的所有人员--返回人员的对象数组
  462. listPersonWithRole: function(name, async){
  463. getOrgActions();
  464. var data = {"roleList": getNameFlag(name)};
  465. var v = null;
  466. var cb = function(json){
  467. v = json.data;
  468. if (async && o2.typeOf(async)=="function") return async(v);
  469. return v;
  470. };
  471. var promise
  472. promise = orgActions.listPersonWithRole(data, cb, null, !!async);
  473. return (!!async) ? promise : v;
  474. },
  475. //获取身份的所有人员--返回人员的对象数组
  476. listPersonWithIdentity: function(name, async){
  477. getOrgActions();
  478. var data = {"identityList": getNameFlag(name)};
  479. var v = null;
  480. var cb = function(json){
  481. v = json.data;
  482. if (async && o2.typeOf(async)=="function") return async(v);
  483. return v;
  484. };
  485. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  486. return (!!async) ? promise : v;
  487. },
  488. //获取身份的所有人员--返回人员的对象数组或人员对象
  489. getPersonWithIdentity: function(name, async){
  490. getOrgActions();
  491. var data = {"identityList": getNameFlag(name)};
  492. var v = null;
  493. var cb = function(json){
  494. v = json.data;
  495. v = (v && v.length===1) ? v[0] : v;
  496. if (async && o2.typeOf(async)=="function") return async(v);
  497. return v;
  498. };
  499. var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
  500. return (!!async) ? promise : v;
  501. },
  502. //查询组织成员的人员--返回人员的对象数组
  503. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  504. listPersonWithUnit: function(name, nested, async){
  505. getOrgActions();
  506. var data = {"unitList": getNameFlag(name)};
  507. var v = null;
  508. var cb = function(json){
  509. v = json.data;
  510. if (async && o2.typeOf(async)=="function") return async(v);
  511. return v;
  512. };
  513. var promise;
  514. if (nested){
  515. promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
  516. }else{
  517. promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
  518. }
  519. return (!!async) ? promise : v;
  520. },
  521. //根据属性查询人员--返回人员的对象数组
  522. //name string 属性名
  523. //value string 属性值
  524. listPersonWithAttribute: function(name, value, async){
  525. getOrgActions();
  526. var data = {"name": name, "attribute": value};
  527. var v = null;
  528. var cb = function(json){
  529. v = json.data;
  530. if (async && o2.typeOf(async)=="function") return async(v);
  531. return v;
  532. };
  533. var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
  534. return (!!async) ? promise : v;
  535. },
  536. //根据属性查询人员--返回人员的全称数组
  537. //name string 属性名
  538. //value string 属性值
  539. listPersonNameWithAttribute: function(name, value, async){
  540. getOrgActions();
  541. var data = {"name": name, "attribute": value};
  542. var v = null;
  543. var cb = function(json){
  544. v = json.data.personList;
  545. if (async && o2.typeOf(async)=="function") return async(v);
  546. return v;
  547. };
  548. var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
  549. return (!!async) ? promise : v;
  550. },
  551. //人员属性************
  552. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  553. appendPersonAttribute: function(person, attr, values, success, failure, async){
  554. getOrgActions();
  555. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  556. var data = {"attributeList":values,"name":attr,"person":personFlag};
  557. var cb = function(json){
  558. if (success) return success(json);
  559. }.ag().catch(function(xhr, text, error){
  560. if (failure) return failure(xhr, text, error);
  561. });
  562. orgActions.appendPersonAttribute(data, cb, null, !!async);
  563. },
  564. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  565. setPersonAttribute: function(person, attr, values, success, failure, async){
  566. getOrgActions();
  567. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  568. var data = {"attributeList":values,"name":attr,"person":personFlag};
  569. var cb = function(json){
  570. if (success) return success(json);
  571. }.ag().catch(function(xhr, text, error){
  572. if (failure) return failure(xhr, text, error);
  573. });
  574. orgActions.setPersonAttribute(data, cb, null, !!async);
  575. },
  576. //获取人员属性值
  577. getPersonAttribute: function(person, attr, async){
  578. getOrgActions();
  579. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  580. var data = {"name":attr,"person":personFlag};
  581. var v = null;
  582. var cb = function(json){
  583. v = json.data.attributeList;
  584. if (async && o2.typeOf(async)=="function") return async(v);
  585. return v;
  586. };
  587. var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
  588. return (!!async) ? promise : v;
  589. },
  590. //列出人员所有属性的名称
  591. listPersonAttributeName: function(name, async){
  592. getOrgActions();
  593. var data = {"personList":getNameFlag(name)};
  594. var v = null;
  595. var cb = function(json){
  596. v = json.data.nameList;
  597. if (async && o2.typeOf(async)=="function") return async(v);
  598. return v;
  599. };
  600. var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
  601. return (!!async) ? promise : v;
  602. },
  603. //列出人员的所有属性
  604. listPersonAllAttribute: function(name, async){
  605. getOrgActions();
  606. var data = {"personList":getNameFlag(name)};
  607. var v = null;
  608. var cb = function(json){
  609. v = json.data;
  610. if (async && o2.typeOf(async)=="function") return async(v);
  611. return v;
  612. };
  613. var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
  614. return (!!async) ? promise : v;
  615. },
  616. //身份**********
  617. //获取身份
  618. getIdentity: function(name, async){
  619. getOrgActions();
  620. var data = {"identityList":getNameFlag(name)};
  621. var v = null;
  622. var cb = function(json){
  623. v = json.data;
  624. v = (v && v.length===1) ? v[0] : v;
  625. if (async && o2.typeOf(async)=="function") return async(v);
  626. return v;
  627. };
  628. var promise = orgActions.listIdentity(data, cb, null, !!async);
  629. return (!!async) ? promise : v;
  630. },
  631. //列出人员的身份
  632. listIdentityWithPerson: function(name, async){
  633. getOrgActions();
  634. var data = {"personList":getNameFlag(name)};
  635. var v = null;
  636. var cb = function(json){
  637. v = json.data;
  638. if (async && o2.typeOf(async)=="function") return async(v);
  639. return v;
  640. };
  641. var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
  642. return (!!async) ? promise : v;
  643. },
  644. //查询组织成员身份--返回身份的对象数组
  645. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  646. listIdentityWithUnit: function(name, nested, async){
  647. getOrgActions();
  648. var data = {"unitList": getNameFlag(name)};
  649. var v = null;
  650. // var cb = function(json){
  651. // v = json.data;
  652. // if (async && o2.typeOf(async)=="function") return async(v);
  653. // return v;
  654. // }.ag().catch(function(json){ return json; });
  655. var cb = function(json){
  656. v = json.data;
  657. if (async && o2.typeOf(async)=="function") return async(v);
  658. return v;
  659. };
  660. var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
  661. var promise = orgActions[method](data, cb, null, !!async);
  662. promise.name = "org";
  663. //
  664. // if (nested){
  665. // orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
  666. // }else{
  667. // orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
  668. // }
  669. return (!!async) ? promise : v;
  670. },
  671. //组织**********
  672. //获取组织
  673. getUnit: function(name, async){
  674. getOrgActions();
  675. var data = {"unitList":getNameFlag(name)};
  676. var v = null;
  677. var cb = function(json){
  678. v = json.data;
  679. v = (v && v.length===1) ? v[0] : v;
  680. if (async && o2.typeOf(async)=="function") return async(v);
  681. return v;
  682. };
  683. var promise = orgActions.listUnit(data, cb, null, !!async);
  684. return (!!async) ? promise : v;
  685. },
  686. //查询组织的下级--返回组织的对象数组
  687. //nested 布尔 true嵌套下级;false直接下级;默认false;
  688. listSubUnit: function(name, nested, async){
  689. getOrgActions();
  690. var data = {"unitList": getNameFlag(name)};
  691. var v = null;
  692. var cb = function(json){
  693. v = json.data;
  694. if (async && o2.typeOf(async)=="function") return async(v);
  695. return v;
  696. };
  697. var promise;
  698. if (nested){
  699. promise = orgActions.listUnitSubNested(data, cb, null, !!async);
  700. }else{
  701. promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
  702. }
  703. return (!!async) ? promise : v;
  704. },
  705. //查询组织的上级--返回组织的对象数组
  706. //nested 布尔 true嵌套上级;false直接上级;默认false;
  707. //async 布尔 true异步请求
  708. listSupUnit: function(name, nested, async){
  709. getOrgActions();
  710. var data = {"unitList": getNameFlag(name)};
  711. var v = null;
  712. var cb = function(json){
  713. v = json.data;
  714. if (async && o2.typeOf(async)=="function") return async(v);
  715. return v;
  716. };
  717. var promise;
  718. if (nested){
  719. promise = orgActions.listUnitSupNested(data, cb, null, !!async);
  720. }else{
  721. promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
  722. }
  723. return (!!async) ? promise : v;
  724. // if (callback){
  725. // if (nested){
  726. // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  727. // }else{
  728. // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  729. // }
  730. // }else{
  731. // var v = null;
  732. // if (nested){
  733. // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  734. // }else{
  735. // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  736. // }
  737. // return v;
  738. // }
  739. },
  740. //根据个人身份获取组织
  741. //flag 数字 表示获取第几层的组织
  742. // 字符串 表示获取指定类型的组织
  743. // 空 表示获取直接所在的组织
  744. getUnitByIdentity: function(name, flag, async){
  745. getOrgActions();
  746. var getUnitMethod = "current";
  747. var v;
  748. if (flag){
  749. if (typeOf(flag)==="string") getUnitMethod = "type";
  750. if (typeOf(flag)==="number") getUnitMethod = "level";
  751. }
  752. var cb;
  753. var promise;
  754. switch (getUnitMethod){
  755. case "current":
  756. var data = {"identityList":getNameFlag(name)};
  757. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  758. // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
  759. // }.ag().catch(function(json){ return json; });
  760. cb = function(json){
  761. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  762. if (async && o2.typeOf(async)=="function") return async(v);
  763. return v;
  764. };
  765. promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
  766. break;
  767. case "type":
  768. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  769. cb = function(json){
  770. v = json.data;
  771. if (async && o2.typeOf(async)=="function") return async(v);
  772. return v;
  773. };
  774. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  775. // v = json.data; return v;
  776. // }.ag().catch(function(json){ return json; });
  777. promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  778. break;
  779. case "level":
  780. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  781. cb = function(json){
  782. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  783. if (async && o2.typeOf(async)=="function") return async(v);
  784. return v;
  785. };
  786. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  787. // v = json.data; return v;
  788. // }.ag().catch(function(json){ return json; });
  789. promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  790. break;
  791. }
  792. return (!!async) ? promise : v;
  793. },
  794. //列出身份所在组织的所有上级组织
  795. listAllSupUnitWithIdentity: function(name, async){
  796. getOrgActions();
  797. var data = {"identityList":getNameFlag(name)};
  798. var v = null;
  799. var cb = function(json){
  800. v = json.data;
  801. if (async && o2.typeOf(async)=="function") return async(v);
  802. return v;
  803. };
  804. var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  805. return (!!async) ? promise : v;
  806. },
  807. //获取人员所在的所有组织
  808. listUnitWithPerson: function(name, async){
  809. getOrgActions();
  810. var data = {"personList":getNameFlag(name)};
  811. var v = null;
  812. var cb = function(json){
  813. v = json.data;
  814. if (async && o2.typeOf(async)=="function") return async(v);
  815. return v;
  816. };
  817. var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
  818. return (!!async) ? promise : v;
  819. },
  820. //列出人员所在组织的所有上级组织
  821. listAllSupUnitWithPerson: function(name, async){
  822. getOrgActions();
  823. var data = {"personList":getNameFlag(name)};
  824. var v = null;
  825. var cb = function(json){
  826. v = json.data;
  827. if (async && o2.typeOf(async)=="function") return async(v);
  828. return v;
  829. };
  830. var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  831. return (!!async) ? promise : v;
  832. },
  833. //根据组织属性,获取所有符合的组织
  834. listUnitWithAttribute: function(name, attribute, async){
  835. getOrgActions();
  836. var data = {"name":name,"attribute":attribute};
  837. var v = null;
  838. var cb = function(json){
  839. v = json.data;
  840. if (async && o2.typeOf(async)=="function") return async(v);
  841. return v;
  842. };
  843. promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
  844. return (!!async) ? promise : v;
  845. },
  846. //根据组织职务,获取所有符合的组织
  847. listUnitWithDuty: function(name, id, async){
  848. getOrgActions();
  849. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  850. var v = null;
  851. var cb = function(json){
  852. v = json.data;
  853. if (async && o2.typeOf(async)=="function") return async(v);
  854. return v;
  855. };
  856. var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
  857. return (!!async) ? promise : v;
  858. },
  859. //组织职务***********
  860. //获取指定的组织职务的身份
  861. getDuty: function(duty, id, async){
  862. getOrgActions();
  863. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  864. var v = null;
  865. var cb = function(json){
  866. v = json.data;
  867. if (async && o2.typeOf(async)=="function") return async(v);
  868. return v;
  869. };
  870. var promise = orgActions.getDuty(data, cb, null, !!async);
  871. return (!!async) ? promise : v;
  872. },
  873. //获取身份的所有职务名称
  874. listDutyNameWithIdentity: function(name, async){
  875. getOrgActions();
  876. var data = {"identityList":getNameFlag(name)};
  877. var v = null;
  878. var cb = function(json){
  879. v = json.data.nameList;
  880. if (async && o2.typeOf(async)=="function") return async(v);
  881. return v;
  882. };
  883. var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  884. return (!!async) ? promise : v;
  885. },
  886. //获取组织的所有职务名称
  887. listDutyNameWithUnit: function(name, async){
  888. getOrgActions();
  889. var data = {"unitList":getNameFlag(name)};
  890. var v = null;
  891. var cb = function(json){
  892. v = json.data.nameList;
  893. if (async && o2.typeOf(async)=="function") return async(v);
  894. return v;
  895. };
  896. var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  897. return (!!async) ? promise : v;
  898. },
  899. //获取组织的所有职务
  900. listUnitAllDuty: function(name, async){
  901. getOrgActions();
  902. var data = {"unitList":getNameFlag(name)};
  903. var v = null;
  904. var cb = function(json){
  905. v = json.data;
  906. if (async && o2.typeOf(async)=="function") return async(v);
  907. return v;
  908. };
  909. var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
  910. return (!!async) ? promise : v;
  911. },
  912. //列出顶层组织
  913. listTopUnit: function(async){
  914. var action = MWF.Actions.get("x_organization_assemble_control");
  915. var v = null;
  916. var cb = function(json){
  917. v = json.data;
  918. if (async && o2.typeOf(async)=="function") return async(v);
  919. return v;
  920. };
  921. var promise = action.listTopUnit(cb, null, !!async);
  922. return (!!async) ? promise : v;
  923. },
  924. //组织属性**************
  925. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  926. appendUnitAttribute: function(unit, attr, values, success, failure, async){
  927. getOrgActions();
  928. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  929. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  930. var cb = function(json){
  931. if (success) return success(json);
  932. }.ag().catch(function(xhr, text, error){
  933. if (failure) return failure(xhr, text, error);
  934. });
  935. orgActions.appendPersonAttribute(data, cb, null, !!async);
  936. // orgActions.appendUnitAttribute(data, function(json){
  937. // if (json.data.value){
  938. // if (success) success();
  939. // }else{
  940. // if (failure) failure(null, "", "append values failed");
  941. // }
  942. // }, function(xhr, text, error){
  943. // if (failure) failure(xhr, text, error);
  944. // }, false);
  945. },
  946. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  947. setUnitAttribute: function(unit, attr, values, success, failure, async){
  948. getOrgActions();
  949. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  950. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  951. var cb = function(json){
  952. if (success) return success(json);
  953. }.ag().catch(function(xhr, text, error){
  954. if (failure) return failure(xhr, text, error);
  955. });
  956. orgActions.setUnitAttribute(data, cb, null, !!async);
  957. // orgActions.setUnitAttribute(data, function(json){
  958. // if (json.data.value){
  959. // if (success) success();
  960. // }else{
  961. // if (failure) failure(null, "", "append values failed");
  962. // }
  963. // }, function(xhr, text, error){
  964. // if (failure) failure(xhr, text, error);
  965. // }, false);
  966. },
  967. //获取组织属性值
  968. getUnitAttribute: function(unit, attr, async){
  969. getOrgActions();
  970. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  971. var data = {"name":attr,"unit":unitFlag};
  972. var v = null;
  973. var cb = function(json){
  974. v = json.data.attributeList;
  975. if (async && o2.typeOf(async)=="function") return async(v);
  976. return v;
  977. };
  978. var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
  979. return (!!async) ? promise : v;
  980. },
  981. //列出组织所有属性的名称
  982. listUnitAttributeName: function(name, async){
  983. getOrgActions();
  984. var data = {"unitList":getNameFlag(name)};
  985. var v = null;
  986. var cb = function(json){
  987. v = json.data.nameList;
  988. if (async && o2.typeOf(async)=="function") return async(v);
  989. return v;
  990. };
  991. var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
  992. return (!!async) ? promise : v;
  993. },
  994. //列出组织的所有属性
  995. listUnitAllAttribute: function(name, async){
  996. getOrgActions();
  997. var data = {"unitList":getNameFlag(name)};
  998. var v = null;
  999. var cb = function(json){
  1000. v = json.data;
  1001. if (async && o2.typeOf(async)=="function") return async(v);
  1002. return v;
  1003. };
  1004. var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
  1005. return (!!async) ? promise : v;
  1006. }
  1007. };
  1008. this.Action = (function(){
  1009. var actions = [];
  1010. return function(root, json){
  1011. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  1012. action.getActions = function(callback){
  1013. if (!this.actions) this.actions = {};
  1014. Object.merge(this.actions, json);
  1015. if (callback) callback();
  1016. };
  1017. this.invoke = function(option){
  1018. action.invoke(option)
  1019. }
  1020. }
  1021. })();
  1022. this.service = {
  1023. "jaxwsClient":{},
  1024. "jaxrsClient":{}
  1025. };
  1026. var lookupAction = null;
  1027. var getLookupAction = function(callback){
  1028. if (!lookupAction){
  1029. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  1030. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  1031. lookupAction.getActions = function(actionCallback){
  1032. this.actions = {
  1033. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  1034. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  1035. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  1036. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  1037. };
  1038. if (actionCallback) actionCallback();
  1039. };
  1040. if (callback) callback();
  1041. });
  1042. }else{
  1043. if (callback) callback();
  1044. }
  1045. };
  1046. this.view = {
  1047. "lookup": function(view, callback, async){
  1048. var filterList = {"filterList": (view.filter || null)};
  1049. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  1050. var data = {
  1051. "grid": json.data.grid || json.data.groupGrid,
  1052. "groupGrid": json.data.groupGrid
  1053. };
  1054. if (callback) callback(data);
  1055. }, null, async);
  1056. },
  1057. "lookupV1": function(view, callback){
  1058. getLookupAction(function(){
  1059. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  1060. var data = {
  1061. "grid": json.data.grid,
  1062. "groupGrid": json.data.groupGrid
  1063. };
  1064. if (callback) callback(data);
  1065. }.bind(this)});
  1066. }.bind(this));
  1067. },
  1068. "select": function(view, callback, options){
  1069. if (view.view){
  1070. var viewJson = {
  1071. "application": view.application || _form.json.application,
  1072. "viewName": view.view || "",
  1073. "isTitle": (view.isTitle===false) ? "no" : "yes",
  1074. "select": (view.isMulti===false) ? "single" : "multi",
  1075. "filter": view.filter
  1076. };
  1077. if (!options) options = {};
  1078. options.width = view.width;
  1079. options.height = view.height;
  1080. options.title = view.caption;
  1081. var width = options.width || "700";
  1082. var height = options.height || "400";
  1083. if (layout.mobile){
  1084. var size = document.body.getSize();
  1085. width = size.x;
  1086. height = size.y;
  1087. options.style = "viewmobile";
  1088. }
  1089. width = width.toInt();
  1090. height = height.toInt();
  1091. var size = _form.app.content.getSize();
  1092. var x = (size.x-width)/2;
  1093. var y = (size.y-height)/2;
  1094. if (x<0) x = 0;
  1095. if (y<0) y = 0;
  1096. if (layout.mobile){
  1097. x = 20;
  1098. y = 0;
  1099. }
  1100. var _self = this;
  1101. MWF.require("MWF.xDesktop.Dialog", function(){
  1102. var dlg = new MWF.xDesktop.Dialog({
  1103. "title": options.title || "select view",
  1104. "style": options.style || "view",
  1105. "top": y,
  1106. "left": x-20,
  1107. "fromTop":y,
  1108. "fromLeft": x-20,
  1109. "width": width,
  1110. "height": height,
  1111. "html": "<div style='height: 100%;'></div>",
  1112. "maskNode": _form.app.content,
  1113. "container": _form.app.content,
  1114. "buttonList": [
  1115. {
  1116. "text": MWF.LP.process.button.ok,
  1117. "action": function(){
  1118. //if (callback) callback(_self.view.selectedItems);
  1119. if (callback) callback(_self.view.getData());
  1120. this.close();
  1121. }
  1122. },
  1123. {
  1124. "text": MWF.LP.process.button.cancel,
  1125. "action": function(){this.close();}
  1126. }
  1127. ]
  1128. });
  1129. dlg.show();
  1130. if (layout.mobile){
  1131. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1132. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1133. if (backAction) backAction.addEvent("click", function(e){
  1134. dlg.close();
  1135. }.bind(this));
  1136. if (okAction) okAction.addEvent("click", function(e){
  1137. //if (callback) callback(this.view.selectedItems);
  1138. if (callback) callback(this.view.getData());
  1139. dlg.close();
  1140. }.bind(this));
  1141. }
  1142. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  1143. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  1144. }.bind(this));
  1145. }.bind(this));
  1146. }
  1147. }
  1148. };
  1149. this.statement = {
  1150. "execute": function (statement, callback, async) {
  1151. var parameter = this.parseParameter(statement.parameter);
  1152. var filterList = this.parseFilter(statement.filter, parameter);
  1153. var obj = {
  1154. "filterList": filterList,
  1155. "parameter" : parameter
  1156. };
  1157. MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  1158. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  1159. function (json) {
  1160. if (callback) callback(json);
  1161. }, null, async);
  1162. },
  1163. parseFilter : function( filter, parameter ){
  1164. if( typeOf(filter) !== "array" )return [];
  1165. var filterList = [];
  1166. ( filter || [] ).each( function (d) {
  1167. var parameterName = d.path.replace(/\./g, "_");
  1168. var value = d.value;
  1169. if( d.comparison === "like" || d.comparison === "notLike" ){
  1170. if( value.substr(0, 1) !== "%" )value = "%"+value;
  1171. if( value.substr(value.length-1,1) !== "%" )value = value+"%";
  1172. parameter[ parameterName ] = value; //"%"+value+"%";
  1173. }else{
  1174. if( d.formatType === "dateTimeValue" || d.formatType === "datetimeValue"){
  1175. value = "{ts '"+value+"'}"
  1176. }else if( d.formatType === "dateValue" ){
  1177. value = "{d '"+value+"'}"
  1178. }else if( d.formatType === "timeValue" ){
  1179. value = "{t '"+value+"'}"
  1180. }
  1181. parameter[ parameterName ] = value;
  1182. }
  1183. d.value = parameterName;
  1184. filterList.push( d );
  1185. }.bind(this));
  1186. return filterList;
  1187. },
  1188. parseParameter : function( obj ){
  1189. if( typeOf(obj) !== "object" )return {};
  1190. var parameter = {};
  1191. //传入的参数
  1192. for( var p in obj ){
  1193. var value = obj[p];
  1194. if( typeOf( value ) === "date" ){
  1195. value = "{ts '"+value.format("db")+"'}"
  1196. }
  1197. parameter[ p ] = value;
  1198. }
  1199. return parameter;
  1200. },
  1201. "select": function (statement, callback, options) {
  1202. if (statement.name) {
  1203. // var parameter = this.parseParameter(statement.parameter);
  1204. // var filterList = this.parseFilter(statement.filter, parameter);
  1205. var statementJson = {
  1206. "statementId": statement.name || "",
  1207. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  1208. "select": (statement.isMulti === false) ? "single" : "multi",
  1209. "filter": statement.filter,
  1210. "parameter": statement.parameter
  1211. };
  1212. if (!options) options = {};
  1213. options.width = statement.width;
  1214. options.height = statement.height;
  1215. options.title = statement.caption;
  1216. var width = options.width || "700";
  1217. var height = options.height || "400";
  1218. if (layout.mobile) {
  1219. var size = document.body.getSize();
  1220. width = size.x;
  1221. height = size.y;
  1222. options.style = "viewmobile";
  1223. }
  1224. width = width.toInt();
  1225. height = height.toInt();
  1226. var size = _form.app.content.getSize();
  1227. var x = (size.x - width) / 2;
  1228. var y = (size.y - height) / 2;
  1229. if (x < 0) x = 0;
  1230. if (y < 0) y = 0;
  1231. if (layout.mobile) {
  1232. x = 20;
  1233. y = 0;
  1234. }
  1235. var _self = this;
  1236. MWF.require("MWF.xDesktop.Dialog", function () {
  1237. var dlg = new MWF.xDesktop.Dialog({
  1238. "title": options.title || "select statement view",
  1239. "style": options.style || "view",
  1240. "top": y,
  1241. "left": x - 20,
  1242. "fromTop": y,
  1243. "fromLeft": x - 20,
  1244. "width": width,
  1245. "height": height,
  1246. "html": "<div style='height: 100%;'></div>",
  1247. "maskNode": _form.app.content,
  1248. "container": _form.app.content,
  1249. "buttonList": [
  1250. {
  1251. "text": MWF.LP.process.button.ok,
  1252. "action": function () {
  1253. //if (callback) callback(_self.view.selectedItems);
  1254. if (callback) callback(_self.statement.getData());
  1255. this.close();
  1256. }
  1257. },
  1258. {
  1259. "text": MWF.LP.process.button.cancel,
  1260. "action": function () { this.close(); }
  1261. }
  1262. ]
  1263. });
  1264. dlg.show();
  1265. if (layout.mobile) {
  1266. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1267. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1268. if (backAction) backAction.addEvent("click", function (e) {
  1269. dlg.close();
  1270. }.bind(this));
  1271. if (okAction) okAction.addEvent("click", function (e) {
  1272. //if (callback) callback(this.view.selectedItems);
  1273. if (callback) callback(this.statement.getData());
  1274. dlg.close();
  1275. }.bind(this));
  1276. }
  1277. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  1278. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
  1279. }.bind(this));
  1280. }.bind(this));
  1281. }
  1282. }
  1283. };
  1284. //include 引用脚本
  1285. //optionsOrName : {
  1286. // type : "", 默认为process, 可以为 portal process cms
  1287. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  1288. // name : "" // 脚本名称/别名/id
  1289. //}
  1290. //或者name: "" // 脚本名称/别名/id
  1291. // if( !window.includedScripts ){
  1292. // var includedScripts = window.includedScripts = [];
  1293. // }else{
  1294. // var includedScripts = window.includedScripts;
  1295. // }
  1296. var includedScripts = [];
  1297. var _includeSingle = function( optionsOrName , callback, async){
  1298. var options = optionsOrName;
  1299. if( typeOf( options ) == "string" ){
  1300. options = { name : options };
  1301. }
  1302. var name = options.name;
  1303. var type = ( options.type && options.application ) ? options.type : "process";
  1304. var application = options.application || _form.json.application;
  1305. var key = type +"-" + application + "-" + name;
  1306. if (includedScripts.indexOf( key )> -1){
  1307. if (callback) callback.apply(this);
  1308. return;
  1309. }
  1310. //if (includedScripts.indexOf( name )> -1){
  1311. // if (callback) callback.apply(this);
  1312. // return;
  1313. //}
  1314. var scriptAction;
  1315. switch ( type ){
  1316. case "portal" :
  1317. if( this.scriptActionPortal ){
  1318. scriptAction = this.scriptActionPortal;
  1319. }else{
  1320. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  1321. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  1322. }
  1323. break;
  1324. case "process" :
  1325. if( this.scriptActionProcess ){
  1326. scriptAction = this.scriptActionProcess;
  1327. }else{
  1328. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1329. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1330. }
  1331. break;
  1332. case "cms" :
  1333. if( this.scriptActionCMS ){
  1334. scriptAction = this.scriptActionCMS;
  1335. }else{
  1336. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1337. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1338. }
  1339. break;
  1340. }
  1341. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  1342. if (json.data){
  1343. includedScripts.push( key );
  1344. //名称、别名、id
  1345. json.data.importedList.each( function ( flag ) {
  1346. if( type === "portal" ){
  1347. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  1348. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  1349. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  1350. }else if( type === "cms" ){
  1351. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  1352. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1353. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1354. }else if( type === "process" ){
  1355. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  1356. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1357. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1358. }
  1359. });
  1360. includedScripts = includedScripts.concat(json.data.importedList);
  1361. MWF.Macro.exec(json.data.text, this);
  1362. if (callback) callback.apply(this);
  1363. }else{
  1364. if (callback) callback.apply(this);
  1365. }
  1366. }.bind(this), null, !!async);
  1367. }
  1368. this.include = function( optionsOrName , callback, async){
  1369. if (o2.typeOf(optionsOrName)=="array"){
  1370. if (!!async){
  1371. var count = optionsOrName.length;
  1372. var loaded = 0;
  1373. optionsOrName.each(function(option){
  1374. _includeSingle.apply(this, [option, function(){
  1375. loaded++;
  1376. if (loaded>=count) if (callback) callback.apply(this);;
  1377. }.bind(this), true]);
  1378. }.bind(this));
  1379. }else{
  1380. optionsOrName.each(function(option){
  1381. _includeSingle.apply(this, [option]);
  1382. }.bind(this));
  1383. if (callback) callback.apply(this);
  1384. }
  1385. }else{
  1386. _includeSingle.apply(this, [optionsOrName , callback, async])
  1387. }
  1388. };
  1389. this.define = function(name, fun, overwrite){
  1390. var over = true;
  1391. if (overwrite===false) over = false;
  1392. var o = {};
  1393. o[name] = {"value": fun, "configurable": over};
  1394. MWF.defineProperties(this, o);
  1395. }.bind(this);
  1396. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1397. //可在调用前执行 var resolve = this.wait();
  1398. //在异步调用结束后 执行 resolve.cb();
  1399. //目前只有表单的queryload事件支持此方法。
  1400. this.wait = function(){
  1401. var _self = this;
  1402. resolve = {"cb": _self.goon.bind(_self)};
  1403. var setResolve = function(callback){
  1404. resolve.cb = callback;
  1405. }.bind(this);
  1406. this.target.event_resolve = setResolve;
  1407. return resolve;
  1408. }
  1409. //和this.wait配合使用,
  1410. //如果没有异步,则resolve.cb方法不存在,
  1411. //所以在回调中中使用this.goon();使表单继续加载
  1412. this.goon = function(){
  1413. this.target.event_resolve = null;
  1414. }
  1415. //仅前台对象-----------------------------------------
  1416. //form
  1417. this.page = this.form = {
  1418. "getInfor": function(){return ev.formInfor;},
  1419. "infor": ev.formInfor,
  1420. "getApp": function(){return _form.app;},
  1421. "app": _form.app,
  1422. "node": function(){return _form.node;},
  1423. "readonly": _form.options.readonly,
  1424. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  1425. "getField": function(name){return _forms[name];},
  1426. "getAction": function(){return _form.workAction},
  1427. "getDesktop": function(){return _form.app.desktop},
  1428. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  1429. "save": function(callback, silent){_form.saveWork(callback, silent); },
  1430. "close": function(){_form.closeWork();},
  1431. "verify": function(){
  1432. return !(!_form.formCustomValidation("", "") || !_form.formValidation("", ""));
  1433. },
  1434. "process": function(option){
  1435. var op = _form.getOpinion();
  1436. var mds = op.medias;
  1437. if (option){
  1438. _form.submitWork(option.routeName, option.opinion, mds, option.callback,
  1439. option.processor, null, option.appendTaskIdentityList, option.processorOrgList, option.callbackBeforeSave );
  1440. }else{
  1441. _form.processWork();
  1442. }
  1443. },
  1444. "reset": function(option){
  1445. if (!option){
  1446. if (_form.businessData.control["allowReset"]) _form.resetWork();
  1447. }else{
  1448. _form.resetWorkToPeson(option.names, option.opinion, option.keep, option.success, option.failure);
  1449. }
  1450. },
  1451. "retract": function(option){
  1452. if (!option){
  1453. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  1454. }else{
  1455. _form.doRetractWork(option.success, option.failure);
  1456. }
  1457. },
  1458. "addSplit": function(option){
  1459. if (!option){
  1460. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  1461. }else{
  1462. _form.addSplitWork(option.value, option.success, option.failure);
  1463. }
  1464. },
  1465. "rollback": function(option){
  1466. if (!option){
  1467. if (_form.businessData.control["allowRollback"]) _form.rollback();
  1468. }else{
  1469. _form.doRollbackActionInvoke(option.log, option.flow, option.success, option.failure);
  1470. }
  1471. },
  1472. "print": function(application, form){
  1473. if (arguments.length){
  1474. var app = (arguments.length>1) ? arguments[0] : null;
  1475. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1476. _form.printWork(app, formName);
  1477. }else{
  1478. _form.printWork();
  1479. }
  1480. },
  1481. "deleteWork": function(option){
  1482. if (!option){
  1483. if (_form.businessData.control["allowDelete"]) _form.deleteWork();
  1484. }else{
  1485. _form.doDeleteWork(option.success, option.failure);
  1486. }
  1487. },
  1488. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  1489. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  1490. var p = MWF.getCenter({"x": width, "y": height});
  1491. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1492. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1493. }else{
  1494. e = (arguments.length>1) ? arguments[1] : null;
  1495. title = (arguments.length>2) ? arguments[2] : null;
  1496. text = (arguments.length>3) ? arguments[3] : null;
  1497. width = (arguments.length>4) ? arguments[4] : null;
  1498. height = (arguments.length>5) ? arguments[5] : null;
  1499. ok = (arguments.length>6) ? arguments[6] : null;
  1500. cancel = (arguments.length>7) ? arguments[7] : null;
  1501. callback = (arguments.length>8) ? arguments[8] : null;
  1502. mask = (arguments.length>9) ? arguments[9] : null;
  1503. style = (arguments.length>10) ? arguments[10] : null;
  1504. // var p = MWF.getCenter({"x": width, "y": height});
  1505. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1506. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1507. }
  1508. },
  1509. "alert": function(type, title, text, width, height){
  1510. _form.alert(type, title, text, width, height);
  1511. },
  1512. "notice": function(content, type, target, where, offset, option){
  1513. _form.notice(content, type, target, where, offset, option);
  1514. },
  1515. "addEvent": function(e, f){_form.addEvent(e, f);},
  1516. "openWindow": function(application, form){
  1517. if (arguments.length){
  1518. var app = (arguments.length>1) ? arguments[0] : null;
  1519. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1520. _form.openWindow(formName, app);
  1521. }else{
  1522. _form.openWindow();
  1523. }
  1524. },
  1525. "openWork": function(id, completedId, title, options){
  1526. var op = options || {};
  1527. op.workId = id;
  1528. op.workCompletedId = completedId;
  1529. op.docTitle = title;
  1530. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1531. return layout.desktop.openApplication(this.event, "process.Work", op);
  1532. },
  1533. "openJob": function(id, choice, options){
  1534. var workData = null;
  1535. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1536. if (json.data) workData = json.data;
  1537. }.bind(this), null, false);
  1538. if (workData){
  1539. var len = workData.workList.length + workData.workCompletedList.length;
  1540. if (len){
  1541. if (len>1 && choice){
  1542. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1543. workData.workList.each(function(work){
  1544. var workNode = new Element("div", {
  1545. "styles": {
  1546. "background": "#ffffff",
  1547. "border-radius": "10px",
  1548. "clear": "both",
  1549. "margin-bottom": "10px",
  1550. "height": "40px",
  1551. "padding": "10px 10px"
  1552. }
  1553. }).inject(node);
  1554. 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>" +
  1555. "<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>"+
  1556. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1557. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1558. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1559. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1560. workNode.set("html", html);
  1561. var action = workNode.getElement(".MWFAction");
  1562. action.store("work", work);
  1563. action.addEvent("click", function(e){
  1564. var work = e.target.retrieve("work");
  1565. if (work) this.openWork(work.id, null, work.title, options);
  1566. dlg.close();
  1567. }.bind(this));
  1568. }.bind(this));
  1569. workData.workCompletedList.each(function(work){
  1570. var workNode = new Element("div", {
  1571. "styles": {
  1572. "background": "#ffffff",
  1573. "border-radius": "10px",
  1574. "clear": "both",
  1575. "margin-bottom": "10px",
  1576. "height": "40px",
  1577. "padding": "10px 10px"
  1578. }
  1579. }).inject(node);
  1580. 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>" +
  1581. "<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>"+
  1582. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1583. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1584. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1585. workNode.set("html", html);
  1586. var action = workNode.getElement(".MWFAction");
  1587. action.store("work", work);
  1588. action.addEvent("click", function(e){
  1589. var work = e.target.retrieve("work");
  1590. if (work) this.openWork(null, work.id, work.title, options);
  1591. dlg.close();
  1592. }.bind(this));
  1593. }.bind(this));
  1594. var height = node.getSize().y+20;
  1595. if (height>600) height = 600;
  1596. var dlg = o2.DL.open({
  1597. "title": o2.LP.widget.choiceWork,
  1598. "style" : "user",
  1599. "isResize": false,
  1600. "content": node,
  1601. "buttonList": [
  1602. {
  1603. "type" : "cancel",
  1604. "text": o2.LP.widget.close,
  1605. "action": function(){dlg.close();}
  1606. }
  1607. ]
  1608. });
  1609. }else{
  1610. if (workData.workList.length){
  1611. var work = workData.workList[0];
  1612. return this.openWork(work.id, null, work.title, options);
  1613. }else{
  1614. var work = workData.workCompletedList[0];
  1615. return this.openWork(null, work.id, work.title, options);
  1616. }
  1617. }
  1618. }
  1619. }
  1620. // var op = options || {};
  1621. // op.workId = id;
  1622. // op.workCompletedId = completedId;
  1623. // op.docTitle = title;
  1624. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1625. // layout.desktop.openApplication(this.event, "process.Work", op);
  1626. },
  1627. "openDocument": function(id, title, options){
  1628. var op = options || {};
  1629. op.documentId = id;
  1630. op.docTitle = title;
  1631. layout.desktop.openApplication(this.event, "cms.Document", op);
  1632. },
  1633. "openPortal": function(name, page, par){
  1634. var action = MWF.Actions.get("x_portal_assemble_surface");
  1635. action.getApplication(name, function(json){
  1636. if (json.data){
  1637. if (page){
  1638. action.getPageByName(page, json.data.id, function(pageJson){
  1639. layout.desktop.openApplication(null, "portal.Portal", {
  1640. "portalId": json.data.id,
  1641. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1642. "parameters": par,
  1643. "appId": "portal.Portal"+json.data.id
  1644. })
  1645. });
  1646. }else{
  1647. layout.desktop.openApplication(null, "portal.Portal", {
  1648. "portalId": json.data.id,
  1649. "parameters": par,
  1650. "appId": "portal.Portal"+json.data.id
  1651. })
  1652. }
  1653. }
  1654. });
  1655. },
  1656. "openCMS": function(name){
  1657. var action = MWF.Actions.get("x_cms_assemble_control");
  1658. action.getColumn(name, function(json){
  1659. if (json.data){
  1660. layout.desktop.openApplication(null, "cms.Module", {
  1661. "columnId": json.data.id,
  1662. "appId": "cms.Module"+json.data.id
  1663. });
  1664. }
  1665. });
  1666. },
  1667. "openProcess": function(name){
  1668. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1669. action.getApplication(name, function(json){
  1670. if (json.data){
  1671. layout.desktop.openApplication(null, "process.Application", {
  1672. "id": json.data.id,
  1673. "appId": "process.Application"+json.data.id
  1674. });
  1675. }
  1676. });
  1677. },
  1678. "openApplication":function(name, options){
  1679. layout.desktop.openApplication(null, name, options);
  1680. },
  1681. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1682. var column = columnOrOptions;
  1683. var onAfterPublish, onPostPublish;
  1684. if (typeOf(columnOrOptions) == "object") {
  1685. column = columnOrOptions.column;
  1686. category = columnOrOptions.category;
  1687. data = columnOrOptions.data;
  1688. identity = columnOrOptions.identity;
  1689. callback = columnOrOptions.callback;
  1690. target = columnOrOptions.target;
  1691. latest = columnOrOptions.latest;
  1692. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1693. ignoreTitle = columnOrOptions.ignoreTitle;
  1694. onAfterPublish = columnOrOptions.onAfterPublish;
  1695. onPostPublish = columnOrOptions.onPostPublish;
  1696. }
  1697. if (target) {
  1698. if (layout.app && layout.app.inBrowser) {
  1699. layout.app.content.empty();
  1700. layout.app = null;
  1701. }
  1702. }
  1703. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1704. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1705. "documentData": data,
  1706. "identity": identity,
  1707. "ignoreTitle": ignoreTitle === true,
  1708. "ignoreDrafted": latest === false,
  1709. "selectColumnEnable": !category || selectColumnEnable === true,
  1710. "restrictToColumn": !!category && selectColumnEnable !== true,
  1711. "categoryFlag": category, //category id or name
  1712. "columnFlag": column, //column id or name,
  1713. "onStarted": function (documentId, data) {
  1714. if (callback) callback();
  1715. },
  1716. "onPostPublish": function () {
  1717. if(onPostPublish)onPostPublish();
  1718. },
  1719. "onAfterPublish": function () {
  1720. if(onAfterPublish)onAfterPublish();
  1721. }
  1722. });
  1723. starter.load();
  1724. })
  1725. },
  1726. "startProcess": function(app, process, data, identity, callback, target, latest){
  1727. if (arguments.length>2){
  1728. for (var i=2; i<arguments.length; i++){
  1729. if (typeOf(arguments[i])=="boolean"){
  1730. target = arguments[i];
  1731. break;
  1732. }
  1733. }
  1734. }
  1735. if (target){
  1736. if (layout.app && layout.app.inBrowser){
  1737. //layout.app.content.empty();
  1738. layout.app.$openWithSelf = true;
  1739. }
  1740. }
  1741. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1742. if (json.data){
  1743. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1744. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1745. "workData": data,
  1746. "identity": identity,
  1747. "latest": latest,
  1748. "onStarted": function(data, title, processName){
  1749. if (data.work){
  1750. var work = data.work;
  1751. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1752. layout.desktop.openApplication(null, "process.Work", options);
  1753. }else{
  1754. var currentTask = [];
  1755. data.each(function(work){
  1756. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1757. }.bind(this));
  1758. if (currentTask.length==1){
  1759. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1760. layout.desktop.openApplication(null, "process.Work", options);
  1761. }else{}
  1762. }
  1763. if (callback) callback(data);
  1764. }.bind(this)
  1765. });
  1766. starter.load();
  1767. }.bind(this));
  1768. }
  1769. });
  1770. }
  1771. };
  1772. this.form.currentRouteName = _form.json.currentRouteName;
  1773. this.form.opinion = _form.json.opinion;
  1774. this.target = ev.target;
  1775. this.event = ev.event;
  1776. this.status = ev.status;
  1777. this.session = layout.desktop.session;
  1778. this.Actions = o2.Actions;
  1779. this.query = function(option){
  1780. // options = {
  1781. // "name": "statementName",
  1782. // "data": "json data",
  1783. // "firstResult": 1,
  1784. // "maxResults": 100,
  1785. // "success": function(){},
  1786. // "error": function(){},
  1787. // "async": true or false, default is true
  1788. // }
  1789. if (option){
  1790. var json = (option.data) || {};
  1791. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1792. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1793. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1794. }
  1795. }
  1796. this.Table = MWF.xScript.createTable();
  1797. };
  1798. MWF.xScript.createTable = function(){
  1799. return function(name){
  1800. this.name = name;
  1801. this.action = o2.Actions.get("x_query_assemble_surface");
  1802. this.listRowNext = function(id, count, success, error, async){
  1803. this.action.listRowNext(this.name, id, count, success, error, async);
  1804. };
  1805. this.listRowPrev = function(id, count, success, error, async){
  1806. this.action.listRowPrev(this.name, id, count, success, error, async);
  1807. };
  1808. this.listRowPrev = function(id, count, success, error, async){
  1809. this.action.listRowPrev(this.name, id, count, success, error, async);
  1810. };
  1811. this.listRowSelectWhere = function(where, success, error, async){
  1812. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1813. };
  1814. this.listRowCountWhere = function(where, success, error, async){
  1815. this.action.listRowCountWhere(this.name, where, success, error, async);
  1816. };
  1817. this.deleteRow = function(id, success, error, async){
  1818. this.action.deleteRow(this.name, id, success, error, async);
  1819. };
  1820. this.deleteAllRow = function(success, error, async){
  1821. this.action.deleteAllRow(this.name, success, error, async);
  1822. };
  1823. this.getRow = function(id, success, error, async){
  1824. this.action.getRow(this.name, id, success, error, async);
  1825. };
  1826. this.insertRow = function(data, success, error, async){
  1827. this.action.insertRow(this.name, data, success, error, async);
  1828. };
  1829. this.updateRow = function(id, data, success, error, async){
  1830. this.action.updateRow(this.name, id, data, success, error, async);
  1831. };
  1832. }
  1833. };
  1834. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  1835. var getter = function(data, callback, k, _self){
  1836. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  1837. };
  1838. var setter = function(data, callback, k, _self){
  1839. return function(v){
  1840. data[k] = v;
  1841. //debugger;
  1842. //this.add(k, v, true);
  1843. if (callback) callback(data, k, _self);
  1844. }
  1845. };
  1846. var define = function(){
  1847. var o = {};
  1848. 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])};
  1849. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1850. o["some"] = {"get": function(){return data.some;}};
  1851. MWF.defineProperties(this, o);
  1852. var methods = {
  1853. "getKey": {"value": function(){ return key; }},
  1854. "getParent": {"value": function(){ return parent; }},
  1855. "toString": {"value": function() { return data.toString();}},
  1856. "setSection": {"value": function(newKey, newValue){
  1857. this.add(newKey, newValue, true);
  1858. try {
  1859. var path = [this.getKey()];
  1860. p = this.getParent();
  1861. while (p && p.getKey()){
  1862. path.unshift(p.getKey());
  1863. p = p.getParent();
  1864. }
  1865. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  1866. }catch(e){
  1867. }
  1868. }},
  1869. "add": {"value": function(newKey, newValue, overwrite){
  1870. var flag = true;
  1871. var type = typeOf(data);
  1872. if (type==="array"){
  1873. if (arguments.length<2){
  1874. data.push(newKey);
  1875. newValue = newKey;
  1876. newKey = data.length-1;
  1877. }else{
  1878. if (!newKey && newKey!==0){
  1879. data.push(newValue);
  1880. newKey = data.length-1;
  1881. }else{
  1882. flag = false;
  1883. }
  1884. }
  1885. if (flag){
  1886. var o = {};
  1887. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1888. MWF.defineProperties(this, o);
  1889. }
  1890. this[newKey] = newValue;
  1891. }else if (type==="object"){
  1892. if (!this.hasOwnProperty(newKey)){
  1893. data[newKey] = newValue;
  1894. if (flag){
  1895. var o = {};
  1896. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1897. MWF.defineProperties(this, o);
  1898. }
  1899. this[newKey] = newValue;
  1900. }else{
  1901. if (overwrite) this[newKey] = newValue;
  1902. }
  1903. }
  1904. return this[newKey];
  1905. }},
  1906. "del": {"value": function(delKey){
  1907. if (!this.hasOwnProperty(delKey)) return null;
  1908. // delete data[delKey];
  1909. // delete this[delKey];
  1910. data[delKey] = "";
  1911. this[delKey] = "";
  1912. return this;
  1913. }}
  1914. };
  1915. MWF.defineProperties(this, methods);
  1916. //this.getKey = function(){ return key; };
  1917. //this.getParent = function(){ return parent; };
  1918. //this.toString = function() { return data.toString();};
  1919. //this.add = function(newKey, newValue, overwrite){
  1920. // var flag = true;
  1921. // var type = typeOf(data);
  1922. // if (!this.hasOwnProperty(newKey)){
  1923. // if (type=="array"){
  1924. // if (arguments.length<2){
  1925. // data.push(newKey);
  1926. // newValue = newKey;
  1927. // newKey = data.length-1;
  1928. // }else{
  1929. // debugger;
  1930. // if (!newKey && newKey!=0){
  1931. // data.push(newValue);
  1932. // newKey = data.length-1;
  1933. // }else{
  1934. // flag == false;
  1935. // }
  1936. // }
  1937. // }else{
  1938. // data[newKey] = newValue;
  1939. // }
  1940. // //var valueType = typeOf(newValue);
  1941. // //var newValueData = newValue;
  1942. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1943. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1944. // if (flag){
  1945. // var o = {};
  1946. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1947. // MWF.defineProperties(this, o);
  1948. // }
  1949. // this[newKey] = newValue;
  1950. // }else{
  1951. // if (overwrite) this[newKey] = newValue;
  1952. // }
  1953. //
  1954. // //var valueType = typeOf(newValue);
  1955. // //var newValueData = newValue;
  1956. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1957. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1958. // //
  1959. // //this[newKey] = newValueData;
  1960. //
  1961. // return this[newKey];
  1962. //};
  1963. //this.del = function(delKey){
  1964. // if (!this.hasOwnProperty(delKey)) return null;
  1965. // delete data[newKey];
  1966. // delete this[newKey];
  1967. // return this;
  1968. //};
  1969. };
  1970. var type = typeOf(data);
  1971. if (type==="object" || type==="array") define.apply(this);
  1972. };
  1973. //MWF.xScript.createDict = function(application){
  1974. // return function(name){
  1975. // var applicationId = application;
  1976. // this.name = name;
  1977. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1978. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1979. //
  1980. // this.get = function(path, success, failure){
  1981. // debugger;
  1982. // var value = null;
  1983. // if (path){
  1984. // var arr = path.split(/\./g);
  1985. // var ar = arr.map(function(v){
  1986. // return encodeURIComponent(v);
  1987. // });
  1988. // //var p = path.replace(/\./g, "/");
  1989. // var p = ar.join("/");
  1990. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1991. // value = json.data;
  1992. // if (success) success(json.data);
  1993. // }, function(xhr, text, error){
  1994. // if (failure) failure(xhr, text, error);
  1995. // }, false);
  1996. // }else{
  1997. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  1998. // value = json.data;
  1999. // if (success) success(json.data);
  2000. // }, function(xhr, text, error){
  2001. // if (failure) failure(xhr, text, error);
  2002. // }, false);
  2003. // }
  2004. //
  2005. // return value;
  2006. // };
  2007. //
  2008. // this.set = function(path, value, success, failure){
  2009. // var p = path.replace(/\./g, "/");
  2010. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2011. // if (success) success(json.data);
  2012. // }, function(xhr, text, error){
  2013. // if (failure) failure(xhr, text, error);
  2014. // });
  2015. // };
  2016. // this.add = function(path, value, success, failure){
  2017. // var p = path.replace(/\./g, "/");
  2018. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2019. // if (success) success(json.data);
  2020. // }, function(xhr, text, error){
  2021. // if (failure) failure(xhr, text, error);
  2022. // });
  2023. // };
  2024. // this["delete"] = function(path, success, failure){
  2025. // var p = path.replace(/\./g, "/");
  2026. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2027. // if (success) success(json.data);
  2028. // }, function(xhr, text, error){
  2029. // if (failure) failure(xhr, text, error);
  2030. // });
  2031. // };
  2032. // this.destory = this["delete"];
  2033. // }
  2034. //};
  2035. // var dictLoaded = {};
  2036. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  2037. MWF.xScript.addDictToCache = function ( options, path, json ) {
  2038. if( !path )path = "root";
  2039. if( path.indexOf("root") !== 0 )path = "root." + path ;
  2040. var type = options.appType || "process";
  2041. var enableAnonymous = options.enableAnonymous || false;
  2042. var appFlagList = [];
  2043. if( options.application )appFlagList.push( options.application );
  2044. if( options.appId )appFlagList.push( options.appId );
  2045. if( options.appName )appFlagList.push( options.appName );
  2046. if( options.appAlias )appFlagList.push( options.appAlias );
  2047. var dictFlagList = [];
  2048. if( options.id )dictFlagList.push( options.id );
  2049. if( options.name )dictFlagList.push( options.name );
  2050. if( options.alias )dictFlagList.push( options.alias );
  2051. var cache = {};
  2052. cache[path] = json;
  2053. for( var i=0; i<appFlagList.length; i++ ){
  2054. for( var j=0; j<dictFlagList.length; j++ ){
  2055. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  2056. if( !MWF.xScript.dictLoaded[k] ){
  2057. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  2058. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  2059. }else if( i===0 && j===0 ){
  2060. MWF.xScript.setDictToCache( k, path ,json );
  2061. var arr = path.split(/\./g);
  2062. var p;
  2063. var cache = MWF.xScript.dictLoaded[k];
  2064. for( var l=0 ; l<arr.length; l++ ){
  2065. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  2066. if( cache[ p ] )break;
  2067. }
  2068. if( p ){
  2069. var mathP = p+".";
  2070. Object.keys( cache ).each( function( path, idx){
  2071. if( path.indexOf( mathP ) === 0 )delete cache[path];
  2072. })
  2073. }
  2074. }
  2075. }
  2076. }
  2077. };
  2078. MWF.xScript.getMatchedDict = function(key, path){
  2079. if( !path )path = "root";
  2080. if( path.indexOf("root") !== 0 )path = "root." + path ;
  2081. var arr = path.split(/\./g);
  2082. if( MWF.xScript.dictLoaded[key] ){
  2083. var dicts = MWF.xScript.dictLoaded[key];
  2084. var list = Array.clone(arr);
  2085. var p;
  2086. var dict;
  2087. for( var i=0 ; i<arr.length; i++ ){
  2088. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  2089. list.shift();
  2090. if( dicts[ p ] ){
  2091. dict = dicts[ p ];
  2092. break;
  2093. }
  2094. }
  2095. return {
  2096. dict : dict,
  2097. unmatchedPathList : list
  2098. }
  2099. }
  2100. return {
  2101. dict : null,
  2102. unmatchedPathList : list
  2103. }
  2104. };
  2105. MWF.xScript.insertDictToCache = function(key, path, json){
  2106. if( MWF.xScript.dictLoaded[key] ){
  2107. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2108. var dict = matchedDict.dict;
  2109. var list = matchedDict.unmatchedPathList;
  2110. if( !dict ){
  2111. MWF.xScript.dictLoaded[key][path] = json;
  2112. }else{
  2113. for( var j=0; j<list.length-1; j++ ){
  2114. if( !dict[ list[j] ] ){
  2115. dict[ list[j] ] = {};
  2116. }
  2117. dict = dict[ list[j] ];
  2118. }
  2119. var lastPath = list[list.length-1];
  2120. if( !dict[lastPath] ){
  2121. dict[lastPath] = json;
  2122. }else if( typeOf( dict[lastPath] ) === "array" ){
  2123. dict[lastPath].push( json );
  2124. }
  2125. }
  2126. }else{
  2127. MWF.xScript.dictLoaded[key] = {};
  2128. MWF.xScript.dictLoaded[key][path] = json;
  2129. }
  2130. };
  2131. MWF.xScript.setDictToCache = function(key, path, json){
  2132. if( MWF.xScript.dictLoaded[key] ){
  2133. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2134. var dict = matchedDict.dict;
  2135. var list = matchedDict.unmatchedPathList;
  2136. if( !dict ){
  2137. MWF.xScript.dictLoaded[key][path] = json;
  2138. }else{
  2139. for( var j=0; j<list.length-1; j++ ){
  2140. if( !dict[ list[j] ] ){
  2141. dict[ list[j] ] = {};
  2142. }
  2143. dict = dict[ list[j] ];
  2144. }
  2145. dict[list[list.length-1]] = json;
  2146. }
  2147. }else{
  2148. MWF.xScript.dictLoaded[key] = {};
  2149. MWF.xScript.dictLoaded[key][path] = json;
  2150. }
  2151. };
  2152. MWF.xScript.getDictFromCache = function( key, path ){
  2153. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2154. var dict = matchedDict.dict;
  2155. var list = matchedDict.unmatchedPathList;
  2156. if( dict ){
  2157. for( var j=0; j<list.length; j++ ){
  2158. dict = dict[ list[j] ];
  2159. if( !dict )return null;
  2160. }
  2161. return dict;
  2162. }
  2163. return null;
  2164. };
  2165. MWF.xScript.deleteDictToCache = function(key, path){
  2166. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2167. var dict = matchedDict.dict;
  2168. var list = matchedDict.unmatchedPathList;
  2169. if( dict){
  2170. for( var j=0; j<list.length-1; j++ ){
  2171. dict = dict[ list[j] ];
  2172. if( !dict )return;
  2173. }
  2174. delete dict[list[list.length-1]];
  2175. }
  2176. };
  2177. MWF.xScript.createDict = function(application){
  2178. //optionsOrName : {
  2179. // type : "", //默认为process, 可以为 process cms
  2180. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  2181. // name : "", // 数据字典名称/别名/id
  2182. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  2183. //}
  2184. //或者name: "" // 数据字典名称/别名/id
  2185. return function(optionsOrName){
  2186. var options = optionsOrName;
  2187. if( typeOf( options ) == "string" ){
  2188. options = { name : options };
  2189. }
  2190. var name = this.name = options.name;
  2191. var type = ( options.type && options.application ) ? options.type : "process";
  2192. var applicationId = options.application || application;
  2193. var enableAnonymous = options.enableAnonymous || false;
  2194. var opt = {
  2195. "appType" : type,
  2196. "name" : name,
  2197. "appId" : applicationId,
  2198. "enableAnonymous" : enableAnonymous
  2199. };
  2200. var key = name+type+applicationId+enableAnonymous;
  2201. // if (!dictLoaded[key]) dictLoaded[key] = {};
  2202. // this.dictData = dictLoaded[key];
  2203. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2204. if( type == "cms" ){
  2205. var action = MWF.Actions.get("x_cms_assemble_control");
  2206. }else{
  2207. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2208. }
  2209. var encodePath = function( path ){
  2210. var arr = path.split(/\./g);
  2211. var ar = arr.map(function(v){
  2212. return encodeURIComponent(v);
  2213. });
  2214. return ar.join("/");
  2215. };
  2216. this.get = function(path, success, failure, async, refresh){
  2217. var value = null;
  2218. if (!refresh ){
  2219. var data = MWF.xScript.getDictFromCache( key, path );
  2220. if( data ){
  2221. if (success && o2.typeOf(success)=="function") success( data );
  2222. return data;
  2223. }
  2224. }
  2225. if (success===true) async=true;
  2226. if (failure===true) async=true;
  2227. // var cb = function(json){
  2228. // value = json.data;
  2229. // MWF.xScript.addDictToCache(opt, path, value);
  2230. // if (success && o2.typeOf(success)=="function") value = success(json.data);
  2231. // return value;
  2232. // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  2233. var cb = function(json){
  2234. value = json.data;
  2235. MWF.xScript.addDictToCache(opt, path, value);
  2236. if (success && o2.typeOf(success)=="function") value = success(json.data);
  2237. return value;
  2238. };
  2239. var promise;
  2240. if (path){
  2241. var p = encodePath( path );
  2242. //var p = path.replace(/\./g, "/");
  2243. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async, false);
  2244. }else{
  2245. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async, false);
  2246. }
  2247. return (!!async) ? promise : value;
  2248. // if (path){
  2249. // var p = encodePath( path );
  2250. // //var p = path.replace(/\./g, "/");
  2251. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  2252. // value = json.data;
  2253. // // this.dictData[path] = value;
  2254. // MWF.xScript.addDictToCache(opt, path, value);
  2255. // if (success) success(json.data);
  2256. // }.bind(this), function(xhr, text, error){
  2257. // if (failure) failure(xhr, text, error);
  2258. // }, !!async);
  2259. // }else{
  2260. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  2261. // value = json.data;
  2262. // // this.dictData["root"] = value;
  2263. // MWF.xScript.addDictToCache(opt, path, value);
  2264. // if (success) success(json.data);
  2265. // }.bind(this), function(xhr, text, error){
  2266. // if (failure) failure(xhr, text, error);
  2267. // }, !!async);
  2268. // }
  2269. //return value;
  2270. };
  2271. this.set = function(path, value, success, failure){
  2272. var p = encodePath( path );
  2273. //var p = path.replace(/\./g, "/");
  2274. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2275. MWF.xScript.setDictToCache(key, path, value);
  2276. if (success) return success(json.data);
  2277. }, function(xhr, text, error){
  2278. if (failure) return failure(xhr, text, error);
  2279. }, false, false);
  2280. };
  2281. this.add = function(path, value, success, failure){
  2282. var p = encodePath( path );
  2283. //var p = path.replace(/\./g, "/");
  2284. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2285. MWF.xScript.insertDictToCache(key, path, value);
  2286. if (success) return success(json.data);
  2287. }, function(xhr, text, error){
  2288. if (failure) return failure(xhr, text, error);
  2289. }, false, false);
  2290. };
  2291. this["delete"] = function(path, success, failure){
  2292. var p = encodePath( path );
  2293. //var p = path.replace(/\./g, "/");
  2294. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2295. MWF.xScript.deleteDictToCache(key, path);
  2296. if (success) return success(json.data);
  2297. }, function(xhr, text, error){
  2298. if (failure) return failure(xhr, text, error);
  2299. }, false, false);
  2300. };
  2301. this.destory = this["delete"];
  2302. }
  2303. };