ViewEnvironment.js 85 KB

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