CMSEnvironment.js 104 KB

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