CMSEnvironment.js 104 KB

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