Environment.js 105 KB

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