ViewEnvironment.js 71 KB

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