CMSEnvironment.js 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  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 = {"identityList":getNameFlag(name)};
  356. orgActions.listUnitWithIdentity(data, function(json){ v = json.data; v=(v&&v.length===1) ? v[0] : v }, 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 = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  364. orgActions.getUnitWithIdentityAndLevel(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===false) ? "no" : "yes",
  572. "select": (view.isMulti===false) ? "single" : "multi",
  573. "filter": view.filter
  574. };
  575. if (!options) options = {};
  576. options.width = view.width;
  577. options.height = view.height;
  578. options.title = view.caption;
  579. var width = options.width || "700";
  580. var height = options.height || "400";
  581. if (layout.mobile){
  582. var size = document.body.getSize();
  583. width = size.x;
  584. height = size.y;
  585. options.style = "viewmobile";
  586. }
  587. width = width.toInt();
  588. height = height.toInt();
  589. var size = _form.app.content.getSize();
  590. var x = (size.x-width)/2;
  591. var y = (size.y-height)/2;
  592. if (x<0) x = 0;
  593. if (y<0) y = 0;
  594. if (layout.mobile){
  595. x = 20;
  596. y = 0;
  597. }
  598. var _self = this;
  599. MWF.require("MWF.xDesktop.Dialog", function(){
  600. var dlg = new MWF.xDesktop.Dialog({
  601. "title": options.title || "select view",
  602. "style": options.style || "view",
  603. "top": y,
  604. "left": x-20,
  605. "fromTop":y,
  606. "fromLeft": x-20,
  607. "width": width,
  608. "height": height,
  609. "html": "<div style='height: 100%;'></div>",
  610. "maskNode": _form.app.content,
  611. "container": _form.app.content,
  612. "buttonList": [
  613. {
  614. "text": MWF.LP.process.button.ok,
  615. "action": function(){
  616. //if (callback) callback(_self.view.selectedItems);
  617. if (callback) callback(_self.view.getData());
  618. this.close();
  619. }
  620. },
  621. {
  622. "text": MWF.LP.process.button.cancel,
  623. "action": function(){this.close();}
  624. }
  625. ]
  626. });
  627. dlg.show();
  628. if (layout.mobile){
  629. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  630. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  631. if (backAction) backAction.addEvent("click", function(e){
  632. dlg.close();
  633. }.bind(this));
  634. if (okAction) okAction.addEvent("click", function(e){
  635. //if (callback) callback(this.view.selectedItems);
  636. if (callback) callback(this.view.getData());
  637. dlg.close();
  638. }.bind(this));
  639. }
  640. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  641. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  642. }.bind(this));
  643. }.bind(this));
  644. }
  645. }
  646. };
  647. //var lookupAction = null;
  648. //var getLookupAction = function(callback){
  649. // if (!lookupAction){
  650. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  651. // lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  652. // lookupAction.getActions = function(actionCallback){
  653. // this.actions = {
  654. // "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  655. // "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  656. // };
  657. // if (actionCallback) actionCallback();
  658. // }
  659. // if (callback) callback();
  660. // }.bind(this));
  661. // }else{
  662. // if (callback) callback();
  663. // }
  664. //};
  665. //
  666. //this.view = {
  667. // "lookup": function(view, callback){
  668. // getLookupAction(function(){
  669. // lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  670. // var data = {
  671. // "grid": json.data.grid,
  672. // "groupGrid": json.data.groupGrid
  673. // };
  674. // if (callback) callback(data);
  675. // }.bind(this)});
  676. // }.bind(this));
  677. // },
  678. // "select": function(view, callback, options){
  679. // if (view.view){
  680. // var viewJson = {
  681. // "application": view.application || "",
  682. // "viewName": view.view || "",
  683. // "isTitle": view.isTitle || "yes",
  684. // "select": view.select || "multi",
  685. // "title": view.title || "Select View"
  686. // };
  687. // if (!options) options = {};
  688. // var width = options.width || "700";
  689. // var height = options.height || "400";
  690. //
  691. // if (layout.mobile){
  692. // var size = document.body.getSize();
  693. // width = size.x;
  694. // height = size.y;
  695. // options.style = "viewmobile";
  696. // }
  697. // width = width.toInt();
  698. // height = height.toInt();
  699. //
  700. // var size = _form.app.content.getSize();
  701. // var x = (size.x-width)/2;
  702. // var y = (size.y-height)/2;
  703. // if (x<0) x = 0;
  704. // if (y<0) y = 0;
  705. // if (layout.mobile){
  706. // x = 20;
  707. // y = 0;
  708. // }
  709. //
  710. // var _self = this;
  711. // MWF.require("MWF.xDesktop.Dialog", function(){
  712. // var dlg = new MWF.xDesktop.Dialog({
  713. // "title": options.title || "select View",
  714. // "style": options.style || "view",
  715. // "top": y,
  716. // "left": x-20,
  717. // "fromTop":y,
  718. // "fromLeft": x-20,
  719. // "width": width,
  720. // "height": height,
  721. // "html": "<div style='height: 100%;'></div>",
  722. // "maskNode": _form.app.content,
  723. // "container": _form.app.content,
  724. // "buttonList": [
  725. // {
  726. // "text": MWF.LP.process.button.ok,
  727. // "action": function(){
  728. // //if (callback) callback(_self.view.selectedItems);
  729. // if (callback) callback(_self.view.getData());
  730. // this.close();
  731. // }
  732. // },
  733. // {
  734. // "text": MWF.LP.process.button.cancel,
  735. // "action": function(){this.close();}
  736. // }
  737. // ]
  738. // });
  739. // dlg.show();
  740. // if (layout.mobile){
  741. // var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  742. // var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  743. // if (backAction) backAction.addEvent("click", function(e){
  744. // dlg.close();
  745. // }.bind(this));
  746. // if (okAction) okAction.addEvent("click", function(e){
  747. // //if (callback) callback(this.view.selectedItems);
  748. // if (callback) callback(this.view.getData());
  749. // dlg.close();
  750. // }.bind(this));
  751. // }
  752. //
  753. // // MWF.xDesktop.requireApp("cms.Xform", "widget.View", function(){
  754. // // this.view = new MWF.xApplication.cms.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  755. // // }.bind(this));
  756. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  757. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  758. // }.bind(this));
  759. // }.bind(this));
  760. // }
  761. // }
  762. //};
  763. //include 引用脚本
  764. //optionsOrName : {
  765. // type : "", 默认为cms, 可以为 portal process cms
  766. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  767. // name : "" // 脚本名称/别名/id
  768. //}
  769. //或者name: "" // 脚本名称/别名/id
  770. if( !window.includedScripts ){
  771. var includedScripts = window.includedScripts = [];
  772. }else{
  773. var includedScripts = window.includedScripts;
  774. }
  775. this.include = function( optionsOrName , callback ){
  776. var options = optionsOrName;
  777. if( typeOf( options ) == "string" ){
  778. options = { name : options };
  779. }
  780. var name = options.name;
  781. var type = ( options.type && options.application ) ? options.type : "cms";
  782. var application = options.application || _form.json.application;
  783. if (includedScripts.indexOf( name )> -1){
  784. if (callback) callback.apply(this);
  785. return;
  786. }
  787. var scriptAction;
  788. switch ( type ){
  789. case "portal" :
  790. if( this.scriptActionPortal ){
  791. scriptAction = this.scriptActionPortal;
  792. }else{
  793. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  794. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  795. }
  796. break;
  797. case "process" :
  798. if( this.scriptActionProcess ){
  799. scriptAction = this.scriptActionProcess;
  800. }else{
  801. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  802. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  803. }
  804. break;
  805. case "cms" :
  806. if( this.scriptActionCMS ){
  807. scriptAction = this.scriptActionCMS;
  808. }else{
  809. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  810. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  811. }
  812. break;
  813. }
  814. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  815. if (json.data){
  816. includedScripts = includedScripts.concat(json.data.importedList);
  817. MWF.Macro.exec(json.data.text, this);
  818. if (callback) callback.apply(this);
  819. }else{
  820. if (callback) callback.apply(this);
  821. }
  822. }.bind(this), null, false);
  823. };
  824. //var includedScripts = [];
  825. //this.include = function(name, callback){
  826. // if (includedScripts.indexOf(name)==-1){
  827. // if (!this.scriptAction){
  828. // MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  829. // this.scriptAction = new MWF.xScript.Actions.CMSScriptActions();
  830. // }
  831. // this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
  832. // includedScripts = includedScripts.concat(json.data.importedList);
  833. // MWF.Macro.exec(json.data.text, this);
  834. // if (callback) callback.apply(this);
  835. // }.bind(this), null, false);
  836. // }else{
  837. // if (callback) callback.apply(this);
  838. // }
  839. //}.bind(this);
  840. this.define = function(name, fun, overwrite){
  841. var over = true;
  842. if (overwrite===false) over = false;
  843. var o = {};
  844. o[name] = {"value": fun, "configurable": over};
  845. MWF.defineProperties(this, o);
  846. }.bind(this);
  847. //仅前台对象-----------------------------------------
  848. //form
  849. this.form = {
  850. "getInfor": function(){return ev.formInfor;},
  851. "infor": ev.formInfor,
  852. "getApp": function(){return _form.app;},
  853. "app": _form.app,
  854. "node": function(){return _form.node;},
  855. "readonly": _form.options.readonly,
  856. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  857. "getField": function(name){return _forms[name];},
  858. "getAction": function(){return _form.documentAction},
  859. "getData": function(){return new MWF.xScript.CMSJSONData(_form.getData());},
  860. "save": function(callback){
  861. _form.saveDocument(callback);
  862. },
  863. "close": function(){_form.closeDocument();},
  864. "publish": function(option){
  865. _form.publishDocument()
  866. },
  867. //"archive": function(option){
  868. // _form.archiveDocument()
  869. //},
  870. //"redraft": function(option){
  871. // _form.redraftDocument()
  872. //},
  873. "confirm": function(type, title, text, width, height, ok, cancel, callback){
  874. var p = MWF.getCenter({"x": width, "y": height});
  875. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  876. _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  877. },
  878. //"confirm": function(type, e, title, text, width, height, ok, cancel, callback){
  879. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  880. //},
  881. "notice": function(content, type, target, where){
  882. _form.notice(content, type, target, where);
  883. },
  884. "addEvent": function(e, f){_form.addEvent(e, f);},
  885. "openWork": function(id, completedId, title, options){
  886. var op = options || {};
  887. op.workId = id;
  888. op.workCompletedId = completedId;
  889. op.docTitle = title;
  890. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  891. layout.desktop.openApplication(this.event, "process.Work", op);
  892. },
  893. "openDocument": function(id, title, options){
  894. var op = options || {};
  895. op.documentId = id;
  896. op.docTitle = title;
  897. layout.desktop.openApplication(this.event, "cms.Document", op);
  898. },
  899. "openPortal": function(name, page, par){
  900. var action = MWF.Actions.get("x_portal_assemble_surface");
  901. action.getApplication(name, function(json){
  902. if (json.data){
  903. if (page){
  904. action.getPageByName(page, json.data.id, function(pageJson){
  905. layout.desktop.openApplication(null, "portal.Portal", {
  906. "portalId": json.data.id,
  907. "pageId": (pageJson.data) ? pageJson.data.id : "",
  908. "parameters": par,
  909. "appId": "portal.Portal"+json.data.id
  910. })
  911. });
  912. }else{
  913. layout.desktop.openApplication(null, "portal.Portal", {
  914. "portalId": json.data.id,
  915. "parameters": par,
  916. "appId": "portal.Portal"+json.data.id
  917. })
  918. }
  919. }
  920. });
  921. },
  922. "openCMS": function(name){
  923. var action = MWF.Actions.get("x_cms_assemble_control");
  924. action.getColumn(name, function(json){
  925. if (json.data){
  926. layout.desktop.openApplication(null, "cms.Module", {
  927. "columnId": json.data.id,
  928. "appId": "cms.Module"+json.data.id
  929. });
  930. }
  931. });
  932. },
  933. "openProcess": function(name){
  934. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  935. action.getApplication(name, function(json){
  936. if (json.data){
  937. layout.desktop.openApplication(null, "process.Application", {
  938. "id": json.data.id,
  939. "appId": "process.Application"+json.data.id
  940. });
  941. }
  942. });
  943. },
  944. "openApplication":function(name, options){
  945. layout.desktop.openApplication(null, name, options);
  946. },
  947. "createDocument" : function(columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle){
  948. var column = columnOrOptions;
  949. if( typeOf( columnOrOptions ) == "object" ){
  950. column = columnOrOptions.column;
  951. category = columnOrOptions.category;
  952. data = columnOrOptions.data;
  953. identity = columnOrOptions.identity;
  954. callback = columnOrOptions.callback;
  955. target = columnOrOptions.target;
  956. latest = columnOrOptions.latest;
  957. selectColumnEnable = columnOrOptions.selectColumnEnable;
  958. ignoreTitle = columnOrOptions.ignoreTitle;
  959. }
  960. if (target){
  961. if (layout.app && layout.app.inBrowser){
  962. layout.app.content.empty();
  963. layout.app = null;
  964. }
  965. }
  966. MWF.xDesktop.requireApp("cms.Index", "Newer", function(){
  967. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  968. "documentData": data,
  969. "identity": identity,
  970. "ignoreTitle" : ignoreTitle === true,
  971. "ignoreDrafted" : latest === false,
  972. "selectColumnEnable" : !category || selectColumnEnable === true,
  973. "restrictToColumn" : !!category && selectColumnEnable !== true,
  974. "categoryFlag" : category, //category id or name
  975. "columnFlag" : column, //column id or name,
  976. "onStarted" : function( documentId, data ){
  977. if(callback)callback();
  978. },
  979. "onPostLoad" : function(){
  980. },
  981. "onPostPublish" : function(){
  982. }
  983. });
  984. starter.load();
  985. })
  986. },
  987. "startProcess": function(app, process, data, identity, callback, target, latest){
  988. if (arguments.length>2){
  989. for (var i=2; i<arguments.length; i++){
  990. if (typeOf(arguments[i])=="boolean"){
  991. target = arguments[i];
  992. break;
  993. }
  994. }
  995. }
  996. if (target){
  997. if (layout.app && layout.app.inBrowser){
  998. layout.app.content.empty();
  999. layout.app = null;
  1000. }
  1001. }
  1002. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1003. if (json.data){
  1004. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1005. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1006. "workData": data,
  1007. "identity": identity,
  1008. "latest": latest,
  1009. "onStarted": function(data, title, processName){
  1010. var currentTask = [];
  1011. data.each(function(work){
  1012. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1013. }.bind(this));
  1014. if (currentTask.length==1){
  1015. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1016. layout.desktop.openApplication(null, "process.Work", options);
  1017. }else{}
  1018. if (callback) callback(data);
  1019. }.bind(this)
  1020. });
  1021. starter.load();
  1022. }.bind(this));
  1023. }
  1024. });
  1025. }
  1026. };
  1027. this.target = ev.target;
  1028. this.event = ev.event;
  1029. this.status = ev.status;
  1030. this.session = layout.desktop.session;
  1031. this.Actions = o2.Actions;
  1032. this.query = function(option){
  1033. // options = {
  1034. // "name": "statementName",
  1035. // "data": "json data",
  1036. // "firstResult": 1,
  1037. // "maxResults": 100,
  1038. // "success": function(){},
  1039. // "error": function(){},
  1040. // "async": true or false, default is true
  1041. // }
  1042. if (option){
  1043. var json = (option.data) || {};
  1044. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1045. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1046. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1047. }
  1048. };
  1049. this.Table = MWF.xScript.createTable();
  1050. };
  1051. MWF.xScript.createTable = function(){
  1052. return function(name){
  1053. this.name = name;
  1054. this.action = o2.Actions.get("x_query_assemble_surface");
  1055. this.listRowNext = function(id, count, success, error, async){
  1056. this.action.listRowNext(this.name, id, count, success, error, async);
  1057. };
  1058. this.listRowPrev = function(id, count, success, error, async){
  1059. this.action.listRowPrev(this.name, id, count, success, error, async);
  1060. };
  1061. this.listRowPrev = function(id, count, success, error, async){
  1062. this.action.listRowPrev(this.name, id, count, success, error, async);
  1063. };
  1064. this.listRowSelectWhere = function(where, success, error, async){
  1065. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1066. };
  1067. this.listRowCountWhere = function(where, success, error, async){
  1068. this.action.listRowCountWhere(this.name, where, success, error, async);
  1069. };
  1070. this.deleteRow = function(id, success, error, async){
  1071. this.action.deleteRow(this.name, id, success, error, async);
  1072. };
  1073. this.deleteAllRow = function(success, error, async){
  1074. this.action.deleteAllRow(this.name, success, error, async);
  1075. };
  1076. this.getRow = function(id, success, error, async){
  1077. this.action.getRow(this.name, id, success, error, async);
  1078. };
  1079. this.insertRow = function(data, success, error, async){
  1080. this.action.insertRow(this.name, data, success, error, async);
  1081. };
  1082. this.updateRow = function(id, data, success, error, async){
  1083. this.action.updateRow(this.name, id, data, success, error, async);
  1084. };
  1085. }
  1086. };
  1087. MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1088. var getter = function(data, callback, k, _self){
  1089. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1090. };
  1091. var setter = function(data, callback, k, _self){
  1092. return function(v){
  1093. data[k] = v;
  1094. //debugger;
  1095. //this.add(k, v, true);
  1096. if (callback) callback(data, k, _self);
  1097. }
  1098. };
  1099. var define = function(){
  1100. var o = {};
  1101. 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])};
  1102. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1103. MWF.defineProperties(this, o);
  1104. var methods = {
  1105. "getKey": {"value": function(){ return key; }},
  1106. "getParent": {"value": function(){ return parent; }},
  1107. "toString": {"value": function() { return data.toString();}},
  1108. "add": {"value": function(newKey, newValue, overwrite){
  1109. var flag = true;
  1110. var type = typeOf(data);
  1111. if (type==="array"){
  1112. if (arguments.length<2){
  1113. data.push(newKey);
  1114. newValue = newKey;
  1115. newKey = data.length-1;
  1116. }else{
  1117. if (!newKey && newKey!==0){
  1118. data.push(newValue);
  1119. newKey = data.length-1;
  1120. }else{
  1121. flag = false;
  1122. }
  1123. }
  1124. if (flag){
  1125. var o = {};
  1126. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1127. MWF.defineProperties(this, o);
  1128. }
  1129. this[newKey] = newValue;
  1130. }else if (type==="object"){
  1131. if (!this.hasOwnProperty(newKey)){
  1132. data[newKey] = newValue;
  1133. if (flag){
  1134. var o = {};
  1135. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1136. MWF.defineProperties(this, o);
  1137. }
  1138. this[newKey] = newValue;
  1139. }else{
  1140. if (overwrite) this[newKey] = newValue;
  1141. }
  1142. }
  1143. return this[newKey];
  1144. }},
  1145. "del": {"value": function(delKey){
  1146. if (!this.hasOwnProperty(delKey)) return null;
  1147. delete data[delKey];
  1148. delete this[delKey];
  1149. return this;
  1150. }}
  1151. };
  1152. MWF.defineProperties(this, methods);
  1153. //this.getKey = function(){ return key; };
  1154. //this.getParent = function(){ return parent; };
  1155. //this.toString = function() { return data.toString();};
  1156. //this.add = function(newKey, newValue, overwrite){
  1157. // var flag = true;
  1158. // var type = typeOf(data);
  1159. // if (!this.hasOwnProperty(newKey)){
  1160. // if (type=="array"){
  1161. // if (arguments.length<2){
  1162. // data.push(newKey);
  1163. // newValue = newKey;
  1164. // newKey = data.length-1;
  1165. // }else{
  1166. // debugger;
  1167. // if (!newKey && newKey!=0){
  1168. // data.push(newValue);
  1169. // newKey = data.length-1;
  1170. // }else{
  1171. // flag == false;
  1172. // }
  1173. // }
  1174. // }else{
  1175. // data[newKey] = newValue;
  1176. // }
  1177. // //var valueType = typeOf(newValue);
  1178. // //var newValueData = newValue;
  1179. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1180. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1181. // if (flag){
  1182. // var o = {};
  1183. // o[newKey] = {"configurable": true, "enumerable": 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. // }else{
  1188. // if (overwrite) this[newKey] = newValue;
  1189. // }
  1190. //
  1191. // //var valueType = typeOf(newValue);
  1192. // //var newValueData = newValue;
  1193. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1194. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1195. // //
  1196. // //this[newKey] = newValueData;
  1197. //
  1198. // return this[newKey];
  1199. //};
  1200. //this.del = function(delKey){
  1201. // if (!this.hasOwnProperty(delKey)) return null;
  1202. // delete data[newKey];
  1203. // delete this[newKey];
  1204. // return this;
  1205. //};
  1206. };
  1207. var type = typeOf(data);
  1208. if (type==="object" || type==="array") define.apply(this);
  1209. };
  1210. //MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1211. // var getter = function(data, callback, k, _self){
  1212. // return function(){return (["array","object"].indexOf(typeOf(data[k]))==-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1213. // }
  1214. // var setter = function(data, callback, k, _self){
  1215. // return function(v){
  1216. // data[k] = v;
  1217. // if (callback) callback(data, k, _self);
  1218. // }
  1219. // }
  1220. // var define = function(){
  1221. // var o = {};
  1222. // for (var k in data) o[k] = {
  1223. // "configurable": true,
  1224. // "get": getter.apply(this, [data, callback, k, this]),
  1225. // "set": setter.apply(this, [data, callback, k, this])
  1226. // };
  1227. // o["length"] = {"get": function(){return Object.keys(data).length;}};
  1228. // MWF.defineProperties(this, o);
  1229. // this.getKey = function(){ return key; };
  1230. // this.getParent = function(){ return parent; };
  1231. // this.toString = function() { return data.toString();};
  1232. // this.add = function(newKey, newValue){
  1233. // var type = typeOf(data);
  1234. // if (!this.hasOwnProperty(newKey)){
  1235. // if (type=="array"){
  1236. // data.push(newValue || {});
  1237. // newKey = data.length-1;
  1238. // }else{
  1239. // data[newKey] = newValue || {};
  1240. // }
  1241. // var o = {};
  1242. // o[newKey] = {"configurable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1243. // MWF.defineProperties(this, o);
  1244. // }
  1245. // this[newKey] = newValue;
  1246. // return this;
  1247. // };
  1248. // this.del = function(delKey){
  1249. // if (!this.hasOwnProperty(delKey)) return null;
  1250. // delete data[newKey];
  1251. // delete this[newKey];
  1252. // return this;
  1253. // };
  1254. // }
  1255. // var type = typeOf(data);
  1256. // if (type=="object" || type=="array") define.apply(this);
  1257. //};
  1258. //MWF.xScript.createCMSDict = function(application){
  1259. // return function(name){
  1260. // var applicationId = application;
  1261. // this.name = name;
  1262. // MWF.require("MWF.xScript.Actions.CMSDictActions", null, false);
  1263. // var action = new MWF.xScript.Actions.CMSDictActions();
  1264. //
  1265. // this.get = function(path, success, failure){
  1266. // var value = null;
  1267. // if( path ){
  1268. // var arr = path.split(/\./g);
  1269. // var ar = arr.map(function(v){
  1270. // return encodeURIComponent(v);
  1271. // });
  1272. // //var p = path.replace(/\./g, "/");
  1273. // var p = ar.join("/");
  1274. // action.getDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1275. // value = json.data;
  1276. // if (success) success(json.data);
  1277. // }, function(xhr, text, error){
  1278. // if (failure) failure(xhr, text, error);
  1279. // }, false);
  1280. // }else{
  1281. // action.getDictWhole(applicationId, encodeURIComponent(this.name), function(json){
  1282. // value = json.data;
  1283. // if (success) success(json.data);
  1284. // }, function(xhr, text, error){
  1285. // if (failure) failure(xhr, text, error);
  1286. // }, false);
  1287. // }
  1288. // return value;
  1289. // };
  1290. //
  1291. // this.set = function(path, value, success, failure){
  1292. // var p = path.replace(/\./g, "/");
  1293. // action.setDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1294. // if (success) success(json.data);
  1295. // }, function(xhr, text, error){
  1296. // if (failure) failure(xhr, text, error);
  1297. // });
  1298. // };
  1299. // this.add = function(path, value, success, failure){
  1300. // var p = path.replace(/\./g, "/");
  1301. // action.addDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1302. // if (success) success(json.data);
  1303. // }, function(xhr, text, error){
  1304. // if (failure) failure(xhr, text, error);
  1305. // });
  1306. // };
  1307. // this["delete"] = function(path, success, failure){
  1308. // var p = path.replace(/\./g, "/");
  1309. // action.deleteDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1310. // if (success) success(json.data);
  1311. // }, function(xhr, text, error){
  1312. // if (failure) failure(xhr, text, error);
  1313. // });
  1314. // };
  1315. // this.destory = this["delete"];
  1316. // }
  1317. //};
  1318. MWF.xScript.createCMSDict = function(application){
  1319. //optionsOrName : {
  1320. // type : "", //默认为cms, 可以为 process cms
  1321. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1322. // name : "", // 数据字典名称/别名/id
  1323. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1324. //}
  1325. //或者name: "" // 数据字典名称/别名/id
  1326. return function(optionsOrName){
  1327. var options = optionsOrName;
  1328. if( typeOf( options ) == "string" ){
  1329. options = { name : options };
  1330. }
  1331. var name = this.name = options.name;
  1332. var type = ( options.type && options.application ) ? options.type : "cms";
  1333. var applicationId = options.application || application;
  1334. var enableAnonymous = options.enableAnonymous || false;
  1335. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1336. if( type == "cms" ){
  1337. var action = MWF.Actions.get("x_cms_assemble_control");
  1338. }else{
  1339. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1340. }
  1341. var encodePath = function( path ){
  1342. var arr = path.split(/\./g);
  1343. var ar = arr.map(function(v){
  1344. return encodeURIComponent(v);
  1345. });
  1346. return ar.join("/");
  1347. };
  1348. this.get = function(path, success, failure){
  1349. var value = null;
  1350. if (path){
  1351. var p = encodePath( path );
  1352. //var p = path.replace(/\./g, "/");
  1353. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1354. value = json.data;
  1355. if (success) success(json.data);
  1356. }, function(xhr, text, error){
  1357. if (failure) failure(xhr, text, error);
  1358. }, false, false);
  1359. }else{
  1360. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](encodeURIComponent(this.name), applicationId, function(json){
  1361. value = json.data;
  1362. if (success) success(json.data);
  1363. }, function(xhr, text, error){
  1364. if (failure) failure(xhr, text, error);
  1365. }, false);
  1366. }
  1367. return value;
  1368. };
  1369. this.set = function(path, value, success, failure){
  1370. var p = encodePath( path );
  1371. //var p = path.replace(/\./g, "/");
  1372. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1373. if (success) success(json.data);
  1374. }, function(xhr, text, error){
  1375. if (failure) failure(xhr, text, error);
  1376. });
  1377. };
  1378. this.add = function(path, value, success, failure){
  1379. var p = encodePath( path );
  1380. //var p = path.replace(/\./g, "/");
  1381. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1382. if (success) success(json.data);
  1383. }, function(xhr, text, error){
  1384. if (failure) failure(xhr, text, error);
  1385. });
  1386. };
  1387. this["delete"] = function(path, success, failure){
  1388. var p = encodePath( path );
  1389. //var p = path.replace(/\./g, "/");
  1390. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1391. if (success) success(json.data);
  1392. }, function(xhr, text, error){
  1393. if (failure) failure(xhr, text, error);
  1394. });
  1395. };
  1396. this.destory = this["delete"];
  1397. }
  1398. };