ViewEnvironment.js 85 KB

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