ViewEnvironment.js 50 KB

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