ViewEnvironment.js 51 KB

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