Environment.js 58 KB

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