CMSEnvironment.js 105 KB

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