Environment.js 84 KB

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