CMSEnvironment.js 102 KB

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