Environment.js 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241
  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, callback){
  237. getOrgActions();
  238. var data = {"groupList": getNameFlag(name)};
  239. var v = null;
  240. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  254. getOrgActions();
  255. var data = {"groupList": getNameFlag(name)};
  256. var v = null;
  257. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  278. getOrgActions();
  279. var data = {"groupList": getNameFlag(name)};
  280. var v = null;
  281. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  301. getOrgActions();
  302. var data = {"personList": getNameFlag(name)};
  303. var v = null;
  304. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  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 = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  333. getOrgActions();
  334. var data = {"roleList": getNameFlag(name)};
  335. var v = null;
  336. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  349. getOrgActions();
  350. var data = {"personList": getNameFlag(name)};
  351. var v = null;
  352. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  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 = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  381. getOrgActions();
  382. var data = {"personList": getNameFlag(name)};
  383. var v = null;
  384. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  398. getOrgActions();
  399. var data = {"personList": getNameFlag(name)};
  400. var v = null;
  401. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  415. getOrgActions();
  416. var data = {"personList": getNameFlag(name)};
  417. var v = null;
  418. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  431. getOrgActions();
  432. var data = {"groupList": getNameFlag(name)};
  433. var v = null;
  434. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  443. getOrgActions();
  444. var data = {"roleList": getNameFlag(name)};
  445. var v = null;
  446. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  455. getOrgActions();
  456. var data = {"identityList": getNameFlag(name)};
  457. var v = null;
  458. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  467. getOrgActions();
  468. var data = {"identityList": getNameFlag(name)};
  469. var v = null;
  470. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  481. getOrgActions();
  482. var data = {"unitList": getNameFlag(name)};
  483. var v = null;
  484. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  499. getOrgActions();
  500. var data = {"name": name, "attribute": value};
  501. var v = null;
  502. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  513. getOrgActions();
  514. var data = {"name": name, "attribute": value};
  515. var v = null;
  516. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  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 = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  563. getOrgActions();
  564. var data = {"personList":getNameFlag(name)};
  565. var v = null;
  566. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  575. getOrgActions();
  576. var data = {"personList":getNameFlag(name)};
  577. var v = null;
  578. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  588. getOrgActions();
  589. var data = {"identityList":getNameFlag(name)};
  590. var v = null;
  591. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  601. getOrgActions();
  602. var data = {"personList":getNameFlag(name)};
  603. var v = null;
  604. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  614. getOrgActions();
  615. var data = {"unitList": getNameFlag(name)};
  616. var v = null;
  617. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  631. getOrgActions();
  632. var data = {"unitList":getNameFlag(name)};
  633. var v = null;
  634. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  645. getOrgActions();
  646. var data = {"unitList": getNameFlag(name)};
  647. var v = null;
  648. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  663. getOrgActions();
  664. var data = {"unitList": getNameFlag(name)};
  665. var v = null;
  666. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || 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, callback){
  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. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  709. v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
  710. }.ag().catch(function(json){ return v; });
  711. orgActions.listUnitWithIdentity(data, cb, null, !!async);
  712. break;
  713. case "type":
  714. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  715. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  716. v = json.data; return v;
  717. }.ag().catch(function(json){ return v; });
  718. orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  719. break;
  720. case "level":
  721. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  722. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  723. v = json.data; return v;
  724. }.ag().catch(function(json){ return v; });
  725. orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  726. break;
  727. }
  728. return (!!async) ? cb : v;
  729. },
  730. //列出身份所在组织的所有上级组织
  731. listAllSupUnitWithIdentity: function(name, async, callback){
  732. getOrgActions();
  733. var data = {"identityList":getNameFlag(name)};
  734. var v = null;
  735. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  736. v = json.data;
  737. return v;
  738. }.ag().catch(function(json){ return v; });
  739. orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  740. return (!!async) ? cb : v;
  741. },
  742. //获取人员所在的所有组织
  743. listUnitWithPerson: function(name, async, callback){
  744. getOrgActions();
  745. var data = {"personList":getNameFlag(name)};
  746. var v = null;
  747. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  748. v = json.data;
  749. return v;
  750. }.ag().catch(function(json){ return v; });
  751. orgActions.listUnitWithPerson(data, cb, null, !!async);
  752. return (!!async) ? cb : v;
  753. },
  754. //列出人员所在组织的所有上级组织
  755. listAllSupUnitWithPerson: function(name, async, callback){
  756. getOrgActions();
  757. var data = {"personList":getNameFlag(name)};
  758. var v = null;
  759. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  760. v = json.data;
  761. return v;
  762. }.ag().catch(function(json){ return v; });
  763. orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  764. return (!!async) ? cb : v;
  765. },
  766. //根据组织属性,获取所有符合的组织
  767. listUnitWithAttribute: function(name, attribute, async, callback){
  768. getOrgActions();
  769. var data = {"name":name,"attribute":attribute};
  770. var v = null;
  771. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  772. v = json.data;
  773. return v;
  774. }.ag().catch(function(json){ return v; });
  775. orgActions.listUnitWithAttribute(data, cb, null, !!async);
  776. return (!!async) ? cb : v;
  777. },
  778. //根据组织职务,获取所有符合的组织
  779. listUnitWithDuty: function(name, id, async, callback){
  780. getOrgActions();
  781. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  782. var v = null;
  783. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  784. v = json.data;
  785. return v;
  786. }.ag().catch(function(json){ return v; });
  787. orgActions.listUnitWithDuty(data, cb, null, !!async);
  788. return (!!async) ? cb : v;
  789. },
  790. //组织职务***********
  791. //获取指定的组织职务的身份
  792. getDuty: function(duty, id, async, callback){
  793. getOrgActions();
  794. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  795. var v = null;
  796. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  797. v = json.data;
  798. return v;
  799. }.ag().catch(function(json){ return v; });
  800. orgActions.getDuty(data, cb, null, !!async);
  801. return (!!async) ? cb : v;
  802. },
  803. //获取身份的所有职务名称
  804. listDutyNameWithIdentity: function(name, async, callback){
  805. getOrgActions();
  806. var data = {"identityList":getNameFlag(name)};
  807. var v = null;
  808. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  809. v = json.data;
  810. return v;
  811. }.ag().catch(function(json){ return v; });
  812. orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  813. return (!!async) ? cb : v;
  814. },
  815. //获取组织的所有职务名称
  816. listDutyNameWithUnit: function(name, async, callback){
  817. getOrgActions();
  818. var data = {"unitList":getNameFlag(name)};
  819. var v = null;
  820. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  821. v = json.data.nameList;
  822. return v;
  823. }.ag().catch(function(json){ return v; });
  824. orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  825. return (!!async) ? cb : v;
  826. },
  827. //获取组织的所有职务
  828. listUnitAllDuty: function(name, async, callback){
  829. getOrgActions();
  830. var data = {"unitList":getNameFlag(name)};
  831. var v = null;
  832. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  833. v = json.data;
  834. return v;
  835. }.ag().catch(function(json){ return v; });
  836. orgActions.listUnitAllDuty(data, cb, null, !!async);
  837. return (!!async) ? cb : v;
  838. },
  839. //列出顶层组织
  840. listTopUnit: function(async, callback){
  841. var action = MWF.Actions.get("x_organization_assemble_control");
  842. var v = null;
  843. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  844. v = json.data;
  845. return v;
  846. }.ag().catch(function(json){ return v; });
  847. action.listTopUnit(cb, null, !!async);
  848. return (!!async) ? cb : v;
  849. },
  850. //组织属性**************
  851. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  852. appendUnitAttribute: function(unit, attr, values, success, failure, async){
  853. getOrgActions();
  854. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  855. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  856. var cb = function(json){
  857. if (success) return success(json);
  858. }.ag().catch(function(xhr, text, error){
  859. if (failure) return failure(xhr, text, error);
  860. });
  861. orgActions.appendPersonAttribute(data, cb, null, !!async);
  862. // orgActions.appendUnitAttribute(data, function(json){
  863. // if (json.data.value){
  864. // if (success) success();
  865. // }else{
  866. // if (failure) failure(null, "", "append values failed");
  867. // }
  868. // }, function(xhr, text, error){
  869. // if (failure) failure(xhr, text, error);
  870. // }, false);
  871. },
  872. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  873. setUnitAttribute: function(unit, attr, values, success, failure, async){
  874. getOrgActions();
  875. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  876. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  877. var cb = function(json){
  878. if (success) return success(json);
  879. }.ag().catch(function(xhr, text, error){
  880. if (failure) return failure(xhr, text, error);
  881. });
  882. orgActions.setUnitAttribute(data, cb, null, !!async);
  883. // orgActions.setUnitAttribute(data, function(json){
  884. // if (json.data.value){
  885. // if (success) success();
  886. // }else{
  887. // if (failure) failure(null, "", "append values failed");
  888. // }
  889. // }, function(xhr, text, error){
  890. // if (failure) failure(xhr, text, error);
  891. // }, false);
  892. },
  893. //获取组织属性值
  894. getUnitAttribute: function(unit, attr, async, callback){
  895. getOrgActions();
  896. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  897. var data = {"name":attr,"unit":unitFlag};
  898. var v = null;
  899. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  900. v = json.data.attributeList;
  901. return v;
  902. }.ag().catch(function(json){ return v; });
  903. orgActions.getUnitAttribute(data, cb, null, !!async);
  904. return (!!async) ? cb : v;
  905. },
  906. //列出组织所有属性的名称
  907. listUnitAttributeName: function(name, async, callback){
  908. getOrgActions();
  909. var data = {"unitList":getNameFlag(name)};
  910. var v = null;
  911. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  912. v = json.data.nameList;
  913. return v;
  914. }.ag().catch(function(json){ return v; });
  915. orgActions.listUnitAttributeName(data, cb, null, !!async);
  916. return (!!async) ? cb : v;
  917. },
  918. //列出组织的所有属性
  919. listUnitAllAttribute: function(name, async, callback){
  920. getOrgActions();
  921. var data = {"unitList":getNameFlag(name)};
  922. var v = null;
  923. var cb = ((callback) ? (callback.isAG ? callback : callback.ag()) : null) || function(json){
  924. v = json.data;
  925. return v;
  926. }.ag().catch(function(json){ return v; });
  927. orgActions.listUnitAllAttribute(data, cb, null, !!async);
  928. return (!!async) ? cb : v;
  929. }
  930. };
  931. this.Action = (function(){
  932. var actions = [];
  933. return function(root, json){
  934. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  935. action.getActions = function(callback){
  936. if (!this.actions) this.actions = {};
  937. Object.merge(this.actions, json);
  938. if (callback) callback();
  939. };
  940. this.invoke = function(option){
  941. action.invoke(option)
  942. }
  943. }
  944. })();
  945. this.service = {
  946. "jaxwsClient":{},
  947. "jaxrsClient":{}
  948. };
  949. var lookupAction = null;
  950. var getLookupAction = function(callback){
  951. if (!lookupAction){
  952. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  953. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  954. lookupAction.getActions = function(actionCallback){
  955. this.actions = {
  956. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  957. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  958. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  959. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  960. };
  961. if (actionCallback) actionCallback();
  962. };
  963. if (callback) callback();
  964. });
  965. }else{
  966. if (callback) callback();
  967. }
  968. };
  969. this.view = {
  970. "lookup": function(view, callback, async){
  971. var filterList = {"filterList": (view.filter || null)};
  972. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  973. var data = {
  974. "grid": json.data.grid || json.data.groupGrid,
  975. "groupGrid": json.data.groupGrid
  976. };
  977. if (callback) callback(data);
  978. }, null, async);
  979. },
  980. "lookupV1": function(view, callback){
  981. getLookupAction(function(){
  982. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  983. var data = {
  984. "grid": json.data.grid,
  985. "groupGrid": json.data.groupGrid
  986. };
  987. if (callback) callback(data);
  988. }.bind(this)});
  989. }.bind(this));
  990. },
  991. "select": function(view, callback, options){
  992. if (view.view){
  993. var viewJson = {
  994. "application": view.application || _form.json.application,
  995. "viewName": view.view || "",
  996. "isTitle": (view.isTitle===false) ? "no" : "yes",
  997. "select": (view.isMulti===false) ? "single" : "multi",
  998. "filter": view.filter
  999. };
  1000. if (!options) options = {};
  1001. options.width = view.width;
  1002. options.height = view.height;
  1003. options.title = view.caption;
  1004. var width = options.width || "700";
  1005. var height = options.height || "400";
  1006. if (layout.mobile){
  1007. var size = document.body.getSize();
  1008. width = size.x;
  1009. height = size.y;
  1010. options.style = "viewmobile";
  1011. }
  1012. width = width.toInt();
  1013. height = height.toInt();
  1014. var size = _form.app.content.getSize();
  1015. var x = (size.x-width)/2;
  1016. var y = (size.y-height)/2;
  1017. if (x<0) x = 0;
  1018. if (y<0) y = 0;
  1019. if (layout.mobile){
  1020. x = 20;
  1021. y = 0;
  1022. }
  1023. var _self = this;
  1024. MWF.require("MWF.xDesktop.Dialog", function(){
  1025. var dlg = new MWF.xDesktop.Dialog({
  1026. "title": options.title || "select view",
  1027. "style": options.style || "view",
  1028. "top": y,
  1029. "left": x-20,
  1030. "fromTop":y,
  1031. "fromLeft": x-20,
  1032. "width": width,
  1033. "height": height,
  1034. "html": "<div style='height: 100%;'></div>",
  1035. "maskNode": _form.app.content,
  1036. "container": _form.app.content,
  1037. "buttonList": [
  1038. {
  1039. "text": MWF.LP.process.button.ok,
  1040. "action": function(){
  1041. //if (callback) callback(_self.view.selectedItems);
  1042. if (callback) callback(_self.view.getData());
  1043. this.close();
  1044. }
  1045. },
  1046. {
  1047. "text": MWF.LP.process.button.cancel,
  1048. "action": function(){this.close();}
  1049. }
  1050. ]
  1051. });
  1052. dlg.show();
  1053. if (layout.mobile){
  1054. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  1055. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  1056. if (backAction) backAction.addEvent("click", function(e){
  1057. dlg.close();
  1058. }.bind(this));
  1059. if (okAction) okAction.addEvent("click", function(e){
  1060. //if (callback) callback(this.view.selectedItems);
  1061. if (callback) callback(this.view.getData());
  1062. dlg.close();
  1063. }.bind(this));
  1064. }
  1065. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  1066. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  1067. }.bind(this));
  1068. }.bind(this));
  1069. }
  1070. }
  1071. };
  1072. //include 引用脚本
  1073. //optionsOrName : {
  1074. // type : "", 默认为process, 可以为 portal process cms
  1075. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  1076. // name : "" // 脚本名称/别名/id
  1077. //}
  1078. //或者name: "" // 脚本名称/别名/id
  1079. // if( !window.includedScripts ){
  1080. // var includedScripts = window.includedScripts = [];
  1081. // }else{
  1082. // var includedScripts = window.includedScripts;
  1083. // }
  1084. var includedScripts = [];
  1085. var _includeSingle = function( optionsOrName , callback, async){
  1086. var options = optionsOrName;
  1087. if( typeOf( options ) == "string" ){
  1088. options = { name : options };
  1089. }
  1090. var name = options.name;
  1091. var type = ( options.type && options.application ) ? options.type : "process";
  1092. var application = options.application || _form.json.application;
  1093. var key = type +"-" + application + "-" + name;
  1094. if (includedScripts.indexOf( key )> -1){
  1095. if (callback) callback.apply(this);
  1096. return;
  1097. }
  1098. //if (includedScripts.indexOf( name )> -1){
  1099. // if (callback) callback.apply(this);
  1100. // return;
  1101. //}
  1102. var scriptAction;
  1103. switch ( type ){
  1104. case "portal" :
  1105. if( this.scriptActionPortal ){
  1106. scriptAction = this.scriptActionPortal;
  1107. }else{
  1108. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  1109. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  1110. }
  1111. break;
  1112. case "process" :
  1113. if( this.scriptActionProcess ){
  1114. scriptAction = this.scriptActionProcess;
  1115. }else{
  1116. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  1117. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  1118. }
  1119. break;
  1120. case "cms" :
  1121. if( this.scriptActionCMS ){
  1122. scriptAction = this.scriptActionCMS;
  1123. }else{
  1124. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1125. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1126. }
  1127. break;
  1128. }
  1129. debugger;
  1130. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  1131. if (json.data){
  1132. includedScripts.push( key );
  1133. //名称、别名、id
  1134. json.data.importedList.each( function ( flag ) {
  1135. if( type === "portal" ){
  1136. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  1137. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  1138. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  1139. }else if( type === "cms" ){
  1140. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  1141. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1142. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1143. }else if( type === "process" ){
  1144. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  1145. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1146. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1147. }
  1148. });
  1149. includedScripts = includedScripts.concat(json.data.importedList);
  1150. MWF.Macro.exec(json.data.text, this);
  1151. if (callback) callback.apply(this);
  1152. }else{
  1153. if (callback) callback.apply(this);
  1154. }
  1155. }.bind(this), null, !!async);
  1156. }
  1157. this.include = function( optionsOrName , callback, async){
  1158. if (o2.typeOf(optionsOrName)=="array"){
  1159. if (!!async){
  1160. var count = optionsOrName.length;
  1161. var loaded = 0;
  1162. optionsOrName.each(function(option){
  1163. _includeSingle.apply(this, [option, function(){
  1164. loaded++;
  1165. if (loaded>=count) if (callback) callback.apply(this);;
  1166. }.bind(this), true]);
  1167. }.bind(this));
  1168. }else{
  1169. optionsOrName.each(function(option){
  1170. _includeSingle.apply(this, [option]);
  1171. if (callback) callback.apply(this);
  1172. }.bind(this));
  1173. }
  1174. }else{
  1175. _includeSingle.apply(this, [optionsOrName , callback, async])
  1176. }
  1177. };
  1178. this.define = function(name, fun, overwrite){
  1179. var over = true;
  1180. if (overwrite===false) over = false;
  1181. var o = {};
  1182. o[name] = {"value": fun, "configurable": over};
  1183. MWF.defineProperties(this, o);
  1184. }.bind(this);
  1185. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1186. //可在调用前执行 var resolve = this.wait();
  1187. //在异步调用结束后 执行 resolve.cb();
  1188. //目前只有表单的queryload事件支持此方法。
  1189. this.wait = function(){
  1190. resolve = {};
  1191. var setResolve = function(callback){
  1192. resolve.cb = callback;
  1193. }.bind(this);
  1194. this.target.event_resolve = setResolve;
  1195. return resolve;
  1196. }
  1197. //和this.wait配合使用,
  1198. //如果没有异步,则resolve.cb方法不存在,
  1199. //所以在回调中中使用this.goon();使表单继续加载
  1200. this.goon = function(){
  1201. this.target.event_resolve = null;
  1202. }
  1203. //仅前台对象-----------------------------------------
  1204. //form
  1205. this.page = this.form = {
  1206. "getInfor": function(){return ev.formInfor;},
  1207. "infor": ev.formInfor,
  1208. "getApp": function(){return _form.app;},
  1209. "app": _form.app,
  1210. "node": function(){return _form.node;},
  1211. "readonly": _form.options.readonly,
  1212. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  1213. "getField": function(name){return _forms[name];},
  1214. "getAction": function(){return _form.workAction},
  1215. "getDesktop": function(){return _form.app.desktop},
  1216. "getData": function(){return new MWF.xScript.JSONData(_form.getData());},
  1217. "save": function(callback, silent){_form.saveWork(callback, silent); },
  1218. "close": function(){_form.closeWork();},
  1219. "verify": function(){
  1220. return !(!_form.formCustomValidation("", "") || !_form.formValidation("", ""));
  1221. },
  1222. "process": function(option){
  1223. var op = _form.getOpinion();
  1224. var mds = op.medias;
  1225. if (option){
  1226. _form.submitWork(option.routeName, option.opinion, mds, option.callback,
  1227. option.processor, null, option.appendTaskIdentityList, option.processorOrgList, option.callbackBeforeSave );
  1228. }else{
  1229. _form.processWork();
  1230. }
  1231. },
  1232. "reset": function(option){
  1233. if (!option){
  1234. if (_form.businessData.control["allowReset"]) _form.resetWork();
  1235. }else{
  1236. _form.resetWorkToPeson(option.names, option.opinion, option.keep, option.success, option.failure);
  1237. }
  1238. },
  1239. "retract": function(option){
  1240. if (!option){
  1241. if (_form.businessData.control["allowAddSplit"]) _form.addSplit();
  1242. }else{
  1243. _form.doRetractWork(option.success, option.failure);
  1244. }
  1245. },
  1246. "addSplit": function(option){
  1247. if (!option){
  1248. if (_form.businessData.control["allowRetract"]) _form.retractWork();
  1249. }else{
  1250. _form.addSplitWork(option.value, option.success, option.failure);
  1251. }
  1252. },
  1253. "rollback": function(option){
  1254. if (!option){
  1255. if (_form.businessData.control["allowRollback"]) _form.rollback();
  1256. }else{
  1257. _form.doRollbackActionInvoke(option.log, option.flow, option.success, option.failure);
  1258. }
  1259. },
  1260. "print": function(application, form){
  1261. if (arguments.length){
  1262. var app = (arguments.length>1) ? arguments[0] : null;
  1263. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1264. _form.printWork(app, formName);
  1265. }else{
  1266. _form.printWork();
  1267. }
  1268. },
  1269. "deleteWork": function(option){
  1270. if (!option){
  1271. if (_form.businessData.control["allowDelete"]) _form.deleteWork();
  1272. }else{
  1273. _form.doDeleteWork(option.success, option.failure);
  1274. }
  1275. },
  1276. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  1277. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  1278. var p = MWF.getCenter({"x": width, "y": height});
  1279. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1280. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1281. }else{
  1282. e = (arguments.length>1) ? arguments[1] : null;
  1283. title = (arguments.length>2) ? arguments[2] : null;
  1284. text = (arguments.length>3) ? arguments[3] : null;
  1285. width = (arguments.length>4) ? arguments[4] : null;
  1286. height = (arguments.length>5) ? arguments[5] : null;
  1287. ok = (arguments.length>6) ? arguments[6] : null;
  1288. cancel = (arguments.length>7) ? arguments[7] : null;
  1289. callback = (arguments.length>8) ? arguments[8] : null;
  1290. mask = (arguments.length>9) ? arguments[9] : null;
  1291. style = (arguments.length>10) ? arguments[10] : null;
  1292. // var p = MWF.getCenter({"x": width, "y": height});
  1293. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1294. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1295. }
  1296. },
  1297. "alert": function(type, title, text, width, height){
  1298. _form.alert(type, title, text, width, height);
  1299. },
  1300. "notice": function(content, type, target, where, offset, option){
  1301. _form.notice(content, type, target, where, offset, option);
  1302. },
  1303. "addEvent": function(e, f){_form.addEvent(e, f);},
  1304. "openWindow": function(application, form){
  1305. if (arguments.length){
  1306. var app = (arguments.length>1) ? arguments[0] : null;
  1307. var formName = (arguments.length>1) ? arguments[1] : arguments[0];
  1308. _form.openWindow(formName, app);
  1309. }else{
  1310. _form.openWindow();
  1311. }
  1312. },
  1313. "openWork": function(id, completedId, title, options){
  1314. var op = options || {};
  1315. op.workId = id;
  1316. op.workCompletedId = completedId;
  1317. op.docTitle = title;
  1318. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1319. return layout.desktop.openApplication(this.event, "process.Work", op);
  1320. },
  1321. "openJob": function(id, choice, options){
  1322. var workData = null;
  1323. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1324. if (json.data) workData = json.data;
  1325. }.bind(this), null, false);
  1326. if (workData){
  1327. var len = workData.workList.length + workData.workCompletedList.length;
  1328. if (len){
  1329. if (len>1 && choice){
  1330. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1331. workData.workList.each(function(work){
  1332. var workNode = new Element("div", {
  1333. "styles": {
  1334. "background": "#ffffff",
  1335. "border-radius": "10px",
  1336. "clear": "both",
  1337. "margin-bottom": "10px",
  1338. "height": "40px",
  1339. "padding": "10px 10px"
  1340. }
  1341. }).inject(node);
  1342. 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>" +
  1343. "<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>"+
  1344. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1345. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1346. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1347. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1348. workNode.set("html", html);
  1349. var action = workNode.getElement(".MWFAction");
  1350. action.store("work", work);
  1351. action.addEvent("click", function(e){
  1352. var work = e.target.retrieve("work");
  1353. if (work) this.openWork(work.id, null, work.title, options);
  1354. dlg.close();
  1355. }.bind(this));
  1356. }.bind(this));
  1357. workData.workCompletedList.each(function(work){
  1358. var workNode = new Element("div", {
  1359. "styles": {
  1360. "background": "#ffffff",
  1361. "border-radius": "10px",
  1362. "clear": "both",
  1363. "margin-bottom": "10px",
  1364. "height": "40px",
  1365. "padding": "10px 10px"
  1366. }
  1367. }).inject(node);
  1368. 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>" +
  1369. "<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>"+
  1370. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1371. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1372. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1373. workNode.set("html", html);
  1374. var action = workNode.getElement(".MWFAction");
  1375. action.store("work", work);
  1376. action.addEvent("click", function(e){
  1377. var work = e.target.retrieve("work");
  1378. if (work) this.openWork(null, work.id, work.title, options);
  1379. dlg.close();
  1380. }.bind(this));
  1381. }.bind(this));
  1382. var height = node.getSize().y+20;
  1383. if (height>600) height = 600;
  1384. var dlg = o2.DL.open({
  1385. "title": o2.LP.widget.choiceWork,
  1386. "style" : "user",
  1387. "isResize": false,
  1388. "content": node,
  1389. "buttonList": [
  1390. {
  1391. "type" : "cancel",
  1392. "text": o2.LP.widget.close,
  1393. "action": function(){dlg.close();}
  1394. }
  1395. ]
  1396. });
  1397. }else{
  1398. if (workData.workList.length){
  1399. var work = workData.workList[0];
  1400. return this.openWork(work.id, null, work.title, options);
  1401. }else{
  1402. var work = workData.workCompletedList[0];
  1403. return this.openWork(null, work.id, work.title, options);
  1404. }
  1405. }
  1406. }
  1407. }
  1408. // var op = options || {};
  1409. // op.workId = id;
  1410. // op.workCompletedId = completedId;
  1411. // op.docTitle = title;
  1412. // op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1413. // layout.desktop.openApplication(this.event, "process.Work", op);
  1414. },
  1415. "openDocument": function(id, title, options){
  1416. var op = options || {};
  1417. op.documentId = id;
  1418. op.docTitle = title;
  1419. layout.desktop.openApplication(this.event, "cms.Document", op);
  1420. },
  1421. "openPortal": function(name, page, par){
  1422. var action = MWF.Actions.get("x_portal_assemble_surface");
  1423. action.getApplication(name, function(json){
  1424. if (json.data){
  1425. if (page){
  1426. action.getPageByName(page, json.data.id, function(pageJson){
  1427. layout.desktop.openApplication(null, "portal.Portal", {
  1428. "portalId": json.data.id,
  1429. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1430. "parameters": par,
  1431. "appId": "portal.Portal"+json.data.id
  1432. })
  1433. });
  1434. }else{
  1435. layout.desktop.openApplication(null, "portal.Portal", {
  1436. "portalId": json.data.id,
  1437. "parameters": par,
  1438. "appId": "portal.Portal"+json.data.id
  1439. })
  1440. }
  1441. }
  1442. });
  1443. },
  1444. "openCMS": function(name){
  1445. var action = MWF.Actions.get("x_cms_assemble_control");
  1446. action.getColumn(name, function(json){
  1447. if (json.data){
  1448. layout.desktop.openApplication(null, "cms.Module", {
  1449. "columnId": json.data.id,
  1450. "appId": "cms.Module"+json.data.id
  1451. });
  1452. }
  1453. });
  1454. },
  1455. "openProcess": function(name){
  1456. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1457. action.getApplication(name, function(json){
  1458. if (json.data){
  1459. layout.desktop.openApplication(null, "process.Application", {
  1460. "id": json.data.id,
  1461. "appId": "process.Application"+json.data.id
  1462. });
  1463. }
  1464. });
  1465. },
  1466. "openApplication":function(name, options){
  1467. layout.desktop.openApplication(null, name, options);
  1468. },
  1469. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1470. var column = columnOrOptions;
  1471. var onAfterPublish, onPostPublish;
  1472. if (typeOf(columnOrOptions) == "object") {
  1473. column = columnOrOptions.column;
  1474. category = columnOrOptions.category;
  1475. data = columnOrOptions.data;
  1476. identity = columnOrOptions.identity;
  1477. callback = columnOrOptions.callback;
  1478. target = columnOrOptions.target;
  1479. latest = columnOrOptions.latest;
  1480. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1481. ignoreTitle = columnOrOptions.ignoreTitle;
  1482. onAfterPublish = columnOrOptions.onAfterPublish;
  1483. onPostPublish = columnOrOptions.onPostPublish;
  1484. }
  1485. if (target) {
  1486. if (layout.app && layout.app.inBrowser) {
  1487. layout.app.content.empty();
  1488. layout.app = null;
  1489. }
  1490. }
  1491. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1492. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1493. "documentData": data,
  1494. "identity": identity,
  1495. "ignoreTitle": ignoreTitle === true,
  1496. "ignoreDrafted": latest === false,
  1497. "selectColumnEnable": !category || selectColumnEnable === true,
  1498. "restrictToColumn": !!category && selectColumnEnable !== true,
  1499. "categoryFlag": category, //category id or name
  1500. "columnFlag": column, //column id or name,
  1501. "onStarted": function (documentId, data) {
  1502. if (callback) callback();
  1503. },
  1504. "onPostPublish": function () {
  1505. if(onPostPublish)onPostPublish();
  1506. },
  1507. "onAfterPublish": function () {
  1508. if(onAfterPublish)onAfterPublish();
  1509. }
  1510. });
  1511. starter.load();
  1512. })
  1513. },
  1514. "startProcess": function(app, process, data, identity, callback, target, latest){
  1515. if (arguments.length>2){
  1516. for (var i=2; i<arguments.length; i++){
  1517. if (typeOf(arguments[i])=="boolean"){
  1518. target = arguments[i];
  1519. break;
  1520. }
  1521. }
  1522. }
  1523. if (target){
  1524. if (layout.app && layout.app.inBrowser){
  1525. //layout.app.content.empty();
  1526. layout.app.$openWithSelf = true;
  1527. }
  1528. }
  1529. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1530. if (json.data){
  1531. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1532. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1533. "workData": data,
  1534. "identity": identity,
  1535. "latest": latest,
  1536. "onStarted": function(data, title, processName){
  1537. var currentTask = [];
  1538. data.each(function(work){
  1539. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1540. }.bind(this));
  1541. if (currentTask.length==1){
  1542. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1543. layout.desktop.openApplication(null, "process.Work", options);
  1544. }else{}
  1545. if (callback) callback(data);
  1546. }.bind(this)
  1547. });
  1548. starter.load();
  1549. }.bind(this));
  1550. }
  1551. });
  1552. }
  1553. };
  1554. this.form.currentRouteName = _form.json.currentRouteName;
  1555. this.form.opinion = _form.json.opinion;
  1556. this.target = ev.target;
  1557. this.event = ev.event;
  1558. this.status = ev.status;
  1559. this.session = layout.desktop.session;
  1560. this.Actions = o2.Actions;
  1561. this.query = function(option){
  1562. // options = {
  1563. // "name": "statementName",
  1564. // "data": "json data",
  1565. // "firstResult": 1,
  1566. // "maxResults": 100,
  1567. // "success": function(){},
  1568. // "error": function(){},
  1569. // "async": true or false, default is true
  1570. // }
  1571. if (option){
  1572. var json = (option.data) || {};
  1573. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1574. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1575. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1576. }
  1577. }
  1578. this.Table = MWF.xScript.createTable();
  1579. };
  1580. MWF.xScript.createTable = function(){
  1581. return function(name){
  1582. this.name = name;
  1583. this.action = o2.Actions.get("x_query_assemble_surface");
  1584. this.listRowNext = function(id, count, success, error, async){
  1585. this.action.listRowNext(this.name, id, count, success, error, async);
  1586. };
  1587. this.listRowPrev = function(id, count, success, error, async){
  1588. this.action.listRowPrev(this.name, id, count, success, error, async);
  1589. };
  1590. this.listRowPrev = function(id, count, success, error, async){
  1591. this.action.listRowPrev(this.name, id, count, success, error, async);
  1592. };
  1593. this.listRowSelectWhere = function(where, success, error, async){
  1594. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1595. };
  1596. this.listRowCountWhere = function(where, success, error, async){
  1597. this.action.listRowCountWhere(this.name, where, success, error, async);
  1598. };
  1599. this.deleteRow = function(id, success, error, async){
  1600. this.action.deleteRow(this.name, id, success, error, async);
  1601. };
  1602. this.deleteAllRow = function(success, error, async){
  1603. this.action.deleteAllRow(this.name, success, error, async);
  1604. };
  1605. this.getRow = function(id, success, error, async){
  1606. this.action.getRow(this.name, id, success, error, async);
  1607. };
  1608. this.insertRow = function(data, success, error, async){
  1609. this.action.insertRow(this.name, data, success, error, async);
  1610. };
  1611. this.updateRow = function(id, data, success, error, async){
  1612. this.action.updateRow(this.name, id, data, success, error, async);
  1613. };
  1614. }
  1615. };
  1616. MWF.xScript.JSONData = function(data, callback, key, parent, _form){
  1617. var getter = function(data, callback, k, _self){
  1618. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.JSONData(data[k], callback, k, _self, _form);};
  1619. };
  1620. var setter = function(data, callback, k, _self){
  1621. return function(v){
  1622. data[k] = v;
  1623. //debugger;
  1624. //this.add(k, v, true);
  1625. if (callback) callback(data, k, _self);
  1626. }
  1627. };
  1628. var define = function(){
  1629. var o = {};
  1630. 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])};
  1631. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1632. MWF.defineProperties(this, o);
  1633. var methods = {
  1634. "getKey": {"value": function(){ return key; }},
  1635. "getParent": {"value": function(){ return parent; }},
  1636. "toString": {"value": function() { return data.toString();}},
  1637. "setSection": {"value": function(newKey, newValue){
  1638. this.add(newKey, newValue, true);
  1639. try {
  1640. var path = [this.getKey()];
  1641. p = this.getParent();
  1642. while (p && p.getKey()){
  1643. path.unshift(p.getKey());
  1644. p = p.getParent();
  1645. }
  1646. if (path.length) _form.sectionListObj[path.join(".")] = newKey;
  1647. }catch(e){
  1648. debugger;
  1649. }
  1650. }},
  1651. "add": {"value": function(newKey, newValue, overwrite){
  1652. var flag = true;
  1653. var type = typeOf(data);
  1654. if (type==="array"){
  1655. if (arguments.length<2){
  1656. data.push(newKey);
  1657. newValue = newKey;
  1658. newKey = data.length-1;
  1659. }else{
  1660. if (!newKey && newKey!==0){
  1661. data.push(newValue);
  1662. newKey = data.length-1;
  1663. }else{
  1664. flag = false;
  1665. }
  1666. }
  1667. if (flag){
  1668. var o = {};
  1669. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1670. MWF.defineProperties(this, o);
  1671. }
  1672. this[newKey] = newValue;
  1673. }else if (type==="object"){
  1674. if (!this.hasOwnProperty(newKey)){
  1675. data[newKey] = newValue;
  1676. if (flag){
  1677. var o = {};
  1678. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1679. MWF.defineProperties(this, o);
  1680. }
  1681. this[newKey] = newValue;
  1682. }else{
  1683. if (overwrite) this[newKey] = newValue;
  1684. }
  1685. }
  1686. return this[newKey];
  1687. }},
  1688. "del": {"value": function(delKey){
  1689. if (!this.hasOwnProperty(delKey)) return null;
  1690. delete data[delKey];
  1691. delete this[delKey];
  1692. return this;
  1693. }}
  1694. };
  1695. MWF.defineProperties(this, methods);
  1696. //this.getKey = function(){ return key; };
  1697. //this.getParent = function(){ return parent; };
  1698. //this.toString = function() { return data.toString();};
  1699. //this.add = function(newKey, newValue, overwrite){
  1700. // var flag = true;
  1701. // var type = typeOf(data);
  1702. // if (!this.hasOwnProperty(newKey)){
  1703. // if (type=="array"){
  1704. // if (arguments.length<2){
  1705. // data.push(newKey);
  1706. // newValue = newKey;
  1707. // newKey = data.length-1;
  1708. // }else{
  1709. // debugger;
  1710. // if (!newKey && newKey!=0){
  1711. // data.push(newValue);
  1712. // newKey = data.length-1;
  1713. // }else{
  1714. // flag == false;
  1715. // }
  1716. // }
  1717. // }else{
  1718. // data[newKey] = newValue;
  1719. // }
  1720. // //var valueType = typeOf(newValue);
  1721. // //var newValueData = newValue;
  1722. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1723. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1724. // if (flag){
  1725. // var o = {};
  1726. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1727. // MWF.defineProperties(this, o);
  1728. // }
  1729. // this[newKey] = newValue;
  1730. // }else{
  1731. // if (overwrite) this[newKey] = newValue;
  1732. // }
  1733. //
  1734. // //var valueType = typeOf(newValue);
  1735. // //var newValueData = newValue;
  1736. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1737. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1738. // //
  1739. // //this[newKey] = newValueData;
  1740. //
  1741. // return this[newKey];
  1742. //};
  1743. //this.del = function(delKey){
  1744. // if (!this.hasOwnProperty(delKey)) return null;
  1745. // delete data[newKey];
  1746. // delete this[newKey];
  1747. // return this;
  1748. //};
  1749. };
  1750. var type = typeOf(data);
  1751. if (type==="object" || type==="array") define.apply(this);
  1752. };
  1753. //MWF.xScript.createDict = function(application){
  1754. // return function(name){
  1755. // var applicationId = application;
  1756. // this.name = name;
  1757. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1758. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1759. //
  1760. // this.get = function(path, success, failure){
  1761. // debugger;
  1762. // var value = null;
  1763. // if (path){
  1764. // var arr = path.split(/\./g);
  1765. // var ar = arr.map(function(v){
  1766. // return encodeURIComponent(v);
  1767. // });
  1768. // //var p = path.replace(/\./g, "/");
  1769. // var p = ar.join("/");
  1770. // action.getDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1771. // value = json.data;
  1772. // if (success) success(json.data);
  1773. // }, function(xhr, text, error){
  1774. // if (failure) failure(xhr, text, error);
  1775. // }, false);
  1776. // }else{
  1777. // action.getDictRoot(encodeURIComponent(this.name), applicationId, function(json){
  1778. // value = json.data;
  1779. // if (success) success(json.data);
  1780. // }, function(xhr, text, error){
  1781. // if (failure) failure(xhr, text, error);
  1782. // }, false);
  1783. // }
  1784. //
  1785. // return value;
  1786. // };
  1787. //
  1788. // this.set = function(path, value, success, failure){
  1789. // var p = path.replace(/\./g, "/");
  1790. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1791. // if (success) success(json.data);
  1792. // }, function(xhr, text, error){
  1793. // if (failure) failure(xhr, text, error);
  1794. // });
  1795. // };
  1796. // this.add = function(path, value, success, failure){
  1797. // var p = path.replace(/\./g, "/");
  1798. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1799. // if (success) success(json.data);
  1800. // }, function(xhr, text, error){
  1801. // if (failure) failure(xhr, text, error);
  1802. // });
  1803. // };
  1804. // this["delete"] = function(path, success, failure){
  1805. // var p = path.replace(/\./g, "/");
  1806. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1807. // if (success) success(json.data);
  1808. // }, function(xhr, text, error){
  1809. // if (failure) failure(xhr, text, error);
  1810. // });
  1811. // };
  1812. // this.destory = this["delete"];
  1813. // }
  1814. //};
  1815. // var dictLoaded = {};
  1816. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  1817. MWF.xScript.addDictToCache = function ( options, path, json ) {
  1818. if( !path )path = "root";
  1819. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1820. var type = options.appType || "process";
  1821. var enableAnonymous = options.enableAnonymous || false;
  1822. var appFlagList = [];
  1823. if( options.application )appFlagList.push( options.application );
  1824. if( options.appId )appFlagList.push( options.appId );
  1825. if( options.appName )appFlagList.push( options.appName );
  1826. if( options.appAlias )appFlagList.push( options.appAlias );
  1827. var dictFlagList = [];
  1828. if( options.id )dictFlagList.push( options.id );
  1829. if( options.name )dictFlagList.push( options.name );
  1830. if( options.alias )dictFlagList.push( options.alias );
  1831. var cache = {};
  1832. cache[path] = json;
  1833. for( var i=0; i<appFlagList.length; i++ ){
  1834. for( var j=0; j<dictFlagList.length; j++ ){
  1835. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  1836. if( !MWF.xScript.dictLoaded[k] ){
  1837. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  1838. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  1839. }else if( i===0 && j===0 ){
  1840. MWF.xScript.setDictToCache( k, path ,json );
  1841. var arr = path.split(/\./g);
  1842. var p;
  1843. var cache = MWF.xScript.dictLoaded[k];
  1844. for( var l=0 ; l<arr.length; l++ ){
  1845. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  1846. if( cache[ p ] )break;
  1847. }
  1848. if( p ){
  1849. var mathP = p+".";
  1850. Object.keys( cache ).each( function( path, idx){
  1851. if( path.indexOf( mathP ) === 0 )delete cache[path];
  1852. })
  1853. }
  1854. }
  1855. }
  1856. }
  1857. };
  1858. MWF.xScript.getMatchedDict = function(key, path){
  1859. if( !path )path = "root";
  1860. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1861. var arr = path.split(/\./g);
  1862. if( MWF.xScript.dictLoaded[key] ){
  1863. var dicts = MWF.xScript.dictLoaded[key];
  1864. var list = Array.clone(arr);
  1865. var p;
  1866. var dict;
  1867. for( var i=0 ; i<arr.length; i++ ){
  1868. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  1869. list.shift();
  1870. if( dicts[ p ] ){
  1871. dict = dicts[ p ];
  1872. break;
  1873. }
  1874. }
  1875. return {
  1876. dict : dict,
  1877. unmatchedPathList : list
  1878. }
  1879. }
  1880. return {
  1881. dict : null,
  1882. unmatchedPathList : list
  1883. }
  1884. };
  1885. MWF.xScript.insertDictToCache = function(key, path, json){
  1886. if( MWF.xScript.dictLoaded[key] ){
  1887. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1888. var dict = matchedDict.dict;
  1889. var list = matchedDict.unmatchedPathList;
  1890. if( !dict ){
  1891. MWF.xScript.dictLoaded[key][path] = json;
  1892. }else{
  1893. for( var j=0; j<list.length-1; j++ ){
  1894. if( !dict[ list[j] ] ){
  1895. dict[ list[j] ] = {};
  1896. }
  1897. dict = dict[ list[j] ];
  1898. }
  1899. var lastPath = list[list.length-1];
  1900. if( !dict[lastPath] ){
  1901. dict[lastPath] = json;
  1902. }else if( typeOf( dict[lastPath] ) === "array" ){
  1903. dict[lastPath].push( json );
  1904. }
  1905. }
  1906. }else{
  1907. MWF.xScript.dictLoaded[key] = {};
  1908. MWF.xScript.dictLoaded[key][path] = json;
  1909. }
  1910. };
  1911. MWF.xScript.setDictToCache = function(key, path, json){
  1912. if( MWF.xScript.dictLoaded[key] ){
  1913. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1914. var dict = matchedDict.dict;
  1915. var list = matchedDict.unmatchedPathList;
  1916. if( !dict ){
  1917. MWF.xScript.dictLoaded[key][path] = json;
  1918. }else{
  1919. for( var j=0; j<list.length-1; j++ ){
  1920. if( !dict[ list[j] ] ){
  1921. dict[ list[j] ] = {};
  1922. }
  1923. dict = dict[ list[j] ];
  1924. }
  1925. dict[list[list.length-1]] = json;
  1926. }
  1927. }else{
  1928. MWF.xScript.dictLoaded[key] = {};
  1929. MWF.xScript.dictLoaded[key][path] = json;
  1930. }
  1931. };
  1932. MWF.xScript.getDictFromCache = function( key, path ){
  1933. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1934. var dict = matchedDict.dict;
  1935. var list = matchedDict.unmatchedPathList;
  1936. if( dict ){
  1937. for( var j=0; j<list.length; j++ ){
  1938. dict = dict[ list[j] ];
  1939. if( !dict )return null;
  1940. }
  1941. return dict;
  1942. }
  1943. return null;
  1944. };
  1945. MWF.xScript.deleteDictToCache = function(key, path){
  1946. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1947. var dict = matchedDict.dict;
  1948. var list = matchedDict.unmatchedPathList;
  1949. if( dict){
  1950. for( var j=0; j<list.length-1; j++ ){
  1951. dict = dict[ list[j] ];
  1952. if( !dict )return;
  1953. }
  1954. delete dict[list[list.length-1]];
  1955. }
  1956. };
  1957. MWF.xScript.createDict = function(application){
  1958. //optionsOrName : {
  1959. // type : "", //默认为process, 可以为 process cms
  1960. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1961. // name : "", // 数据字典名称/别名/id
  1962. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1963. //}
  1964. //或者name: "" // 数据字典名称/别名/id
  1965. return function(optionsOrName){
  1966. var options = optionsOrName;
  1967. if( typeOf( options ) == "string" ){
  1968. options = { name : options };
  1969. }
  1970. var name = this.name = options.name;
  1971. var type = ( options.type && options.application ) ? options.type : "process";
  1972. var applicationId = options.application || application;
  1973. var enableAnonymous = options.enableAnonymous || false;
  1974. var opt = {
  1975. "appType" : type,
  1976. "name" : name,
  1977. "appId" : applicationId,
  1978. "enableAnonymous" : enableAnonymous
  1979. };
  1980. var key = name+type+applicationId+enableAnonymous;
  1981. // if (!dictLoaded[key]) dictLoaded[key] = {};
  1982. // this.dictData = dictLoaded[key];
  1983. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1984. if( type == "cms" ){
  1985. var action = MWF.Actions.get("x_cms_assemble_control");
  1986. }else{
  1987. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1988. }
  1989. var encodePath = function( path ){
  1990. var arr = path.split(/\./g);
  1991. var ar = arr.map(function(v){
  1992. return encodeURIComponent(v);
  1993. });
  1994. return ar.join("/");
  1995. };
  1996. this.get = function(path, success, failure, async, refresh){
  1997. var value = null;
  1998. if (!refresh ){
  1999. var data = MWF.xScript.getDictFromCache( key, path );
  2000. if( data ){
  2001. if (success) success( data );
  2002. return data;
  2003. }
  2004. }
  2005. if (success===true) async=true;
  2006. if (failure===true) async=true;
  2007. var cb = function(json){
  2008. value = json.data;
  2009. MWF.xScript.addDictToCache(opt, path, value);
  2010. if (success) value = success(json.data);
  2011. return value;
  2012. }.ag().catch(function(xhr, text, error){ if (failure) return failure(xhr, text, error); });
  2013. if (path){
  2014. var p = encodePath( path );
  2015. //var p = path.replace(/\./g, "/");
  2016. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
  2017. }else{
  2018. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
  2019. }
  2020. return (!!async) ? cb : value;
  2021. // if (path){
  2022. // var p = encodePath( path );
  2023. // //var p = path.replace(/\./g, "/");
  2024. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  2025. // value = json.data;
  2026. // // this.dictData[path] = value;
  2027. // MWF.xScript.addDictToCache(opt, path, value);
  2028. // if (success) success(json.data);
  2029. // }.bind(this), function(xhr, text, error){
  2030. // if (failure) failure(xhr, text, error);
  2031. // }, !!async);
  2032. // }else{
  2033. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  2034. // value = json.data;
  2035. // // this.dictData["root"] = value;
  2036. // MWF.xScript.addDictToCache(opt, path, value);
  2037. // if (success) success(json.data);
  2038. // }.bind(this), function(xhr, text, error){
  2039. // if (failure) failure(xhr, text, error);
  2040. // }, !!async);
  2041. // }
  2042. //return value;
  2043. };
  2044. this.set = function(path, value, success, failure){
  2045. var p = encodePath( path );
  2046. //var p = path.replace(/\./g, "/");
  2047. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2048. MWF.xScript.setDictToCache(key, path, value);
  2049. if (success) return success(json.data);
  2050. }, function(xhr, text, error){
  2051. if (failure) return failure(xhr, text, error);
  2052. }, false, false);
  2053. };
  2054. this.add = function(path, value, success, failure){
  2055. var p = encodePath( path );
  2056. //var p = path.replace(/\./g, "/");
  2057. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2058. MWF.xScript.insertDictToCache(key, path, value);
  2059. if (success) return success(json.data);
  2060. }, function(xhr, text, error){
  2061. if (failure) return failure(xhr, text, error);
  2062. }, false, false);
  2063. };
  2064. this["delete"] = function(path, success, failure){
  2065. var p = encodePath( path );
  2066. //var p = path.replace(/\./g, "/");
  2067. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2068. MWF.xScript.deleteDictToCache(key, path);
  2069. if (success) return success(json.data);
  2070. }, function(xhr, text, error){
  2071. if (failure) return failure(xhr, text, error);
  2072. }, false, false);
  2073. };
  2074. this.destory = this["delete"];
  2075. }
  2076. };