Environment.js 99 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341
  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){
  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;
  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. //include 引用脚本
  1150. //optionsOrName : {
  1151. // type : "", 默认为process, 可以为 portal process cms
  1152. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  1153. // name : "" // 脚本名称/别名/id
  1154. //}
  1155. //或者name: "" // 脚本名称/别名/id
  1156. // if( !window.includedScripts ){
  1157. // var includedScripts = window.includedScripts = [];
  1158. // }else{
  1159. // var includedScripts = window.includedScripts;
  1160. // }
  1161. var includedScripts = [];
  1162. var _includeSingle = function( optionsOrName , callback, async){
  1163. var options = optionsOrName;
  1164. if( typeOf( options ) == "string" ){
  1165. options = { name : options };
  1166. }
  1167. var name = options.name;
  1168. var type = ( options.type && options.application ) ? options.type : "process";
  1169. var application = options.application || _form.json.application;
  1170. var key = type +"-" + application + "-" + name;
  1171. if (includedScripts.indexOf( key )> -1){
  1172. if (callback) callback.apply(this);
  1173. return;
  1174. }
  1175. //if (includedScripts.indexOf( name )> -1){
  1176. // if (callback) callback.apply(this);
  1177. // return;
  1178. //}
  1179. var scriptAction;
  1180. switch ( type ){
  1181. case "portal" :
  1182. if( this.scriptActionPortal ){
  1183. scriptAction = this.scriptActionPortal;
  1184. }else{
  1185. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  1186. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  1187. }
  1188. break;
  1189. case "process" :
  1190. if( this.scriptActionProcess ){
  1191. scriptAction = this.scriptActionProcess;
  1192. }else{
  1193. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1194. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1195. }
  1196. break;
  1197. case "cms" :
  1198. if( this.scriptActionCMS ){
  1199. scriptAction = this.scriptActionCMS;
  1200. }else{
  1201. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1202. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1203. }
  1204. break;
  1205. }
  1206. debugger;
  1207. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  1208. if (json.data){
  1209. includedScripts.push( key );
  1210. //名称、别名、id
  1211. json.data.importedList.each( function ( flag ) {
  1212. if( type === "portal" ){
  1213. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  1214. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  1215. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  1216. }else if( type === "cms" ){
  1217. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  1218. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1219. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1220. }else if( type === "process" ){
  1221. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  1222. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1223. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1224. }
  1225. });
  1226. includedScripts = includedScripts.concat(json.data.importedList);
  1227. MWF.Macro.exec(json.data.text, this);
  1228. if (callback) callback.apply(this);
  1229. }else{
  1230. if (callback) callback.apply(this);
  1231. }
  1232. }.bind(this), null, !!async);
  1233. }
  1234. this.include = function( optionsOrName , callback, async){
  1235. if (o2.typeOf(optionsOrName)=="array"){
  1236. if (!!async){
  1237. var count = optionsOrName.length;
  1238. var loaded = 0;
  1239. optionsOrName.each(function(option){
  1240. _includeSingle.apply(this, [option, function(){
  1241. loaded++;
  1242. if (loaded>=count) if (callback) callback.apply(this);;
  1243. }.bind(this), true]);
  1244. }.bind(this));
  1245. }else{
  1246. optionsOrName.each(function(option){
  1247. _includeSingle.apply(this, [option]);
  1248. if (callback) callback.apply(this);
  1249. }.bind(this));
  1250. }
  1251. }else{
  1252. _includeSingle.apply(this, [optionsOrName , callback, async])
  1253. }
  1254. };
  1255. this.define = function(name, fun, overwrite){
  1256. var over = true;
  1257. if (overwrite===false) over = false;
  1258. var o = {};
  1259. o[name] = {"value": fun, "configurable": over};
  1260. MWF.defineProperties(this, o);
  1261. }.bind(this);
  1262. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1263. //可在调用前执行 var resolve = this.wait();
  1264. //在异步调用结束后 执行 resolve.cb();
  1265. //目前只有表单的queryload事件支持此方法。
  1266. this.wait = function(){
  1267. resolve = {};
  1268. var setResolve = function(callback){
  1269. resolve.cb = callback;
  1270. }.bind(this);
  1271. this.target.event_resolve = setResolve;
  1272. return resolve;
  1273. }
  1274. //和this.wait配合使用,
  1275. //如果没有异步,则resolve.cb方法不存在,
  1276. //所以在回调中中使用this.goon();使表单继续加载
  1277. this.goon = function(){
  1278. this.target.event_resolve = null;
  1279. }
  1280. //仅前台对象-----------------------------------------
  1281. //form
  1282. this.page = this.form = {
  1283. "getInfor": function(){return ev.formInfor;},
  1284. "infor": ev.formInfor,
  1285. "getApp": function(){return _form.app;},
  1286. "app": _form.app,
  1287. "node": function(){return _form.node;},
  1288. "readonly": _form.options.readonly,
  1289. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  1290. "getField": function(name){return _forms[name];},
  1291. "getAction": function(){return _form.workAction},
  1292. "getDesktop": function(){return _form.app.desktop},
  1293. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  1294. "save": function(callback, silent){_form.saveWork(callback, silent); },
  1295. "close": function(){_form.closeWork();},
  1296. "verify": function(){
  1297. return !(!_form.formCustomValidation("", "") || !_form.formValidation("", ""));
  1298. },
  1299. "process": function(option){
  1300. var op = _form.getOpinion();
  1301. var mds = op.medias;
  1302. if (option){
  1303. _form.submitWork(option.routeName, option.opinion, mds, option.callback,
  1304. option.processor, null, option.appendTaskIdentityList, option.processorOrgList, option.callbackBeforeSave );
  1305. }else{
  1306. _form.processWork();
  1307. }
  1308. },
  1309. "reset": function(option){
  1310. if (!option){
  1311. if (_form.businessData.control["allowReset"]) _form.resetWork();
  1312. }else{
  1313. _form.resetWorkToPeson(option.names, option.opinion, option.keep, option.success, option.failure);
  1314. }
  1315. },
  1316. "retract": function(option){
  1317. if (!option){
  1318. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  1319. }else{
  1320. _form.doRetractWork(option.success, option.failure);
  1321. }
  1322. },
  1323. "addSplit": function(option){
  1324. if (!option){
  1325. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  1326. }else{
  1327. _form.addSplitWork(option.value, option.success, option.failure);
  1328. }
  1329. },
  1330. "rollback": function(option){
  1331. if (!option){
  1332. if (_form.businessData.control["allowRollback"]) _form.rollback();
  1333. }else{
  1334. _form.doRollbackActionInvoke(option.log, option.flow, option.success, option.failure);
  1335. }
  1336. },
  1337. "print": function(application, form){
  1338. if (arguments.length){
  1339. var app = (arguments.length>1) ? arguments[0] : null;
  1340. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1341. _form.printWork(app, formName);
  1342. }else{
  1343. _form.printWork();
  1344. }
  1345. },
  1346. "deleteWork": function(option){
  1347. if (!option){
  1348. if (_form.businessData.control["allowDelete"]) _form.deleteWork();
  1349. }else{
  1350. _form.doDeleteWork(option.success, option.failure);
  1351. }
  1352. },
  1353. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  1354. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  1355. var p = MWF.getCenter({"x": width, "y": height});
  1356. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1357. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1358. }else{
  1359. e = (arguments.length>1) ? arguments[1] : null;
  1360. title = (arguments.length>2) ? arguments[2] : null;
  1361. text = (arguments.length>3) ? arguments[3] : null;
  1362. width = (arguments.length>4) ? arguments[4] : null;
  1363. height = (arguments.length>5) ? arguments[5] : null;
  1364. ok = (arguments.length>6) ? arguments[6] : null;
  1365. cancel = (arguments.length>7) ? arguments[7] : null;
  1366. callback = (arguments.length>8) ? arguments[8] : null;
  1367. mask = (arguments.length>9) ? arguments[9] : null;
  1368. style = (arguments.length>10) ? arguments[10] : null;
  1369. // var p = MWF.getCenter({"x": width, "y": height});
  1370. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1371. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1372. }
  1373. },
  1374. "alert": function(type, title, text, width, height){
  1375. _form.alert(type, title, text, width, height);
  1376. },
  1377. "notice": function(content, type, target, where, offset, option){
  1378. _form.notice(content, type, target, where, offset, option);
  1379. },
  1380. "addEvent": function(e, f){_form.addEvent(e, f);},
  1381. "openWindow": function(application, form){
  1382. if (arguments.length){
  1383. var app = (arguments.length>1) ? arguments[0] : null;
  1384. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1385. _form.openWindow(formName, app);
  1386. }else{
  1387. _form.openWindow();
  1388. }
  1389. },
  1390. "openWork": function(id, completedId, title, options){
  1391. var op = options || {};
  1392. op.workId = id;
  1393. op.workCompletedId = completedId;
  1394. op.docTitle = title;
  1395. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1396. return layout.desktop.openApplication(this.event, "process.Work", op);
  1397. },
  1398. "openJob": function(id, choice, options){
  1399. var workData = null;
  1400. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1401. if (json.data) workData = json.data;
  1402. }.bind(this), null, false);
  1403. if (workData){
  1404. var len = workData.workList.length + workData.workCompletedList.length;
  1405. if (len){
  1406. if (len>1 && choice){
  1407. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1408. workData.workList.each(function(work){
  1409. var workNode = new Element("div", {
  1410. "styles": {
  1411. "background": "#ffffff",
  1412. "border-radius": "10px",
  1413. "clear": "both",
  1414. "margin-bottom": "10px",
  1415. "height": "40px",
  1416. "padding": "10px 10px"
  1417. }
  1418. }).inject(node);
  1419. 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>" +
  1420. "<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>"+
  1421. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1422. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1423. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1424. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1425. workNode.set("html", html);
  1426. var action = workNode.getElement(".MWFAction");
  1427. action.store("work", work);
  1428. action.addEvent("click", function(e){
  1429. var work = e.target.retrieve("work");
  1430. if (work) this.openWork(work.id, null, work.title, options);
  1431. dlg.close();
  1432. }.bind(this));
  1433. }.bind(this));
  1434. workData.workCompletedList.each(function(work){
  1435. var workNode = new Element("div", {
  1436. "styles": {
  1437. "background": "#ffffff",
  1438. "border-radius": "10px",
  1439. "clear": "both",
  1440. "margin-bottom": "10px",
  1441. "height": "40px",
  1442. "padding": "10px 10px"
  1443. }
  1444. }).inject(node);
  1445. 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>" +
  1446. "<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>"+
  1447. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1448. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1449. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1450. workNode.set("html", html);
  1451. var action = workNode.getElement(".MWFAction");
  1452. action.store("work", work);
  1453. action.addEvent("click", function(e){
  1454. var work = e.target.retrieve("work");
  1455. if (work) this.openWork(null, work.id, work.title, options);
  1456. dlg.close();
  1457. }.bind(this));
  1458. }.bind(this));
  1459. var height = node.getSize().y+20;
  1460. if (height>600) height = 600;
  1461. var dlg = o2.DL.open({
  1462. "title": o2.LP.widget.choiceWork,
  1463. "style" : "user",
  1464. "isResize": false,
  1465. "content": node,
  1466. "buttonList": [
  1467. {
  1468. "type" : "cancel",
  1469. "text": o2.LP.widget.close,
  1470. "action": function(){dlg.close();}
  1471. }
  1472. ]
  1473. });
  1474. }else{
  1475. if (workData.workList.length){
  1476. var work = workData.workList[0];
  1477. return this.openWork(work.id, null, work.title, options);
  1478. }else{
  1479. var work = workData.workCompletedList[0];
  1480. return this.openWork(null, work.id, work.title, options);
  1481. }
  1482. }
  1483. }
  1484. }
  1485. // var op = options || {};
  1486. // op.workId = id;
  1487. // op.workCompletedId = completedId;
  1488. // op.docTitle = title;
  1489. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1490. // layout.desktop.openApplication(this.event, "process.Work", op);
  1491. },
  1492. "openDocument": function(id, title, options){
  1493. var op = options || {};
  1494. op.documentId = id;
  1495. op.docTitle = title;
  1496. layout.desktop.openApplication(this.event, "cms.Document", op);
  1497. },
  1498. "openPortal": function(name, page, par){
  1499. var action = MWF.Actions.get("x_portal_assemble_surface");
  1500. action.getApplication(name, function(json){
  1501. if (json.data){
  1502. if (page){
  1503. action.getPageByName(page, json.data.id, function(pageJson){
  1504. layout.desktop.openApplication(null, "portal.Portal", {
  1505. "portalId": json.data.id,
  1506. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1507. "parameters": par,
  1508. "appId": "portal.Portal"+json.data.id
  1509. })
  1510. });
  1511. }else{
  1512. layout.desktop.openApplication(null, "portal.Portal", {
  1513. "portalId": json.data.id,
  1514. "parameters": par,
  1515. "appId": "portal.Portal"+json.data.id
  1516. })
  1517. }
  1518. }
  1519. });
  1520. },
  1521. "openCMS": function(name){
  1522. var action = MWF.Actions.get("x_cms_assemble_control");
  1523. action.getColumn(name, function(json){
  1524. if (json.data){
  1525. layout.desktop.openApplication(null, "cms.Module", {
  1526. "columnId": json.data.id,
  1527. "appId": "cms.Module"+json.data.id
  1528. });
  1529. }
  1530. });
  1531. },
  1532. "openProcess": function(name){
  1533. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1534. action.getApplication(name, function(json){
  1535. if (json.data){
  1536. layout.desktop.openApplication(null, "process.Application", {
  1537. "id": json.data.id,
  1538. "appId": "process.Application"+json.data.id
  1539. });
  1540. }
  1541. });
  1542. },
  1543. "openApplication":function(name, options){
  1544. layout.desktop.openApplication(null, name, options);
  1545. },
  1546. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1547. var column = columnOrOptions;
  1548. var onAfterPublish, onPostPublish;
  1549. if (typeOf(columnOrOptions) == "object") {
  1550. column = columnOrOptions.column;
  1551. category = columnOrOptions.category;
  1552. data = columnOrOptions.data;
  1553. identity = columnOrOptions.identity;
  1554. callback = columnOrOptions.callback;
  1555. target = columnOrOptions.target;
  1556. latest = columnOrOptions.latest;
  1557. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1558. ignoreTitle = columnOrOptions.ignoreTitle;
  1559. onAfterPublish = columnOrOptions.onAfterPublish;
  1560. onPostPublish = columnOrOptions.onPostPublish;
  1561. }
  1562. if (target) {
  1563. if (layout.app && layout.app.inBrowser) {
  1564. layout.app.content.empty();
  1565. layout.app = null;
  1566. }
  1567. }
  1568. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1569. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1570. "documentData": data,
  1571. "identity": identity,
  1572. "ignoreTitle": ignoreTitle === true,
  1573. "ignoreDrafted": latest === false,
  1574. "selectColumnEnable": !category || selectColumnEnable === true,
  1575. "restrictToColumn": !!category && selectColumnEnable !== true,
  1576. "categoryFlag": category, //category id or name
  1577. "columnFlag": column, //column id or name,
  1578. "onStarted": function (documentId, data) {
  1579. if (callback) callback();
  1580. },
  1581. "onPostPublish": function () {
  1582. if(onPostPublish)onPostPublish();
  1583. },
  1584. "onAfterPublish": function () {
  1585. if(onAfterPublish)onAfterPublish();
  1586. }
  1587. });
  1588. starter.load();
  1589. })
  1590. },
  1591. "startProcess": function(app, process, data, identity, callback, target, latest){
  1592. if (arguments.length>2){
  1593. for (var i=2; i<arguments.length; i++){
  1594. if (typeOf(arguments[i])=="boolean"){
  1595. target = arguments[i];
  1596. break;
  1597. }
  1598. }
  1599. }
  1600. if (target){
  1601. if (layout.app && layout.app.inBrowser){
  1602. //layout.app.content.empty();
  1603. layout.app.$openWithSelf = true;
  1604. }
  1605. }
  1606. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1607. if (json.data){
  1608. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1609. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1610. "workData": data,
  1611. "identity": identity,
  1612. "latest": latest,
  1613. "onStarted": function(data, title, processName){
  1614. if (data.work){
  1615. var work = data.work;
  1616. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1617. layout.desktop.openApplication(null, "process.Work", options);
  1618. }else{
  1619. var currentTask = [];
  1620. data.each(function(work){
  1621. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1622. }.bind(this));
  1623. if (currentTask.length==1){
  1624. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1625. layout.desktop.openApplication(null, "process.Work", options);
  1626. }else{}
  1627. }
  1628. if (callback) callback(data);
  1629. }.bind(this)
  1630. });
  1631. starter.load();
  1632. }.bind(this));
  1633. }
  1634. });
  1635. }
  1636. };
  1637. this.form.currentRouteName = _form.json.currentRouteName;
  1638. this.form.opinion = _form.json.opinion;
  1639. this.target = ev.target;
  1640. this.event = ev.event;
  1641. this.status = ev.status;
  1642. this.session = layout.desktop.session;
  1643. this.Actions = o2.Actions;
  1644. this.query = function(option){
  1645. // options = {
  1646. // "name": "statementName",
  1647. // "data": "json data",
  1648. // "firstResult": 1,
  1649. // "maxResults": 100,
  1650. // "success": function(){},
  1651. // "error": function(){},
  1652. // "async": true or false, default is true
  1653. // }
  1654. if (option){
  1655. var json = (option.data) || {};
  1656. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1657. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1658. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1659. }
  1660. }
  1661. this.Table = MWF.xScript.createTable();
  1662. };
  1663. MWF.xScript.createTable = function(){
  1664. return function(name){
  1665. this.name = name;
  1666. this.action = o2.Actions.get("x_query_assemble_surface");
  1667. this.listRowNext = function(id, count, success, error, async){
  1668. this.action.listRowNext(this.name, id, count, success, error, async);
  1669. };
  1670. this.listRowPrev = function(id, count, success, error, async){
  1671. this.action.listRowPrev(this.name, id, count, success, error, async);
  1672. };
  1673. this.listRowPrev = function(id, count, success, error, async){
  1674. this.action.listRowPrev(this.name, id, count, success, error, async);
  1675. };
  1676. this.listRowSelectWhere = function(where, success, error, async){
  1677. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1678. };
  1679. this.listRowCountWhere = function(where, success, error, async){
  1680. this.action.listRowCountWhere(this.name, where, success, error, async);
  1681. };
  1682. this.deleteRow = function(id, success, error, async){
  1683. this.action.deleteRow(this.name, id, success, error, async);
  1684. };
  1685. this.deleteAllRow = function(success, error, async){
  1686. this.action.deleteAllRow(this.name, success, error, async);
  1687. };
  1688. this.getRow = function(id, success, error, async){
  1689. this.action.getRow(this.name, id, success, error, async);
  1690. };
  1691. this.insertRow = function(data, success, error, async){
  1692. this.action.insertRow(this.name, data, success, error, async);
  1693. };
  1694. this.updateRow = function(id, data, success, error, async){
  1695. this.action.updateRow(this.name, id, data, success, error, async);
  1696. };
  1697. }
  1698. };
  1699. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  1700. var getter = function(data, callback, k, _self){
  1701. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  1702. };
  1703. var setter = function(data, callback, k, _self){
  1704. return function(v){
  1705. debugger;
  1706. data[k] = v;
  1707. //debugger;
  1708. //this.add(k, v, true);
  1709. if (callback) callback(data, k, _self);
  1710. }
  1711. };
  1712. var define = function(){
  1713. var o = {};
  1714. 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])};
  1715. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1716. MWF.defineProperties(this, o);
  1717. var methods = {
  1718. "getKey": {"value": function(){ return key; }},
  1719. "getParent": {"value": function(){ return parent; }},
  1720. "toString": {"value": function() { return data.toString();}},
  1721. "setSection": {"value": function(newKey, newValue){
  1722. this.add(newKey, newValue, true);
  1723. try {
  1724. var path = [this.getKey()];
  1725. p = this.getParent();
  1726. while (p && p.getKey()){
  1727. path.unshift(p.getKey());
  1728. p = p.getParent();
  1729. }
  1730. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  1731. }catch(e){
  1732. debugger;
  1733. }
  1734. }},
  1735. "add": {"value": function(newKey, newValue, overwrite){
  1736. var flag = true;
  1737. var type = typeOf(data);
  1738. if (type==="array"){
  1739. if (arguments.length<2){
  1740. data.push(newKey);
  1741. newValue = newKey;
  1742. newKey = data.length-1;
  1743. }else{
  1744. if (!newKey && newKey!==0){
  1745. data.push(newValue);
  1746. newKey = data.length-1;
  1747. }else{
  1748. flag = false;
  1749. }
  1750. }
  1751. if (flag){
  1752. var o = {};
  1753. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1754. MWF.defineProperties(this, o);
  1755. }
  1756. this[newKey] = newValue;
  1757. }else if (type==="object"){
  1758. if (!this.hasOwnProperty(newKey)){
  1759. data[newKey] = newValue;
  1760. if (flag){
  1761. var o = {};
  1762. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1763. MWF.defineProperties(this, o);
  1764. }
  1765. this[newKey] = newValue;
  1766. }else{
  1767. if (overwrite) this[newKey] = newValue;
  1768. }
  1769. }
  1770. return this[newKey];
  1771. }},
  1772. "del": {"value": function(delKey){
  1773. if (!this.hasOwnProperty(delKey)) return null;
  1774. delete data[delKey];
  1775. delete this[delKey];
  1776. return this;
  1777. }}
  1778. };
  1779. MWF.defineProperties(this, methods);
  1780. //this.getKey = function(){ return key; };
  1781. //this.getParent = function(){ return parent; };
  1782. //this.toString = function() { return data.toString();};
  1783. //this.add = function(newKey, newValue, overwrite){
  1784. // var flag = true;
  1785. // var type = typeOf(data);
  1786. // if (!this.hasOwnProperty(newKey)){
  1787. // if (type=="array"){
  1788. // if (arguments.length<2){
  1789. // data.push(newKey);
  1790. // newValue = newKey;
  1791. // newKey = data.length-1;
  1792. // }else{
  1793. // debugger;
  1794. // if (!newKey && newKey!=0){
  1795. // data.push(newValue);
  1796. // newKey = data.length-1;
  1797. // }else{
  1798. // flag == false;
  1799. // }
  1800. // }
  1801. // }else{
  1802. // data[newKey] = newValue;
  1803. // }
  1804. // //var valueType = typeOf(newValue);
  1805. // //var newValueData = newValue;
  1806. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1807. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1808. // if (flag){
  1809. // var o = {};
  1810. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1811. // MWF.defineProperties(this, o);
  1812. // }
  1813. // this[newKey] = newValue;
  1814. // }else{
  1815. // if (overwrite) this[newKey] = newValue;
  1816. // }
  1817. //
  1818. // //var valueType = typeOf(newValue);
  1819. // //var newValueData = newValue;
  1820. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1821. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1822. // //
  1823. // //this[newKey] = newValueData;
  1824. //
  1825. // return this[newKey];
  1826. //};
  1827. //this.del = function(delKey){
  1828. // if (!this.hasOwnProperty(delKey)) return null;
  1829. // delete data[newKey];
  1830. // delete this[newKey];
  1831. // return this;
  1832. //};
  1833. };
  1834. var type = typeOf(data);
  1835. if (type==="object" || type==="array") define.apply(this);
  1836. };
  1837. //MWF.xScript.createDict = function(application){
  1838. // return function(name){
  1839. // var applicationId = application;
  1840. // this.name = name;
  1841. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1842. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1843. //
  1844. // this.get = function(path, success, failure){
  1845. // debugger;
  1846. // var value = null;
  1847. // if (path){
  1848. // var arr = path.split(/\./g);
  1849. // var ar = arr.map(function(v){
  1850. // return encodeURIComponent(v);
  1851. // });
  1852. // //var p = path.replace(/\./g, "/");
  1853. // var p = ar.join("/");
  1854. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1855. // value = json.data;
  1856. // if (success) success(json.data);
  1857. // }, function(xhr, text, error){
  1858. // if (failure) failure(xhr, text, error);
  1859. // }, false);
  1860. // }else{
  1861. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  1862. // value = json.data;
  1863. // if (success) success(json.data);
  1864. // }, function(xhr, text, error){
  1865. // if (failure) failure(xhr, text, error);
  1866. // }, false);
  1867. // }
  1868. //
  1869. // return value;
  1870. // };
  1871. //
  1872. // this.set = function(path, value, success, failure){
  1873. // var p = path.replace(/\./g, "/");
  1874. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1875. // if (success) success(json.data);
  1876. // }, function(xhr, text, error){
  1877. // if (failure) failure(xhr, text, error);
  1878. // });
  1879. // };
  1880. // this.add = function(path, value, success, failure){
  1881. // var p = path.replace(/\./g, "/");
  1882. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1883. // if (success) success(json.data);
  1884. // }, function(xhr, text, error){
  1885. // if (failure) failure(xhr, text, error);
  1886. // });
  1887. // };
  1888. // this["delete"] = function(path, success, failure){
  1889. // var p = path.replace(/\./g, "/");
  1890. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1891. // if (success) success(json.data);
  1892. // }, function(xhr, text, error){
  1893. // if (failure) failure(xhr, text, error);
  1894. // });
  1895. // };
  1896. // this.destory = this["delete"];
  1897. // }
  1898. //};
  1899. // var dictLoaded = {};
  1900. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  1901. MWF.xScript.addDictToCache = function ( options, path, json ) {
  1902. if( !path )path = "root";
  1903. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1904. var type = options.appType || "process";
  1905. var enableAnonymous = options.enableAnonymous || false;
  1906. var appFlagList = [];
  1907. if( options.application )appFlagList.push( options.application );
  1908. if( options.appId )appFlagList.push( options.appId );
  1909. if( options.appName )appFlagList.push( options.appName );
  1910. if( options.appAlias )appFlagList.push( options.appAlias );
  1911. var dictFlagList = [];
  1912. if( options.id )dictFlagList.push( options.id );
  1913. if( options.name )dictFlagList.push( options.name );
  1914. if( options.alias )dictFlagList.push( options.alias );
  1915. var cache = {};
  1916. cache[path] = json;
  1917. for( var i=0; i<appFlagList.length; i++ ){
  1918. for( var j=0; j<dictFlagList.length; j++ ){
  1919. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  1920. if( !MWF.xScript.dictLoaded[k] ){
  1921. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  1922. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  1923. }else if( i===0 && j===0 ){
  1924. MWF.xScript.setDictToCache( k, path ,json );
  1925. var arr = path.split(/\./g);
  1926. var p;
  1927. var cache = MWF.xScript.dictLoaded[k];
  1928. for( var l=0 ; l<arr.length; l++ ){
  1929. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  1930. if( cache[ p ] )break;
  1931. }
  1932. if( p ){
  1933. var mathP = p+".";
  1934. Object.keys( cache ).each( function( path, idx){
  1935. if( path.indexOf( mathP ) === 0 )delete cache[path];
  1936. })
  1937. }
  1938. }
  1939. }
  1940. }
  1941. };
  1942. MWF.xScript.getMatchedDict = function(key, path){
  1943. if( !path )path = "root";
  1944. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1945. var arr = path.split(/\./g);
  1946. if( MWF.xScript.dictLoaded[key] ){
  1947. var dicts = MWF.xScript.dictLoaded[key];
  1948. var list = Array.clone(arr);
  1949. var p;
  1950. var dict;
  1951. for( var i=0 ; i<arr.length; i++ ){
  1952. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  1953. list.shift();
  1954. if( dicts[ p ] ){
  1955. dict = dicts[ p ];
  1956. break;
  1957. }
  1958. }
  1959. return {
  1960. dict : dict,
  1961. unmatchedPathList : list
  1962. }
  1963. }
  1964. return {
  1965. dict : null,
  1966. unmatchedPathList : list
  1967. }
  1968. };
  1969. MWF.xScript.insertDictToCache = function(key, path, json){
  1970. if( MWF.xScript.dictLoaded[key] ){
  1971. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1972. var dict = matchedDict.dict;
  1973. var list = matchedDict.unmatchedPathList;
  1974. if( !dict ){
  1975. MWF.xScript.dictLoaded[key][path] = json;
  1976. }else{
  1977. for( var j=0; j<list.length-1; j++ ){
  1978. if( !dict[ list[j] ] ){
  1979. dict[ list[j] ] = {};
  1980. }
  1981. dict = dict[ list[j] ];
  1982. }
  1983. var lastPath = list[list.length-1];
  1984. if( !dict[lastPath] ){
  1985. dict[lastPath] = json;
  1986. }else if( typeOf( dict[lastPath] ) === "array" ){
  1987. dict[lastPath].push( json );
  1988. }
  1989. }
  1990. }else{
  1991. MWF.xScript.dictLoaded[key] = {};
  1992. MWF.xScript.dictLoaded[key][path] = json;
  1993. }
  1994. };
  1995. MWF.xScript.setDictToCache = function(key, path, json){
  1996. if( MWF.xScript.dictLoaded[key] ){
  1997. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1998. var dict = matchedDict.dict;
  1999. var list = matchedDict.unmatchedPathList;
  2000. if( !dict ){
  2001. MWF.xScript.dictLoaded[key][path] = json;
  2002. }else{
  2003. for( var j=0; j<list.length-1; j++ ){
  2004. if( !dict[ list[j] ] ){
  2005. dict[ list[j] ] = {};
  2006. }
  2007. dict = dict[ list[j] ];
  2008. }
  2009. dict[list[list.length-1]] = json;
  2010. }
  2011. }else{
  2012. MWF.xScript.dictLoaded[key] = {};
  2013. MWF.xScript.dictLoaded[key][path] = json;
  2014. }
  2015. };
  2016. MWF.xScript.getDictFromCache = function( key, path ){
  2017. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2018. var dict = matchedDict.dict;
  2019. var list = matchedDict.unmatchedPathList;
  2020. if( dict ){
  2021. for( var j=0; j<list.length; j++ ){
  2022. dict = dict[ list[j] ];
  2023. if( !dict )return null;
  2024. }
  2025. return dict;
  2026. }
  2027. return null;
  2028. };
  2029. MWF.xScript.deleteDictToCache = function(key, path){
  2030. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  2031. var dict = matchedDict.dict;
  2032. var list = matchedDict.unmatchedPathList;
  2033. if( dict){
  2034. for( var j=0; j<list.length-1; j++ ){
  2035. dict = dict[ list[j] ];
  2036. if( !dict )return;
  2037. }
  2038. delete dict[list[list.length-1]];
  2039. }
  2040. };
  2041. MWF.xScript.createDict = function(application){
  2042. //optionsOrName : {
  2043. // type : "", //默认为process, 可以为 process cms
  2044. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  2045. // name : "", // 数据字典名称/别名/id
  2046. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  2047. //}
  2048. //或者name: "" // 数据字典名称/别名/id
  2049. return function(optionsOrName){
  2050. var options = optionsOrName;
  2051. if( typeOf( options ) == "string" ){
  2052. options = { name : options };
  2053. }
  2054. var name = this.name = options.name;
  2055. var type = ( options.type && options.application ) ? options.type : "process";
  2056. var applicationId = options.application || application;
  2057. var enableAnonymous = options.enableAnonymous || false;
  2058. var opt = {
  2059. "appType" : type,
  2060. "name" : name,
  2061. "appId" : applicationId,
  2062. "enableAnonymous" : enableAnonymous
  2063. };
  2064. var key = name+type+applicationId+enableAnonymous;
  2065. // if (!dictLoaded[key]) dictLoaded[key] = {};
  2066. // this.dictData = dictLoaded[key];
  2067. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2068. if( type == "cms" ){
  2069. var action = MWF.Actions.get("x_cms_assemble_control");
  2070. }else{
  2071. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2072. }
  2073. var encodePath = function( path ){
  2074. var arr = path.split(/\./g);
  2075. var ar = arr.map(function(v){
  2076. return encodeURIComponent(v);
  2077. });
  2078. return ar.join("/");
  2079. };
  2080. this.get = function(path, success, failure, async, refresh){
  2081. var value = null;
  2082. if (!refresh ){
  2083. var data = MWF.xScript.getDictFromCache( key, path );
  2084. if( data ){
  2085. if (success && o2.typeOf(success)=="function") success( data );
  2086. return data;
  2087. }
  2088. }
  2089. if (success===true) async=true;
  2090. if (failure===true) async=true;
  2091. // var cb = function(json){
  2092. // value = json.data;
  2093. // MWF.xScript.addDictToCache(opt, path, value);
  2094. // if (success && o2.typeOf(success)=="function") value = success(json.data);
  2095. // return value;
  2096. // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  2097. var cb = function(json){
  2098. value = json.data;
  2099. MWF.xScript.addDictToCache(opt, path, value);
  2100. if (success && o2.typeOf(success)=="function") value = success(json.data);
  2101. return value;
  2102. };
  2103. var promise;
  2104. if (path){
  2105. var p = encodePath( path );
  2106. //var p = path.replace(/\./g, "/");
  2107. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
  2108. }else{
  2109. promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
  2110. }
  2111. return (!!async) ? promise : value;
  2112. // if (path){
  2113. // var p = encodePath( path );
  2114. // //var p = path.replace(/\./g, "/");
  2115. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  2116. // value = json.data;
  2117. // // this.dictData[path] = value;
  2118. // MWF.xScript.addDictToCache(opt, path, value);
  2119. // if (success) success(json.data);
  2120. // }.bind(this), function(xhr, text, error){
  2121. // if (failure) failure(xhr, text, error);
  2122. // }, !!async);
  2123. // }else{
  2124. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  2125. // value = json.data;
  2126. // // this.dictData["root"] = value;
  2127. // MWF.xScript.addDictToCache(opt, path, value);
  2128. // if (success) success(json.data);
  2129. // }.bind(this), function(xhr, text, error){
  2130. // if (failure) failure(xhr, text, error);
  2131. // }, !!async);
  2132. // }
  2133. //return value;
  2134. };
  2135. this.set = function(path, value, success, failure){
  2136. var p = encodePath( path );
  2137. //var p = path.replace(/\./g, "/");
  2138. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2139. MWF.xScript.setDictToCache(key, path, value);
  2140. if (success) return success(json.data);
  2141. }, function(xhr, text, error){
  2142. if (failure) return failure(xhr, text, error);
  2143. }, false, false);
  2144. };
  2145. this.add = function(path, value, success, failure){
  2146. var p = encodePath( path );
  2147. //var p = path.replace(/\./g, "/");
  2148. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2149. MWF.xScript.insertDictToCache(key, path, value);
  2150. if (success) return success(json.data);
  2151. }, function(xhr, text, error){
  2152. if (failure) return failure(xhr, text, error);
  2153. }, false, false);
  2154. };
  2155. this["delete"] = function(path, success, failure){
  2156. var p = encodePath( path );
  2157. //var p = path.replace(/\./g, "/");
  2158. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2159. MWF.xScript.deleteDictToCache(key, path);
  2160. if (success) return success(json.data);
  2161. }, function(xhr, text, error){
  2162. if (failure) return failure(xhr, text, error);
  2163. }, false, false);
  2164. };
  2165. this.destory = this["delete"];
  2166. }
  2167. };