CMSEnvironment.js 64 KB

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