Environment.js 94 KB

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