ViewEnvironment.js 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  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, async){
  51. getOrgActions();
  52. var data = {"groupList": getNameFlag(name)};
  53. var v = null;
  54. var cb = function(json){
  55. v = json.data;
  56. v = (v && v.length===1) ? v[0] : v
  57. if (async && o2.typeOf(async)=="function") return async(v);
  58. return v;
  59. }.ag().catch(function(json){ return json; });
  60. orgActions.listGroup(data, cb, null, !!async);
  61. return (!!async) ? cb : v;
  62. // var v = null;
  63. // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  64. // return (v && v.length===1) ? v[0] : v;
  65. },
  66. //查询下级群组--返回群组的对象数组
  67. //nested 布尔 true嵌套下级;false直接下级;默认false;
  68. listSubGroup: function(name, nested, async){
  69. getOrgActions();
  70. var data = {"groupList": getNameFlag(name)};
  71. var v = null;
  72. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  73. // v = json.data;
  74. // return v;
  75. // }.ag().catch(function(json){ return json; });
  76. var cb = function(json){
  77. v = json.data;
  78. if (async && o2.typeOf(async)=="function") return async(v);
  79. return v;
  80. }.ag().catch(function(json){ return json; });
  81. if (nested){
  82. orgActions.listSubGroupNested(data, cb, null, !!async);
  83. }else{
  84. orgActions.listSubGroupDirect(data, cb, null, !!async);
  85. }
  86. return (!!async) ? cb : v;
  87. // var v = null;
  88. // if (nested){
  89. // orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  90. // }else{
  91. // orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  92. // }
  93. // return v;
  94. },
  95. //查询上级群组--返回群组的对象数组
  96. //nested 布尔 true嵌套上级;false直接上级;默认false;
  97. listSupGroup:function(name, nested, async){
  98. getOrgActions();
  99. var data = {"groupList": getNameFlag(name)};
  100. var v = null;
  101. var cb = function(json){
  102. v = json.data;
  103. if (async && o2.typeOf(async)=="function") return async(v);
  104. return v;
  105. }.ag().catch(function(json){ return json; });
  106. if (nested){
  107. orgActions.listSupGroupNested(data, cb, null, !!async);
  108. }else{
  109. orgActions.listSupGroupDirect(data, cb, null, !!async);
  110. }
  111. return (!!async) ? cb : v;
  112. // var v = null;
  113. // if (nested){
  114. // orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  115. // }else{
  116. // orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  117. // }
  118. // return v;
  119. },
  120. //人员所在群组(嵌套)--返回群组的对象数组
  121. listGroupWithPerson:function(name, async){
  122. getOrgActions();
  123. var data = {"personList": getNameFlag(name)};
  124. var v = null;
  125. var cb = function(json){
  126. v = json.data;
  127. if (async && o2.typeOf(async)=="function") return async(v);
  128. return v;
  129. }.ag().catch(function(json){ return json; });
  130. orgActions.listGroupWithPerson(data, cb, null, !!async);
  131. return (!!async) ? cb : v;
  132. // var v = null;
  133. // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  134. // return v;
  135. },
  136. //群组是否拥有角色--返回true, false
  137. groupHasRole: function(name, role, async){
  138. getOrgActions();
  139. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  140. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  141. var v = false;
  142. var cb = function(json){
  143. v = json.data.value;
  144. if (async && o2.typeOf(async)=="function") return async(v);
  145. return v;
  146. }.ag().catch(function(json){ return json; });
  147. orgActions.groupHasRole(data, cb, null, !!async);
  148. return (!!async) ? cb : v;
  149. // var v = false;
  150. // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  151. // return v;
  152. },
  153. //角色***************
  154. //获取角色--返回角色的对象数组
  155. getRole: function(name, async){
  156. getOrgActions();
  157. var data = {"roleList": getNameFlag(name)};
  158. var v = null;
  159. var cb = function(json){
  160. v = json.data;
  161. v = (v && v.length===1) ? v[0] : v;
  162. if (async && o2.typeOf(async)=="function") return async(v);
  163. return v;
  164. }.ag().catch(function(json){ return json; });
  165. orgActions.listRole(data, cb, null, !!async);
  166. return (!!async) ? cb : v;
  167. // var v = null;
  168. // orgActions.listRole(data, function(json){v = json.data;}, null, false);
  169. // return (v && v.length===1) ? v[0] : v;
  170. },
  171. //人员所有角色(嵌套)--返回角色的对象数组
  172. listRoleWithPerson:function(name, async){
  173. getOrgActions();
  174. var data = {"personList": getNameFlag(name)};
  175. var v = null;
  176. var cb = function(json){
  177. v = json.data;
  178. if (async && o2.typeOf(async)=="function") return async(v);
  179. return v;
  180. }.ag().catch(function(json){ return json; });
  181. orgActions.listRoleWithPerson(data, cb, null, !!async);
  182. return (!!async) ? cb : v;
  183. // var v = null;
  184. // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  185. // return v;
  186. },
  187. //人员***************
  188. //人员是否拥有角色--返回true, false
  189. personHasRole: function(name, role, async){
  190. getOrgActions();
  191. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  192. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  193. var v = false;
  194. var cb = function(json){
  195. v = json.data.value;
  196. if (async && o2.typeOf(async)=="function") return async(v);
  197. return v;
  198. }.ag().catch(function(json){ return json; });
  199. orgActions.listRoleWithPerson(data, cb, null, !!async);
  200. return (!!async) ? cb : v;
  201. // var v = false;
  202. // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  203. // return v;
  204. },
  205. //获取人员--返回人员的对象数组
  206. getPerson: function(name, async){
  207. getOrgActions();
  208. var data = {"personList": getNameFlag(name)};
  209. var v = null;
  210. var cb = function(json){
  211. v = json.data;
  212. v = (v && v.length===1) ? v[0] : v;
  213. if (async && o2.typeOf(async)=="function") return async(v);
  214. return v;
  215. }.ag().catch(function(json){ return json; });
  216. orgActions.listPerson(data, cb, null, !!async);
  217. return (!!async) ? cb : v;
  218. // var v = null;
  219. // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  220. // return (v && v.length===1) ? v[0] : v;
  221. },
  222. //查询下级人员--返回人员的对象数组
  223. //nested 布尔 true嵌套下级;false直接下级;默认false;
  224. listSubPerson: function(name, nested, async){
  225. getOrgActions();
  226. var data = {"personList": getNameFlag(name)};
  227. var v = null;
  228. var cb = function(json){
  229. v = json.data;
  230. if (async && o2.typeOf(async)=="function") return async(v);
  231. return v;
  232. }.ag().catch(function(json){ return json; });
  233. if (nested){
  234. orgActions.listPersonSubNested(data, cb, null, !!async);
  235. }else{
  236. orgActions.listPersonSubDirect(data, cb, null, !!async);
  237. }
  238. return (!!async) ? cb : v;
  239. },
  240. //查询上级人员--返回人员的对象数组
  241. //nested 布尔 true嵌套上级;false直接上级;默认false;
  242. listSupPerson: function(name, nested, async){
  243. getOrgActions();
  244. var data = {"personList": getNameFlag(name)};
  245. var v = null;
  246. var cb = function(json){
  247. v = json.data;
  248. if (async && o2.typeOf(async)=="function") return async(v);
  249. return v;
  250. }.ag().catch(function(json){ return json; });
  251. if (nested){
  252. orgActions.listPersonSupNested(data, cb, null, !!async);
  253. }else{
  254. orgActions.listPersonSupDirect(data, cb, null, !!async);
  255. }
  256. return (!!async) ? cb : v;
  257. },
  258. //获取群组的所有人员--返回人员的对象数组
  259. listPersonWithGroup: function(name, async){
  260. getOrgActions();
  261. var data = {"groupList": getNameFlag(name)};
  262. var v = null;
  263. var cb = function(json){
  264. v = json.data;
  265. if (async && o2.typeOf(async)=="function") return async(v);
  266. return v;
  267. }.ag().catch(function(json){ return json; });
  268. orgActions.listPersonWithGroup(data, cb, null, !!async);
  269. return (!!async) ? cb : v;
  270. },
  271. //获取角色的所有人员--返回人员的对象数组
  272. listPersonWithRole: function(name, async){
  273. getOrgActions();
  274. var data = {"roleList": getNameFlag(name)};
  275. var v = null;
  276. var cb = function(json){
  277. v = json.data;
  278. if (async && o2.typeOf(async)=="function") return async(v);
  279. return v;
  280. }.ag().catch(function(json){ return json; });
  281. orgActions.listPersonWithRole(data, cb, null, !!async);
  282. return (!!async) ? cb : v;
  283. },
  284. //获取身份的所有人员--返回人员的对象数组
  285. listPersonWithIdentity: function(name, async){
  286. getOrgActions();
  287. var data = {"identityList": getNameFlag(name)};
  288. var v = null;
  289. var cb = function(json){
  290. v = json.data;
  291. if (async && o2.typeOf(async)=="function") return async(v);
  292. return v;
  293. }.ag().catch(function(json){ return json; });
  294. orgActions.listPersonWithIdentity(data, cb, null, !!async);
  295. return (!!async) ? cb : v;
  296. },
  297. //获取身份的所有人员--返回人员的对象数组或人员对象
  298. getPersonWithIdentity: function(name, async){
  299. getOrgActions();
  300. var data = {"identityList": getNameFlag(name)};
  301. var v = null;
  302. var cb = function(json){
  303. v = json.data;
  304. v = (v && v.length===1) ? v[0] : v;
  305. if (async && o2.typeOf(async)=="function") return async(v);
  306. return v;
  307. }.ag().catch(function(json){ return json; });
  308. orgActions.listPersonWithIdentity(data, cb, null, !!async);
  309. return (!!async) ? cb : v;
  310. },
  311. //查询组织成员的人员--返回人员的对象数组
  312. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  313. listPersonWithUnit: function(name, nested, async){
  314. getOrgActions();
  315. var data = {"unitList": getNameFlag(name)};
  316. var v = null;
  317. var cb = function(json){
  318. v = json.data;
  319. if (async && o2.typeOf(async)=="function") return async(v);
  320. return v;
  321. }.ag().catch(function(json){ return json; });
  322. if (nested){
  323. orgActions.listPersonWithUnitNested(data, cb, null, !!async);
  324. }else{
  325. orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
  326. }
  327. return (!!async) ? cb : v;
  328. },
  329. //根据属性查询人员--返回人员的对象数组
  330. //name string 属性名
  331. //value string 属性值
  332. listPersonWithAttribute: function(name, value, async){
  333. getOrgActions();
  334. var data = {"name": name, "attribute": value};
  335. var v = null;
  336. var cb = function(json){
  337. v = json.data;
  338. if (async && o2.typeOf(async)=="function") return async(v);
  339. return v;
  340. }.ag().catch(function(json){ return json; });
  341. orgActions.listPersonWithAttribute(data, cb, null, !!async);
  342. return (!!async) ? cb : v;
  343. },
  344. //根据属性查询人员--返回人员的全称数组
  345. //name string 属性名
  346. //value string 属性值
  347. listPersonNameWithAttribute: function(name, value, async){
  348. getOrgActions();
  349. var data = {"name": name, "attribute": value};
  350. var v = null;
  351. var cb = function(json){
  352. v = json.data.personList;
  353. if (async && o2.typeOf(async)=="function") return async(v);
  354. return v;
  355. }.ag().catch(function(json){ return json; });
  356. orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
  357. return (!!async) ? cb : v;
  358. },
  359. //人员属性************
  360. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  361. appendPersonAttribute: function(person, attr, values, success, failure, async){
  362. getOrgActions();
  363. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  364. var data = {"attributeList":values,"name":attr,"person":personFlag};
  365. var cb = function(json){
  366. if (success) return success(json);
  367. }.ag().catch(function(xhr, text, error){
  368. if (failure) return failure(xhr, text, error);
  369. });
  370. orgActions.appendPersonAttribute(data, cb, null, !!async);
  371. },
  372. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  373. setPersonAttribute: function(person, attr, values, success, failure, async){
  374. getOrgActions();
  375. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  376. var data = {"attributeList":values,"name":attr,"person":personFlag};
  377. var cb = function(json){
  378. if (success) return success(json);
  379. }.ag().catch(function(xhr, text, error){
  380. if (failure) return failure(xhr, text, error);
  381. });
  382. orgActions.setPersonAttribute(data, cb, null, !!async);
  383. },
  384. //获取人员属性值
  385. getPersonAttribute: function(person, attr, async){
  386. getOrgActions();
  387. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  388. var data = {"name":attr,"person":personFlag};
  389. var v = null;
  390. var cb = function(json){
  391. v = json.data.attributeList;
  392. if (async && o2.typeOf(async)=="function") return async(v);
  393. return v;
  394. }.ag().catch(function(json){ return json; });
  395. orgActions.getPersonAttribute(data, cb, null, !!async);
  396. return (!!async) ? cb : v;
  397. },
  398. //列出人员所有属性的名称
  399. listPersonAttributeName: function(name, async){
  400. getOrgActions();
  401. var data = {"personList":getNameFlag(name)};
  402. var v = null;
  403. var cb = function(json){
  404. v = json.data.nameList;
  405. if (async && o2.typeOf(async)=="function") return async(v);
  406. return v;
  407. }.ag().catch(function(json){ return json; });
  408. orgActions.listPersonAttributeName(data, cb, null, !!async);
  409. return (!!async) ? cb : v;
  410. },
  411. //列出人员的所有属性
  412. listPersonAllAttribute: function(name, async){
  413. getOrgActions();
  414. var data = {"personList":getNameFlag(name)};
  415. var v = null;
  416. var cb = function(json){
  417. v = json.data;
  418. if (async && o2.typeOf(async)=="function") return async(v);
  419. return v;
  420. }.ag().catch(function(json){ return json; });
  421. orgActions.listPersonAllAttribute(data, cb, null, !!async);
  422. return (!!async) ? cb : v;
  423. },
  424. //身份**********
  425. //获取身份
  426. getIdentity: function(name, async){
  427. getOrgActions();
  428. var data = {"identityList":getNameFlag(name)};
  429. var v = null;
  430. var cb = function(json){
  431. v = json.data;
  432. v = (v && v.length===1) ? v[0] : v;
  433. if (async && o2.typeOf(async)=="function") return async(v);
  434. return v;
  435. }.ag().catch(function(json){ return json; });
  436. orgActions.listIdentity(data, cb, null, !!async);
  437. return (!!async) ? cb : v;
  438. },
  439. //列出人员的身份
  440. listIdentityWithPerson: function(name, async){
  441. getOrgActions();
  442. var data = {"personList":getNameFlag(name)};
  443. var v = null;
  444. var cb = function(json){
  445. v = json.data;
  446. if (async && o2.typeOf(async)=="function") return async(v);
  447. return v;
  448. }.ag().catch(function(json){ return json; });
  449. orgActions.listIdentityWithPerson(data, cb, null, !!async);
  450. return (!!async) ? cb : v;
  451. },
  452. //查询组织成员身份--返回身份的对象数组
  453. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  454. listIdentityWithUnit: function(name, nested, async){
  455. getOrgActions();
  456. var data = {"unitList": getNameFlag(name)};
  457. var v = null;
  458. var cb = function(json){
  459. v = json.data;
  460. if (async && o2.typeOf(async)=="function") return async(v);
  461. return v;
  462. }.ag().catch(function(json){ return json; });
  463. if (nested){
  464. orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
  465. }else{
  466. orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
  467. }
  468. return (!!async) ? cb : v;
  469. },
  470. //组织**********
  471. //获取组织
  472. getUnit: function(name, async){
  473. getOrgActions();
  474. var data = {"unitList":getNameFlag(name)};
  475. var v = null;
  476. var cb = function(json){
  477. v = json.data;
  478. v = (v && v.length===1) ? v[0] : v;
  479. if (async && o2.typeOf(async)=="function") return async(v);
  480. return v;
  481. }.ag().catch(function(json){ return json; });
  482. orgActions.listUnit(data, cb, null, !!async);
  483. return (!!async) ? cb : v;
  484. },
  485. //查询组织的下级--返回组织的对象数组
  486. //nested 布尔 true嵌套下级;false直接下级;默认false;
  487. listSubUnit: function(name, nested){
  488. getOrgActions();
  489. var data = {"unitList": getNameFlag(name)};
  490. var v = null;
  491. var cb = function(json){
  492. v = json.data;
  493. if (async && o2.typeOf(async)=="function") return async(v);
  494. return v;
  495. }.ag().catch(function(json){ return json; });
  496. if (nested){
  497. orgActions.listUnitSubNested(data, cb, null, !!async);
  498. }else{
  499. orgActions.listUnitSubDirect(data, cb, null, !!async);
  500. }
  501. return (!!async) ? cb : v;
  502. },
  503. //查询组织的上级--返回组织的对象数组
  504. //nested 布尔 true嵌套上级;false直接上级;默认false;
  505. //async 布尔 true异步请求
  506. listSupUnit: function(name, nested, async){
  507. getOrgActions();
  508. var data = {"unitList": getNameFlag(name)};
  509. var v = null;
  510. var cb = function(json){
  511. v = json.data;
  512. if (async && o2.typeOf(async)=="function") return async(v);
  513. return v;
  514. }.ag().catch(function(json){ return json; });
  515. if (nested){
  516. orgActions.listUnitSupNested(data, cb, null, !!async);
  517. }else{
  518. orgActions.listUnitSupDirect(data, cb, null, !!async);
  519. }
  520. return (!!async) ? cb : v;
  521. // if (callback){
  522. // if (nested){
  523. // orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  524. // }else{
  525. // orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
  526. // }
  527. // }else{
  528. // var v = null;
  529. // if (nested){
  530. // orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  531. // }else{
  532. // orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  533. // }
  534. // return v;
  535. // }
  536. },
  537. //根据个人身份获取组织
  538. //flag 数字 表示获取第几层的组织
  539. // 字符串 表示获取指定类型的组织
  540. // 空 表示获取直接所在的组织
  541. getUnitByIdentity: function(name, flag, async){
  542. getOrgActions();
  543. var getUnitMethod = "current";
  544. var v;
  545. if (flag){
  546. if (typeOf(flag)==="string") getUnitMethod = "type";
  547. if (typeOf(flag)==="number") getUnitMethod = "level";
  548. }
  549. var cb;
  550. switch (getUnitMethod){
  551. case "current":
  552. var data = {"identityList":getNameFlag(name)};
  553. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  554. // v = json.data; v=(v&&v.length===1) ? v[0] : v; return v;
  555. // }.ag().catch(function(json){ return json; });
  556. var cb = function(json){
  557. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  558. if (async && o2.typeOf(async)=="function") return async(v);
  559. return v;
  560. }.ag().catch(function(json){ return json; });
  561. orgActions.listUnitWithIdentity(data, cb, null, !!async);
  562. break;
  563. case "type":
  564. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  565. var cb = function(json){
  566. v = json.data;
  567. if (async && o2.typeOf(async)=="function") return async(v);
  568. return v;
  569. }.ag().catch(function(json){ return json; });
  570. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  571. // v = json.data; return v;
  572. // }.ag().catch(function(json){ return json; });
  573. orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
  574. break;
  575. case "level":
  576. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  577. var cb = function(json){
  578. v = json.data; v=(v&&v.length===1) ? v[0] : v;
  579. if (async && o2.typeOf(async)=="function") return async(v);
  580. return v;
  581. }.ag().catch(function(json){ return json; });
  582. // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
  583. // v = json.data; return v;
  584. // }.ag().catch(function(json){ return json; });
  585. orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
  586. break;
  587. }
  588. return (!!async) ? cb : v;
  589. },
  590. //列出身份所在组织的所有上级组织
  591. listAllSupUnitWithIdentity: function(name, async){
  592. getOrgActions();
  593. var data = {"identityList":getNameFlag(name)};
  594. var v = null;
  595. var cb = function(json){
  596. v = json.data;
  597. if (async && o2.typeOf(async)=="function") return async(v);
  598. return v;
  599. }.ag().catch(function(json){ return json; });
  600. orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
  601. return (!!async) ? cb : v;
  602. },
  603. //获取人员所在的所有组织
  604. listUnitWithPerson: function(name, async){
  605. getOrgActions();
  606. var data = {"personList":getNameFlag(name)};
  607. var v = null;
  608. var cb = function(json){
  609. v = json.data;
  610. if (async && o2.typeOf(async)=="function") return async(v);
  611. return v;
  612. }.ag().catch(function(json){ return json; });
  613. orgActions.listUnitWithPerson(data, cb, null, !!async);
  614. return (!!async) ? cb : v;
  615. },
  616. //列出人员所在组织的所有上级组织
  617. listAllSupUnitWithPerson: function(name, async){
  618. getOrgActions();
  619. var data = {"personList":getNameFlag(name)};
  620. var v = null;
  621. var cb = function(json){
  622. v = json.data;
  623. if (async && o2.typeOf(async)=="function") return async(v);
  624. return v;
  625. }.ag().catch(function(json){ return json; });
  626. orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
  627. return (!!async) ? cb : v;
  628. },
  629. //根据组织属性,获取所有符合的组织
  630. listUnitWithAttribute: function(name, attribute, async){
  631. getOrgActions();
  632. var data = {"name":name,"attribute":attribute};
  633. var v = null;
  634. var cb = function(json){
  635. v = json.data;
  636. if (async && o2.typeOf(async)=="function") return async(v);
  637. return v;
  638. }.ag().catch(function(json){ return json; });
  639. orgActions.listUnitWithAttribute(data, cb, null, !!async);
  640. return (!!async) ? cb : v;
  641. },
  642. //根据组织职务,获取所有符合的组织
  643. listUnitWithDuty: function(name, id, async){
  644. getOrgActions();
  645. var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  646. var v = null;
  647. var cb = function(json){
  648. v = json.data;
  649. if (async && o2.typeOf(async)=="function") return async(v);
  650. return v;
  651. }.ag().catch(function(json){ return json; });
  652. orgActions.listUnitWithDuty(data, cb, null, !!async);
  653. return (!!async) ? cb : v;
  654. },
  655. //组织职务***********
  656. //获取指定的组织职务的身份
  657. getDuty: function(duty, id, async){
  658. getOrgActions();
  659. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  660. var v = null;
  661. var cb = function(json){
  662. v = json.data;
  663. if (async && o2.typeOf(async)=="function") return async(v);
  664. return v;
  665. }.ag().catch(function(json){ return json; });
  666. orgActions.getDuty(data, cb, null, !!async);
  667. return (!!async) ? cb : v;
  668. },
  669. //获取身份的所有职务名称
  670. listDutyNameWithIdentity: function(name, async){
  671. getOrgActions();
  672. var data = {"identityList":getNameFlag(name)};
  673. var v = null;
  674. var cb = function(json){
  675. v = json.data;
  676. if (async && o2.typeOf(async)=="function") return async(v);
  677. return v;
  678. }.ag().catch(function(json){ return json; });
  679. orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
  680. return (!!async) ? cb : v;
  681. },
  682. //获取组织的所有职务名称
  683. listDutyNameWithUnit: function(name, async){
  684. getOrgActions();
  685. var data = {"unitList":getNameFlag(name)};
  686. var v = null;
  687. var cb = function(json){
  688. v = json.data.nameList;
  689. if (async && o2.typeOf(async)=="function") return async(v);
  690. return v;
  691. }.ag().catch(function(json){ return json; });
  692. orgActions.listDutyNameWithUnit(data, cb, null, !!async);
  693. return (!!async) ? cb : v;
  694. },
  695. //获取组织的所有职务
  696. listUnitAllDuty: function(name, async){
  697. getOrgActions();
  698. var data = {"unitList":getNameFlag(name)};
  699. var v = null;
  700. var cb = function(json){
  701. v = json.data;
  702. if (async && o2.typeOf(async)=="function") return async(v);
  703. return v;
  704. }.ag().catch(function(json){ return json; });
  705. orgActions.listUnitAllDuty(data, cb, null, !!async);
  706. return (!!async) ? cb : v;
  707. },
  708. //列出顶层组织
  709. listTopUnit: function(async){
  710. var action = MWF.Actions.get("x_organization_assemble_control");
  711. var v = null;
  712. var cb = function(json){
  713. v = json.data;
  714. if (async && o2.typeOf(async)=="function") return async(v);
  715. return v;
  716. }.ag().catch(function(json){ return json; });
  717. action.listTopUnit(cb, null, !!async);
  718. return (!!async) ? cb : v;
  719. },
  720. //组织属性**************
  721. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  722. appendUnitAttribute: function(unit, attr, values, success, failure, async){
  723. getOrgActions();
  724. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  725. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  726. var cb = function(json){
  727. if (success) return success(json);
  728. }.ag().catch(function(xhr, text, error){
  729. if (failure) return failure(xhr, text, error);
  730. });
  731. orgActions.appendPersonAttribute(data, cb, null, !!async);
  732. // orgActions.appendUnitAttribute(data, function(json){
  733. // if (json.data.value){
  734. // if (success) success();
  735. // }else{
  736. // if (failure) failure(null, "", "append values failed");
  737. // }
  738. // }, function(xhr, text, error){
  739. // if (failure) failure(xhr, text, error);
  740. // }, false);
  741. },
  742. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  743. setUnitAttribute: function(unit, attr, values, success, failure, async){
  744. getOrgActions();
  745. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  746. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  747. var cb = function(json){
  748. if (success) return success(json);
  749. }.ag().catch(function(xhr, text, error){
  750. if (failure) return failure(xhr, text, error);
  751. });
  752. orgActions.setUnitAttribute(data, cb, null, !!async);
  753. // orgActions.setUnitAttribute(data, function(json){
  754. // if (json.data.value){
  755. // if (success) success();
  756. // }else{
  757. // if (failure) failure(null, "", "append values failed");
  758. // }
  759. // }, function(xhr, text, error){
  760. // if (failure) failure(xhr, text, error);
  761. // }, false);
  762. },
  763. //获取组织属性值
  764. getUnitAttribute: function(unit, attr, async){
  765. getOrgActions();
  766. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  767. var data = {"name":attr,"unit":unitFlag};
  768. var v = null;
  769. var cb = function(json){
  770. v = json.data.attributeList;
  771. if (async && o2.typeOf(async)=="function") return async(v);
  772. return v;
  773. }.ag().catch(function(json){ return json; });
  774. orgActions.getUnitAttribute(data, cb, null, !!async);
  775. return (!!async) ? cb : v;
  776. },
  777. //列出组织所有属性的名称
  778. listUnitAttributeName: function(name, async){
  779. getOrgActions();
  780. var data = {"unitList":getNameFlag(name)};
  781. var v = null;
  782. var cb = function(json){
  783. v = json.data.nameList;
  784. if (async && o2.typeOf(async)=="function") return async(v);
  785. return v;
  786. }.ag().catch(function(json){ return json; });
  787. orgActions.listUnitAttributeName(data, cb, null, !!async);
  788. return (!!async) ? cb : v;
  789. },
  790. //列出组织的所有属性
  791. listUnitAllAttribute: function(name, async){
  792. getOrgActions();
  793. var data = {"unitList":getNameFlag(name)};
  794. var v = null;
  795. var cb = function(json){
  796. v = json.data;
  797. if (async && o2.typeOf(async)=="function") return async(v);
  798. return v;
  799. }.ag().catch(function(json){ return json; });
  800. orgActions.listUnitAllAttribute(data, cb, null, !!async);
  801. return (!!async) ? cb : v;
  802. }
  803. };
  804. this.Action = (function () {
  805. var actions = [];
  806. return function (root, json) {
  807. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  808. action.getActions = function (callback) {
  809. if (!this.actions) this.actions = {};
  810. Object.merge(this.actions, json);
  811. if (callback) callback();
  812. };
  813. this.invoke = function (option) {
  814. action.invoke(option)
  815. }
  816. }
  817. })();
  818. this.service = {
  819. "jaxwsClient": {},
  820. "jaxrsClient": {}
  821. };
  822. var lookupAction = null;
  823. var getLookupAction = function (callback) {
  824. if (!lookupAction) {
  825. MWF.require("MWF.xDesktop.Actions.RestActions", function () {
  826. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_processplatform_assemble_surface", "");
  827. lookupAction.getActions = function (actionCallback) {
  828. this.actions = {
  829. //"lookup": {"uri": "/jaxrs/view/flag/{view}/application/flag/{application}"},
  830. //"getView": {"uri": "/jaxrs/view/{id}/design"}
  831. "lookup": { "uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method": "PUT" },
  832. "getView": { "uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}" }
  833. };
  834. if (actionCallback) actionCallback();
  835. }
  836. if (callback) callback();
  837. });
  838. } else {
  839. if (callback) callback();
  840. }
  841. };
  842. this.view = {
  843. "lookup": function (view, callback, async) {
  844. var filterList = { "filterList": (view.filter || null) };
  845. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function (json) {
  846. var data = {
  847. "grid": json.data.grid || json.data.groupGrid,
  848. "groupGrid": json.data.groupGrid
  849. };
  850. if (callback) callback(data);
  851. }, null, async);
  852. },
  853. "lookupV1": function (view, callback) {
  854. getLookupAction(function () {
  855. lookupAction.invoke({
  856. "name": "lookup", "async": true, "parameter": { "view": view.view, "application": view.application }, "success": function (json) {
  857. var data = {
  858. "grid": json.data.grid,
  859. "groupGrid": json.data.groupGrid
  860. };
  861. if (callback) callback(data);
  862. }.bind(this)
  863. });
  864. }.bind(this));
  865. },
  866. "select": function (view, callback, options) {
  867. if (view.view) {
  868. var viewJson = {
  869. "application": view.application || _form.json.application,
  870. "viewName": view.view || "",
  871. "isTitle": (view.isTitle === false) ? "no" : "yes",
  872. "select": (view.isMulti === false) ? "single" : "multi",
  873. "filter": view.filter
  874. };
  875. if (!options) options = {};
  876. options.width = view.width;
  877. options.height = view.height;
  878. options.title = view.caption;
  879. var width = options.width || "700";
  880. var height = options.height || "400";
  881. if (layout.mobile) {
  882. var size = document.body.getSize();
  883. width = size.x;
  884. height = size.y;
  885. options.style = "viewmobile";
  886. }
  887. width = width.toInt();
  888. height = height.toInt();
  889. var size = _form.app.content.getSize();
  890. var x = (size.x - width) / 2;
  891. var y = (size.y - height) / 2;
  892. if (x < 0) x = 0;
  893. if (y < 0) y = 0;
  894. if (layout.mobile) {
  895. x = 20;
  896. y = 0;
  897. }
  898. var _self = this;
  899. MWF.require("MWF.xDesktop.Dialog", function () {
  900. var dlg = new MWF.xDesktop.Dialog({
  901. "title": options.title || "select view",
  902. "style": options.style || "view",
  903. "top": y,
  904. "left": x - 20,
  905. "fromTop": y,
  906. "fromLeft": x - 20,
  907. "width": width,
  908. "height": height,
  909. "html": "<div style='height: 100%;'></div>",
  910. "maskNode": _form.app.content,
  911. "container": _form.app.content,
  912. "buttonList": [
  913. {
  914. "text": MWF.LP.process.button.ok,
  915. "action": function () {
  916. //if (callback) callback(_self.view.selectedItems);
  917. if (callback) callback(_self.view.getData());
  918. this.close();
  919. }
  920. },
  921. {
  922. "text": MWF.LP.process.button.cancel,
  923. "action": function () { this.close(); }
  924. }
  925. ]
  926. });
  927. dlg.show();
  928. if (layout.mobile) {
  929. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  930. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  931. if (backAction) backAction.addEvent("click", function (e) {
  932. dlg.close();
  933. }.bind(this));
  934. if (okAction) okAction.addEvent("click", function (e) {
  935. //if (callback) callback(this.view.selectedItems);
  936. if (callback) callback(this.view.getData());
  937. dlg.close();
  938. }.bind(this));
  939. }
  940. MWF.xDesktop.requireApp("query.Query", "Viewer", function () {
  941. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, { "style": "select" }, _form.app, _form.Macro);
  942. }.bind(this));
  943. }.bind(this));
  944. }
  945. }
  946. };
  947. //include 引用脚本
  948. //optionsOrName : {
  949. // type : "", 默认为portal, 可以为 portal process cms
  950. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  951. // name : "" // 脚本名称/别名/id
  952. //}
  953. //或者name: "" // 脚本名称/别名/id
  954. // if( !window.includedScripts ){
  955. // var includedScripts = window.includedScripts = [];
  956. // }else{
  957. // var includedScripts = window.includedScripts;
  958. // }
  959. var includedScripts = [];
  960. this.include = function (optionsOrName, callback) {
  961. var options = optionsOrName;
  962. if (typeOf(options) == "string") {
  963. options = { name: options };
  964. }
  965. var name = options.name;
  966. var type = (options.type && options.application) ? options.type : "portal";
  967. var application = options.application || _form.json.application;
  968. var key = type + "-" + application + "-" + name;
  969. if (includedScripts.indexOf(key) > -1) {
  970. if (callback) callback.apply(this);
  971. return;
  972. }
  973. //if (includedScripts.indexOf( name )> -1){
  974. // if (callback) callback.apply(this);
  975. // return;
  976. //}
  977. var scriptAction;
  978. switch (type) {
  979. case "portal":
  980. if (this.scriptActionPortal) {
  981. scriptAction = this.scriptActionPortal;
  982. } else {
  983. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  984. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  985. }
  986. break;
  987. case "process":
  988. if (this.scriptActionProcess) {
  989. scriptAction = this.scriptActionProcess;
  990. } else {
  991. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  992. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  993. }
  994. break;
  995. case "cms":
  996. if (this.scriptActionCMS) {
  997. scriptAction = this.scriptActionCMS;
  998. } else {
  999. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1000. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  1001. }
  1002. break;
  1003. }
  1004. scriptAction.getScriptByName(application, name, includedScripts, function (json) {
  1005. if (json.data) {
  1006. includedScripts.push(key);
  1007. //名称、别名、id
  1008. json.data.importedList.each( function ( flag ) {
  1009. if( type === "portal" ){
  1010. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  1011. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  1012. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  1013. }else if( type === "cms" ){
  1014. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  1015. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1016. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1017. }else if( type === "process" ){
  1018. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  1019. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  1020. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1021. }
  1022. });
  1023. includedScripts = includedScripts.concat(json.data.importedList);
  1024. MWF.Macro.exec(json.data.text, this);
  1025. if (callback) callback.apply(this);
  1026. } else {
  1027. if (callback) callback.apply(this);
  1028. }
  1029. }.bind(this), null, false);
  1030. };
  1031. this.define = function (name, fun, overwrite) {
  1032. var over = true;
  1033. if (overwrite === false) over = false;
  1034. var o = {};
  1035. o[name] = { "value": fun, "configurable": over };
  1036. MWF.defineProperties(this, o);
  1037. }.bind(this);
  1038. //仅前台对象-----------------------------------------
  1039. //form
  1040. this.page = this.form = this.queryView = {
  1041. "getParentEnvironment" : function () { return _form.getParentEnvironment(); }, //视图嵌入的表单或页面的上下文
  1042. "getViewInfor" : function () { return _form.getViewInfor(); },
  1043. "getPageInfor" : function () { return _form.getPageInfor(); },
  1044. "getPageData" : function () { return _form.getPageData(); },
  1045. "toPage" : function ( pageNumber, callback ) { return _form.toPage(pageNumber, callback); },
  1046. "selectAll" : function () { return _form.selectAll(); },
  1047. "unSelectAll" : function () { return _form.unSelectAll(); },
  1048. "getSelectedData" : function () { return _form.getSelectedData(); },
  1049. "setFilter" : function ( filter ) { return _form.setFilter(filter); },
  1050. "switchView" : function ( options ) { return _form.switchView(options); },
  1051. "reload" : function () { _form.reload(); },
  1052. // "getInfor": function () { return ev.pageInfor; },
  1053. // "infor": ev.pageInfor,
  1054. // "getApp": function () { return _form.app; },
  1055. // "app": _form.app,
  1056. "node": function () { return _form.node; },
  1057. // "get": function (name) { return (_form.all) ? _form.all[name] : null; },
  1058. // "getWidgetModule": function (widget, moduleName) {
  1059. // if (!_form.widgetModules || !_form.widgetModules[widget]) return null;
  1060. // var module = _form.widgetModules[widget][moduleName];
  1061. // return module || null;
  1062. // },
  1063. // "getField": function (name) { return _forms[name]; },
  1064. // "getAction": function () { return _form.workAction },
  1065. "getDesktop": function () { return _form.app ? _form.app.desktop : null},
  1066. // "getData": function () { return new MWF.xScript.JSONData(_form.getData()); },
  1067. //"save": function(callback){_form.saveWork(callback);},
  1068. // "close": function () { _form.closeWork(); },
  1069. // "print": function (application, form) {
  1070. // _form.printWork(application, form);
  1071. // },
  1072. "confirm": function (type, title, text, width, height, ok, cancel, callback, mask, style) {
  1073. // var p = MWF.getCenter({"x": width, "y": height});
  1074. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1075. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1076. if ((arguments.length <= 1) || o2.typeOf(arguments[1]) === "string") {
  1077. var p = MWF.getCenter({ "x": width, "y": height });
  1078. e = { "event": { "clientX": p.x, "x": p.x, "clientY": p.y, "y": p.y } };
  1079. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1080. } else {
  1081. e = (arguments.length > 1) ? arguments[1] : null;
  1082. title = (arguments.length > 2) ? arguments[2] : null;
  1083. text = (arguments.length > 3) ? arguments[3] : null;
  1084. width = (arguments.length > 4) ? arguments[4] : null;
  1085. height = (arguments.length > 5) ? arguments[5] : null;
  1086. ok = (arguments.length > 6) ? arguments[6] : null;
  1087. cancel = (arguments.length > 7) ? arguments[7] : null;
  1088. callback = (arguments.length > 8) ? arguments[8] : null;
  1089. mask = (arguments.length > 9) ? arguments[9] : null;
  1090. style = (arguments.length > 10) ? arguments[10] : null;
  1091. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1092. }
  1093. },
  1094. "alert": function(type, title, text, width, height){
  1095. _form.alert(type, title, text, width, height);
  1096. },
  1097. "notice": function (content, type, target, where, offset, option) {
  1098. _form.notice(content, type, target, where, offset, option);
  1099. },
  1100. "addEvent": function (e, f) { _form.addEvent(e, f); },
  1101. // "openWindow": function (form, app) {
  1102. // _form.openWindow(form, app);
  1103. // },
  1104. // "toPage": function (name, par, nohis) {
  1105. // _form.app.toPage(name, par, nohis);
  1106. // },
  1107. // "toPortal": function (portal, page, par) {
  1108. // _form.app.toPortal(portal, page, par);
  1109. // },
  1110. "openWork": function (id, completedId, title, options) {
  1111. var op = options || {};
  1112. op.workId = id;
  1113. op.workCompletedId = completedId;
  1114. op.docTitle = title;
  1115. op.appId = "process.Work" + (op.workId || op.workCompletedId);
  1116. return layout.desktop.openApplication(this.event, "process.Work", op);
  1117. },
  1118. "openJob": function (id, choice, options) {
  1119. var workData = null;
  1120. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function (json) {
  1121. if (json.data) workData = json.data;
  1122. }.bind(this), null, false);
  1123. if (workData) {
  1124. var len = workData.workList.length + workData.workCompletedList.length;
  1125. if (len) {
  1126. if (len > 1 && choice) {
  1127. var node = new Element("div", { "styles": { "padding": "20px", "width": "500px" } }).inject(_form.node);
  1128. workData.workList.each(function (work) {
  1129. var workNode = new Element("div", {
  1130. "styles": {
  1131. "background": "#ffffff",
  1132. "border-radius": "10px",
  1133. "clear": "both",
  1134. "margin-bottom": "10px",
  1135. "height": "40px",
  1136. "padding": "10px 10px"
  1137. }
  1138. }).inject(node);
  1139. 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>" +
  1140. "<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>" +
  1141. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>" + work.title + "</div>" +
  1142. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>" + work.activityName + "</div>" +
  1143. "<div style='color:#999999; float: left; margin-right: 10px'>" + work.activityArrivedTime + "</div>" +
  1144. "<div style='color:#999999; float: left; margin-right: 10px'>" + (work.manualTaskIdentityText || "") + "</div></div>";
  1145. workNode.set("html", html);
  1146. var action = workNode.getElement(".MWFAction");
  1147. action.store("work", work);
  1148. action.addEvent("click", function (e) {
  1149. var work = e.target.retrieve("work");
  1150. if (work) this.openWork(work.id, null, work.title, options);
  1151. dlg.close();
  1152. }.bind(this));
  1153. }.bind(this));
  1154. workData.workCompletedList.each(function (work) {
  1155. var workNode = new Element("div", {
  1156. "styles": {
  1157. "background": "#ffffff",
  1158. "border-radius": "10px",
  1159. "clear": "both",
  1160. "margin-bottom": "10px",
  1161. "height": "40px",
  1162. "padding": "10px 10px"
  1163. }
  1164. }).inject(node);
  1165. 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>" +
  1166. "<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>" +
  1167. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>" + work.title + "</div>" +
  1168. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>" + o2.LP.widget.workcompleted + "</div>" +
  1169. "<div style='color:#999999; float: left; margin-right: 10px'>" + work.completedTime + "</div>";
  1170. workNode.set("html", html);
  1171. var action = workNode.getElement(".MWFAction");
  1172. action.store("work", work);
  1173. action.addEvent("click", function (e) {
  1174. var work = e.target.retrieve("work");
  1175. if (work) this.openWork(null, work.id, work.title, options);
  1176. dlg.close();
  1177. }.bind(this));
  1178. }.bind(this));
  1179. var height = node.getSize().y + 20;
  1180. if (height > 600) height = 600;
  1181. var dlg = o2.DL.open({
  1182. "title": o2.LP.widget.choiceWork,
  1183. "style": "user",
  1184. "isResize": false,
  1185. "content": node,
  1186. "buttonList": [
  1187. {
  1188. "type": "cancel",
  1189. "text": o2.LP.widget.close,
  1190. "action": function () { dlg.close(); }
  1191. }
  1192. ]
  1193. });
  1194. } else {
  1195. if (workData.workList.length) {
  1196. var work = workData.workList[0];
  1197. return this.openWork(work.id, null, work.title, options);
  1198. } else {
  1199. var work = workData.workCompletedList[0];
  1200. return this.openWork(null, work.id, work.title, options);
  1201. }
  1202. }
  1203. }
  1204. }
  1205. },
  1206. "openDocument": function (id, title, options) {
  1207. var op = options || {};
  1208. op.documentId = id;
  1209. op.docTitle = title || "";
  1210. layout.desktop.openApplication(this.event, "cms.Document", op);
  1211. },
  1212. "openPortal": function (name, page, par) {
  1213. var action = MWF.Actions.get("x_portal_assemble_surface");
  1214. action.getApplication(name, function (json) {
  1215. if (json.data) {
  1216. if (page) {
  1217. action.getPageByName(page, json.data.id, function (pageJson) {
  1218. layout.desktop.openApplication(null, "portal.Portal", {
  1219. "portalId": json.data.id,
  1220. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1221. "parameters": par,
  1222. "appId": "portal.Portal" + json.data.id
  1223. })
  1224. });
  1225. } else {
  1226. layout.desktop.openApplication(null, "portal.Portal", {
  1227. "portalId": json.data.id,
  1228. "parameters": par,
  1229. "appId": "portal.Portal" + json.data.id
  1230. })
  1231. }
  1232. }
  1233. });
  1234. },
  1235. "openCMS": function (name) {
  1236. var action = MWF.Actions.get("x_cms_assemble_control");
  1237. action.getColumn(name, function (json) {
  1238. if (json.data) {
  1239. layout.desktop.openApplication(null, "cms.Module", {
  1240. "columnId": json.data.id,
  1241. "appId": "cms.Module" + json.data.id
  1242. });
  1243. }
  1244. });
  1245. },
  1246. "openProcess": function (name) {
  1247. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1248. action.getApplication(name, function (json) {
  1249. if (json.data) {
  1250. layout.desktop.openApplication(null, "process.Application", {
  1251. "id": json.data.id,
  1252. "appId": "process.Application" + json.data.id
  1253. });
  1254. }
  1255. });
  1256. },
  1257. "openApplication": function (name, options) {
  1258. layout.desktop.openApplication(null, name, options);
  1259. },
  1260. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1261. var column = columnOrOptions;
  1262. var onAfterPublish, onPostPublish;
  1263. if (typeOf(columnOrOptions) == "object") {
  1264. column = columnOrOptions.column;
  1265. category = columnOrOptions.category;
  1266. data = columnOrOptions.data;
  1267. identity = columnOrOptions.identity;
  1268. callback = columnOrOptions.callback;
  1269. target = columnOrOptions.target;
  1270. latest = columnOrOptions.latest;
  1271. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1272. ignoreTitle = columnOrOptions.ignoreTitle;
  1273. onAfterPublish = columnOrOptions.onAfterPublish;
  1274. onPostPublish = columnOrOptions.onPostPublish;
  1275. }
  1276. if (target) {
  1277. if (layout.app && layout.app.inBrowser) {
  1278. layout.app.content.empty();
  1279. layout.app = null;
  1280. }
  1281. }
  1282. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1283. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1284. "documentData": data,
  1285. "identity": identity,
  1286. "ignoreTitle": ignoreTitle === true,
  1287. "ignoreDrafted": latest === false,
  1288. "selectColumnEnable": !category || selectColumnEnable === true,
  1289. "restrictToColumn": !!category && selectColumnEnable !== true,
  1290. "categoryFlag": category, //category id or name
  1291. "columnFlag": column, //column id or name,
  1292. "onStarted": function (documentId, data) {
  1293. if (callback) callback();
  1294. },
  1295. "onPostPublish": function () {
  1296. if(onPostPublish)onPostPublish();
  1297. },
  1298. "onAfterPublish": function () {
  1299. if(onAfterPublish)onAfterPublish();
  1300. }
  1301. });
  1302. starter.load();
  1303. })
  1304. },
  1305. "startProcess": function (app, process, data, identity, callback, target, latest) {
  1306. debugger;
  1307. if (arguments.length > 2) {
  1308. for (var i = 2; i < arguments.length; i++) {
  1309. if (typeOf(arguments[i]) == "boolean") {
  1310. target = arguments[i];
  1311. break;
  1312. }
  1313. }
  1314. }
  1315. if (target) {
  1316. if (layout.app && layout.app.inBrowser) {
  1317. //layout.app.content.empty();
  1318. layout.app.$openWithSelf = true;
  1319. }
  1320. }
  1321. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function (json) {
  1322. if (json.data) {
  1323. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function () {
  1324. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1325. "workData": data,
  1326. "identity": identity,
  1327. "latest": latest,
  1328. "onStarted": function (data, title, processName) {
  1329. if (data.work){
  1330. var work = data.work;
  1331. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1332. layout.desktop.openApplication(null, "process.Work", options);
  1333. }else{
  1334. var currentTask = [];
  1335. data.each(function(work){
  1336. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1337. }.bind(this));
  1338. if (currentTask.length==1){
  1339. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1340. layout.desktop.openApplication(null, "process.Work", options);
  1341. }else{}
  1342. }
  1343. // var currentTask = [];
  1344. // data.each(function (work) {
  1345. // if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1346. // }.bind(this));
  1347. //
  1348. // if (currentTask.length == 1) {
  1349. // var options = { "workId": currentTask[0], "appId": currentTask[0] };
  1350. // layout.desktop.openApplication(null, "process.Work", options);
  1351. // } else { }
  1352. if (callback) callback(data);
  1353. }.bind(this)
  1354. });
  1355. starter.load();
  1356. }.bind(this));
  1357. }
  1358. });
  1359. }
  1360. //"app": _form.app
  1361. };
  1362. // this.form.currentRouteName = _form.json.currentRouteName;
  1363. // this.form.opinion = _form.json.opinion;
  1364. this.target = ev.target;
  1365. this.event = ev.event;
  1366. this.status = ev.status;
  1367. this.session = layout.desktop.session;
  1368. this.Actions = o2.Actions;
  1369. this.query = function (option) {
  1370. // options = {
  1371. // "name": "statementName",
  1372. // "data": "json data",
  1373. // "firstResult": 1,
  1374. // "maxResults": 100,
  1375. // "success": function(){},
  1376. // "error": function(){},
  1377. // "async": true or false, default is true
  1378. // }
  1379. if (option) {
  1380. var json = (option.data) || {};
  1381. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1382. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1383. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1384. }
  1385. };
  1386. // this.Table = MWF.xScript.createTable();
  1387. };
  1388. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  1389. if( !MWF.xScript.createDict ){
  1390. MWF.xScript.addDictToCache = function ( options, path, json ) {
  1391. if( !path )path = "root";
  1392. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1393. var type = options.appType || "process";
  1394. var enableAnonymous = options.enableAnonymous || false;
  1395. var appFlagList = [];
  1396. if( options.application )appFlagList.push( options.application );
  1397. if( options.appId )appFlagList.push( options.appId );
  1398. if( options.appName )appFlagList.push( options.appName );
  1399. if( options.appAlias )appFlagList.push( options.appAlias );
  1400. var dictFlagList = [];
  1401. if( options.id )dictFlagList.push( options.id );
  1402. if( options.name )dictFlagList.push( options.name );
  1403. if( options.alias )dictFlagList.push( options.alias );
  1404. var cache = {};
  1405. cache[path] = json;
  1406. for( var i=0; i<appFlagList.length; i++ ){
  1407. for( var j=0; j<dictFlagList.length; j++ ){
  1408. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  1409. if( !MWF.xScript.dictLoaded[k] ){
  1410. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  1411. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  1412. }else if( i===0 && j===0 ){
  1413. MWF.xScript.setDictToCache( k, path ,json );
  1414. var arr = path.split(/\./g);
  1415. var p;
  1416. var cache = MWF.xScript.dictLoaded[k];
  1417. for( var l=0 ; l<arr.length; l++ ){
  1418. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  1419. if( cache[ p ] )break;
  1420. }
  1421. if( p ){
  1422. var mathP = p+".";
  1423. Object.keys( cache ).each( function( path, idx){
  1424. if( path.indexOf( mathP ) === 0 )delete cache[path];
  1425. })
  1426. }
  1427. }
  1428. }
  1429. }
  1430. };
  1431. MWF.xScript.getMatchedDict = function(key, path){
  1432. if( !path )path = "root";
  1433. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1434. var arr = path.split(/\./g);
  1435. if( MWF.xScript.dictLoaded[key] ){
  1436. var dicts = MWF.xScript.dictLoaded[key];
  1437. var list = Array.clone(arr);
  1438. var p;
  1439. var dict;
  1440. for( var i=0 ; i<arr.length; i++ ){
  1441. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  1442. list.shift();
  1443. if( dicts[ p ] ){
  1444. dict = dicts[ p ];
  1445. break;
  1446. }
  1447. }
  1448. return {
  1449. dict : dict,
  1450. unmatchedPathList : list
  1451. }
  1452. }
  1453. return {
  1454. dict : null,
  1455. unmatchedPathList : list
  1456. }
  1457. };
  1458. MWF.xScript.insertDictToCache = function(key, path, json){
  1459. if( MWF.xScript.dictLoaded[key] ){
  1460. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1461. var dict = matchedDict.dict;
  1462. var list = matchedDict.unmatchedPathList;
  1463. if( !dict ){
  1464. MWF.xScript.dictLoaded[key][path] = json;
  1465. }else{
  1466. for( var j=0; j<list.length-1; j++ ){
  1467. if( !dict[ list[j] ] ){
  1468. dict[ list[j] ] = {};
  1469. }
  1470. dict = dict[ list[j] ];
  1471. }
  1472. var lastPath = list[list.length-1];
  1473. if( !dict[lastPath] ){
  1474. dict[lastPath] = json;
  1475. }else if( typeOf( dict[lastPath] ) === "array" ){
  1476. dict[lastPath].push( json );
  1477. }
  1478. }
  1479. }else{
  1480. MWF.xScript.dictLoaded[key] = {};
  1481. MWF.xScript.dictLoaded[key][path] = json;
  1482. }
  1483. };
  1484. MWF.xScript.setDictToCache = function(key, path, json){
  1485. if( MWF.xScript.dictLoaded[key] ){
  1486. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1487. var dict = matchedDict.dict;
  1488. var list = matchedDict.unmatchedPathList;
  1489. if( !dict ){
  1490. MWF.xScript.dictLoaded[key][path] = json;
  1491. }else{
  1492. for( var j=0; j<list.length-1; j++ ){
  1493. if( !dict[ list[j] ] ){
  1494. dict[ list[j] ] = {};
  1495. }
  1496. dict = dict[ list[j] ];
  1497. }
  1498. dict[list[list.length-1]] = json;
  1499. }
  1500. }else{
  1501. MWF.xScript.dictLoaded[key] = {};
  1502. MWF.xScript.dictLoaded[key][path] = json;
  1503. }
  1504. };
  1505. MWF.xScript.getDictFromCache = function( key, path ){
  1506. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1507. var dict = matchedDict.dict;
  1508. var list = matchedDict.unmatchedPathList;
  1509. if( dict ){
  1510. for( var j=0; j<list.length; j++ ){
  1511. dict = dict[ list[j] ];
  1512. if( !dict )return null;
  1513. }
  1514. return dict;
  1515. }
  1516. return null;
  1517. };
  1518. MWF.xScript.deleteDictToCache = function(key, path){
  1519. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1520. var dict = matchedDict.dict;
  1521. var list = matchedDict.unmatchedPathList;
  1522. if( dict){
  1523. for( var j=0; j<list.length-1; j++ ){
  1524. dict = dict[ list[j] ];
  1525. if( !dict )return;
  1526. }
  1527. delete dict[list[list.length-1]];
  1528. }
  1529. };
  1530. MWF.xScript.createDict = function(application){
  1531. //optionsOrName : {
  1532. // type : "", //默认为process, 可以为 process cms
  1533. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1534. // name : "", // 数据字典名称/别名/id
  1535. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1536. //}
  1537. //或者name: "" // 数据字典名称/别名/id
  1538. return function(optionsOrName){
  1539. var options = optionsOrName;
  1540. if( typeOf( options ) == "string" ){
  1541. options = { name : options };
  1542. }
  1543. var name = this.name = options.name;
  1544. var type = ( options.type && options.application ) ? options.type : "process";
  1545. var applicationId = options.application || application;
  1546. var enableAnonymous = options.enableAnonymous || false;
  1547. var opt = {
  1548. "appType" : type,
  1549. "name" : name,
  1550. "appId" : applicationId,
  1551. "enableAnonymous" : enableAnonymous
  1552. };
  1553. var key = name+type+applicationId+enableAnonymous;
  1554. // if (!dictLoaded[key]) dictLoaded[key] = {};
  1555. // this.dictData = dictLoaded[key];
  1556. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1557. if( type == "cms" ){
  1558. var action = MWF.Actions.get("x_cms_assemble_control");
  1559. }else{
  1560. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1561. }
  1562. var encodePath = function( path ){
  1563. var arr = path.split(/\./g);
  1564. var ar = arr.map(function(v){
  1565. return encodeURIComponent(v);
  1566. });
  1567. return ar.join("/");
  1568. };
  1569. this.get = function(path, success, failure, async, refresh){
  1570. var value = null;
  1571. if (!refresh ){
  1572. var data = MWF.xScript.getDictFromCache( key, path );
  1573. if( data ){
  1574. if (success && o2.typeOf(success)=="function") success( data );
  1575. return data;
  1576. }
  1577. }
  1578. if (success===true) async=true;
  1579. if (failure===true) async=true;
  1580. var cb = function(json){
  1581. value = json.data;
  1582. MWF.xScript.addDictToCache(opt, path, value);
  1583. if (success && o2.typeOf(success)=="function") value = success(json.data);
  1584. return value;
  1585. }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
  1586. if (path){
  1587. var p = encodePath( path );
  1588. //var p = path.replace(/\./g, "/");
  1589. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
  1590. }else{
  1591. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
  1592. }
  1593. return (!!async) ? cb : value;
  1594. // if (path){
  1595. // var p = encodePath( path );
  1596. // //var p = path.replace(/\./g, "/");
  1597. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1598. // value = json.data;
  1599. // // this.dictData[path] = value;
  1600. // MWF.xScript.addDictToCache(opt, path, value);
  1601. // if (success) success(json.data);
  1602. // }.bind(this), function(xhr, text, error){
  1603. // if (failure) failure(xhr, text, error);
  1604. // }, !!async);
  1605. // }else{
  1606. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1607. // value = json.data;
  1608. // // this.dictData["root"] = value;
  1609. // MWF.xScript.addDictToCache(opt, path, value);
  1610. // if (success) success(json.data);
  1611. // }.bind(this), function(xhr, text, error){
  1612. // if (failure) failure(xhr, text, error);
  1613. // }, !!async);
  1614. // }
  1615. //return value;
  1616. };
  1617. this.set = function(path, value, success, failure){
  1618. var p = encodePath( path );
  1619. //var p = path.replace(/\./g, "/");
  1620. return action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1621. MWF.xScript.setDictToCache(key, path, value);
  1622. if (success) return success(json.data);
  1623. }, function(xhr, text, error){
  1624. if (failure) return failure(xhr, text, error);
  1625. }, false, false);
  1626. };
  1627. this.add = function(path, value, success, failure){
  1628. var p = encodePath( path );
  1629. //var p = path.replace(/\./g, "/");
  1630. return action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1631. MWF.xScript.insertDictToCache(key, path, value);
  1632. if (success) return success(json.data);
  1633. }, function(xhr, text, error){
  1634. if (failure) return failure(xhr, text, error);
  1635. }, false, false);
  1636. };
  1637. this["delete"] = function(path, success, failure){
  1638. var p = encodePath( path );
  1639. //var p = path.replace(/\./g, "/");
  1640. return action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1641. MWF.xScript.deleteDictToCache(key, path);
  1642. if (success) return success(json.data);
  1643. }, function(xhr, text, error){
  1644. if (failure) return failure(xhr, text, error);
  1645. }, false, false);
  1646. };
  1647. this.destory = this["delete"];
  1648. }
  1649. };
  1650. }