ViewEnvironment.js 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508
  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, _form.Macro);
  644. }.bind(this));
  645. }.bind(this));
  646. }
  647. }
  648. };
  649. this.statement = {
  650. "execute": function (statement, callback, async) {
  651. var filterList = { "filterList": (statement.filter || null) };
  652. MWF.Actions.get("x_query_assemble_surface").execute(statement.view, statement.application, filterList, function (json) {
  653. var data = {
  654. "grid": json.data.grid,
  655. };
  656. if (callback) callback(data);
  657. }, null, async);
  658. },
  659. "select": function (statement, callback, options) {
  660. if (statement.statement) {
  661. var statementJson = {
  662. "application": statement.application || _form.json.application,
  663. "statementName": statement.statement || "",
  664. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  665. "select": (statement.isMulti === false) ? "single" : "multi",
  666. "filter": statement.filter
  667. };
  668. if (!options) options = {};
  669. options.width = statement.width;
  670. options.height = statement.height;
  671. options.title = statement.caption;
  672. var width = options.width || "700";
  673. var height = options.height || "400";
  674. if (layout.mobile) {
  675. var size = document.body.getSize();
  676. width = size.x;
  677. height = size.y;
  678. options.style = "viewmobile";
  679. }
  680. width = width.toInt();
  681. height = height.toInt();
  682. var size = _form.app.content.getSize();
  683. var x = (size.x - width) / 2;
  684. var y = (size.y - height) / 2;
  685. if (x < 0) x = 0;
  686. if (y < 0) y = 0;
  687. if (layout.mobile) {
  688. x = 20;
  689. y = 0;
  690. }
  691. var _self = this;
  692. MWF.require("MWF.xDesktop.Dialog", function () {
  693. var dlg = new MWF.xDesktop.Dialog({
  694. "title": options.title || "select statement view",
  695. "style": options.style || "view",
  696. "top": y,
  697. "left": x - 20,
  698. "fromTop": y,
  699. "fromLeft": x - 20,
  700. "width": width,
  701. "height": height,
  702. "html": "<div style='height: 100%;'></div>",
  703. "maskNode": _form.app.content,
  704. "container": _form.app.content,
  705. "buttonList": [
  706. {
  707. "text": MWF.LP.process.button.ok,
  708. "action": function () {
  709. //if (callback) callback(_self.view.selectedItems);
  710. if (callback) callback(_self.statement.getData());
  711. this.close();
  712. }
  713. },
  714. {
  715. "text": MWF.LP.process.button.cancel,
  716. "action": function () { this.close(); }
  717. }
  718. ]
  719. });
  720. dlg.show();
  721. if (layout.mobile) {
  722. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  723. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  724. if (backAction) backAction.addEvent("click", function (e) {
  725. dlg.close();
  726. }.bind(this));
  727. if (okAction) okAction.addEvent("click", function (e) {
  728. //if (callback) callback(this.view.selectedItems);
  729. if (callback) callback(this.statement.getData());
  730. dlg.close();
  731. }.bind(this));
  732. }
  733. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  734. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
  735. }.bind(this));
  736. }.bind(this));
  737. }
  738. }
  739. };
  740. //include 引用脚本
  741. //optionsOrName : {
  742. // type : "", 默认为portal, 可以为 portal process cms
  743. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  744. // name : "" // 脚本名称/别名/id
  745. //}
  746. //或者name: "" // 脚本名称/别名/id
  747. // if( !window.includedScripts ){
  748. // var includedScripts = window.includedScripts = [];
  749. // }else{
  750. // var includedScripts = window.includedScripts;
  751. // }
  752. var includedScripts = [];
  753. this.include = function (optionsOrName, callback) {
  754. var options = optionsOrName;
  755. if (typeOf(options) == "string") {
  756. options = { name: options };
  757. }
  758. var name = options.name;
  759. var type = (options.type && options.application) ? options.type : "portal";
  760. var application = options.application || _form.json.application;
  761. var key = type + "-" + application + "-" + name;
  762. if (includedScripts.indexOf(key) > -1) {
  763. if (callback) callback.apply(this);
  764. return;
  765. }
  766. //if (includedScripts.indexOf( name )> -1){
  767. // if (callback) callback.apply(this);
  768. // return;
  769. //}
  770. var scriptAction;
  771. switch (type) {
  772. case "portal":
  773. if (this.scriptActionPortal) {
  774. scriptAction = this.scriptActionPortal;
  775. } else {
  776. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  777. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  778. }
  779. break;
  780. case "process":
  781. if (this.scriptActionProcess) {
  782. scriptAction = this.scriptActionProcess;
  783. } else {
  784. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  785. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  786. }
  787. break;
  788. case "cms":
  789. if (this.scriptActionCMS) {
  790. scriptAction = this.scriptActionCMS;
  791. } else {
  792. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  793. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  794. }
  795. break;
  796. }
  797. scriptAction.getScriptByName(application, name, includedScripts, function (json) {
  798. if (json.data) {
  799. includedScripts.push(key);
  800. //名称、别名、id
  801. json.data.importedList.each( function ( flag ) {
  802. if( type === "portal" ){
  803. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  804. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  805. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  806. }else if( type === "cms" ){
  807. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  808. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  809. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  810. }else if( type === "process" ){
  811. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  812. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  813. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  814. }
  815. });
  816. includedScripts = includedScripts.concat(json.data.importedList);
  817. MWF.Macro.exec(json.data.text, this);
  818. if (callback) callback.apply(this);
  819. } else {
  820. if (callback) callback.apply(this);
  821. }
  822. }.bind(this), null, false);
  823. };
  824. this.define = function (name, fun, overwrite) {
  825. var over = true;
  826. if (overwrite === false) over = false;
  827. var o = {};
  828. o[name] = { "value": fun, "configurable": over };
  829. MWF.defineProperties(this, o);
  830. }.bind(this);
  831. //仅前台对象-----------------------------------------
  832. //form
  833. this.page = this.form = this.queryView = this.queryStatement = {
  834. "getParentEnvironment" : function () { return _form.getParentEnvironment(); }, //视图嵌入的表单或页面的上下文
  835. "getStatementInfor" : function () { return _form.getStatementInfor ? _form.getStatementInfor() : null; },
  836. "getViewInfor" : function () { return _form.getViewInfor(); },
  837. "getPageInfor" : function () { return _form.getPageInfor(); },
  838. "getPageData" : function () { return _form.getPageData(); },
  839. "toPage" : function ( pageNumber, callback ) { return _form.toPage(pageNumber, callback); },
  840. "selectAll" : function () { return _form.selectAll(); },
  841. "unSelectAll" : function () { return _form.unSelectAll(); },
  842. "getSelectedData" : function () { return _form.getSelectedData(); },
  843. "setFilter" : function ( filter ) { return _form.setFilter(filter); },
  844. "switchView" : function ( options ) { return _form.switchView(options); },
  845. "switchStatement" : function ( options ) { if(_form.switchStatement)_form.switchStatement(options) ; },
  846. "reload" : function () { _form.reload(); },
  847. // "getInfor": function () { return ev.pageInfor; },
  848. // "infor": ev.pageInfor,
  849. // "getApp": function () { return _form.app; },
  850. // "app": _form.app,
  851. "node": function () { return _form.node; },
  852. // "get": function (name) { return (_form.all) ? _form.all[name] : null; },
  853. // "getWidgetModule": function (widget, moduleName) {
  854. // if (!_form.widgetModules || !_form.widgetModules[widget]) return null;
  855. // var module = _form.widgetModules[widget][moduleName];
  856. // return module || null;
  857. // },
  858. // "getField": function (name) { return _forms[name]; },
  859. // "getAction": function () { return _form.workAction },
  860. "getDesktop": function () { return _form.app ? _form.app.desktop : null},
  861. // "getData": function () { return new MWF.xScript.JSONData(_form.getData()); },
  862. //"save": function(callback){_form.saveWork(callback);},
  863. // "close": function () { _form.closeWork(); },
  864. // "print": function (application, form) {
  865. // _form.printWork(application, form);
  866. // },
  867. "confirm": function (type, title, text, width, height, ok, cancel, callback, mask, style) {
  868. // var p = MWF.getCenter({"x": width, "y": height});
  869. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  870. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  871. if ((arguments.length <= 1) || o2.typeOf(arguments[1]) === "string") {
  872. var p = MWF.getCenter({ "x": width, "y": height });
  873. e = { "event": { "clientX": p.x, "x": p.x, "clientY": p.y, "y": p.y } };
  874. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  875. } else {
  876. e = (arguments.length > 1) ? arguments[1] : null;
  877. title = (arguments.length > 2) ? arguments[2] : null;
  878. text = (arguments.length > 3) ? arguments[3] : null;
  879. width = (arguments.length > 4) ? arguments[4] : null;
  880. height = (arguments.length > 5) ? arguments[5] : null;
  881. ok = (arguments.length > 6) ? arguments[6] : null;
  882. cancel = (arguments.length > 7) ? arguments[7] : null;
  883. callback = (arguments.length > 8) ? arguments[8] : null;
  884. mask = (arguments.length > 9) ? arguments[9] : null;
  885. style = (arguments.length > 10) ? arguments[10] : null;
  886. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  887. }
  888. },
  889. "alert": function(type, title, text, width, height){
  890. _form.alert(type, title, text, width, height);
  891. },
  892. "notice": function (content, type, target, where, offset, option) {
  893. _form.notice(content, type, target, where, offset, option);
  894. },
  895. "addEvent": function (e, f) { _form.addEvent(e, f); },
  896. // "openWindow": function (form, app) {
  897. // _form.openWindow(form, app);
  898. // },
  899. // "toPage": function (name, par, nohis) {
  900. // _form.app.toPage(name, par, nohis);
  901. // },
  902. // "toPortal": function (portal, page, par) {
  903. // _form.app.toPortal(portal, page, par);
  904. // },
  905. "openWork": function (id, completedId, title, options) {
  906. var op = options || {};
  907. op.workId = id;
  908. op.workCompletedId = completedId;
  909. op.docTitle = title;
  910. op.appId = "process.Work" + (op.workId || op.workCompletedId);
  911. return layout.desktop.openApplication(this.event, "process.Work", op);
  912. },
  913. "openJob": function (id, choice, options) {
  914. var workData = null;
  915. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function (json) {
  916. if (json.data) workData = json.data;
  917. }.bind(this), null, false);
  918. if (workData) {
  919. var len = workData.workList.length + workData.workCompletedList.length;
  920. if (len) {
  921. if (len > 1 && choice) {
  922. var node = new Element("div", { "styles": { "padding": "20px", "width": "500px" } }).inject(_form.node);
  923. workData.workList.each(function (work) {
  924. var workNode = new Element("div", {
  925. "styles": {
  926. "background": "#ffffff",
  927. "border-radius": "10px",
  928. "clear": "both",
  929. "margin-bottom": "10px",
  930. "height": "40px",
  931. "padding": "10px 10px"
  932. }
  933. }).inject(node);
  934. 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>" +
  935. "<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>" +
  936. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>" + work.title + "</div>" +
  937. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>" + work.activityName + "</div>" +
  938. "<div style='color:#999999; float: left; margin-right: 10px'>" + work.activityArrivedTime + "</div>" +
  939. "<div style='color:#999999; float: left; margin-right: 10px'>" + (work.manualTaskIdentityText || "") + "</div></div>";
  940. workNode.set("html", html);
  941. var action = workNode.getElement(".MWFAction");
  942. action.store("work", work);
  943. action.addEvent("click", function (e) {
  944. var work = e.target.retrieve("work");
  945. if (work) this.openWork(work.id, null, work.title, options);
  946. dlg.close();
  947. }.bind(this));
  948. }.bind(this));
  949. workData.workCompletedList.each(function (work) {
  950. var workNode = new Element("div", {
  951. "styles": {
  952. "background": "#ffffff",
  953. "border-radius": "10px",
  954. "clear": "both",
  955. "margin-bottom": "10px",
  956. "height": "40px",
  957. "padding": "10px 10px"
  958. }
  959. }).inject(node);
  960. 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>" +
  961. "<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>" +
  962. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>" + work.title + "</div>" +
  963. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>" + o2.LP.widget.workcompleted + "</div>" +
  964. "<div style='color:#999999; float: left; margin-right: 10px'>" + work.completedTime + "</div>";
  965. workNode.set("html", html);
  966. var action = workNode.getElement(".MWFAction");
  967. action.store("work", work);
  968. action.addEvent("click", function (e) {
  969. var work = e.target.retrieve("work");
  970. if (work) this.openWork(null, work.id, work.title, options);
  971. dlg.close();
  972. }.bind(this));
  973. }.bind(this));
  974. var height = node.getSize().y + 20;
  975. if (height > 600) height = 600;
  976. var dlg = o2.DL.open({
  977. "title": o2.LP.widget.choiceWork,
  978. "style": "user",
  979. "isResize": false,
  980. "content": node,
  981. "buttonList": [
  982. {
  983. "type": "cancel",
  984. "text": o2.LP.widget.close,
  985. "action": function () { dlg.close(); }
  986. }
  987. ]
  988. });
  989. } else {
  990. if (workData.workList.length) {
  991. var work = workData.workList[0];
  992. return this.openWork(work.id, null, work.title, options);
  993. } else {
  994. var work = workData.workCompletedList[0];
  995. return this.openWork(null, work.id, work.title, options);
  996. }
  997. }
  998. }
  999. }
  1000. },
  1001. "openDocument": function (id, title, options) {
  1002. var op = options || {};
  1003. op.documentId = id;
  1004. op.docTitle = title || "";
  1005. layout.desktop.openApplication(this.event, "cms.Document", op);
  1006. },
  1007. "openPortal": function (name, page, par) {
  1008. var action = MWF.Actions.get("x_portal_assemble_surface");
  1009. action.getApplication(name, function (json) {
  1010. if (json.data) {
  1011. if (page) {
  1012. action.getPageByName(page, json.data.id, function (pageJson) {
  1013. layout.desktop.openApplication(null, "portal.Portal", {
  1014. "portalId": json.data.id,
  1015. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1016. "parameters": par,
  1017. "appId": "portal.Portal" + json.data.id
  1018. })
  1019. });
  1020. } else {
  1021. layout.desktop.openApplication(null, "portal.Portal", {
  1022. "portalId": json.data.id,
  1023. "parameters": par,
  1024. "appId": "portal.Portal" + json.data.id
  1025. })
  1026. }
  1027. }
  1028. });
  1029. },
  1030. "openCMS": function (name) {
  1031. var action = MWF.Actions.get("x_cms_assemble_control");
  1032. action.getColumn(name, function (json) {
  1033. if (json.data) {
  1034. layout.desktop.openApplication(null, "cms.Module", {
  1035. "columnId": json.data.id,
  1036. "appId": "cms.Module" + json.data.id
  1037. });
  1038. }
  1039. });
  1040. },
  1041. "openProcess": function (name) {
  1042. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1043. action.getApplication(name, function (json) {
  1044. if (json.data) {
  1045. layout.desktop.openApplication(null, "process.Application", {
  1046. "id": json.data.id,
  1047. "appId": "process.Application" + json.data.id
  1048. });
  1049. }
  1050. });
  1051. },
  1052. "openApplication": function (name, options) {
  1053. layout.desktop.openApplication(null, name, options);
  1054. },
  1055. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1056. var column = columnOrOptions;
  1057. var onAfterPublish, onPostPublish;
  1058. if (typeOf(columnOrOptions) == "object") {
  1059. column = columnOrOptions.column;
  1060. category = columnOrOptions.category;
  1061. data = columnOrOptions.data;
  1062. identity = columnOrOptions.identity;
  1063. callback = columnOrOptions.callback;
  1064. target = columnOrOptions.target;
  1065. latest = columnOrOptions.latest;
  1066. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1067. ignoreTitle = columnOrOptions.ignoreTitle;
  1068. onAfterPublish = columnOrOptions.onAfterPublish;
  1069. onPostPublish = columnOrOptions.onPostPublish;
  1070. }
  1071. if (target) {
  1072. if (layout.app && layout.app.inBrowser) {
  1073. layout.app.content.empty();
  1074. layout.app = null;
  1075. }
  1076. }
  1077. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1078. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1079. "documentData": data,
  1080. "identity": identity,
  1081. "ignoreTitle": ignoreTitle === true,
  1082. "ignoreDrafted": latest === false,
  1083. "selectColumnEnable": !category || selectColumnEnable === true,
  1084. "restrictToColumn": !!category && selectColumnEnable !== true,
  1085. "categoryFlag": category, //category id or name
  1086. "columnFlag": column, //column id or name,
  1087. "onStarted": function (documentId, data) {
  1088. if (callback) callback();
  1089. },
  1090. "onPostPublish": function () {
  1091. if(onPostPublish)onPostPublish();
  1092. },
  1093. "onAfterPublish": function () {
  1094. if(onAfterPublish)onAfterPublish();
  1095. }
  1096. });
  1097. starter.load();
  1098. })
  1099. },
  1100. "startProcess": function (app, process, data, identity, callback, target, latest) {
  1101. debugger;
  1102. if (arguments.length > 2) {
  1103. for (var i = 2; i < arguments.length; i++) {
  1104. if (typeOf(arguments[i]) == "boolean") {
  1105. target = arguments[i];
  1106. break;
  1107. }
  1108. }
  1109. }
  1110. if (target) {
  1111. if (layout.app && layout.app.inBrowser) {
  1112. //layout.app.content.empty();
  1113. layout.app.$openWithSelf = true;
  1114. }
  1115. }
  1116. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function (json) {
  1117. if (json.data) {
  1118. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
  1119. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1120. "workData": data,
  1121. "identity": identity,
  1122. "latest": latest,
  1123. "onStarted": function (data, title, processName) {
  1124. if (data.work){
  1125. var work = data.work;
  1126. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1127. layout.desktop.openApplication(null, "process.Work", options);
  1128. }else{
  1129. var currentTask = [];
  1130. data.each(function(work){
  1131. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1132. }.bind(this));
  1133. if (currentTask.length==1){
  1134. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1135. layout.desktop.openApplication(null, "process.Work", options);
  1136. }else{}
  1137. }
  1138. // var currentTask = [];
  1139. // data.each(function (work) {
  1140. // if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1141. // }.bind(this));
  1142. //
  1143. // if (currentTask.length == 1) {
  1144. // var options = { "workId": currentTask[0], "appId": currentTask[0] };
  1145. // layout.desktop.openApplication(null, "process.Work", options);
  1146. // } else { }
  1147. if (callback) callback(data);
  1148. }.bind(this)
  1149. });
  1150. starter.load();
  1151. }.bind(this));
  1152. }
  1153. });
  1154. }
  1155. //"app": _form.app
  1156. };
  1157. // this.form.currentRouteName = _form.json.currentRouteName;
  1158. // this.form.opinion = _form.json.opinion;
  1159. this.target = ev.target;
  1160. this.event = ev.event;
  1161. this.status = ev.status;
  1162. this.session = layout.desktop.session;
  1163. this.Actions = o2.Actions;
  1164. this.query = function (option) {
  1165. // options = {
  1166. // "name": "statementName",
  1167. // "data": "json data",
  1168. // "firstResult": 1,
  1169. // "maxResults": 100,
  1170. // "success": function(){},
  1171. // "error": function(){},
  1172. // "async": true or false, default is true
  1173. // }
  1174. if (option) {
  1175. var json = (option.data) || {};
  1176. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1177. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1178. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1179. }
  1180. };
  1181. // this.Table = MWF.xScript.createTable();
  1182. };
  1183. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  1184. if( !MWF.xScript.createDict ){
  1185. MWF.xScript.addDictToCache = function ( options, path, json ) {
  1186. if( !path )path = "root";
  1187. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1188. var type = options.appType || "process";
  1189. var enableAnonymous = options.enableAnonymous || false;
  1190. var appFlagList = [];
  1191. if( options.application )appFlagList.push( options.application );
  1192. if( options.appId )appFlagList.push( options.appId );
  1193. if( options.appName )appFlagList.push( options.appName );
  1194. if( options.appAlias )appFlagList.push( options.appAlias );
  1195. var dictFlagList = [];
  1196. if( options.id )dictFlagList.push( options.id );
  1197. if( options.name )dictFlagList.push( options.name );
  1198. if( options.alias )dictFlagList.push( options.alias );
  1199. var cache = {};
  1200. cache[path] = json;
  1201. for( var i=0; i<appFlagList.length; i++ ){
  1202. for( var j=0; j<dictFlagList.length; j++ ){
  1203. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  1204. if( !MWF.xScript.dictLoaded[k] ){
  1205. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  1206. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  1207. }else if( i===0 && j===0 ){
  1208. MWF.xScript.setDictToCache( k, path ,json );
  1209. var arr = path.split(/\./g);
  1210. var p;
  1211. var cache = MWF.xScript.dictLoaded[k];
  1212. for( var l=0 ; l<arr.length; l++ ){
  1213. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  1214. if( cache[ p ] )break;
  1215. }
  1216. if( p ){
  1217. var mathP = p+".";
  1218. Object.keys( cache ).each( function( path, idx){
  1219. if( path.indexOf( mathP ) === 0 )delete cache[path];
  1220. })
  1221. }
  1222. }
  1223. }
  1224. }
  1225. };
  1226. MWF.xScript.getMatchedDict = function(key, path){
  1227. if( !path )path = "root";
  1228. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1229. var arr = path.split(/\./g);
  1230. if( MWF.xScript.dictLoaded[key] ){
  1231. var dicts = MWF.xScript.dictLoaded[key];
  1232. var list = Array.clone(arr);
  1233. var p;
  1234. var dict;
  1235. for( var i=0 ; i<arr.length; i++ ){
  1236. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  1237. list.shift();
  1238. if( dicts[ p ] ){
  1239. dict = dicts[ p ];
  1240. break;
  1241. }
  1242. }
  1243. return {
  1244. dict : dict,
  1245. unmatchedPathList : list
  1246. }
  1247. }
  1248. return {
  1249. dict : null,
  1250. unmatchedPathList : list
  1251. }
  1252. };
  1253. MWF.xScript.insertDictToCache = function(key, path, json){
  1254. if( MWF.xScript.dictLoaded[key] ){
  1255. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1256. var dict = matchedDict.dict;
  1257. var list = matchedDict.unmatchedPathList;
  1258. if( !dict ){
  1259. MWF.xScript.dictLoaded[key][path] = json;
  1260. }else{
  1261. for( var j=0; j<list.length-1; j++ ){
  1262. if( !dict[ list[j] ] ){
  1263. dict[ list[j] ] = {};
  1264. }
  1265. dict = dict[ list[j] ];
  1266. }
  1267. var lastPath = list[list.length-1];
  1268. if( !dict[lastPath] ){
  1269. dict[lastPath] = json;
  1270. }else if( typeOf( dict[lastPath] ) === "array" ){
  1271. dict[lastPath].push( json );
  1272. }
  1273. }
  1274. }else{
  1275. MWF.xScript.dictLoaded[key] = {};
  1276. MWF.xScript.dictLoaded[key][path] = json;
  1277. }
  1278. };
  1279. MWF.xScript.setDictToCache = function(key, path, json){
  1280. if( MWF.xScript.dictLoaded[key] ){
  1281. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1282. var dict = matchedDict.dict;
  1283. var list = matchedDict.unmatchedPathList;
  1284. if( !dict ){
  1285. MWF.xScript.dictLoaded[key][path] = json;
  1286. }else{
  1287. for( var j=0; j<list.length-1; j++ ){
  1288. if( !dict[ list[j] ] ){
  1289. dict[ list[j] ] = {};
  1290. }
  1291. dict = dict[ list[j] ];
  1292. }
  1293. dict[list[list.length-1]] = json;
  1294. }
  1295. }else{
  1296. MWF.xScript.dictLoaded[key] = {};
  1297. MWF.xScript.dictLoaded[key][path] = json;
  1298. }
  1299. };
  1300. MWF.xScript.getDictFromCache = function( key, path ){
  1301. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1302. var dict = matchedDict.dict;
  1303. var list = matchedDict.unmatchedPathList;
  1304. if( dict ){
  1305. for( var j=0; j<list.length; j++ ){
  1306. dict = dict[ list[j] ];
  1307. if( !dict )return null;
  1308. }
  1309. return dict;
  1310. }
  1311. return null;
  1312. };
  1313. MWF.xScript.deleteDictToCache = function(key, path){
  1314. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1315. var dict = matchedDict.dict;
  1316. var list = matchedDict.unmatchedPathList;
  1317. if( dict){
  1318. for( var j=0; j<list.length-1; j++ ){
  1319. dict = dict[ list[j] ];
  1320. if( !dict )return;
  1321. }
  1322. delete dict[list[list.length-1]];
  1323. }
  1324. };
  1325. MWF.xScript.createDict = function(application){
  1326. //optionsOrName : {
  1327. // type : "", //默认为process, 可以为 process cms
  1328. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1329. // name : "", // 数据字典名称/别名/id
  1330. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1331. //}
  1332. //或者name: "" // 数据字典名称/别名/id
  1333. return function(optionsOrName){
  1334. var options = optionsOrName;
  1335. if( typeOf( options ) == "string" ){
  1336. options = { name : options };
  1337. }
  1338. var name = this.name = options.name;
  1339. var type = ( options.type && options.application ) ? options.type : "process";
  1340. var applicationId = options.application || application;
  1341. var enableAnonymous = options.enableAnonymous || false;
  1342. var opt = {
  1343. "appType" : type,
  1344. "name" : name,
  1345. "appId" : applicationId,
  1346. "enableAnonymous" : enableAnonymous
  1347. };
  1348. var key = name+type+applicationId+enableAnonymous;
  1349. // if (!dictLoaded[key]) dictLoaded[key] = {};
  1350. // this.dictData = dictLoaded[key];
  1351. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1352. if( type == "cms" ){
  1353. var action = MWF.Actions.get("x_cms_assemble_control");
  1354. }else{
  1355. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1356. }
  1357. var encodePath = function( path ){
  1358. var arr = path.split(/\./g);
  1359. var ar = arr.map(function(v){
  1360. return encodeURIComponent(v);
  1361. });
  1362. return ar.join("/");
  1363. };
  1364. this.get = function(path, success, failure, async, refresh){
  1365. var value = null;
  1366. if (!refresh ){
  1367. var data = MWF.xScript.getDictFromCache( key, path );
  1368. if( data ){
  1369. if (success) success( data );
  1370. return data;
  1371. }
  1372. }
  1373. if (path){
  1374. var p = encodePath( path );
  1375. //var p = path.replace(/\./g, "/");
  1376. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1377. value = json.data;
  1378. // this.dictData[path] = value;
  1379. MWF.xScript.addDictToCache(opt, path, value);
  1380. if (success) success(json.data);
  1381. }.bind(this), function(xhr, text, error){
  1382. if (failure) failure(xhr, text, error);
  1383. }, !!async, false);
  1384. }else{
  1385. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1386. value = json.data;
  1387. // this.dictData["root"] = value;
  1388. MWF.xScript.addDictToCache(opt, path, value);
  1389. if (success) success(json.data);
  1390. }.bind(this), function(xhr, text, error){
  1391. if (failure) failure(xhr, text, error);
  1392. }, !!async);
  1393. }
  1394. return value;
  1395. };
  1396. this.set = function(path, value, success, failure){
  1397. var p = encodePath( path );
  1398. //var p = path.replace(/\./g, "/");
  1399. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1400. MWF.xScript.setDictToCache(key, path, value);
  1401. if (success) success(json.data);
  1402. }, function(xhr, text, error){
  1403. if (failure) failure(xhr, text, error);
  1404. }, false, false);
  1405. };
  1406. this.add = function(path, value, success, failure){
  1407. var p = encodePath( path );
  1408. //var p = path.replace(/\./g, "/");
  1409. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1410. MWF.xScript.insertDictToCache(key, path, value);
  1411. if (success) success(json.data);
  1412. }, function(xhr, text, error){
  1413. if (failure) failure(xhr, text, error);
  1414. }, false, false);
  1415. };
  1416. this["delete"] = function(path, success, failure){
  1417. var p = encodePath( path );
  1418. //var p = path.replace(/\./g, "/");
  1419. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1420. MWF.xScript.deleteDictToCache(key, path);
  1421. if (success) success(json.data);
  1422. }, function(xhr, text, error){
  1423. if (failure) failure(xhr, text, error);
  1424. }, false, false);
  1425. };
  1426. this.destory = this["delete"];
  1427. }
  1428. };
  1429. }