ViewEnvironment.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099
  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) {
  51. getOrgActions();
  52. var data = { "groupList": getNameFlag(name) };
  53. var v = null;
  54. orgActions.listGroup(data, function (json) { v = json.data; }, null, false);
  55. return (v && v.length === 1) ? v[0] : v;
  56. },
  57. //查询下级群组--返回群组的对象数组
  58. //nested 布尔 true嵌套下级;false直接下级;默认false;
  59. listSubGroup: function (name, nested) {
  60. getOrgActions();
  61. var data = { "groupList": getNameFlag(name) };
  62. var v = null;
  63. if (nested) {
  64. orgActions.listSubGroupNested(data, function (json) { v = json.data; }, null, false);
  65. } else {
  66. orgActions.listSubGroupDirect(data, function (json) { v = json.data; }, null, false);
  67. }
  68. return v;
  69. },
  70. //查询上级群组--返回群组的对象数组
  71. //nested 布尔 true嵌套上级;false直接上级;默认false;
  72. listSupGroup: function (name, nested) {
  73. getOrgActions();
  74. var data = { "groupList": getNameFlag(name) };
  75. var v = null;
  76. if (nested) {
  77. orgActions.listSupGroupNested(data, function (json) { v = json.data; }, null, false);
  78. } else {
  79. orgActions.listSupGroupDirect(data, function (json) { v = json.data; }, null, false);
  80. }
  81. return v;
  82. },
  83. //人员所在群组(嵌套)--返回群组的对象数组
  84. listGroupWithPerson: function (name) {
  85. getOrgActions();
  86. var data = { "personList": getNameFlag(name) };
  87. var v = null;
  88. orgActions.listGroupWithPerson(data, function (json) { v = json.data; }, null, false);
  89. return v;
  90. },
  91. //群组是否拥有角色--返回true, false
  92. groupHasRole: function (name, role) {
  93. getOrgActions();
  94. nameFlag = (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  95. var data = { "group": nameFlag, "roleList": getNameFlag(role) };
  96. var v = false;
  97. orgActions.groupHasRole(data, function (json) { v = json.data.value; }, null, false);
  98. return v;
  99. },
  100. //角色***************
  101. //获取角色--返回角色的对象数组
  102. getRole: function (name) {
  103. getOrgActions();
  104. var data = { "roleList": getNameFlag(name) };
  105. var v = null;
  106. orgActions.listRole(data, function (json) { v = json.data; }, null, false);
  107. return (v && v.length === 1) ? v[0] : v;
  108. },
  109. //人员所有角色(嵌套)--返回角色的对象数组
  110. listRoleWithPerson: function (name) {
  111. getOrgActions();
  112. var data = { "personList": getNameFlag(name) };
  113. var v = null;
  114. orgActions.listRoleWithPerson(data, function (json) { v = json.data; }, null, false);
  115. return v;
  116. },
  117. //人员***************
  118. //人员是否拥有角色--返回true, false
  119. personHasRole: function (name, role) {
  120. getOrgActions();
  121. nameFlag = (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  122. var data = { "person": nameFlag, "roleList": getNameFlag(role) };
  123. var v = false;
  124. orgActions.personHasRole(data, function (json) { v = json.data.value; }, null, false);
  125. return v;
  126. },
  127. //获取人员--返回人员的对象数组
  128. getPerson: function (name) {
  129. getOrgActions();
  130. var data = { "personList": getNameFlag(name) };
  131. var v = null;
  132. orgActions.listPerson(data, function (json) { v = json.data; }, null, false);
  133. return (v && v.length === 1) ? v[0] : v;
  134. },
  135. //查询下级人员--返回人员的对象数组
  136. //nested 布尔 true嵌套下级;false直接下级;默认false;
  137. listSubPerson: function (name, nested) {
  138. getOrgActions();
  139. var data = { "personList": getNameFlag(name) };
  140. var v = null;
  141. if (nested) {
  142. orgActions.listPersonSubNested(data, function (json) { v = json.data; }, null, false);
  143. } else {
  144. orgActions.listPersonSubDirect(data, function (json) { v = json.data; }, null, false);
  145. }
  146. return v;
  147. },
  148. //查询上级人员--返回人员的对象数组
  149. //nested 布尔 true嵌套上级;false直接上级;默认false;
  150. listSupPerson: function (name, nested) {
  151. getOrgActions();
  152. var data = { "personList": getNameFlag(name) };
  153. var v = null;
  154. if (nested) {
  155. orgActions.listPersonSupNested(data, function (json) { v = json.data; }, null, false);
  156. } else {
  157. orgActions.listPersonSupDirect(data, function (json) { v = json.data; }, null, false);
  158. }
  159. return v;
  160. },
  161. //获取群组的所有人员--返回人员的对象数组
  162. listPersonWithGroup: function (name) {
  163. getOrgActions();
  164. var data = { "groupList": getNameFlag(name) };
  165. var v = null;
  166. orgActions.listPersonWithGroup(data, function (json) { v = json.data; }, null, false);
  167. return v;
  168. },
  169. //获取角色的所有人员--返回人员的对象数组
  170. listPersonWithRole: function (name) {
  171. getOrgActions();
  172. var data = { "roleList": getNameFlag(name) };
  173. var v = null;
  174. orgActions.listPersonWithRole(data, function (json) { v = json.data; }, null, false);
  175. return v;
  176. },
  177. //获取身份的所有人员--返回人员的对象数组
  178. listPersonWithIdentity: function (name) {
  179. getOrgActions();
  180. var data = { "identityList": getNameFlag(name) };
  181. var v = null;
  182. orgActions.listPersonWithIdentity(data, function (json) { v = json.data; }, null, false);
  183. return v;
  184. },
  185. //查询组织成员的人员--返回人员的对象数组
  186. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  187. listPersonWithUnit: function (name, nested) {
  188. getOrgActions();
  189. var data = { "unitList": getNameFlag(name) };
  190. var v = null;
  191. if (nested) {
  192. orgActions.listPersonWithUnitNested(data, function (json) { v = json.data; }, null, false);
  193. } else {
  194. orgActions.listPersonWithUnitDirect(data, function (json) { v = json.data; }, null, false);
  195. }
  196. return v;
  197. },
  198. //根据属性查询人员--返回人员的对象数组
  199. //name string 属性名
  200. //value string 属性值
  201. listPersonWithAttribute: function (name, value) {
  202. getOrgActions();
  203. var data = { "name": name, "attribute": value };
  204. var v = null;
  205. orgActions.listPersonWithAttribute(data, function (json) { v = json.data; }, null, false);
  206. return v;
  207. },
  208. //根据属性查询人员--返回人员的全称数组
  209. //name string 属性名
  210. //value string 属性值
  211. listPersonNameWithAttribute: function (name, value) {
  212. getOrgActions();
  213. var data = { "name": name, "attribute": value };
  214. var v = null;
  215. orgActions.listPersonWithAttributeValue(data, function (json) { v = json.data.personList; }, null, false);
  216. return v;
  217. },
  218. //人员属性************
  219. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  220. appendPersonAttribute: function (person, attr, values, success, failure) {
  221. getOrgActions();
  222. var personFlag = (typeOf(person) === "object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  223. var data = { "attributeList": values, "name": attr, "person": personFlag };
  224. orgActions.appendPersonAttribute(data, function (json) {
  225. if (json.data.value) {
  226. if (success) success();
  227. } else {
  228. if (failure) failure(null, "", "append values failed");
  229. }
  230. }, function (xhr, text, error) {
  231. if (failure) failure(xhr, text, error);
  232. }, false);
  233. },
  234. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  235. setPersonAttribute: function (person, attr, values, success, failure) {
  236. getOrgActions();
  237. var personFlag = (typeOf(person) === "object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  238. var data = { "attributeList": values, "name": attr, "person": personFlag };
  239. orgActions.setPersonAttribute(data, function (json) {
  240. if (json.data.value) {
  241. if (success) success();
  242. } else {
  243. if (failure) failure(null, "", "append values failed");
  244. }
  245. }, function (xhr, text, error) {
  246. if (failure) failure(xhr, text, error);
  247. }, false);
  248. },
  249. //获取人员属性值
  250. getPersonAttribute: function (person, attr) {
  251. getOrgActions();
  252. var personFlag = (typeOf(person) === "object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  253. var data = { "name": attr, "person": personFlag };
  254. var v = null;
  255. orgActions.getPersonAttribute(data, function (json) { v = json.data.attributeList; }, null, false);
  256. return v;
  257. },
  258. //列出人员所有属性的名称
  259. listPersonAttributeName: function (name) {
  260. getOrgActions();
  261. var data = { "personList": getNameFlag(name) };
  262. var v = null;
  263. orgActions.listPersonAttributeName(data, function (json) { v = json.data.nameList; }, null, false);
  264. return v;
  265. },
  266. //列出人员的所有属性
  267. listPersonAllAttribute: function (name) {
  268. getOrgActions();
  269. var data = { "personList": getNameFlag(name) };
  270. var v = null;
  271. orgActions.listPersonAllAttribute(data, function (json) { v = json.data; }, null, false);
  272. return v;
  273. },
  274. //身份**********
  275. //获取身份
  276. getIdentity: function (name) {
  277. getOrgActions();
  278. var data = { "identityList": getNameFlag(name) };
  279. var v = null;
  280. orgActions.listIdentity(data, function (json) { v = json.data; }, null, false);
  281. return (v && v.length === 1) ? v[0] : v;
  282. },
  283. //列出人员的身份
  284. listIdentityWithPerson: function (name) {
  285. getOrgActions();
  286. var data = { "personList": getNameFlag(name) };
  287. var v = null;
  288. orgActions.listIdentityWithPerson(data, function (json) { v = json.data; }, null, false);
  289. return v;
  290. },
  291. //查询组织成员身份--返回身份的对象数组
  292. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  293. listIdentityWithUnit: function (name, nested) {
  294. getOrgActions();
  295. var data = { "unitList": getNameFlag(name) };
  296. var v = null;
  297. if (nested) {
  298. orgActions.listIdentityWithUnitNested(data, function (json) { v = json.data; }, null, false);
  299. } else {
  300. orgActions.listIdentityWithUnitDirect(data, function (json) { v = json.data; }, null, false);
  301. }
  302. return v;
  303. },
  304. //组织**********
  305. //获取组织
  306. getUnit: function (name) {
  307. getOrgActions();
  308. var data = { "unitList": getNameFlag(name) };
  309. var v = null;
  310. orgActions.listUnit(data, function (json) { v = json.data; }, null, false);
  311. return (v && v.length === 1) ? v[0] : v;
  312. },
  313. //查询组织的下级--返回组织的对象数组
  314. //nested 布尔 true嵌套下级;false直接下级;默认false;
  315. listSubUnit: function (name, nested) {
  316. getOrgActions();
  317. var data = { "unitList": getNameFlag(name) };
  318. var v = null;
  319. if (nested) {
  320. orgActions.listUnitSubNested(data, function (json) { v = json.data; }, null, false);
  321. } else {
  322. orgActions.listUnitSubDirect(data, function (json) { v = json.data; }, null, false);
  323. }
  324. return v;
  325. },
  326. //查询组织的上级--返回组织的对象数组
  327. //nested 布尔 true嵌套上级;false直接上级;默认false;
  328. listSupUnit: function (name, nested) {
  329. getOrgActions();
  330. var data = { "unitList": getNameFlag(name) };
  331. var v = null;
  332. if (nested) {
  333. orgActions.listUnitSupNested(data, function (json) { v = json.data; }, null, false);
  334. } else {
  335. orgActions.listUnitSupDirect(data, function (json) { v = json.data; }, null, false);
  336. }
  337. return v;
  338. },
  339. //根据个人身份获取组织
  340. //flag 数字 表示获取第几层的组织
  341. // 字符串 表示获取指定类型的组织
  342. // 空 表示获取直接所在的组织
  343. getUnitByIdentity: function (name, flag) {
  344. getOrgActions();
  345. var getUnitMethod = "current";
  346. var v;
  347. if (flag) {
  348. if (typeOf(flag) === "string") getUnitMethod = "type";
  349. if (typeOf(flag) === "number") getUnitMethod = "level";
  350. }
  351. switch (getUnitMethod) {
  352. case "current":
  353. var data = { "identityList": getNameFlag(name) };
  354. orgActions.listUnitWithIdentity(data, function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v }, null, false);
  355. break;
  356. case "type":
  357. var data = { "identity": (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name, "type": flag };
  358. orgActions.getUnitWithIdentityAndType(data, function (json) { v = json.data; }, null, false);
  359. break;
  360. case "level":
  361. var data = { "identity": (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name, "level": flag };
  362. orgActions.getUnitWithIdentityAndLevel(data, function (json) { v = json.data; }, null, false);
  363. break;
  364. }
  365. return v;
  366. },
  367. //列出身份所在组织的所有上级组织
  368. listAllSupUnitWithIdentity: function (name) {
  369. getOrgActions();
  370. var data = { "identityList": getNameFlag(name) };
  371. var v = null;
  372. orgActions.listUnitSupNestedWithIdentity(data, function (json) { v = json.data; }, null, false);
  373. return v;
  374. },
  375. //获取人员所在的所有组织
  376. listUnitWithPerson: function (name) {
  377. getOrgActions();
  378. var data = { "personList": getNameFlag(name) };
  379. var v = null;
  380. orgActions.listUnitWithPerson(data, function (json) { v = json.data; }, null, false);
  381. return v;
  382. },
  383. //列出身份所在组织的所有上级组织
  384. listAllSupUnitWithPerson: function (name) {
  385. getOrgActions();
  386. var data = { "personList": getNameFlag(name) };
  387. var v = null;
  388. orgActions.listUnitSupNestedWithPerson(data, function (json) { v = json.data; }, null, false);
  389. return v;
  390. },
  391. //根据组织属性,获取所有符合的组织
  392. listUnitWithAttribute: function (name, attribute) {
  393. getOrgActions();
  394. var data = { "name": name, "attribute": attribute };
  395. var v = null;
  396. orgActions.listUnitWithAttribute(data, function (json) { v = json.data; }, null, false);
  397. return v;
  398. },
  399. //根据组织职务,获取所有符合的组织
  400. listUnitWithDuty: function (name, id) {
  401. getOrgActions();
  402. var data = { "name": "", "identity": (typeOf(id) === "object") ? (id.distinguishedName || id.id || id.unique || id.name) : id };
  403. var v = null;
  404. orgActions.listUnitWithDuty(data, function (json) { v = json.data; }, null, false);
  405. return v;
  406. },
  407. //列出顶层组织
  408. listTopUnit: function () {
  409. var action = MWF.Actions.get("x_organization_assemble_control");
  410. var v = null;
  411. action.listTopUnit(function (json) {
  412. v = json.data;
  413. }, null, false);
  414. return v;
  415. },
  416. //组织职务***********
  417. //获取指定的组织职务的身份
  418. getDuty: function (duty, id) {
  419. getOrgActions();
  420. var data = { "name": duty, "unit": (typeOf(id) === "object") ? (id.distinguishedName || id.id || id.unique || id.name) : id };
  421. var v = null;
  422. orgActions.getDuty(data, function (json) { v = json.data; }, null, false);
  423. return v;
  424. },
  425. //获取身份的所有职务名称
  426. listDutyNameWithIdentity: function (name) {
  427. getOrgActions();
  428. var data = { "identityList": getNameFlag(name) };
  429. var v = null;
  430. orgActions.listDutyNameWithIdentity(data, function (json) { v = json.data.nameList; }, null, false);
  431. return v;
  432. },
  433. //获取组织的所有职务名称
  434. listDutyNameWithUnit: function (name) {
  435. getOrgActions();
  436. var data = { "unitList": getNameFlag(name) };
  437. var v = null;
  438. orgActions.listDutyNameWithUnit(data, function (json) { v = json.data.nameList; }, null, false);
  439. return v;
  440. },
  441. //获取组织的所有职务
  442. listUnitAllDuty: function (name) {
  443. getOrgActions();
  444. var data = { "unitList": getNameFlag(name) };
  445. var v = null;
  446. orgActions.listUnitAllDuty(data, function (json) { v = json.data; }, null, false);
  447. return v;
  448. },
  449. //组织属性**************
  450. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  451. appendUnitAttribute: function (unit, attr, values, success, failure) {
  452. getOrgActions();
  453. var unitFlag = (typeOf(unit) === "object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  454. var data = { "attributeList": values, "name": attr, "unit": unitFlag };
  455. orgActions.appendUnitAttribute(data, function (json) {
  456. if (json.data.value) {
  457. if (success) success();
  458. } else {
  459. if (failure) failure(null, "", "append values failed");
  460. }
  461. }, function (xhr, text, error) {
  462. if (failure) failure(xhr, text, error);
  463. }, false);
  464. },
  465. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  466. setUnitAttribute: function (unit, attr, values, success, failure) {
  467. getOrgActions();
  468. var unitFlag = (typeOf(unit) === "object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  469. var data = { "attributeList": values, "name": attr, "unit": unitFlag };
  470. orgActions.setUnitAttribute(data, function (json) {
  471. if (json.data.value) {
  472. if (success) success();
  473. } else {
  474. if (failure) failure(null, "", "append values failed");
  475. }
  476. }, function (xhr, text, error) {
  477. if (failure) failure(xhr, text, error);
  478. }, false);
  479. },
  480. //获取组织属性值
  481. getUnitAttribute: function (unit, attr) {
  482. getOrgActions();
  483. var unitFlag = (typeOf(unit) === "object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  484. var data = { "name": attr, "unit": unitFlag };
  485. var v = null;
  486. orgActions.getUnitAttribute(data, function (json) { v = json.data.attributeList; }, null, false);
  487. return v;
  488. },
  489. //列出组织所有属性的名称
  490. listUnitAttributeName: function (name) {
  491. getOrgActions();
  492. var data = { "unitList": getNameFlag(name) };
  493. var v = null;
  494. orgActions.listUnitAttributeName(data, function (json) { v = json.data.nameList; }, null, false);
  495. return v;
  496. },
  497. //列出组织的所有属性
  498. listUnitAllAttribute: function (name) {
  499. getOrgActions();
  500. var data = { "unitList": getNameFlag(name) };
  501. var v = null;
  502. orgActions.listUnitAllAttribute(data, function (json) { v = json.data; }, null, false);
  503. return v;
  504. }
  505. };
  506. this.Action = (function () {
  507. var actions = [];
  508. return function (root, json) {
  509. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  510. action.getActions = function (callback) {
  511. if (!this.actions) this.actions = {};
  512. Object.merge(this.actions, json);
  513. if (callback) callback();
  514. };
  515. this.invoke = function (option) {
  516. action.invoke(option)
  517. }
  518. }
  519. })();
  520. this.service = {
  521. "jaxwsClient": {},
  522. "jaxrsClient": {}
  523. };
  524. var lookupAction = null;
  525. var getLookupAction = function (callback) {
  526. if (!lookupAction) {
  527. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  528. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  529. lookupAction.getActions = function (actionCallback) {
  530. this.actions = {
  531. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  532. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  533. "lookup": { "uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method": "PUT" },
  534. "getView": { "uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}" }
  535. };
  536. if (actionCallback) actionCallback();
  537. }
  538. if (callback) callback();
  539. });
  540. } else {
  541. if (callback) callback();
  542. }
  543. };
  544. this.view = {
  545. "lookup": function (view, callback, async) {
  546. var filterList = { "filterList": (view.filter || null) };
  547. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function (json) {
  548. var data = {
  549. "grid": json.data.grid || json.data.groupGrid,
  550. "groupGrid": json.data.groupGrid
  551. };
  552. if (callback) callback(data);
  553. }, null, async);
  554. },
  555. "lookupV1": function (view, callback) {
  556. getLookupAction(function () {
  557. lookupAction.invoke({
  558. "name": "lookup", "async": true, "parameter": { "view": view.view, "application": view.application }, "success": function (json) {
  559. var data = {
  560. "grid": json.data.grid,
  561. "groupGrid": json.data.groupGrid
  562. };
  563. if (callback) callback(data);
  564. }.bind(this)
  565. });
  566. }.bind(this));
  567. },
  568. "select": function (view, callback, options) {
  569. if (view.view) {
  570. var viewJson = {
  571. "application": view.application || _form.json.application,
  572. "viewName": view.view || "",
  573. "isTitle": (view.isTitle === false) ? "no" : "yes",
  574. "select": (view.isMulti === false) ? "single" : "multi",
  575. "filter": view.filter
  576. };
  577. if (!options) options = {};
  578. options.width = view.width;
  579. options.height = view.height;
  580. options.title = view.caption;
  581. var width = options.width || "700";
  582. var height = options.height || "400";
  583. if (layout.mobile) {
  584. var size = document.body.getSize();
  585. width = size.x;
  586. height = size.y;
  587. options.style = "viewmobile";
  588. }
  589. width = width.toInt();
  590. height = height.toInt();
  591. var size = _form.app.content.getSize();
  592. var x = (size.x - width) / 2;
  593. var y = (size.y - height) / 2;
  594. if (x < 0) x = 0;
  595. if (y < 0) y = 0;
  596. if (layout.mobile) {
  597. x = 20;
  598. y = 0;
  599. }
  600. var _self = this;
  601. MWF.require("MWF.xDesktop.Dialog", function () {
  602. var dlg = new MWF.xDesktop.Dialog({
  603. "title": options.title || "select view",
  604. "style": options.style || "view",
  605. "top": y,
  606. "left": x - 20,
  607. "fromTop": y,
  608. "fromLeft": x - 20,
  609. "width": width,
  610. "height": height,
  611. "html": "<div style='height: 100%;'></div>",
  612. "maskNode": _form.app.content,
  613. "container": _form.app.content,
  614. "buttonList": [
  615. {
  616. "text": MWF.LP.process.button.ok,
  617. "action": function () {
  618. //if (callback) callback(_self.view.selectedItems);
  619. if (callback) callback(_self.view.getData());
  620. this.close();
  621. }
  622. },
  623. {
  624. "text": MWF.LP.process.button.cancel,
  625. "action": function () { this.close(); }
  626. }
  627. ]
  628. });
  629. dlg.show();
  630. if (layout.mobile) {
  631. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  632. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  633. if (backAction) backAction.addEvent("click", function (e) {
  634. dlg.close();
  635. }.bind(this));
  636. if (okAction) okAction.addEvent("click", function (e) {
  637. //if (callback) callback(this.view.selectedItems);
  638. if (callback) callback(this.view.getData());
  639. dlg.close();
  640. }.bind(this));
  641. }
  642. MWF.xDesktop.requireApp("query.Query", "Viewer", function () {
  643. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, { "style": "select" }, _form.app);
  644. }.bind(this));
  645. }.bind(this));
  646. }
  647. }
  648. };
  649. //include 引用脚本
  650. //optionsOrName : {
  651. // type : "", 默认为portal, 可以为 portal process cms
  652. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  653. // name : "" // 脚本名称/别名/id
  654. //}
  655. //或者name: "" // 脚本名称/别名/id
  656. // if( !window.includedScripts ){
  657. // var includedScripts = window.includedScripts = [];
  658. // }else{
  659. // var includedScripts = window.includedScripts;
  660. // }
  661. var includedScripts = [];
  662. this.include = function (optionsOrName, callback) {
  663. var options = optionsOrName;
  664. if (typeOf(options) == "string") {
  665. options = { name: options };
  666. }
  667. var name = options.name;
  668. var type = (options.type && options.application) ? options.type : "portal";
  669. var application = options.application || _form.json.application;
  670. var key = type + "-" + application + "-" + name;
  671. if (includedScripts.indexOf(key) > -1) {
  672. if (callback) callback.apply(this);
  673. return;
  674. }
  675. //if (includedScripts.indexOf( name )> -1){
  676. // if (callback) callback.apply(this);
  677. // return;
  678. //}
  679. var scriptAction;
  680. switch (type) {
  681. case "portal":
  682. if (this.scriptActionPortal) {
  683. scriptAction = this.scriptActionPortal;
  684. } else {
  685. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  686. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  687. }
  688. break;
  689. case "process":
  690. if (this.scriptActionProcess) {
  691. scriptAction = this.scriptActionProcess;
  692. } else {
  693. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  694. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  695. }
  696. break;
  697. case "cms":
  698. if (this.scriptActionCMS) {
  699. scriptAction = this.scriptActionCMS;
  700. } else {
  701. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  702. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  703. }
  704. break;
  705. }
  706. scriptAction.getScriptByName(application, name, includedScripts, function (json) {
  707. if (json.data) {
  708. includedScripts.push(key);
  709. includedScripts = includedScripts.concat(json.data.importedList);
  710. MWF.Macro.exec(json.data.text, this);
  711. if (callback) callback.apply(this);
  712. } else {
  713. if (callback) callback.apply(this);
  714. }
  715. }.bind(this), null, false);
  716. };
  717. this.define = function (name, fun, overwrite) {
  718. var over = true;
  719. if (overwrite === false) over = false;
  720. var o = {};
  721. o[name] = { "value": fun, "configurable": over };
  722. MWF.defineProperties(this, o);
  723. }.bind(this);
  724. //仅前台对象-----------------------------------------
  725. //form
  726. this.page = this.form = this.queryView = {
  727. "getViewInfor" : function () { return _form.getViewInfor(); },
  728. "getPageInfor" : function () { return _form.getPageInfor(); },
  729. "getPageData" : function () { return _form.getPageData(); },
  730. "toPage" : function ( pageNumber, callback ) { return _form.toPage(pageNumber, callback); },
  731. "selectAll" : function () { return _form.selectAll(); },
  732. "unSelectAll" : function () { return _form.unSelectAll(); },
  733. "switchView" : function ( options ) { return _form.switchView(options); },
  734. // "getInfor": function () { return ev.pageInfor; },
  735. // "infor": ev.pageInfor,
  736. "getApp": function () { return _form.app; },
  737. "app": _form.app,
  738. "node": function () { return _form.node; },
  739. // "get": function (name) { return (_form.all) ? _form.all[name] : null; },
  740. // "getWidgetModule": function (widget, moduleName) {
  741. // if (!_form.widgetModules || !_form.widgetModules[widget]) return null;
  742. // var module = _form.widgetModules[widget][moduleName];
  743. // return module || null;
  744. // },
  745. // "getField": function (name) { return _forms[name]; },
  746. // "getAction": function () { return _form.workAction },
  747. "getDesktop": function () { return _form.app.desktop },
  748. // "getData": function () { return new MWF.xScript.JSONData(_form.getData()); },
  749. //"save": function(callback){_form.saveWork(callback);},
  750. // "close": function () { _form.closeWork(); },
  751. // "print": function (application, form) {
  752. // _form.printWork(application, form);
  753. // },
  754. "confirm": function (type, title, text, width, height, ok, cancel, callback, mask, style) {
  755. // var p = MWF.getCenter({"x": width, "y": height});
  756. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  757. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  758. if ((arguments.length <= 1) || o2.typeOf(arguments[1]) === "string") {
  759. var p = MWF.getCenter({ "x": width, "y": height });
  760. e = { "event": { "clientX": p.x, "x": p.x, "clientY": p.y, "y": p.y } };
  761. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  762. } else {
  763. e = (arguments.length > 1) ? arguments[1] : null;
  764. title = (arguments.length > 2) ? arguments[2] : null;
  765. text = (arguments.length > 3) ? arguments[3] : null;
  766. width = (arguments.length > 4) ? arguments[4] : null;
  767. height = (arguments.length > 5) ? arguments[5] : null;
  768. ok = (arguments.length > 6) ? arguments[6] : null;
  769. cancel = (arguments.length > 7) ? arguments[7] : null;
  770. callback = (arguments.length > 8) ? arguments[8] : null;
  771. mask = (arguments.length > 9) ? arguments[9] : null;
  772. style = (arguments.length > 10) ? arguments[10] : null;
  773. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  774. }
  775. },
  776. "alert": function(type, title, text, width, height){
  777. _form.alert(type, title, text, width, height);
  778. },
  779. "notice": function (content, type, target, where, offset, option) {
  780. _form.notice(content, type, target, where, offset, option);
  781. },
  782. "addEvent": function (e, f) { _form.addEvent(e, f); },
  783. // "openWindow": function (form, app) {
  784. // _form.openWindow(form, app);
  785. // },
  786. // "toPage": function (name, par, nohis) {
  787. // _form.app.toPage(name, par, nohis);
  788. // },
  789. // "toPortal": function (portal, page, par) {
  790. // _form.app.toPortal(portal, page, par);
  791. // },
  792. "openWork": function (id, completedId, title, options) {
  793. var op = options || {};
  794. op.workId = id;
  795. op.workCompletedId = completedId;
  796. op.docTitle = title;
  797. op.appId = "process.Work" + (op.workId || op.workCompletedId);
  798. return layout.desktop.openApplication(this.event, "process.Work", op);
  799. },
  800. "openJob": function (id, choice, options) {
  801. var workData = null;
  802. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function (json) {
  803. if (json.data) workData = json.data;
  804. }.bind(this), null, false);
  805. if (workData) {
  806. var len = workData.workList.length + workData.workCompletedList.length;
  807. if (len) {
  808. if (len > 1 && choice) {
  809. var node = new Element("div", { "styles": { "padding": "20px", "width": "500px" } }).inject(_form.node);
  810. workData.workList.each(function (work) {
  811. var workNode = new Element("div", {
  812. "styles": {
  813. "background": "#ffffff",
  814. "border-radius": "10px",
  815. "clear": "both",
  816. "margin-bottom": "10px",
  817. "height": "40px",
  818. "padding": "10px 10px"
  819. }
  820. }).inject(node);
  821. 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>" +
  822. "<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>" +
  823. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>" + work.title + "</div>" +
  824. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>" + work.activityName + "</div>" +
  825. "<div style='color:#999999; float: left; margin-right: 10px'>" + work.activityArrivedTime + "</div>" +
  826. "<div style='color:#999999; float: left; margin-right: 10px'>" + (work.manualTaskIdentityText || "") + "</div></div>";
  827. workNode.set("html", html);
  828. var action = workNode.getElement(".MWFAction");
  829. action.store("work", work);
  830. action.addEvent("click", function (e) {
  831. var work = e.target.retrieve("work");
  832. if (work) this.openWork(work.id, null, work.title, options);
  833. dlg.close();
  834. }.bind(this));
  835. }.bind(this));
  836. workData.workCompletedList.each(function (work) {
  837. var workNode = new Element("div", {
  838. "styles": {
  839. "background": "#ffffff",
  840. "border-radius": "10px",
  841. "clear": "both",
  842. "margin-bottom": "10px",
  843. "height": "40px",
  844. "padding": "10px 10px"
  845. }
  846. }).inject(node);
  847. 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>" +
  848. "<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>" +
  849. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>" + work.title + "</div>" +
  850. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>" + o2.LP.widget.workcompleted + "</div>" +
  851. "<div style='color:#999999; float: left; margin-right: 10px'>" + work.completedTime + "</div>";
  852. workNode.set("html", html);
  853. var action = workNode.getElement(".MWFAction");
  854. action.store("work", work);
  855. action.addEvent("click", function (e) {
  856. var work = e.target.retrieve("work");
  857. if (work) this.openWork(null, work.id, work.title, options);
  858. dlg.close();
  859. }.bind(this));
  860. }.bind(this));
  861. var height = node.getSize().y + 20;
  862. if (height > 600) height = 600;
  863. var dlg = o2.DL.open({
  864. "title": o2.LP.widget.choiceWork,
  865. "style": "user",
  866. "isResize": false,
  867. "content": node,
  868. "buttonList": [
  869. {
  870. "type": "cancel",
  871. "text": o2.LP.widget.close,
  872. "action": function () { dlg.close(); }
  873. }
  874. ]
  875. });
  876. } else {
  877. if (workData.workList.length) {
  878. var work = workData.workList[0];
  879. return this.openWork(work.id, null, work.title, options);
  880. } else {
  881. var work = workData.workCompletedList[0];
  882. return this.openWork(null, work.id, work.title, options);
  883. }
  884. }
  885. }
  886. }
  887. },
  888. "openDocument": function (id, title, options) {
  889. var op = options || {};
  890. op.documentId = id;
  891. op.docTitle = title || "";
  892. layout.desktop.openApplication(this.event, "cms.Document", op);
  893. },
  894. "openPortal": function (name, page, par) {
  895. var action = MWF.Actions.get("x_portal_assemble_surface");
  896. action.getApplication(name, function (json) {
  897. if (json.data) {
  898. if (page) {
  899. action.getPageByName(page, json.data.id, function (pageJson) {
  900. layout.desktop.openApplication(null, "portal.Portal", {
  901. "portalId": json.data.id,
  902. "pageId": (pageJson.data) ? pageJson.data.id : "",
  903. "parameters": par,
  904. "appId": "portal.Portal" + json.data.id
  905. })
  906. });
  907. } else {
  908. layout.desktop.openApplication(null, "portal.Portal", {
  909. "portalId": json.data.id,
  910. "parameters": par,
  911. "appId": "portal.Portal" + json.data.id
  912. })
  913. }
  914. }
  915. });
  916. },
  917. "openCMS": function (name) {
  918. var action = MWF.Actions.get("x_cms_assemble_control");
  919. action.getColumn(name, function (json) {
  920. if (json.data) {
  921. layout.desktop.openApplication(null, "cms.Module", {
  922. "columnId": json.data.id,
  923. "appId": "cms.Module" + json.data.id
  924. });
  925. }
  926. });
  927. },
  928. "openProcess": function (name) {
  929. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  930. action.getApplication(name, function (json) {
  931. if (json.data) {
  932. layout.desktop.openApplication(null, "process.Application", {
  933. "id": json.data.id,
  934. "appId": "process.Application" + json.data.id
  935. });
  936. }
  937. });
  938. },
  939. "openApplication": function (name, options) {
  940. layout.desktop.openApplication(null, name, options);
  941. },
  942. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  943. var column = columnOrOptions;
  944. if (typeOf(columnOrOptions) == "object") {
  945. column = columnOrOptions.column;
  946. category = columnOrOptions.category;
  947. data = columnOrOptions.data;
  948. identity = columnOrOptions.identity;
  949. callback = columnOrOptions.callback;
  950. target = columnOrOptions.target;
  951. latest = columnOrOptions.latest;
  952. selectColumnEnable = columnOrOptions.selectColumnEnable;
  953. ignoreTitle = columnOrOptions.ignoreTitle;
  954. }
  955. if (target) {
  956. if (layout.app && layout.app.inBrowser) {
  957. layout.app.content.empty();
  958. layout.app = null;
  959. }
  960. }
  961. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  962. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  963. "documentData": data,
  964. "identity": identity,
  965. "ignoreTitle": ignoreTitle === true,
  966. "ignoreDrafted": latest === false,
  967. "selectColumnEnable": !category || selectColumnEnable === true,
  968. "restrictToColumn": !!category && selectColumnEnable !== true,
  969. "categoryFlag": category, //category id or name
  970. "columnFlag": column, //column id or name,
  971. "onStarted": function (documentId, data) {
  972. if (callback) callback();
  973. },
  974. "onPostLoad": function () {
  975. },
  976. "onPostPublish": function () {
  977. }
  978. });
  979. starter.load();
  980. })
  981. },
  982. "startProcess": function (app, process, data, identity, callback, target, latest) {
  983. debugger;
  984. if (arguments.length > 2) {
  985. for (var i = 2; i < arguments.length; i++) {
  986. if (typeOf(arguments[i]) == "boolean") {
  987. target = arguments[i];
  988. break;
  989. }
  990. }
  991. }
  992. if (target) {
  993. if (layout.app && layout.app.inBrowser) {
  994. //layout.app.content.empty();
  995. layout.app.$openWithSelf = true;
  996. }
  997. }
  998. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function (json) {
  999. if (json.data) {
  1000. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
  1001. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1002. "workData": data,
  1003. "identity": identity,
  1004. "latest": latest,
  1005. "onStarted": function (data, title, processName) {
  1006. var currentTask = [];
  1007. data.each(function (work) {
  1008. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1009. }.bind(this));
  1010. if (currentTask.length == 1) {
  1011. var options = { "workId": currentTask[0], "appId": currentTask[0] };
  1012. layout.desktop.openApplication(null, "process.Work", options);
  1013. } else { }
  1014. if (callback) callback(data);
  1015. }.bind(this)
  1016. });
  1017. starter.load();
  1018. }.bind(this));
  1019. }
  1020. });
  1021. },
  1022. "parameters": _form.options.parameters,
  1023. "getWidgetPrameters": function () {
  1024. if (!this.target) return null;
  1025. if (!this.target.widget) return null;
  1026. if (!this.widgetParameters) return null;
  1027. var pageId = this.target.widget.json.id;
  1028. return this.widgetParameters[pageId];
  1029. }.bind(this)
  1030. //"app": _form.app
  1031. };
  1032. // this.form.currentRouteName = _form.json.currentRouteName;
  1033. // this.form.opinion = _form.json.opinion;
  1034. this.target = ev.target;
  1035. this.event = ev.event;
  1036. this.status = ev.status;
  1037. this.session = layout.desktop.session;
  1038. this.Actions = o2.Actions;
  1039. this.query = function (option) {
  1040. // options = {
  1041. // "name": "statementName",
  1042. // "data": "json data",
  1043. // "firstResult": 1,
  1044. // "maxResults": 100,
  1045. // "success": function(){},
  1046. // "error": function(){},
  1047. // "async": true or false, default is true
  1048. // }
  1049. if (option) {
  1050. var json = (option.data) || {};
  1051. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1052. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1053. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1054. }
  1055. };
  1056. // this.Table = MWF.xScript.createTable();
  1057. };