Environment.js 85 KB

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