PageEnvironment.js 85 KB

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