Environment.js 106 KB

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