CMSEnvironment.js 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498
  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, ev.document.id, data);
  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. getPersonWithIdentity: function(name){
  209. getOrgActions();
  210. var data = {"identityList": getNameFlag(name)};
  211. var v = null;
  212. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  213. return (v && v.length===1) ? v[0] : v;
  214. },
  215. //查询组织成员的人员--返回人员的对象数组
  216. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  217. listPersonWithUnit: function(name, nested){
  218. getOrgActions();
  219. var data = {"unitList": getNameFlag(name)};
  220. var v = null;
  221. if (nested){
  222. orgActions.listPersonWithUnitNested(data, function(json){v = json.data;}, null, false);
  223. }else{
  224. orgActions.listPersonWithUnitDirect(data, function(json){v = json.data;}, null, false);
  225. }
  226. return v;
  227. },
  228. //根据属性查询人员--返回人员的对象数组
  229. //name string 属性名
  230. //value string 属性值
  231. listPersonWithAttribute: function(name, value){
  232. getOrgActions();
  233. var data = {"name": name, "attribute": value};
  234. var v = null;
  235. orgActions.listPersonWithAttribute(data, function(json){v = json.data;}, null, false);
  236. return v;
  237. },
  238. //根据属性查询人员--返回人员的全称数组
  239. //name string 属性名
  240. //value string 属性值
  241. listPersonNameWithAttribute: function(name, value){
  242. getOrgActions();
  243. var data = {"name": name, "attribute": value};
  244. var v = null;
  245. orgActions.listPersonWithAttributeValue(data, function(json){v = json.data.personList;}, null, false);
  246. return v;
  247. },
  248. //人员属性************
  249. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  250. appendPersonAttribute: function(person, attr, values){
  251. getOrgActions();
  252. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  253. var data = {"attributeList":values,"name":attr,"person":personFlag};
  254. orgActions.appendPersonAttribute(data, function(json){
  255. if (json.data.value){
  256. if (success) success();
  257. }else{
  258. if (failure) failure(null, "", "append values failed");
  259. }
  260. }, function(xhr, text, error){
  261. if (failure) failure(xhr, text, error);
  262. }, false);
  263. },
  264. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  265. setPersonAttribute: function(person, attr, values){
  266. getOrgActions();
  267. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  268. var data = {"attributeList":values,"name":attr,"person":personFlag};
  269. orgActions.setPersonAttribute(data, function(json){
  270. if (json.data.value){
  271. if (success) success();
  272. }else{
  273. if (failure) failure(null, "", "append values failed");
  274. }
  275. }, function(xhr, text, error){
  276. if (failure) failure(xhr, text, error);
  277. }, false);
  278. },
  279. //获取人员属性值
  280. getPersonAttribute: function(person, attr){
  281. getOrgActions();
  282. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  283. var data = {"name":attr,"person":personFlag};
  284. var v = null;
  285. orgActions.getPersonAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  286. return v;
  287. },
  288. //列出人员所有属性的名称
  289. listPersonAttributeName: function(name){
  290. getOrgActions();
  291. var data = {"personList":getNameFlag(name)};
  292. var v = null;
  293. orgActions.listPersonAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  294. return v;
  295. },
  296. //列出人员的所有属性
  297. listPersonAllAttribute: function(name){
  298. getOrgActions();
  299. var data = {"personList":getNameFlag(name)};
  300. var v = null;
  301. orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  302. return v;
  303. },
  304. //身份**********
  305. //获取身份
  306. getIdentity: function(name){
  307. getOrgActions();
  308. var data = {"identityList":getNameFlag(name)};
  309. var v = null;
  310. orgActions.listIdentity(data, function(json){v = json.data;}, null, false);
  311. return (v && v.length===1) ? v[0] : v;
  312. },
  313. //列出人员的身份
  314. listIdentityWithPerson: function(name){
  315. getOrgActions();
  316. var data = {"personList":getNameFlag(name)};
  317. var v = null;
  318. orgActions.listIdentityWithPerson(data, function(json){v = json.data;}, null, false);
  319. return v;
  320. },
  321. //查询组织成员身份--返回身份的对象数组
  322. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  323. listIdentityWithUnit: function(name, nested){
  324. getOrgActions();
  325. var data = {"unitList": getNameFlag(name)};
  326. var v = null;
  327. if (nested){
  328. orgActions.listIdentityWithUnitNested(data, function(json){v = json.data;}, null, false);
  329. }else{
  330. orgActions.listIdentityWithUnitDirect(data, function(json){v = json.data;}, null, false);
  331. }
  332. return v;
  333. },
  334. //组织**********
  335. //获取组织
  336. getUnit: function(name){
  337. getOrgActions();
  338. var data = {"unitList":getNameFlag(name)};
  339. var v = null;
  340. orgActions.listUnit(data, function(json){v = json.data;}, null, false);
  341. return (v && v.length===1) ? v[0] : v;
  342. },
  343. //查询组织的下级--返回组织的对象数组
  344. //nested 布尔 true嵌套下级;false直接下级;默认false;
  345. listSubUnit: function(name, nested){
  346. getOrgActions();
  347. var data = {"unitList": getNameFlag(name)};
  348. var v = null;
  349. if (nested){
  350. orgActions.listUnitSubNested(data, function(json){v = json.data;}, null, false);
  351. }else{
  352. orgActions.listUnitSubDirect(data, function(json){v = json.data;}, null, false);
  353. }
  354. return v;
  355. },
  356. //查询组织的上级--返回组织的对象数组
  357. //nested 布尔 true嵌套上级;false直接上级;默认false;
  358. listSupUnit: function(name, nested){
  359. getOrgActions();
  360. var data = {"unitList": getNameFlag(name)};
  361. var v = null;
  362. if (nested){
  363. orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  364. }else{
  365. orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  366. }
  367. return v;
  368. },
  369. //根据个人身份获取组织
  370. //flag 数字 表示获取第几层的组织
  371. // 字符串 表示获取指定类型的组织
  372. // 空 表示获取直接所在的组织
  373. getUnitByIdentity: function(name, flag){
  374. getOrgActions();
  375. var getUnitMethod = "current";
  376. var v;
  377. if (flag){
  378. if (typeOf(flag)==="string") getUnitMethod = "type";
  379. if (typeOf(flag)==="number") getUnitMethod = "level";
  380. }
  381. switch (getUnitMethod){
  382. case "current":
  383. var data = {"identityList":getNameFlag(name)};
  384. orgActions.listUnitWithIdentity(data, function(json){ v = json.data; v=(v&&v.length===1) ? v[0] : v }, null, false);
  385. break;
  386. case "type":
  387. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  388. orgActions.getUnitWithIdentityAndType(data, function(json){ v = json.data; }, null, false);
  389. break;
  390. case "level":
  391. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  392. orgActions.getUnitWithIdentityAndLevel(data, function(json){ v = json.data; }, null, false);
  393. break;
  394. }
  395. return v;
  396. },
  397. //列出身份所在组织的所有上级组织
  398. listAllSupUnitWithIdentity: function(name){
  399. getOrgActions();
  400. var data = {"identityList":getNameFlag(name)};
  401. var v = null;
  402. orgActions.listUnitSupNestedWithIdentity(data, function(json){v = json.data;}, null, false);
  403. return v;
  404. },
  405. //获取人员所在的所有组织
  406. listUnitWithPerson: function(name){
  407. getOrgActions();
  408. var data = {"personList":getNameFlag(name)};
  409. var v = null;
  410. orgActions.listUnitWithPerson(data, function(json){v = json.data;}, null, false);
  411. return v;
  412. },
  413. //列出身份所在组织的所有上级组织
  414. listAllSupUnitWithPerson: function(name){
  415. getOrgActions();
  416. var data = {"personList":getNameFlag(name)};
  417. var v = null;
  418. orgActions.listUnitSupNestedWithPerson(data, function(json){v = json.data;}, null, false);
  419. return v;
  420. },
  421. //根据组织属性,获取所有符合的组织
  422. listUnitWithAttribute: function(name, attribute){
  423. getOrgActions();
  424. var data = {"name":name,"attribute":attribute};
  425. var v = null;
  426. orgActions.listUnitWithAttribute(data, function(json){v = json.data;}, null, false);
  427. return v;
  428. },
  429. //根据组织职务,获取所有符合的组织
  430. listUnitWithDuty: function(name, id){
  431. getOrgActions();
  432. var data = {"name":"","identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  433. var v = null;
  434. orgActions.listUnitWithDuty(data, function(json){v = json.data;}, null, false);
  435. return v;
  436. },
  437. //列出顶层组织
  438. listTopUnit: function(){
  439. var action = MWF.Actions.get("x_organization_assemble_control");
  440. var v = null;
  441. action.listTopUnit(function(json){
  442. v = json.data;
  443. }, null, false);
  444. return v;
  445. },
  446. //组织职务***********
  447. //获取指定的组织职务的身份
  448. getDuty: function(duty, id){
  449. getOrgActions();
  450. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  451. var v = null;
  452. orgActions.getDuty(data, function(json){v = json.data;}, null, false);
  453. return v;
  454. },
  455. //获取身份的所有职务名称
  456. listDutyNameWithIdentity: function(name){
  457. getOrgActions();
  458. var data = {"identityList":getNameFlag(name)};
  459. var v = null;
  460. orgActions.listDutyNameWithIdentity(data, function(json){v = json.data.nameList;}, null, false);
  461. return v;
  462. },
  463. //获取组织的所有职务名称
  464. listDutyNameWithUnit: function(name){
  465. getOrgActions();
  466. var data = {"unitList":getNameFlag(name)};
  467. var v = null;
  468. orgActions.listDutyNameWithUnit(data, function(json){v = json.data.nameList;}, null, false);
  469. return v;
  470. },
  471. //获取组织的所有职务
  472. listUnitAllDuty: function(name){
  473. getOrgActions();
  474. var data = {"unitList":getNameFlag(name)};
  475. var v = null;
  476. orgActions.listUnitAllDuty(data, function(json){v = json.data.nameList;}, null, false);
  477. return v;
  478. },
  479. //组织属性**************
  480. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  481. appendUnitAttribute: function(unit, attr, values){
  482. getOrgActions();
  483. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  484. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  485. orgActions.appendUnitAttribute(data, function(json){
  486. if (json.data.value){
  487. if (success) success();
  488. }else{
  489. if (failure) failure(null, "", "append values failed");
  490. }
  491. }, function(xhr, text, error){
  492. if (failure) failure(xhr, text, error);
  493. }, false);
  494. },
  495. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  496. setUnitAttribute: function(unit, attr, values){
  497. getOrgActions();
  498. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  499. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  500. orgActions.setUnitAttribute(data, function(json){
  501. if (json.data.value){
  502. if (success) success();
  503. }else{
  504. if (failure) failure(null, "", "append values failed");
  505. }
  506. }, function(xhr, text, error){
  507. if (failure) failure(xhr, text, error);
  508. }, false);
  509. },
  510. //获取组织属性值
  511. getUnitAttribute: function(unit, attr){
  512. getOrgActions();
  513. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  514. var data = {"name":attr,"unit":unitFlag};
  515. var v = null;
  516. orgActions.getUnitAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  517. return v;
  518. },
  519. //列出组织所有属性的名称
  520. listUnitAttributeName: function(name){
  521. getOrgActions();
  522. var data = {"unitList":getNameFlag(name)};
  523. var v = null;
  524. orgActions.listUnitAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  525. return v;
  526. },
  527. //列出组织的所有属性
  528. listUnitAllAttribute: function(name){
  529. getOrgActions();
  530. var data = {"unitList":getNameFlag(name)};
  531. var v = null;
  532. orgActions.listUnitAllAttribute(data, function(json){v = json.data;}, null, false);
  533. return v;
  534. }
  535. };
  536. this.Action = (function(){
  537. var actions = [];
  538. return function(root, json){
  539. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  540. action.getActions = function(callback){
  541. if (!this.actions) this.actions = {};
  542. Object.merge(this.actions, json);
  543. if (callback) callback();
  544. };
  545. this.invoke = function(option){
  546. action.invoke(option)
  547. }
  548. }
  549. })();
  550. this.service = {
  551. "jaxwsClient": {},
  552. "jaxrsClient":{}
  553. };
  554. var lookupAction = null;
  555. var getLookupAction = function(callback){
  556. if (!lookupAction){
  557. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  558. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  559. lookupAction.getActions = function(actionCallback){
  560. this.actions = {
  561. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  562. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  563. };
  564. if (actionCallback) actionCallback();
  565. }
  566. if (callback) callback();
  567. }.bind(this));
  568. }else{
  569. if (callback) callback();
  570. }
  571. };
  572. this.view = {
  573. "lookup": function(view, callback, async){
  574. var filterList = {"filterList": (view.filter || null)};
  575. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  576. var data = {
  577. "grid": json.data.grid || json.data.groupGrid,
  578. "groupGrid": json.data.groupGrid
  579. };
  580. if (callback) callback(data);
  581. }, null, async);
  582. },
  583. "lookupV1": function(view, callback){
  584. getLookupAction(function(){
  585. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  586. var data = {
  587. "grid": json.data.grid,
  588. "groupGrid": json.data.groupGrid
  589. };
  590. if (callback) callback(data);
  591. }.bind(this)});
  592. }.bind(this));
  593. },
  594. "select": function(view, callback, options){
  595. if (view.view){
  596. var viewJson = {
  597. "application": view.application || _form.json.application,
  598. "viewName": view.view || "",
  599. "isTitle": (view.isTitle===false) ? "no" : "yes",
  600. "select": (view.isMulti===false) ? "single" : "multi",
  601. "filter": view.filter
  602. };
  603. if (!options) options = {};
  604. options.width = view.width;
  605. options.height = view.height;
  606. options.title = view.caption;
  607. var width = options.width || "700";
  608. var height = options.height || "400";
  609. if (layout.mobile){
  610. var size = document.body.getSize();
  611. width = size.x;
  612. height = size.y;
  613. options.style = "viewmobile";
  614. }
  615. width = width.toInt();
  616. height = height.toInt();
  617. var size = _form.app.content.getSize();
  618. var x = (size.x-width)/2;
  619. var y = (size.y-height)/2;
  620. if (x<0) x = 0;
  621. if (y<0) y = 0;
  622. if (layout.mobile){
  623. x = 20;
  624. y = 0;
  625. }
  626. var _self = this;
  627. MWF.require("MWF.xDesktop.Dialog", function(){
  628. var dlg = new MWF.xDesktop.Dialog({
  629. "title": options.title || "select view",
  630. "style": options.style || "view",
  631. "top": y,
  632. "left": x-20,
  633. "fromTop":y,
  634. "fromLeft": x-20,
  635. "width": width,
  636. "height": height,
  637. "html": "<div style='height: 100%;'></div>",
  638. "maskNode": _form.app.content,
  639. "container": _form.app.content,
  640. "buttonList": [
  641. {
  642. "text": MWF.LP.process.button.ok,
  643. "action": function(){
  644. //if (callback) callback(_self.view.selectedItems);
  645. if (callback) callback(_self.view.getData());
  646. this.close();
  647. }
  648. },
  649. {
  650. "text": MWF.LP.process.button.cancel,
  651. "action": function(){this.close();}
  652. }
  653. ]
  654. });
  655. dlg.show();
  656. if (layout.mobile){
  657. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  658. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  659. if (backAction) backAction.addEvent("click", function(e){
  660. dlg.close();
  661. }.bind(this));
  662. if (okAction) okAction.addEvent("click", function(e){
  663. //if (callback) callback(this.view.selectedItems);
  664. if (callback) callback(this.view.getData());
  665. dlg.close();
  666. }.bind(this));
  667. }
  668. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  669. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  670. }.bind(this));
  671. }.bind(this));
  672. }
  673. }
  674. };
  675. //var lookupAction = null;
  676. //var getLookupAction = function(callback){
  677. // if (!lookupAction){
  678. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  679. // lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  680. // lookupAction.getActions = function(actionCallback){
  681. // this.actions = {
  682. // "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  683. // "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  684. // };
  685. // if (actionCallback) actionCallback();
  686. // }
  687. // if (callback) callback();
  688. // }.bind(this));
  689. // }else{
  690. // if (callback) callback();
  691. // }
  692. //};
  693. //
  694. //this.view = {
  695. // "lookup": function(view, callback){
  696. // getLookupAction(function(){
  697. // lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  698. // var data = {
  699. // "grid": json.data.grid,
  700. // "groupGrid": json.data.groupGrid
  701. // };
  702. // if (callback) callback(data);
  703. // }.bind(this)});
  704. // }.bind(this));
  705. // },
  706. // "select": function(view, callback, options){
  707. // if (view.view){
  708. // var viewJson = {
  709. // "application": view.application || "",
  710. // "viewName": view.view || "",
  711. // "isTitle": view.isTitle || "yes",
  712. // "select": view.select || "multi",
  713. // "title": view.title || "Select View"
  714. // };
  715. // if (!options) options = {};
  716. // var width = options.width || "700";
  717. // var height = options.height || "400";
  718. //
  719. // if (layout.mobile){
  720. // var size = document.body.getSize();
  721. // width = size.x;
  722. // height = size.y;
  723. // options.style = "viewmobile";
  724. // }
  725. // width = width.toInt();
  726. // height = height.toInt();
  727. //
  728. // var size = _form.app.content.getSize();
  729. // var x = (size.x-width)/2;
  730. // var y = (size.y-height)/2;
  731. // if (x<0) x = 0;
  732. // if (y<0) y = 0;
  733. // if (layout.mobile){
  734. // x = 20;
  735. // y = 0;
  736. // }
  737. //
  738. // var _self = this;
  739. // MWF.require("MWF.xDesktop.Dialog", function(){
  740. // var dlg = new MWF.xDesktop.Dialog({
  741. // "title": options.title || "select View",
  742. // "style": options.style || "view",
  743. // "top": y,
  744. // "left": x-20,
  745. // "fromTop":y,
  746. // "fromLeft": x-20,
  747. // "width": width,
  748. // "height": height,
  749. // "html": "<div style='height: 100%;'></div>",
  750. // "maskNode": _form.app.content,
  751. // "container": _form.app.content,
  752. // "buttonList": [
  753. // {
  754. // "text": MWF.LP.process.button.ok,
  755. // "action": function(){
  756. // //if (callback) callback(_self.view.selectedItems);
  757. // if (callback) callback(_self.view.getData());
  758. // this.close();
  759. // }
  760. // },
  761. // {
  762. // "text": MWF.LP.process.button.cancel,
  763. // "action": function(){this.close();}
  764. // }
  765. // ]
  766. // });
  767. // dlg.show();
  768. // if (layout.mobile){
  769. // var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  770. // var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  771. // if (backAction) backAction.addEvent("click", function(e){
  772. // dlg.close();
  773. // }.bind(this));
  774. // if (okAction) okAction.addEvent("click", function(e){
  775. // //if (callback) callback(this.view.selectedItems);
  776. // if (callback) callback(this.view.getData());
  777. // dlg.close();
  778. // }.bind(this));
  779. // }
  780. //
  781. // // MWF.xDesktop.requireApp("cms.Xform", "widget.View", function(){
  782. // // this.view = new MWF.xApplication.cms.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  783. // // }.bind(this));
  784. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  785. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  786. // }.bind(this));
  787. // }.bind(this));
  788. // }
  789. // }
  790. //};
  791. //include 引用脚本
  792. //optionsOrName : {
  793. // type : "", 默认为cms, 可以为 portal process cms
  794. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  795. // name : "" // 脚本名称/别名/id
  796. //}
  797. //或者name: "" // 脚本名称/别名/id
  798. if( !window.includedScripts ){
  799. var includedScripts = window.includedScripts = [];
  800. }else{
  801. var includedScripts = window.includedScripts;
  802. }
  803. this.include = function( optionsOrName , callback ){
  804. var options = optionsOrName;
  805. if( typeOf( options ) == "string" ){
  806. options = { name : options };
  807. }
  808. var name = options.name;
  809. var type = ( options.type && options.application ) ? options.type : "cms";
  810. var application = options.application || _form.json.application;
  811. if (includedScripts.indexOf( name )> -1){
  812. if (callback) callback.apply(this);
  813. return;
  814. }
  815. var scriptAction;
  816. switch ( type ){
  817. case "portal" :
  818. if( this.scriptActionPortal ){
  819. scriptAction = this.scriptActionPortal;
  820. }else{
  821. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  822. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  823. }
  824. break;
  825. case "process" :
  826. if( this.scriptActionProcess ){
  827. scriptAction = this.scriptActionProcess;
  828. }else{
  829. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  830. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  831. }
  832. break;
  833. case "cms" :
  834. if( this.scriptActionCMS ){
  835. scriptAction = this.scriptActionCMS;
  836. }else{
  837. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  838. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  839. }
  840. break;
  841. }
  842. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  843. if (json.data){
  844. includedScripts = includedScripts.concat(json.data.importedList);
  845. MWF.Macro.exec(json.data.text, this);
  846. if (callback) callback.apply(this);
  847. }else{
  848. if (callback) callback.apply(this);
  849. }
  850. }.bind(this), null, false);
  851. };
  852. //var includedScripts = [];
  853. //this.include = function(name, callback){
  854. // if (includedScripts.indexOf(name)==-1){
  855. // if (!this.scriptAction){
  856. // MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  857. // this.scriptAction = new MWF.xScript.Actions.CMSScriptActions();
  858. // }
  859. // this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
  860. // includedScripts = includedScripts.concat(json.data.importedList);
  861. // MWF.Macro.exec(json.data.text, this);
  862. // if (callback) callback.apply(this);
  863. // }.bind(this), null, false);
  864. // }else{
  865. // if (callback) callback.apply(this);
  866. // }
  867. //}.bind(this);
  868. this.define = function(name, fun, overwrite){
  869. var over = true;
  870. if (overwrite===false) over = false;
  871. var o = {};
  872. o[name] = {"value": fun, "configurable": over};
  873. MWF.defineProperties(this, o);
  874. }.bind(this);
  875. //仅前台对象-----------------------------------------
  876. //form
  877. this.form = {
  878. "getInfor": function(){return ev.formInfor;},
  879. "infor": ev.formInfor,
  880. "getApp": function(){return _form.app;},
  881. "app": _form.app,
  882. "node": function(){return _form.node;},
  883. "readonly": _form.options.readonly,
  884. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  885. "getField": function(name){return _forms[name];},
  886. "getAction": function(){return _form.documentAction},
  887. "getData": function(){return new MWF.xScript.CMSJSONData(_form.getData());},
  888. "save": function(callback){
  889. _form.saveDocument(callback);
  890. },
  891. "close": function(){_form.closeDocument();},
  892. "publish": function(option){
  893. _form.publishDocument()
  894. },
  895. //"archive": function(option){
  896. // _form.archiveDocument()
  897. //},
  898. //"redraft": function(option){
  899. // _form.redraftDocument()
  900. //},
  901. "confirm": function(type, title, text, width, height, ok, cancel, callback){
  902. var p = MWF.getCenter({"x": width, "y": height});
  903. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  904. _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  905. },
  906. //"confirm": function(type, e, title, text, width, height, ok, cancel, callback){
  907. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  908. //},
  909. "notice": function(content, type, target, where){
  910. _form.notice(content, type, target, where);
  911. },
  912. "addEvent": function(e, f){_form.addEvent(e, f);},
  913. "openWork": function(id, completedId, title, options){
  914. var op = options || {};
  915. op.workId = id;
  916. op.workCompletedId = completedId;
  917. op.docTitle = title;
  918. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  919. layout.desktop.openApplication(this.event, "process.Work", op);
  920. },
  921. "openJob": function(id, choice, options){
  922. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  923. var len = json.data.workList.length + json.data.workCompletedList.length;
  924. if (len){
  925. if (len>1 && choice){
  926. }else{
  927. if (json.data.workList.length){
  928. var work = json.data.workList[0];
  929. this.openWork(work.id, null, work.title, options);
  930. }else{
  931. var work = json.data.workCompletedList[0];
  932. this.openWork(null, work.id, work.title, options);
  933. }
  934. }
  935. }
  936. }.bind(this));
  937. },
  938. "openDocument": function(id, title, options){
  939. var op = options || {};
  940. op.documentId = id;
  941. op.docTitle = title;
  942. layout.desktop.openApplication(this.event, "cms.Document", op);
  943. },
  944. "openPortal": function(name, page, par){
  945. var action = MWF.Actions.get("x_portal_assemble_surface");
  946. action.getApplication(name, function(json){
  947. if (json.data){
  948. if (page){
  949. action.getPageByName(page, json.data.id, function(pageJson){
  950. layout.desktop.openApplication(null, "portal.Portal", {
  951. "portalId": json.data.id,
  952. "pageId": (pageJson.data) ? pageJson.data.id : "",
  953. "parameters": par,
  954. "appId": "portal.Portal"+json.data.id
  955. })
  956. });
  957. }else{
  958. layout.desktop.openApplication(null, "portal.Portal", {
  959. "portalId": json.data.id,
  960. "parameters": par,
  961. "appId": "portal.Portal"+json.data.id
  962. })
  963. }
  964. }
  965. });
  966. },
  967. "openCMS": function(name){
  968. var action = MWF.Actions.get("x_cms_assemble_control");
  969. action.getColumn(name, function(json){
  970. if (json.data){
  971. layout.desktop.openApplication(null, "cms.Module", {
  972. "columnId": json.data.id,
  973. "appId": "cms.Module"+json.data.id
  974. });
  975. }
  976. });
  977. },
  978. "openProcess": function(name){
  979. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  980. action.getApplication(name, function(json){
  981. if (json.data){
  982. layout.desktop.openApplication(null, "process.Application", {
  983. "id": json.data.id,
  984. "appId": "process.Application"+json.data.id
  985. });
  986. }
  987. });
  988. },
  989. "openApplication":function(name, options){
  990. layout.desktop.openApplication(null, name, options);
  991. },
  992. "createDocument" : function(columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle){
  993. var column = columnOrOptions;
  994. if( typeOf( columnOrOptions ) == "object" ){
  995. column = columnOrOptions.column;
  996. category = columnOrOptions.category;
  997. data = columnOrOptions.data;
  998. identity = columnOrOptions.identity;
  999. callback = columnOrOptions.callback;
  1000. target = columnOrOptions.target;
  1001. latest = columnOrOptions.latest;
  1002. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1003. ignoreTitle = columnOrOptions.ignoreTitle;
  1004. }
  1005. if (target){
  1006. if (layout.app && layout.app.inBrowser){
  1007. layout.app.content.empty();
  1008. layout.app = null;
  1009. }
  1010. }
  1011. MWF.xDesktop.requireApp("cms.Index", "Newer", function(){
  1012. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1013. "documentData": data,
  1014. "identity": identity,
  1015. "ignoreTitle" : ignoreTitle === true,
  1016. "ignoreDrafted" : latest === false,
  1017. "selectColumnEnable" : !category || selectColumnEnable === true,
  1018. "restrictToColumn" : !!category && selectColumnEnable !== true,
  1019. "categoryFlag" : category, //category id or name
  1020. "columnFlag" : column, //column id or name,
  1021. "onStarted" : function( documentId, data ){
  1022. if(callback)callback();
  1023. },
  1024. "onPostLoad" : function(){
  1025. },
  1026. "onPostPublish" : function(){
  1027. }
  1028. });
  1029. starter.load();
  1030. })
  1031. },
  1032. "startProcess": function(app, process, data, identity, callback, target, latest){
  1033. if (arguments.length>2){
  1034. for (var i=2; i<arguments.length; i++){
  1035. if (typeOf(arguments[i])=="boolean"){
  1036. target = arguments[i];
  1037. break;
  1038. }
  1039. }
  1040. }
  1041. if (target){
  1042. if (layout.app && layout.app.inBrowser){
  1043. layout.app.content.empty();
  1044. layout.app = null;
  1045. }
  1046. }
  1047. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1048. if (json.data){
  1049. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1050. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1051. "workData": data,
  1052. "identity": identity,
  1053. "latest": latest,
  1054. "onStarted": function(data, title, processName){
  1055. var currentTask = [];
  1056. data.each(function(work){
  1057. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1058. }.bind(this));
  1059. if (currentTask.length==1){
  1060. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1061. layout.desktop.openApplication(null, "process.Work", options);
  1062. }else{}
  1063. if (callback) callback(data);
  1064. }.bind(this)
  1065. });
  1066. starter.load();
  1067. }.bind(this));
  1068. }
  1069. });
  1070. }
  1071. };
  1072. this.target = ev.target;
  1073. this.event = ev.event;
  1074. this.status = ev.status;
  1075. this.session = layout.desktop.session;
  1076. this.Actions = o2.Actions;
  1077. this.query = function(option){
  1078. // options = {
  1079. // "name": "statementName",
  1080. // "data": "json data",
  1081. // "firstResult": 1,
  1082. // "maxResults": 100,
  1083. // "success": function(){},
  1084. // "error": function(){},
  1085. // "async": true or false, default is true
  1086. // }
  1087. if (option){
  1088. var json = (option.data) || {};
  1089. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1090. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1091. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1092. }
  1093. };
  1094. this.Table = MWF.xScript.createTable();
  1095. };
  1096. MWF.xScript.createTable = function(){
  1097. return function(name){
  1098. this.name = name;
  1099. this.action = o2.Actions.get("x_query_assemble_surface");
  1100. this.listRowNext = function(id, count, success, error, async){
  1101. this.action.listRowNext(this.name, id, count, success, error, async);
  1102. };
  1103. this.listRowPrev = function(id, count, success, error, async){
  1104. this.action.listRowPrev(this.name, id, count, success, error, async);
  1105. };
  1106. this.listRowPrev = function(id, count, success, error, async){
  1107. this.action.listRowPrev(this.name, id, count, success, error, async);
  1108. };
  1109. this.listRowSelectWhere = function(where, success, error, async){
  1110. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1111. };
  1112. this.listRowCountWhere = function(where, success, error, async){
  1113. this.action.listRowCountWhere(this.name, where, success, error, async);
  1114. };
  1115. this.deleteRow = function(id, success, error, async){
  1116. this.action.deleteRow(this.name, id, success, error, async);
  1117. };
  1118. this.deleteAllRow = function(success, error, async){
  1119. this.action.deleteAllRow(this.name, success, error, async);
  1120. };
  1121. this.getRow = function(id, success, error, async){
  1122. this.action.getRow(this.name, id, success, error, async);
  1123. };
  1124. this.insertRow = function(data, success, error, async){
  1125. this.action.insertRow(this.name, data, success, error, async);
  1126. };
  1127. this.updateRow = function(id, data, success, error, async){
  1128. this.action.updateRow(this.name, id, data, success, error, async);
  1129. };
  1130. }
  1131. };
  1132. MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1133. var getter = function(data, callback, k, _self){
  1134. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1135. };
  1136. var setter = function(data, callback, k, _self){
  1137. return function(v){
  1138. data[k] = v;
  1139. //debugger;
  1140. //this.add(k, v, true);
  1141. if (callback) callback(data, k, _self);
  1142. }
  1143. };
  1144. var define = function(){
  1145. var o = {};
  1146. 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])};
  1147. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1148. MWF.defineProperties(this, o);
  1149. var methods = {
  1150. "getKey": {"value": function(){ return key; }},
  1151. "getParent": {"value": function(){ return parent; }},
  1152. "toString": {"value": function() { return data.toString();}},
  1153. "add": {"value": function(newKey, newValue, overwrite){
  1154. var flag = true;
  1155. var type = typeOf(data);
  1156. if (type==="array"){
  1157. if (arguments.length<2){
  1158. data.push(newKey);
  1159. newValue = newKey;
  1160. newKey = data.length-1;
  1161. }else{
  1162. if (!newKey && newKey!==0){
  1163. data.push(newValue);
  1164. newKey = data.length-1;
  1165. }else{
  1166. flag = false;
  1167. }
  1168. }
  1169. if (flag){
  1170. var o = {};
  1171. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1172. MWF.defineProperties(this, o);
  1173. }
  1174. this[newKey] = newValue;
  1175. }else if (type==="object"){
  1176. if (!this.hasOwnProperty(newKey)){
  1177. data[newKey] = newValue;
  1178. if (flag){
  1179. var o = {};
  1180. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1181. MWF.defineProperties(this, o);
  1182. }
  1183. this[newKey] = newValue;
  1184. }else{
  1185. if (overwrite) this[newKey] = newValue;
  1186. }
  1187. }
  1188. return this[newKey];
  1189. }},
  1190. "del": {"value": function(delKey){
  1191. if (!this.hasOwnProperty(delKey)) return null;
  1192. delete data[delKey];
  1193. delete this[delKey];
  1194. return this;
  1195. }}
  1196. };
  1197. MWF.defineProperties(this, methods);
  1198. //this.getKey = function(){ return key; };
  1199. //this.getParent = function(){ return parent; };
  1200. //this.toString = function() { return data.toString();};
  1201. //this.add = function(newKey, newValue, overwrite){
  1202. // var flag = true;
  1203. // var type = typeOf(data);
  1204. // if (!this.hasOwnProperty(newKey)){
  1205. // if (type=="array"){
  1206. // if (arguments.length<2){
  1207. // data.push(newKey);
  1208. // newValue = newKey;
  1209. // newKey = data.length-1;
  1210. // }else{
  1211. // debugger;
  1212. // if (!newKey && newKey!=0){
  1213. // data.push(newValue);
  1214. // newKey = data.length-1;
  1215. // }else{
  1216. // flag == false;
  1217. // }
  1218. // }
  1219. // }else{
  1220. // data[newKey] = newValue;
  1221. // }
  1222. // //var valueType = typeOf(newValue);
  1223. // //var newValueData = newValue;
  1224. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1225. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1226. // if (flag){
  1227. // var o = {};
  1228. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1229. // MWF.defineProperties(this, o);
  1230. // }
  1231. // this[newKey] = newValue;
  1232. // }else{
  1233. // if (overwrite) this[newKey] = newValue;
  1234. // }
  1235. //
  1236. // //var valueType = typeOf(newValue);
  1237. // //var newValueData = newValue;
  1238. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1239. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1240. // //
  1241. // //this[newKey] = newValueData;
  1242. //
  1243. // return this[newKey];
  1244. //};
  1245. //this.del = function(delKey){
  1246. // if (!this.hasOwnProperty(delKey)) return null;
  1247. // delete data[newKey];
  1248. // delete this[newKey];
  1249. // return this;
  1250. //};
  1251. };
  1252. var type = typeOf(data);
  1253. if (type==="object" || type==="array") define.apply(this);
  1254. };
  1255. //MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1256. // var getter = function(data, callback, k, _self){
  1257. // return function(){return (["array","object"].indexOf(typeOf(data[k]))==-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1258. // }
  1259. // var setter = function(data, callback, k, _self){
  1260. // return function(v){
  1261. // data[k] = v;
  1262. // if (callback) callback(data, k, _self);
  1263. // }
  1264. // }
  1265. // var define = function(){
  1266. // var o = {};
  1267. // for (var k in data) o[k] = {
  1268. // "configurable": true,
  1269. // "get": getter.apply(this, [data, callback, k, this]),
  1270. // "set": setter.apply(this, [data, callback, k, this])
  1271. // };
  1272. // o["length"] = {"get": function(){return Object.keys(data).length;}};
  1273. // MWF.defineProperties(this, o);
  1274. // this.getKey = function(){ return key; };
  1275. // this.getParent = function(){ return parent; };
  1276. // this.toString = function() { return data.toString();};
  1277. // this.add = function(newKey, newValue){
  1278. // var type = typeOf(data);
  1279. // if (!this.hasOwnProperty(newKey)){
  1280. // if (type=="array"){
  1281. // data.push(newValue || {});
  1282. // newKey = data.length-1;
  1283. // }else{
  1284. // data[newKey] = newValue || {};
  1285. // }
  1286. // var o = {};
  1287. // o[newKey] = {"configurable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1288. // MWF.defineProperties(this, o);
  1289. // }
  1290. // this[newKey] = newValue;
  1291. // return this;
  1292. // };
  1293. // this.del = function(delKey){
  1294. // if (!this.hasOwnProperty(delKey)) return null;
  1295. // delete data[newKey];
  1296. // delete this[newKey];
  1297. // return this;
  1298. // };
  1299. // }
  1300. // var type = typeOf(data);
  1301. // if (type=="object" || type=="array") define.apply(this);
  1302. //};
  1303. //MWF.xScript.createCMSDict = function(application){
  1304. // return function(name){
  1305. // var applicationId = application;
  1306. // this.name = name;
  1307. // MWF.require("MWF.xScript.Actions.CMSDictActions", null, false);
  1308. // var action = new MWF.xScript.Actions.CMSDictActions();
  1309. //
  1310. // this.get = function(path, success, failure){
  1311. // var value = null;
  1312. // if( path ){
  1313. // var arr = path.split(/\./g);
  1314. // var ar = arr.map(function(v){
  1315. // return encodeURIComponent(v);
  1316. // });
  1317. // //var p = path.replace(/\./g, "/");
  1318. // var p = ar.join("/");
  1319. // action.getDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1320. // value = json.data;
  1321. // if (success) success(json.data);
  1322. // }, function(xhr, text, error){
  1323. // if (failure) failure(xhr, text, error);
  1324. // }, false);
  1325. // }else{
  1326. // action.getDictWhole(applicationId, encodeURIComponent(this.name), function(json){
  1327. // value = json.data;
  1328. // if (success) success(json.data);
  1329. // }, function(xhr, text, error){
  1330. // if (failure) failure(xhr, text, error);
  1331. // }, false);
  1332. // }
  1333. // return value;
  1334. // };
  1335. //
  1336. // this.set = function(path, value, success, failure){
  1337. // var p = path.replace(/\./g, "/");
  1338. // action.setDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1339. // if (success) success(json.data);
  1340. // }, function(xhr, text, error){
  1341. // if (failure) failure(xhr, text, error);
  1342. // });
  1343. // };
  1344. // this.add = function(path, value, success, failure){
  1345. // var p = path.replace(/\./g, "/");
  1346. // action.addDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1347. // if (success) success(json.data);
  1348. // }, function(xhr, text, error){
  1349. // if (failure) failure(xhr, text, error);
  1350. // });
  1351. // };
  1352. // this["delete"] = function(path, success, failure){
  1353. // var p = path.replace(/\./g, "/");
  1354. // action.deleteDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1355. // if (success) success(json.data);
  1356. // }, function(xhr, text, error){
  1357. // if (failure) failure(xhr, text, error);
  1358. // });
  1359. // };
  1360. // this.destory = this["delete"];
  1361. // }
  1362. //};
  1363. MWF.xScript.createCMSDict = function(application){
  1364. //optionsOrName : {
  1365. // type : "", //默认为cms, 可以为 process cms
  1366. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1367. // name : "", // 数据字典名称/别名/id
  1368. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1369. //}
  1370. //或者name: "" // 数据字典名称/别名/id
  1371. return function(optionsOrName){
  1372. var options = optionsOrName;
  1373. if( typeOf( options ) == "string" ){
  1374. options = { name : options };
  1375. }
  1376. var name = this.name = options.name;
  1377. var type = ( options.type && options.application ) ? options.type : "cms";
  1378. var applicationId = options.application || application;
  1379. var enableAnonymous = options.enableAnonymous || false;
  1380. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1381. if( type == "cms" ){
  1382. var action = MWF.Actions.get("x_cms_assemble_control");
  1383. }else{
  1384. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1385. }
  1386. var encodePath = function( path ){
  1387. var arr = path.split(/\./g);
  1388. var ar = arr.map(function(v){
  1389. return encodeURIComponent(v);
  1390. });
  1391. return ar.join("/");
  1392. };
  1393. this.get = function(path, success, failure){
  1394. var value = null;
  1395. if (path){
  1396. var p = encodePath( path );
  1397. //var p = path.replace(/\./g, "/");
  1398. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1399. value = json.data;
  1400. if (success) success(json.data);
  1401. }, function(xhr, text, error){
  1402. if (failure) failure(xhr, text, error);
  1403. }, false, false);
  1404. }else{
  1405. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](encodeURIComponent(this.name), applicationId, function(json){
  1406. value = json.data;
  1407. if (success) success(json.data);
  1408. }, function(xhr, text, error){
  1409. if (failure) failure(xhr, text, error);
  1410. }, false);
  1411. }
  1412. return value;
  1413. };
  1414. this.set = function(path, value, success, failure){
  1415. var p = encodePath( path );
  1416. //var p = path.replace(/\./g, "/");
  1417. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1418. if (success) success(json.data);
  1419. }, function(xhr, text, error){
  1420. if (failure) failure(xhr, text, error);
  1421. }, false, false);
  1422. };
  1423. this.add = function(path, value, success, failure){
  1424. var p = encodePath( path );
  1425. //var p = path.replace(/\./g, "/");
  1426. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1427. if (success) success(json.data);
  1428. }, function(xhr, text, error){
  1429. if (failure) failure(xhr, text, error);
  1430. }, false, false);
  1431. };
  1432. this["delete"] = function(path, success, failure){
  1433. var p = encodePath( path );
  1434. //var p = path.replace(/\./g, "/");
  1435. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1436. if (success) success(json.data);
  1437. }, function(xhr, text, error){
  1438. if (failure) failure(xhr, text, error);
  1439. }, false, false);
  1440. };
  1441. this.destory = this["delete"];
  1442. }
  1443. };