CMSEnvironment.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.CMSEnvironment = function(ev){
  3. var _data = ev.data;
  4. var _form = ev.form;
  5. var _forms = ev.forms;
  6. this.library = COMMON;
  7. //this.library.version = "4.0";
  8. //data
  9. var getJSONData = function(jData){
  10. return new MWF.xScript.CMSJSONData(jData, function(data, key, _self){
  11. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  12. while (p && !_forms[p.getKey()]) p = p.getParent();
  13. if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  14. });
  15. };
  16. this.setData = function(data){
  17. this.data = getJSONData(data);
  18. this.data.save = function(callback){
  19. form.documentAction.saveData(function(json){if (callback) callback();}.bind(this), null, document.id, jData);
  20. }
  21. };
  22. this.setData(_data);
  23. //task
  24. //this.task = ev.task;
  25. //this.task.process = function(routeName, opinion, callback){
  26. // _form.submitWork(routeName, opinion, callback);
  27. //};
  28. //inquiredRouteList
  29. //this.inquiredRouteList = null;
  30. //workContext
  31. this.documentContext = {
  32. "getDocument": function(){return ev.document },
  33. "getControl": function(){return ev.control;},
  34. "getAttachmentList": function(){return ev.attachmentList;}
  35. //"setTitle": function(title){
  36. // if (!this.workAction){
  37. // MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  38. // this.workAction = new MWF.xScript.Actions.WorkActions();
  39. // }
  40. // this.workAction.setTitle(ev.work.id, {"title": title});
  41. //}
  42. };
  43. //dict
  44. this.Dict = MWF.xScript.createCMSDict(_form.json.application);
  45. //org
  46. var orgActions = null;
  47. var getOrgActions = function(){
  48. // if (!orgActions){
  49. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  50. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  51. // }
  52. if (!orgActions){
  53. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  54. orgActions = new MWF.xScript.Actions.UnitActions();
  55. }
  56. };
  57. var getNameFlag = function(name){
  58. var t = typeOf(name);
  59. if (t==="array"){
  60. var v = [];
  61. name.each(function(id){
  62. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  63. });
  64. return v;
  65. }else{
  66. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  67. }
  68. };
  69. this.org = {
  70. //群组***************
  71. //获取群组--返回群组的对象数组
  72. getGroup: function(name){
  73. getOrgActions();
  74. var data = {"groupList": getNameFlag(name)};
  75. var v = null;
  76. orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  77. return (v && v.length===1) ? v[0] : v;
  78. },
  79. //查询下级群组--返回群组的对象数组
  80. //nested 布尔 true嵌套下级;false直接下级;默认false;
  81. listSubGroup: function(name, nested){
  82. getOrgActions();
  83. var data = {"groupList": getNameFlag(name)};
  84. var v = null;
  85. if (nested){
  86. orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  87. }else{
  88. orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  89. }
  90. return v;
  91. },
  92. //查询上级群组--返回群组的对象数组
  93. //nested 布尔 true嵌套上级;false直接上级;默认false;
  94. listSupGroup:function(name, nested){
  95. getOrgActions();
  96. var data = {"groupList": getNameFlag(name)};
  97. var v = null;
  98. if (nested){
  99. orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  100. }else{
  101. orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  102. }
  103. return v;
  104. },
  105. //人员所在群组(嵌套)--返回群组的对象数组
  106. listGroupWithPerson:function(name){
  107. getOrgActions();
  108. var data = {"personList": getNameFlag(name)};
  109. var v = null;
  110. orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  111. return v;
  112. },
  113. //群组是否拥有角色--返回true, false
  114. groupHasRole: function(name, role){
  115. getOrgActions();
  116. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  117. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  118. var v = false;
  119. orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  120. return v;
  121. },
  122. //角色***************
  123. //获取角色--返回角色的对象数组
  124. getRole: function(name){
  125. getOrgActions();
  126. var data = {"roleList": getNameFlag(name)};
  127. var v = null;
  128. orgActions.listRole(data, function(json){v = json.data;}, null, false);
  129. return (v && v.length===1) ? v[0] : v;
  130. },
  131. //人员所有角色(嵌套)--返回角色的对象数组
  132. listRoleWithPerson:function(name){
  133. getOrgActions();
  134. var data = {"personList": getNameFlag(name)};
  135. var v = null;
  136. orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  137. return v;
  138. },
  139. //人员***************
  140. //人员是否拥有角色--返回true, false
  141. personHasRole: function(name, role){
  142. getOrgActions();
  143. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  144. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  145. var v = false;
  146. orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  147. return v;
  148. },
  149. //获取人员--返回人员的对象数组
  150. getPerson: function(name){
  151. getOrgActions();
  152. var data = {"personList": getNameFlag(name)};
  153. var v = null;
  154. orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  155. return (v && v.length===1) ? v[0] : v;;
  156. },
  157. //查询下级人员--返回人员的对象数组
  158. //nested 布尔 true嵌套下级;false直接下级;默认false;
  159. listSubPerson: function(name, nested){
  160. getOrgActions();
  161. var data = {"personList": getNameFlag(name)};
  162. var v = null;
  163. if (nested){
  164. orgActions.listPersonSubNested(data, function(json){v = json.data;}, null, false);
  165. }else{
  166. orgActions.listPersonSubDirect(data, function(json){v = json.data;}, null, false);
  167. }
  168. return v;
  169. },
  170. //查询上级人员--返回人员的对象数组
  171. //nested 布尔 true嵌套上级;false直接上级;默认false;
  172. listSupPerson: function(name, nested){
  173. getOrgActions();
  174. var data = {"personList": getNameFlag(name)};
  175. var v = null;
  176. if (nested){
  177. orgActions.listPersonSupNested(data, function(json){v = json.data;}, null, false);
  178. }else{
  179. orgActions.listPersonSupDirect(data, function(json){v = json.data;}, null, false);
  180. }
  181. return v;
  182. },
  183. //获取群组的所有人员--返回人员的对象数组
  184. listPersonWithGroup: function(name){
  185. getOrgActions();
  186. var data = {"groupList": getNameFlag(name)};
  187. var v = null;
  188. orgActions.listPersonWithGroup(data, function(json){v = json.data;}, null, false);
  189. return v;
  190. },
  191. //获取角色的所有人员--返回人员的对象数组
  192. listPersonWithRole: function(name){
  193. getOrgActions();
  194. var data = {"roleList": getNameFlag(name)};
  195. var v = null;
  196. orgActions.listPersonWithRole(data, function(json){v = json.data;}, null, false);
  197. return v;
  198. },
  199. //获取身份的所有人员--返回人员的对象数组
  200. listPersonWithIdentity: function(name){
  201. getOrgActions();
  202. var data = {"identityList": getNameFlag(name)};
  203. var v = null;
  204. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  205. return v;
  206. },
  207. //查询组织成员的人员--返回人员的对象数组
  208. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  209. listPersonWithUnit: function(name, nested){
  210. getOrgActions();
  211. var data = {"unitList": getNameFlag(name)};
  212. var v = null;
  213. if (nested){
  214. orgActions.listPersonWithUnitNested(data, function(json){v = json.data;}, null, false);
  215. }else{
  216. orgActions.listPersonWithUnitDirect(data, function(json){v = json.data;}, null, false);
  217. }
  218. return v;
  219. },
  220. //人员属性************
  221. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  222. appendPersonAttribute: function(person, attr, values){
  223. getOrgActions();
  224. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  225. var data = {"attributeList":values,"name":attr,"person":personFlag};
  226. orgActions.appendPersonAttribute(data, function(json){
  227. if (json.data.value){
  228. if (success) success();
  229. }else{
  230. if (failure) failure(null, "", "append values failed");
  231. }
  232. }, function(xhr, text, error){
  233. if (failure) failure(xhr, text, error);
  234. }, false);
  235. },
  236. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  237. setPersonAttribute: function(person, attr, values){
  238. getOrgActions();
  239. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  240. var data = {"attributeList":values,"name":attr,"person":personFlag};
  241. orgActions.setPersonAttribute(data, function(json){
  242. if (json.data.value){
  243. if (success) success();
  244. }else{
  245. if (failure) failure(null, "", "append values failed");
  246. }
  247. }, function(xhr, text, error){
  248. if (failure) failure(xhr, text, error);
  249. }, false);
  250. },
  251. //获取人员属性值
  252. getPersonAttribute: function(person, attr){
  253. getOrgActions();
  254. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  255. var data = {"name":attr,"person":personFlag};
  256. var v = null;
  257. orgActions.getPersonAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  258. return v;
  259. },
  260. //列出人员所有属性的名称
  261. listPersonAttributeName: function(name){
  262. getOrgActions();
  263. var data = {"personList":getNameFlag(name)};
  264. var v = null;
  265. orgActions.listPersonAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  266. return v;
  267. },
  268. //列出人员的所有属性
  269. listPersonAllAttribute: function(name){
  270. getOrgActions();
  271. var data = {"personList":getNameFlag(name)};
  272. var v = null;
  273. orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  274. return v;
  275. },
  276. //身份**********
  277. //获取身份
  278. getIdentity: function(name){
  279. getOrgActions();
  280. var data = {"identityList":getNameFlag(name)};
  281. var v = null;
  282. orgActions.listIdentity(data, function(json){v = json.data;}, null, false);
  283. return (v && v.length===1) ? v[0] : v;
  284. },
  285. //列出人员的身份
  286. listIdentityWithPerson: function(name){
  287. getOrgActions();
  288. var data = {"personList":getNameFlag(name)};
  289. var v = null;
  290. orgActions.listIdentityWithPerson(data, function(json){v = json.data;}, null, false);
  291. return v;
  292. },
  293. //查询组织成员身份--返回身份的对象数组
  294. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  295. listIdentityWithUnit: function(name, nested){
  296. getOrgActions();
  297. var data = {"unitList": getNameFlag(name)};
  298. var v = null;
  299. if (nested){
  300. orgActions.listIdentityWithUnitNested(data, function(json){v = json.data;}, null, false);
  301. }else{
  302. orgActions.listIdentityWithUnitDirect(data, function(json){v = json.data;}, null, false);
  303. }
  304. return v;
  305. },
  306. //组织**********
  307. //获取组织
  308. getUnit: function(name){
  309. getOrgActions();
  310. var data = {"unitList":getNameFlag(name)};
  311. var v = null;
  312. orgActions.listUnit(data, function(json){v = json.data;}, null, false);
  313. return (v && v.length===1) ? v[0] : v;
  314. },
  315. //查询组织的下级--返回组织的对象数组
  316. //nested 布尔 true嵌套下级;false直接下级;默认false;
  317. listSubUnit: function(name, nested){
  318. getOrgActions();
  319. var data = {"unitList": getNameFlag(name)};
  320. var v = null;
  321. if (nested){
  322. orgActions.listUnitSubNested(data, function(json){v = json.data;}, null, false);
  323. }else{
  324. orgActions.listUnitSubDirect(data, function(json){v = json.data;}, null, false);
  325. }
  326. return v;
  327. },
  328. //查询组织的上级--返回组织的对象数组
  329. //nested 布尔 true嵌套上级;false直接上级;默认false;
  330. listSupUnit: function(name, nested){
  331. getOrgActions();
  332. var data = {"unitList": getNameFlag(name)};
  333. var v = null;
  334. if (nested){
  335. orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  336. }else{
  337. orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  338. }
  339. return v;
  340. },
  341. //根据个人身份获取组织
  342. //flag 数字 表示获取第几层的组织
  343. // 字符串 表示获取指定类型的组织
  344. // 空 表示获取直接所在的组织
  345. getUnitByIdentity: function(name, flag){
  346. getOrgActions();
  347. var getUnitMethod = "current";
  348. var v;
  349. if (flag){
  350. if (typeOf(flag)==="string") getUnitMethod = "type";
  351. if (typeOf(flag)==="number") getUnitMethod = "level";
  352. }
  353. switch (getUnitMethod){
  354. case "current":
  355. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  356. orgActions.getUnitWithIdentityAndLevel(data, function(json){ v = json.data; }, null, false);
  357. break;
  358. case "type":
  359. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  360. orgActions.getUnitWithIdentityAndType(data, function(json){ v = json.data; }, null, false);
  361. break;
  362. case "level":
  363. var data = {"identityList":getNameFlag(name)};
  364. orgActions.listUnitWithIdentity(data, function(json){ v = json.data; }, null, false);
  365. break;
  366. }
  367. return v;
  368. },
  369. //列出身份所在组织的所有上级组织
  370. listAllSupUnitWithIdentity: function(name){
  371. getOrgActions();
  372. var data = {"identityList":getNameFlag(name)};
  373. var v = null;
  374. orgActions.listUnitSupNestedWithIdentity(data, function(json){v = json.data;}, null, false);
  375. return v;
  376. },
  377. //获取人员所在的所有组织
  378. listUnitWithPerson: function(name){
  379. getOrgActions();
  380. var data = {"personList":getNameFlag(name)};
  381. var v = null;
  382. orgActions.listUnitWithPerson(data, function(json){v = json.data;}, null, false);
  383. return v;
  384. },
  385. //列出身份所在组织的所有上级组织
  386. listAllSupUnitWithPerson: function(name){
  387. getOrgActions();
  388. var data = {"personList":getNameFlag(name)};
  389. var v = null;
  390. orgActions.listUnitSupNestedWithPerson(data, function(json){v = json.data;}, null, false);
  391. return v;
  392. },
  393. //根据组织属性,获取所有符合的组织
  394. listUnitWithAttribute: function(name, attribute){
  395. getOrgActions();
  396. var data = {"name":name,"attribute":attribute};
  397. var v = null;
  398. orgActions.listUnitWithAttribute(data, function(json){v = json.data;}, null, false);
  399. return v;
  400. },
  401. //根据组织职务,获取所有符合的组织
  402. listUnitWithDuty: function(name, id){
  403. getOrgActions();
  404. var data = {"name":"","identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  405. var v = null;
  406. orgActions.listUnitWithDuty(data, function(json){v = json.data;}, null, false);
  407. return v;
  408. },
  409. //列出顶层组织
  410. listTopUnit: function(){
  411. var action = MWF.Actions.get("x_organization_assemble_control");
  412. var v = null;
  413. action.listTopUnit(function(json){
  414. v = json.data;
  415. }, null, false);
  416. return v;
  417. },
  418. //组织职务***********
  419. //获取指定的组织职务的身份
  420. getDuty: function(duty, id){
  421. getOrgActions();
  422. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  423. var v = null;
  424. orgActions.getDuty(data, function(json){v = json.data;}, null, false);
  425. return v;
  426. },
  427. //获取身份的所有职务名称
  428. listDutyNameWithIdentity: function(name){
  429. getOrgActions();
  430. var data = {"identityList":getNameFlag(name)};
  431. var v = null;
  432. orgActions.listDutyNameWithIdentity(data, function(json){v = json.data.nameList;}, null, false);
  433. return v;
  434. },
  435. //获取组织的所有职务名称
  436. listDutyNameWithUnit: function(name){
  437. getOrgActions();
  438. var data = {"unitList":getNameFlag(name)};
  439. var v = null;
  440. orgActions.listDutyNameWithUnit(data, function(json){v = json.data.nameList;}, null, false);
  441. return v;
  442. },
  443. //获取组织的所有职务
  444. listUnitAllDuty: function(name){
  445. getOrgActions();
  446. var data = {"unitList":getNameFlag(name)};
  447. var v = null;
  448. orgActions.listUnitAllDuty(data, function(json){v = json.data.nameList;}, null, false);
  449. return v;
  450. },
  451. //组织属性**************
  452. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  453. appendUnitAttribute: function(unit, attr, values){
  454. getOrgActions();
  455. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  456. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  457. orgActions.appendUnitAttribute(data, function(json){
  458. if (json.data.value){
  459. if (success) success();
  460. }else{
  461. if (failure) failure(null, "", "append values failed");
  462. }
  463. }, function(xhr, text, error){
  464. if (failure) failure(xhr, text, error);
  465. }, false);
  466. },
  467. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  468. setUnitAttribute: function(unit, attr, values){
  469. getOrgActions();
  470. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  471. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  472. orgActions.setUnitAttribute(data, function(json){
  473. if (json.data.value){
  474. if (success) success();
  475. }else{
  476. if (failure) failure(null, "", "append values failed");
  477. }
  478. }, function(xhr, text, error){
  479. if (failure) failure(xhr, text, error);
  480. }, false);
  481. },
  482. //获取组织属性值
  483. getUnitAttribute: function(unit, attr){
  484. getOrgActions();
  485. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  486. var data = {"name":attr,"unit":unitFlag};
  487. var v = null;
  488. orgActions.getUnitAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  489. return v;
  490. },
  491. //列出组织所有属性的名称
  492. listUnitAttributeName: function(name){
  493. getOrgActions();
  494. var data = {"unitList":getNameFlag(name)};
  495. var v = null;
  496. orgActions.listUnitAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  497. return v;
  498. },
  499. //列出组织的所有属性
  500. listUnitAllAttribute: function(name){
  501. getOrgActions();
  502. var data = {"unitList":getNameFlag(name)};
  503. var v = null;
  504. orgActions.listUnitAllAttribute(data, function(json){v = json.data;}, null, false);
  505. return v;
  506. }
  507. };
  508. this.Action = (function(){
  509. var actions = [];
  510. return function(root, json){
  511. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  512. action.getActions = function(callback){
  513. if (!this.actions) this.actions = {};
  514. Object.merge(this.actions, json);
  515. if (callback) callback();
  516. };
  517. this.invoke = function(option){
  518. action.invoke(option)
  519. }
  520. }
  521. })();
  522. this.service = {
  523. "jaxwsClient": {},
  524. "jaxrsClient":{}
  525. };
  526. var lookupAction = null;
  527. var getLookupAction = function(callback){
  528. if (!lookupAction){
  529. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  530. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  531. lookupAction.getActions = function(actionCallback){
  532. this.actions = {
  533. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  534. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  535. };
  536. if (actionCallback) actionCallback();
  537. }
  538. if (callback) callback();
  539. }.bind(this));
  540. }else{
  541. if (callback) callback();
  542. }
  543. };
  544. this.view = {
  545. "lookup": function(view, callback, async){
  546. var filterList = {"filterList": (view.filter || null)};
  547. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  548. var data = {
  549. "grid": json.data.grid || json.data.groupGrid,
  550. "groupGrid": json.data.groupGrid
  551. };
  552. if (callback) callback(data);
  553. }, null, async);
  554. },
  555. "lookupV1": function(view, callback){
  556. getLookupAction(function(){
  557. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  558. var data = {
  559. "grid": json.data.grid,
  560. "groupGrid": json.data.groupGrid
  561. };
  562. if (callback) callback(data);
  563. }.bind(this)});
  564. }.bind(this));
  565. },
  566. "select": function(view, callback, options){
  567. if (view.view){
  568. var viewJson = {
  569. "application": view.application || _form.json.application,
  570. "viewName": view.view || "",
  571. "isTitle": view.isTitle || "yes",
  572. "select": view.select || "multi"
  573. };
  574. if (!options) options = {};
  575. var width = options.width || "700";
  576. var height = options.height || "400";
  577. if (layout.mobile){
  578. var size = document.body.getSize();
  579. width = size.x;
  580. height = size.y;
  581. options.style = "viewmobile";
  582. }
  583. width = width.toInt();
  584. height = height.toInt();
  585. var size = _form.app.content.getSize();
  586. var x = (size.x-width)/2;
  587. var y = (size.y-height)/2;
  588. if (x<0) x = 0;
  589. if (y<0) y = 0;
  590. if (layout.mobile){
  591. x = 20;
  592. y = 0;
  593. }
  594. var _self = this;
  595. MWF.require("MWF.xDesktop.Dialog", function(){
  596. var dlg = new MWF.xDesktop.Dialog({
  597. "title": options.title || "select view",
  598. "style": options.style || "view",
  599. "top": y,
  600. "left": x-20,
  601. "fromTop":y,
  602. "fromLeft": x-20,
  603. "width": width,
  604. "height": height,
  605. "html": "<div style='height: 100%;'></div>",
  606. "maskNode": _form.app.content,
  607. "container": _form.app.content,
  608. "buttonList": [
  609. {
  610. "text": MWF.LP.process.button.ok,
  611. "action": function(){
  612. //if (callback) callback(_self.view.selectedItems);
  613. if (callback) callback(_self.view.getData());
  614. this.close();
  615. }
  616. },
  617. {
  618. "text": MWF.LP.process.button.cancel,
  619. "action": function(){this.close();}
  620. }
  621. ]
  622. });
  623. dlg.show();
  624. if (layout.mobile){
  625. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  626. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  627. if (backAction) backAction.addEvent("click", function(e){
  628. dlg.close();
  629. }.bind(this));
  630. if (okAction) okAction.addEvent("click", function(e){
  631. //if (callback) callback(this.view.selectedItems);
  632. if (callback) callback(this.view.getData());
  633. dlg.close();
  634. }.bind(this));
  635. }
  636. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  637. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  638. }.bind(this));
  639. }.bind(this));
  640. }
  641. }
  642. };
  643. //var lookupAction = null;
  644. //var getLookupAction = function(callback){
  645. // if (!lookupAction){
  646. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  647. // lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  648. // lookupAction.getActions = function(actionCallback){
  649. // this.actions = {
  650. // "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  651. // "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  652. // };
  653. // if (actionCallback) actionCallback();
  654. // }
  655. // if (callback) callback();
  656. // }.bind(this));
  657. // }else{
  658. // if (callback) callback();
  659. // }
  660. //};
  661. //
  662. //this.view = {
  663. // "lookup": function(view, callback){
  664. // getLookupAction(function(){
  665. // lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  666. // var data = {
  667. // "grid": json.data.grid,
  668. // "groupGrid": json.data.groupGrid
  669. // };
  670. // if (callback) callback(data);
  671. // }.bind(this)});
  672. // }.bind(this));
  673. // },
  674. // "select": function(view, callback, options){
  675. // if (view.view){
  676. // var viewJson = {
  677. // "application": view.application || "",
  678. // "viewName": view.view || "",
  679. // "isTitle": view.isTitle || "yes",
  680. // "select": view.select || "multi",
  681. // "title": view.title || "Select View"
  682. // };
  683. // if (!options) options = {};
  684. // var width = options.width || "700";
  685. // var height = options.height || "400";
  686. //
  687. // if (layout.mobile){
  688. // var size = document.body.getSize();
  689. // width = size.x;
  690. // height = size.y;
  691. // options.style = "viewmobile";
  692. // }
  693. // width = width.toInt();
  694. // height = height.toInt();
  695. //
  696. // var size = _form.app.content.getSize();
  697. // var x = (size.x-width)/2;
  698. // var y = (size.y-height)/2;
  699. // if (x<0) x = 0;
  700. // if (y<0) y = 0;
  701. // if (layout.mobile){
  702. // x = 20;
  703. // y = 0;
  704. // }
  705. //
  706. // var _self = this;
  707. // MWF.require("MWF.xDesktop.Dialog", function(){
  708. // var dlg = new MWF.xDesktop.Dialog({
  709. // "title": options.title || "select View",
  710. // "style": options.style || "view",
  711. // "top": y,
  712. // "left": x-20,
  713. // "fromTop":y,
  714. // "fromLeft": x-20,
  715. // "width": width,
  716. // "height": height,
  717. // "html": "<div style='height: 100%;'></div>",
  718. // "maskNode": _form.app.content,
  719. // "container": _form.app.content,
  720. // "buttonList": [
  721. // {
  722. // "text": MWF.LP.process.button.ok,
  723. // "action": function(){
  724. // //if (callback) callback(_self.view.selectedItems);
  725. // if (callback) callback(_self.view.getData());
  726. // this.close();
  727. // }
  728. // },
  729. // {
  730. // "text": MWF.LP.process.button.cancel,
  731. // "action": function(){this.close();}
  732. // }
  733. // ]
  734. // });
  735. // dlg.show();
  736. // if (layout.mobile){
  737. // var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  738. // var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  739. // if (backAction) backAction.addEvent("click", function(e){
  740. // dlg.close();
  741. // }.bind(this));
  742. // if (okAction) okAction.addEvent("click", function(e){
  743. // //if (callback) callback(this.view.selectedItems);
  744. // if (callback) callback(this.view.getData());
  745. // dlg.close();
  746. // }.bind(this));
  747. // }
  748. //
  749. // // MWF.xDesktop.requireApp("cms.Xform", "widget.View", function(){
  750. // // this.view = new MWF.xApplication.cms.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  751. // // }.bind(this));
  752. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  753. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  754. // }.bind(this));
  755. // }.bind(this));
  756. // }
  757. // }
  758. //};
  759. //include 引用脚本
  760. //optionsOrName : {
  761. // type : "", 默认为cms, 可以为 portal process cms
  762. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  763. // name : "" // 脚本名称/别名/id
  764. //}
  765. //或者name: "" // 脚本名称/别名/id
  766. if( !window.includedScripts ){
  767. var includedScripts = window.includedScripts = [];
  768. }else{
  769. var includedScripts = window.includedScripts;
  770. }
  771. this.include = function( optionsOrName , callback ){
  772. var options = optionsOrName;
  773. if( typeOf( options ) == "string" ){
  774. options = { name : options };
  775. }
  776. var name = options.name;
  777. var type = ( options.type && options.application ) ? options.type : "cms";
  778. var application = options.application || _form.json.application;
  779. if (includedScripts.indexOf( name )> -1){
  780. if (callback) callback.apply(this);
  781. return;
  782. }
  783. var scriptAction;
  784. switch ( type ){
  785. case "portal" :
  786. if( this.scriptActionPortal ){
  787. scriptAction = this.scriptActionPortal;
  788. }else{
  789. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  790. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  791. }
  792. break;
  793. case "process" :
  794. if( this.scriptActionProcess ){
  795. scriptAction = this.scriptActionProcess;
  796. }else{
  797. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  798. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  799. }
  800. break;
  801. case "cms" :
  802. if( this.scriptActionCMS ){
  803. scriptAction = this.scriptActionCMS;
  804. }else{
  805. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  806. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  807. }
  808. break;
  809. }
  810. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  811. if (json.data){
  812. includedScripts = includedScripts.concat(json.data.importedList);
  813. MWF.Macro.exec(json.data.text, this);
  814. if (callback) callback.apply(this);
  815. }else{
  816. if (callback) callback.apply(this);
  817. }
  818. }.bind(this), null, false);
  819. };
  820. //var includedScripts = [];
  821. //this.include = function(name, callback){
  822. // if (includedScripts.indexOf(name)==-1){
  823. // if (!this.scriptAction){
  824. // MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  825. // this.scriptAction = new MWF.xScript.Actions.CMSScriptActions();
  826. // }
  827. // this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
  828. // includedScripts = includedScripts.concat(json.data.importedList);
  829. // MWF.Macro.exec(json.data.text, this);
  830. // if (callback) callback.apply(this);
  831. // }.bind(this), null, false);
  832. // }else{
  833. // if (callback) callback.apply(this);
  834. // }
  835. //}.bind(this);
  836. this.define = function(name, fun, overwrite){
  837. var over = true;
  838. if (overwrite===false) over = false;
  839. var o = {};
  840. o[name] = {"value": fun, "configurable": over};
  841. MWF.defineProperties(this, o);
  842. }.bind(this);
  843. //仅前台对象-----------------------------------------
  844. //form
  845. this.form = {
  846. "getInfor": function(){return ev.formInfor;},
  847. "infor": ev.formInfor,
  848. "getApp": function(){return _form.app;},
  849. "app": _form.app,
  850. "node": function(){return _form.node;},
  851. "readonly": _form.options.readonly,
  852. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  853. "getField": function(name){return _forms[name];},
  854. "getAction": function(){return _form.documentAction},
  855. "getData": function(){return new MWF.xScript.CMSJSONData(_form.getData());},
  856. "save": function(callback){
  857. _form.saveDocument(callback);
  858. },
  859. "close": function(){_form.closeDocument();},
  860. "publish": function(option){
  861. _form.publishDocument()
  862. },
  863. //"archive": function(option){
  864. // _form.archiveDocument()
  865. //},
  866. //"redraft": function(option){
  867. // _form.redraftDocument()
  868. //},
  869. "confirm": function(type, title, text, width, height, ok, cancel, callback){
  870. var p = MWF.getCenter({"x": width, "y": height});
  871. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  872. _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  873. },
  874. //"confirm": function(type, e, title, text, width, height, ok, cancel, callback){
  875. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  876. //},
  877. "notice": function(content, type, target, where){
  878. _form.notice(content, type, target, where);
  879. },
  880. "addEvent": function(e, f){_form.addEvent(e, f);},
  881. "openWork": function(id, completedId, title, options){
  882. var op = options || {};
  883. op.workId = id;
  884. op.workCompletedId = completedId;
  885. op.docTitle = title;
  886. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  887. layout.desktop.openApplication(this.event, "process.Work", op);
  888. },
  889. "openDocument": function(id, title, options){
  890. var op = options || {};
  891. op.documentId = id;
  892. op.docTitle = title;
  893. layout.desktop.openApplication(this.event, "cms.Document", op);
  894. },
  895. "openPortal": function(name, page, par){
  896. var action = MWF.Actions.get("x_portal_assemble_surface");
  897. action.getApplication(name, function(json){
  898. if (json.data){
  899. if (page){
  900. action.getPageByName(page, json.data.id, function(pageJson){
  901. layout.desktop.openApplication(null, "portal.Portal", {
  902. "portalId": json.data.id,
  903. "pageId": (pageJson.data) ? pageJson.data.id : "",
  904. "parameters": par,
  905. "appId": "portal.Portal"+json.data.id
  906. })
  907. });
  908. }else{
  909. layout.desktop.openApplication(null, "portal.Portal", {
  910. "portalId": json.data.id,
  911. "parameters": par,
  912. "appId": "portal.Portal"+json.data.id
  913. })
  914. }
  915. }
  916. });
  917. },
  918. "openCMS": function(name){
  919. var action = MWF.Actions.get("x_cms_assemble_control");
  920. action.getColumn(name, function(json){
  921. if (json.data){
  922. layout.desktop.openApplication(null, "cms.Module", {
  923. "columnId": json.data.id,
  924. "appId": "cms.Module"+json.data.id
  925. });
  926. }
  927. });
  928. },
  929. "openProcess": function(name){
  930. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  931. action.getApplication(name, function(json){
  932. if (json.data){
  933. layout.desktop.openApplication(null, "process.Application", {
  934. "id": json.data.id,
  935. "appId": "process.Application"+json.data.id
  936. });
  937. }
  938. });
  939. },
  940. "openApplication":function(name, options){
  941. layout.desktop.openApplication(null, name, options);
  942. },
  943. "createDocument" : function(columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle){
  944. var column = columnOrOptions;
  945. if( typeOf( columnOrOptions ) == "object" ){
  946. column = columnOrOptions.column;
  947. category = columnOrOptions.category;
  948. data = columnOrOptions.data;
  949. identity = columnOrOptions.identity;
  950. callback = columnOrOptions.callback;
  951. target = columnOrOptions.target;
  952. latest = columnOrOptions.latest;
  953. selectColumnEnable = columnOrOptions.selectColumnEnable;
  954. ignoreTitle = columnOrOptions.ignoreTitle;
  955. }
  956. if (target){
  957. if (layout.app && layout.app.inBrowser){
  958. layout.app.content.empty();
  959. layout.app = null;
  960. }
  961. }
  962. MWF.xDesktop.requireApp("cms.Index", "Newer", function(){
  963. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  964. "documentData": data,
  965. "identity": identity,
  966. "ignoreTitle" : ignoreTitle === true,
  967. "ignoreDrafted" : latest === false,
  968. "selectColumnEnable" : !category || selectColumnEnable === true,
  969. "restrictToColumn" : !!category && selectColumnEnable !== true,
  970. "categoryFlag" : category, //category id or name
  971. "columnFlag" : column, //column id or name,
  972. "onStarted" : function( documentId, data ){
  973. if(callback)callback();
  974. },
  975. "onPostLoad" : function(){
  976. },
  977. "onPostPublish" : function(){
  978. }
  979. });
  980. starter.load();
  981. })
  982. },
  983. "startProcess": function(app, process, data, identity, callback, target, latest){
  984. if (arguments.length>2){
  985. for (var i=2; i<arguments.length; i++){
  986. if (typeOf(arguments[i])=="boolean"){
  987. target = arguments[i];
  988. break;
  989. }
  990. }
  991. }
  992. if (target){
  993. if (layout.app && layout.app.inBrowser){
  994. layout.app.content.empty();
  995. layout.app = null;
  996. }
  997. }
  998. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  999. if (json.data){
  1000. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1001. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1002. "workData": data,
  1003. "identity": identity,
  1004. "latest": latest,
  1005. "onStarted": function(data, title, processName){
  1006. var currentTask = [];
  1007. data.each(function(work){
  1008. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1009. }.bind(this));
  1010. if (currentTask.length==1){
  1011. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1012. layout.desktop.openApplication(null, "process.Work", options);
  1013. }else{}
  1014. if (callback) callback(data);
  1015. }.bind(this)
  1016. });
  1017. starter.load();
  1018. }.bind(this));
  1019. }
  1020. });
  1021. }
  1022. };
  1023. this.target = ev.target;
  1024. this.event = ev.event;
  1025. this.status = ev.status;
  1026. this.session = layout.desktop.session;
  1027. };
  1028. MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1029. var getter = function(data, callback, k, _self){
  1030. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1031. };
  1032. var setter = function(data, callback, k, _self){
  1033. return function(v){
  1034. data[k] = v;
  1035. //debugger;
  1036. //this.add(k, v, true);
  1037. if (callback) callback(data, k, _self);
  1038. }
  1039. };
  1040. var define = function(){
  1041. var o = {};
  1042. for (var k in data) o[k] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, k, this]),"set": setter.apply(this, [data, callback, k, this])};
  1043. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1044. MWF.defineProperties(this, o);
  1045. var methods = {
  1046. "getKey": {"value": function(){ return key; }},
  1047. "getParent": {"value": function(){ return parent; }},
  1048. "toString": {"value": function() { return data.toString();}},
  1049. "add": {"value": function(newKey, newValue, overwrite){
  1050. var flag = true;
  1051. var type = typeOf(data);
  1052. if (type==="array"){
  1053. if (arguments.length<2){
  1054. data.push(newKey);
  1055. newValue = newKey;
  1056. newKey = data.length-1;
  1057. }else{
  1058. if (!newKey && newKey!==0){
  1059. data.push(newValue);
  1060. newKey = data.length-1;
  1061. }else{
  1062. flag = false;
  1063. }
  1064. }
  1065. if (flag){
  1066. var o = {};
  1067. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1068. MWF.defineProperties(this, o);
  1069. }
  1070. this[newKey] = newValue;
  1071. }else if (type==="object"){
  1072. if (!this.hasOwnProperty(newKey)){
  1073. data[newKey] = newValue;
  1074. if (flag){
  1075. var o = {};
  1076. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1077. MWF.defineProperties(this, o);
  1078. }
  1079. this[newKey] = newValue;
  1080. }else{
  1081. if (overwrite) this[newKey] = newValue;
  1082. }
  1083. }
  1084. return this[newKey];
  1085. }},
  1086. "del": {"value": function(delKey){
  1087. if (!this.hasOwnProperty(delKey)) return null;
  1088. delete data[delKey];
  1089. delete this[delKey];
  1090. return this;
  1091. }}
  1092. };
  1093. MWF.defineProperties(this, methods);
  1094. //this.getKey = function(){ return key; };
  1095. //this.getParent = function(){ return parent; };
  1096. //this.toString = function() { return data.toString();};
  1097. //this.add = function(newKey, newValue, overwrite){
  1098. // var flag = true;
  1099. // var type = typeOf(data);
  1100. // if (!this.hasOwnProperty(newKey)){
  1101. // if (type=="array"){
  1102. // if (arguments.length<2){
  1103. // data.push(newKey);
  1104. // newValue = newKey;
  1105. // newKey = data.length-1;
  1106. // }else{
  1107. // debugger;
  1108. // if (!newKey && newKey!=0){
  1109. // data.push(newValue);
  1110. // newKey = data.length-1;
  1111. // }else{
  1112. // flag == false;
  1113. // }
  1114. // }
  1115. // }else{
  1116. // data[newKey] = newValue;
  1117. // }
  1118. // //var valueType = typeOf(newValue);
  1119. // //var newValueData = newValue;
  1120. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1121. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1122. // if (flag){
  1123. // var o = {};
  1124. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1125. // MWF.defineProperties(this, o);
  1126. // }
  1127. // this[newKey] = newValue;
  1128. // }else{
  1129. // if (overwrite) this[newKey] = newValue;
  1130. // }
  1131. //
  1132. // //var valueType = typeOf(newValue);
  1133. // //var newValueData = newValue;
  1134. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1135. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1136. // //
  1137. // //this[newKey] = newValueData;
  1138. //
  1139. // return this[newKey];
  1140. //};
  1141. //this.del = function(delKey){
  1142. // if (!this.hasOwnProperty(delKey)) return null;
  1143. // delete data[newKey];
  1144. // delete this[newKey];
  1145. // return this;
  1146. //};
  1147. };
  1148. var type = typeOf(data);
  1149. if (type==="object" || type==="array") define.apply(this);
  1150. };
  1151. //MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1152. // var getter = function(data, callback, k, _self){
  1153. // return function(){return (["array","object"].indexOf(typeOf(data[k]))==-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1154. // }
  1155. // var setter = function(data, callback, k, _self){
  1156. // return function(v){
  1157. // data[k] = v;
  1158. // if (callback) callback(data, k, _self);
  1159. // }
  1160. // }
  1161. // var define = function(){
  1162. // var o = {};
  1163. // for (var k in data) o[k] = {
  1164. // "configurable": true,
  1165. // "get": getter.apply(this, [data, callback, k, this]),
  1166. // "set": setter.apply(this, [data, callback, k, this])
  1167. // };
  1168. // o["length"] = {"get": function(){return Object.keys(data).length;}};
  1169. // MWF.defineProperties(this, o);
  1170. // this.getKey = function(){ return key; };
  1171. // this.getParent = function(){ return parent; };
  1172. // this.toString = function() { return data.toString();};
  1173. // this.add = function(newKey, newValue){
  1174. // var type = typeOf(data);
  1175. // if (!this.hasOwnProperty(newKey)){
  1176. // if (type=="array"){
  1177. // data.push(newValue || {});
  1178. // newKey = data.length-1;
  1179. // }else{
  1180. // data[newKey] = newValue || {};
  1181. // }
  1182. // var o = {};
  1183. // o[newKey] = {"configurable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1184. // MWF.defineProperties(this, o);
  1185. // }
  1186. // this[newKey] = newValue;
  1187. // return this;
  1188. // };
  1189. // this.del = function(delKey){
  1190. // if (!this.hasOwnProperty(delKey)) return null;
  1191. // delete data[newKey];
  1192. // delete this[newKey];
  1193. // return this;
  1194. // };
  1195. // }
  1196. // var type = typeOf(data);
  1197. // if (type=="object" || type=="array") define.apply(this);
  1198. //};
  1199. //MWF.xScript.createCMSDict = function(application){
  1200. // return function(name){
  1201. // var applicationId = application;
  1202. // this.name = name;
  1203. // MWF.require("MWF.xScript.Actions.CMSDictActions", null, false);
  1204. // var action = new MWF.xScript.Actions.CMSDictActions();
  1205. //
  1206. // this.get = function(path, success, failure){
  1207. // var value = null;
  1208. // if( path ){
  1209. // var arr = path.split(/\./g);
  1210. // var ar = arr.map(function(v){
  1211. // return encodeURIComponent(v);
  1212. // });
  1213. // //var p = path.replace(/\./g, "/");
  1214. // var p = ar.join("/");
  1215. // action.getDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1216. // value = json.data;
  1217. // if (success) success(json.data);
  1218. // }, function(xhr, text, error){
  1219. // if (failure) failure(xhr, text, error);
  1220. // }, false);
  1221. // }else{
  1222. // action.getDictWhole(applicationId, encodeURIComponent(this.name), function(json){
  1223. // value = json.data;
  1224. // if (success) success(json.data);
  1225. // }, function(xhr, text, error){
  1226. // if (failure) failure(xhr, text, error);
  1227. // }, false);
  1228. // }
  1229. // return value;
  1230. // };
  1231. //
  1232. // this.set = function(path, value, success, failure){
  1233. // var p = path.replace(/\./g, "/");
  1234. // action.setDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1235. // if (success) success(json.data);
  1236. // }, function(xhr, text, error){
  1237. // if (failure) failure(xhr, text, error);
  1238. // });
  1239. // };
  1240. // this.add = function(path, value, success, failure){
  1241. // var p = path.replace(/\./g, "/");
  1242. // action.addDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1243. // if (success) success(json.data);
  1244. // }, function(xhr, text, error){
  1245. // if (failure) failure(xhr, text, error);
  1246. // });
  1247. // };
  1248. // this["delete"] = function(path, success, failure){
  1249. // var p = path.replace(/\./g, "/");
  1250. // action.deleteDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1251. // if (success) success(json.data);
  1252. // }, function(xhr, text, error){
  1253. // if (failure) failure(xhr, text, error);
  1254. // });
  1255. // };
  1256. // this.destory = this["delete"];
  1257. // }
  1258. //};
  1259. MWF.xScript.createCMSDict = function(application){
  1260. //optionsOrName : {
  1261. // type : "", //默认为cms, 可以为 process cms
  1262. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1263. // name : "", // 数据字典名称/别名/id
  1264. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1265. //}
  1266. //或者name: "" // 数据字典名称/别名/id
  1267. return function(optionsOrName){
  1268. var options = optionsOrName;
  1269. if( typeOf( options ) == "string" ){
  1270. options = { name : options };
  1271. }
  1272. var name = this.name = options.name;
  1273. var type = ( options.type && options.application ) ? options.type : "cms";
  1274. var applicationId = options.application || application;
  1275. var enableAnonymous = options.enableAnonymous || false;
  1276. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1277. if( type == "cms" ){
  1278. var action = MWF.Actions.get("x_cms_assemble_control");
  1279. }else{
  1280. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1281. }
  1282. var encodePath = function( path ){
  1283. var arr = path.split(/\./g);
  1284. // var ar = arr.map(function(v){
  1285. // return encodeURIComponent(v);
  1286. // });
  1287. return arr.join("/");
  1288. };
  1289. this.get = function(path, success, failure){
  1290. var value = null;
  1291. if (path){
  1292. var p = encodePath( path );
  1293. //var p = path.replace(/\./g, "/");
  1294. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1295. value = json.data;
  1296. if (success) success(json.data);
  1297. }, function(xhr, text, error){
  1298. if (failure) failure(xhr, text, error);
  1299. }, false);
  1300. }else{
  1301. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](encodeURIComponent(this.name), applicationId, function(json){
  1302. value = json.data;
  1303. if (success) success(json.data);
  1304. }, function(xhr, text, error){
  1305. if (failure) failure(xhr, text, error);
  1306. }, false);
  1307. }
  1308. return value;
  1309. };
  1310. this.set = function(path, value, success, failure){
  1311. var p = encodePath( path );
  1312. //var p = path.replace(/\./g, "/");
  1313. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1314. if (success) success(json.data);
  1315. }, function(xhr, text, error){
  1316. if (failure) failure(xhr, text, error);
  1317. });
  1318. };
  1319. this.add = function(path, value, success, failure){
  1320. var p = encodePath( path );
  1321. //var p = path.replace(/\./g, "/");
  1322. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1323. if (success) success(json.data);
  1324. }, function(xhr, text, error){
  1325. if (failure) failure(xhr, text, error);
  1326. });
  1327. };
  1328. this["delete"] = function(path, success, failure){
  1329. var p = encodePath( path );
  1330. //var p = path.replace(/\./g, "/");
  1331. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1332. if (success) success(json.data);
  1333. }, function(xhr, text, error){
  1334. if (failure) failure(xhr, text, error);
  1335. });
  1336. };
  1337. this.destory = this["delete"];
  1338. }
  1339. };