PageEnvironment.js 101 KB

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