CMSEnvironment.js 89 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026
  1. MWF.xScript = MWF.xScript || {};
  2. MWF.xScript.CMSEnvironment = function(ev){
  3. var _data = ev.data;
  4. var _form = ev.form;
  5. var _forms = ev.forms;
  6. this.library = COMMON;
  7. //this.library.version = "4.0";
  8. //data
  9. var getJSONData = function(jData){
  10. return new MWF.xScript.CMSJSONData(jData, function(data, key, _self){
  11. var p = {"getKey": function(){return key;}, "getParent": function(){return _self;}};
  12. while (p && !_forms[p.getKey()]) p = p.getParent();
  13. if (p) if (p.getKey()) if (_forms[p.getKey()]) _forms[p.getKey()].resetData();
  14. });
  15. };
  16. this.setData = function(data){
  17. this.data = getJSONData(data);
  18. this.data.save = function(callback){
  19. _form.documentAction.saveData(function(json){if (callback) callback();}.bind(this), null, ev.document.id, data);
  20. }
  21. };
  22. this.setData(_data);
  23. //task
  24. //this.task = ev.task;
  25. //this.task.process = function(routeName, opinion, callback){
  26. // _form.submitWork(routeName, opinion, callback);
  27. //};
  28. //inquiredRouteList
  29. //this.inquiredRouteList = null;
  30. //workContext
  31. this.documentContext = {
  32. "getDocument": function(){return ev.document },
  33. "getControl": function(){return ev.control;},
  34. "getAttachmentList": function(){return ev.attachmentList;}
  35. //"setTitle": function(title){
  36. // if (!this.workAction){
  37. // MWF.require("MWF.xScript.Actions.WorkActions", null, false);
  38. // this.workAction = new MWF.xScript.Actions.WorkActions();
  39. // }
  40. // this.workAction.setTitle(ev.work.id, {"title": title});
  41. //}
  42. };
  43. //dict
  44. this.Dict = MWF.xScript.createCMSDict(_form.json.application);
  45. //org
  46. var orgActions = null;
  47. var getOrgActions = function(){
  48. // if (!orgActions){
  49. // MWF.xDesktop.requireApp("Org", "Actions.RestActions", null, false);
  50. // orgActions = new MWF.xApplication.Org.Actions.RestActions ();
  51. // }
  52. if (!orgActions){
  53. MWF.require("MWF.xScript.Actions.UnitActions", null, false);
  54. orgActions = new MWF.xScript.Actions.UnitActions();
  55. }
  56. };
  57. var getNameFlag = function(name){
  58. var t = typeOf(name);
  59. if (t==="array"){
  60. var v = [];
  61. name.each(function(id){
  62. v.push((typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id);
  63. });
  64. return v;
  65. }else{
  66. return [(t==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name];
  67. }
  68. };
  69. this.org = {
  70. //群组***************
  71. //获取群组--返回群组的对象数组
  72. getGroup: function(name){
  73. getOrgActions();
  74. var data = {"groupList": getNameFlag(name)};
  75. var v = null;
  76. orgActions.listGroup(data, function(json){v = json.data;}, null, false);
  77. return (v && v.length===1) ? v[0] : v;
  78. },
  79. //查询下级群组--返回群组的对象数组
  80. //nested 布尔 true嵌套下级;false直接下级;默认false;
  81. listSubGroup: function(name, nested){
  82. getOrgActions();
  83. var data = {"groupList": getNameFlag(name)};
  84. var v = null;
  85. if (nested){
  86. orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
  87. }else{
  88. orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
  89. }
  90. return v;
  91. },
  92. //查询上级群组--返回群组的对象数组
  93. //nested 布尔 true嵌套上级;false直接上级;默认false;
  94. listSupGroup:function(name, nested){
  95. getOrgActions();
  96. var data = {"groupList": getNameFlag(name)};
  97. var v = null;
  98. if (nested){
  99. orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
  100. }else{
  101. orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
  102. }
  103. return v;
  104. },
  105. //人员所在群组(嵌套)--返回群组的对象数组
  106. listGroupWithPerson:function(name){
  107. getOrgActions();
  108. var data = {"personList": getNameFlag(name)};
  109. var v = null;
  110. orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
  111. return v;
  112. },
  113. //群组是否拥有角色--返回true, false
  114. groupHasRole: function(name, role){
  115. getOrgActions();
  116. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  117. var data = {"group":nameFlag,"roleList":getNameFlag(role)};
  118. var v = false;
  119. orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
  120. return v;
  121. },
  122. //角色***************
  123. //获取角色--返回角色的对象数组
  124. getRole: function(name){
  125. getOrgActions();
  126. var data = {"roleList": getNameFlag(name)};
  127. var v = null;
  128. orgActions.listRole(data, function(json){v = json.data;}, null, false);
  129. return (v && v.length===1) ? v[0] : v;
  130. },
  131. //人员所有角色(嵌套)--返回角色的对象数组
  132. listRoleWithPerson:function(name){
  133. getOrgActions();
  134. var data = {"personList": getNameFlag(name)};
  135. var v = null;
  136. orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
  137. return v;
  138. },
  139. //人员***************
  140. //人员是否拥有角色--返回true, false
  141. personHasRole: function(name, role){
  142. getOrgActions();
  143. nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
  144. var data = {"person":nameFlag,"roleList":getNameFlag(role)};
  145. var v = false;
  146. orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
  147. return v;
  148. },
  149. //获取人员--返回人员的对象数组
  150. getPerson: function(name){
  151. getOrgActions();
  152. var data = {"personList": getNameFlag(name)};
  153. var v = null;
  154. orgActions.listPerson(data, function(json){v = json.data;}, null, false);
  155. return (v && v.length===1) ? v[0] : v;;
  156. },
  157. //查询下级人员--返回人员的对象数组
  158. //nested 布尔 true嵌套下级;false直接下级;默认false;
  159. listSubPerson: function(name, nested){
  160. getOrgActions();
  161. var data = {"personList": getNameFlag(name)};
  162. var v = null;
  163. if (nested){
  164. orgActions.listPersonSubNested(data, function(json){v = json.data;}, null, false);
  165. }else{
  166. orgActions.listPersonSubDirect(data, function(json){v = json.data;}, null, false);
  167. }
  168. return v;
  169. },
  170. //查询上级人员--返回人员的对象数组
  171. //nested 布尔 true嵌套上级;false直接上级;默认false;
  172. listSupPerson: function(name, nested){
  173. getOrgActions();
  174. var data = {"personList": getNameFlag(name)};
  175. var v = null;
  176. if (nested){
  177. orgActions.listPersonSupNested(data, function(json){v = json.data;}, null, false);
  178. }else{
  179. orgActions.listPersonSupDirect(data, function(json){v = json.data;}, null, false);
  180. }
  181. return v;
  182. },
  183. //获取群组的所有人员--返回人员的对象数组
  184. listPersonWithGroup: function(name){
  185. getOrgActions();
  186. var data = {"groupList": getNameFlag(name)};
  187. var v = null;
  188. orgActions.listPersonWithGroup(data, function(json){v = json.data;}, null, false);
  189. return v;
  190. },
  191. //获取角色的所有人员--返回人员的对象数组
  192. listPersonWithRole: function(name){
  193. getOrgActions();
  194. var data = {"roleList": getNameFlag(name)};
  195. var v = null;
  196. orgActions.listPersonWithRole(data, function(json){v = json.data;}, null, false);
  197. return v;
  198. },
  199. //获取身份的所有人员--返回人员的对象数组
  200. listPersonWithIdentity: function(name){
  201. getOrgActions();
  202. var data = {"identityList": getNameFlag(name)};
  203. var v = null;
  204. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  205. return v;
  206. },
  207. //获取身份的所有人员--返回人员的对象数组或人员对象
  208. getPersonWithIdentity: function(name){
  209. getOrgActions();
  210. var data = {"identityList": getNameFlag(name)};
  211. var v = null;
  212. orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
  213. return (v && v.length===1) ? v[0] : v;
  214. },
  215. //查询组织成员的人员--返回人员的对象数组
  216. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  217. listPersonWithUnit: function(name, nested){
  218. getOrgActions();
  219. var data = {"unitList": getNameFlag(name)};
  220. var v = null;
  221. if (nested){
  222. orgActions.listPersonWithUnitNested(data, function(json){v = json.data;}, null, false);
  223. }else{
  224. orgActions.listPersonWithUnitDirect(data, function(json){v = json.data;}, null, false);
  225. }
  226. return v;
  227. },
  228. //根据属性查询人员--返回人员的对象数组
  229. //name string 属性名
  230. //value string 属性值
  231. listPersonWithAttribute: function(name, value){
  232. getOrgActions();
  233. var data = {"name": name, "attribute": value};
  234. var v = null;
  235. orgActions.listPersonWithAttribute(data, function(json){v = json.data;}, null, false);
  236. return v;
  237. },
  238. //根据属性查询人员--返回人员的全称数组
  239. //name string 属性名
  240. //value string 属性值
  241. listPersonNameWithAttribute: function(name, value){
  242. getOrgActions();
  243. var data = {"name": name, "attribute": value};
  244. var v = null;
  245. orgActions.listPersonWithAttributeValue(data, function(json){v = json.data.personList;}, null, false);
  246. return v;
  247. },
  248. //人员属性************
  249. //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
  250. appendPersonAttribute: function(person, attr, values, success, failure){
  251. getOrgActions();
  252. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  253. var data = {"attributeList":values,"name":attr,"person":personFlag};
  254. orgActions.appendPersonAttribute(data, function(json){
  255. if (json.data.value){
  256. if (success) success();
  257. }else{
  258. if (failure) failure(null, "", "append values failed");
  259. }
  260. }, function(xhr, text, error){
  261. if (failure) failure(xhr, text, error);
  262. }, false);
  263. },
  264. //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
  265. setPersonAttribute: function(person, attr, values, success, failure){
  266. getOrgActions();
  267. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  268. var data = {"attributeList":values,"name":attr,"person":personFlag};
  269. orgActions.setPersonAttribute(data, function(json){
  270. if (json.data.value){
  271. if (success) success();
  272. }else{
  273. if (failure) failure(null, "", "append values failed");
  274. }
  275. }, function(xhr, text, error){
  276. if (failure) failure(xhr, text, error);
  277. }, false);
  278. },
  279. //获取人员属性值
  280. getPersonAttribute: function(person, attr){
  281. getOrgActions();
  282. var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
  283. var data = {"name":attr,"person":personFlag};
  284. var v = null;
  285. orgActions.getPersonAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  286. return v;
  287. },
  288. //列出人员所有属性的名称
  289. listPersonAttributeName: function(name){
  290. getOrgActions();
  291. var data = {"personList":getNameFlag(name)};
  292. var v = null;
  293. orgActions.listPersonAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  294. return v;
  295. },
  296. //列出人员的所有属性
  297. listPersonAllAttribute: function(name){
  298. getOrgActions();
  299. var data = {"personList":getNameFlag(name)};
  300. var v = null;
  301. orgActions.listPersonAllAttribute(data, function(json){v = json.data;}, null, false);
  302. return v;
  303. },
  304. //身份**********
  305. //获取身份
  306. getIdentity: function(name){
  307. getOrgActions();
  308. var data = {"identityList":getNameFlag(name)};
  309. var v = null;
  310. orgActions.listIdentity(data, function(json){v = json.data;}, null, false);
  311. return (v && v.length===1) ? v[0] : v;
  312. },
  313. //列出人员的身份
  314. listIdentityWithPerson: function(name){
  315. getOrgActions();
  316. var data = {"personList":getNameFlag(name)};
  317. var v = null;
  318. orgActions.listIdentityWithPerson(data, function(json){v = json.data;}, null, false);
  319. return v;
  320. },
  321. //查询组织成员身份--返回身份的对象数组
  322. //nested 布尔 true嵌套的所有成员;false直接成员;默认false;
  323. listIdentityWithUnit: function(name, nested){
  324. getOrgActions();
  325. var data = {"unitList": getNameFlag(name)};
  326. var v = null;
  327. if (nested){
  328. orgActions.listIdentityWithUnitNested(data, function(json){v = json.data;}, null, false);
  329. }else{
  330. orgActions.listIdentityWithUnitDirect(data, function(json){v = json.data;}, null, false);
  331. }
  332. return v;
  333. },
  334. //组织**********
  335. //获取组织
  336. getUnit: function(name){
  337. getOrgActions();
  338. var data = {"unitList":getNameFlag(name)};
  339. var v = null;
  340. orgActions.listUnit(data, function(json){v = json.data;}, null, false);
  341. return (v && v.length===1) ? v[0] : v;
  342. },
  343. //查询组织的下级--返回组织的对象数组
  344. //nested 布尔 true嵌套下级;false直接下级;默认false;
  345. listSubUnit: function(name, nested){
  346. getOrgActions();
  347. var data = {"unitList": getNameFlag(name)};
  348. var v = null;
  349. if (nested){
  350. orgActions.listUnitSubNested(data, function(json){v = json.data;}, null, false);
  351. }else{
  352. orgActions.listUnitSubDirect(data, function(json){v = json.data;}, null, false);
  353. }
  354. return v;
  355. },
  356. //查询组织的上级--返回组织的对象数组
  357. //nested 布尔 true嵌套上级;false直接上级;默认false;
  358. listSupUnit: function(name, nested){
  359. getOrgActions();
  360. var data = {"unitList": getNameFlag(name)};
  361. var v = null;
  362. if (nested){
  363. orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
  364. }else{
  365. orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
  366. }
  367. return v;
  368. },
  369. //根据个人身份获取组织
  370. //flag 数字 表示获取第几层的组织
  371. // 字符串 表示获取指定类型的组织
  372. // 空 表示获取直接所在的组织
  373. getUnitByIdentity: function(name, flag){
  374. getOrgActions();
  375. var getUnitMethod = "current";
  376. var v;
  377. if (flag){
  378. if (typeOf(flag)==="string") getUnitMethod = "type";
  379. if (typeOf(flag)==="number") getUnitMethod = "level";
  380. }
  381. switch (getUnitMethod){
  382. case "current":
  383. var data = {"identityList":getNameFlag(name)};
  384. orgActions.listUnitWithIdentity(data, function(json){ v = json.data; v=(v&&v.length===1) ? v[0] : v }, null, false);
  385. break;
  386. case "type":
  387. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
  388. orgActions.getUnitWithIdentityAndType(data, function(json){ v = json.data; }, null, false);
  389. break;
  390. case "level":
  391. var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
  392. orgActions.getUnitWithIdentityAndLevel(data, function(json){ v = json.data; }, null, false);
  393. break;
  394. }
  395. return v;
  396. },
  397. //列出身份所在组织的所有上级组织
  398. listAllSupUnitWithIdentity: function(name){
  399. getOrgActions();
  400. var data = {"identityList":getNameFlag(name)};
  401. var v = null;
  402. orgActions.listUnitSupNestedWithIdentity(data, function(json){v = json.data;}, null, false);
  403. return v;
  404. },
  405. //获取人员所在的所有组织
  406. listUnitWithPerson: function(name){
  407. getOrgActions();
  408. var data = {"personList":getNameFlag(name)};
  409. var v = null;
  410. orgActions.listUnitWithPerson(data, function(json){v = json.data;}, null, false);
  411. return v;
  412. },
  413. //列出身份所在组织的所有上级组织
  414. listAllSupUnitWithPerson: function(name){
  415. getOrgActions();
  416. var data = {"personList":getNameFlag(name)};
  417. var v = null;
  418. orgActions.listUnitSupNestedWithPerson(data, function(json){v = json.data;}, null, false);
  419. return v;
  420. },
  421. //根据组织属性,获取所有符合的组织
  422. listUnitWithAttribute: function(name, attribute){
  423. getOrgActions();
  424. var data = {"name":name,"attribute":attribute};
  425. var v = null;
  426. orgActions.listUnitWithAttribute(data, function(json){v = json.data;}, null, false);
  427. return v;
  428. },
  429. //根据组织职务,获取所有符合的组织
  430. listUnitWithDuty: function(name, id){
  431. getOrgActions();
  432. var data = {"name":"","identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  433. var v = null;
  434. orgActions.listUnitWithDuty(data, function(json){v = json.data;}, null, false);
  435. return v;
  436. },
  437. //列出顶层组织
  438. listTopUnit: function(){
  439. var action = MWF.Actions.get("x_organization_assemble_control");
  440. var v = null;
  441. action.listTopUnit(function(json){
  442. v = json.data;
  443. }, null, false);
  444. return v;
  445. },
  446. //组织职务***********
  447. //获取指定的组织职务的身份
  448. getDuty: function(duty, id){
  449. getOrgActions();
  450. var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
  451. var v = null;
  452. orgActions.getDuty(data, function(json){v = json.data;}, null, false);
  453. return v;
  454. },
  455. //获取身份的所有职务名称
  456. listDutyNameWithIdentity: function(name){
  457. getOrgActions();
  458. var data = {"identityList":getNameFlag(name)};
  459. var v = null;
  460. orgActions.listDutyNameWithIdentity(data, function(json){v = json.data.nameList;}, null, false);
  461. return v;
  462. },
  463. //获取组织的所有职务名称
  464. listDutyNameWithUnit: function(name){
  465. getOrgActions();
  466. var data = {"unitList":getNameFlag(name)};
  467. var v = null;
  468. orgActions.listDutyNameWithUnit(data, function(json){v = json.data.nameList;}, null, false);
  469. return v;
  470. },
  471. //获取组织的所有职务
  472. listUnitAllDuty: function(name){
  473. getOrgActions();
  474. var data = {"unitList":getNameFlag(name)};
  475. var v = null;
  476. orgActions.listUnitAllDuty(data, function(json){v = json.data;}, null, false);
  477. return v;
  478. },
  479. //组织属性**************
  480. //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
  481. appendUnitAttribute: function(unit, attr, values, success, failure){
  482. getOrgActions();
  483. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  484. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  485. orgActions.appendUnitAttribute(data, function(json){
  486. if (json.data.value){
  487. if (success) success();
  488. }else{
  489. if (failure) failure(null, "", "append values failed");
  490. }
  491. }, function(xhr, text, error){
  492. if (failure) failure(xhr, text, error);
  493. }, false);
  494. },
  495. //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
  496. setUnitAttribute: function(unit, attr, values, success, failure){
  497. getOrgActions();
  498. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  499. var data = {"attributeList":values,"name":attr,"unit":unitFlag};
  500. orgActions.setUnitAttribute(data, function(json){
  501. if (json.data.value){
  502. if (success) success();
  503. }else{
  504. if (failure) failure(null, "", "append values failed");
  505. }
  506. }, function(xhr, text, error){
  507. if (failure) failure(xhr, text, error);
  508. }, false);
  509. },
  510. //获取组织属性值
  511. getUnitAttribute: function(unit, attr){
  512. getOrgActions();
  513. var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
  514. var data = {"name":attr,"unit":unitFlag};
  515. var v = null;
  516. orgActions.getUnitAttribute(data, function(json){v = json.data.attributeList;}, null, false);
  517. return v;
  518. },
  519. //列出组织所有属性的名称
  520. listUnitAttributeName: function(name){
  521. getOrgActions();
  522. var data = {"unitList":getNameFlag(name)};
  523. var v = null;
  524. orgActions.listUnitAttributeName(data, function(json){v = json.data.nameList;}, null, false);
  525. return v;
  526. },
  527. //列出组织的所有属性
  528. listUnitAllAttribute: function(name){
  529. getOrgActions();
  530. var data = {"unitList":getNameFlag(name)};
  531. var v = null;
  532. orgActions.listUnitAllAttribute(data, function(json){v = json.data;}, null, false);
  533. return v;
  534. }
  535. };
  536. this.Action = (function(){
  537. var actions = [];
  538. return function(root, json){
  539. var action = actions[root] || (actions[root] = new MWF.xDesktop.Actions.RestActions("", root, ""));
  540. action.getActions = function(callback){
  541. if (!this.actions) this.actions = {};
  542. Object.merge(this.actions, json);
  543. if (callback) callback();
  544. };
  545. this.invoke = function(option){
  546. action.invoke(option)
  547. }
  548. }
  549. })();
  550. this.service = {
  551. "jaxwsClient": {},
  552. "jaxrsClient":{}
  553. };
  554. var lookupAction = null;
  555. var getLookupAction = function(callback){
  556. if (!lookupAction){
  557. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  558. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  559. lookupAction.getActions = function(actionCallback){
  560. this.actions = {
  561. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  562. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  563. };
  564. if (actionCallback) actionCallback();
  565. }
  566. if (callback) callback();
  567. }.bind(this));
  568. }else{
  569. if (callback) callback();
  570. }
  571. };
  572. this.view = {
  573. "lookup": function(view, callback, async){
  574. var filterList = {"filterList": (view.filter || null)};
  575. MWF.Actions.get("x_query_assemble_surface").loadView(view.view, view.application, filterList, function(json){
  576. var data = {
  577. "grid": json.data.grid || json.data.groupGrid,
  578. "groupGrid": json.data.groupGrid
  579. };
  580. if (callback) callback(data);
  581. }, null, async);
  582. },
  583. "lookupV1": function(view, callback){
  584. getLookupAction(function(){
  585. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  586. var data = {
  587. "grid": json.data.grid,
  588. "groupGrid": json.data.groupGrid
  589. };
  590. if (callback) callback(data);
  591. }.bind(this)});
  592. }.bind(this));
  593. },
  594. "select": function(view, callback, options){
  595. if (view.view){
  596. var viewJson = {
  597. "application": view.application || _form.json.application,
  598. "viewName": view.view || "",
  599. "isTitle": (view.isTitle===false) ? "no" : "yes",
  600. "select": (view.isMulti===false) ? "single" : "multi",
  601. "filter": view.filter
  602. };
  603. if (!options) options = {};
  604. options.width = view.width;
  605. options.height = view.height;
  606. options.title = view.caption;
  607. var width = options.width || "700";
  608. var height = options.height || "400";
  609. if (layout.mobile){
  610. var size = document.body.getSize();
  611. width = size.x;
  612. height = size.y;
  613. options.style = "viewmobile";
  614. }
  615. width = width.toInt();
  616. height = height.toInt();
  617. var size = _form.app.content.getSize();
  618. var x = (size.x-width)/2;
  619. var y = (size.y-height)/2;
  620. if (x<0) x = 0;
  621. if (y<0) y = 0;
  622. if (layout.mobile){
  623. x = 20;
  624. y = 0;
  625. }
  626. var _self = this;
  627. MWF.require("MWF.xDesktop.Dialog", function(){
  628. var dlg = new MWF.xDesktop.Dialog({
  629. "title": options.title || "select view",
  630. "style": options.style || "view",
  631. "top": y,
  632. "left": x-20,
  633. "fromTop":y,
  634. "fromLeft": x-20,
  635. "width": width,
  636. "height": height,
  637. "html": "<div style='height: 100%;'></div>",
  638. "maskNode": _form.app.content,
  639. "container": _form.app.content,
  640. "buttonList": [
  641. {
  642. "text": MWF.LP.process.button.ok,
  643. "action": function(){
  644. //if (callback) callback(_self.view.selectedItems);
  645. if (callback) callback(_self.view.getData());
  646. this.close();
  647. }
  648. },
  649. {
  650. "text": MWF.LP.process.button.cancel,
  651. "action": function(){this.close();}
  652. }
  653. ]
  654. });
  655. dlg.show();
  656. if (layout.mobile){
  657. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  658. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  659. if (backAction) backAction.addEvent("click", function(e){
  660. dlg.close();
  661. }.bind(this));
  662. if (okAction) okAction.addEvent("click", function(e){
  663. //if (callback) callback(this.view.selectedItems);
  664. if (callback) callback(this.view.getData());
  665. dlg.close();
  666. }.bind(this));
  667. }
  668. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  669. this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"}, _form.app, _form.Macro);
  670. }.bind(this));
  671. }.bind(this));
  672. }
  673. }
  674. };
  675. //var lookupAction = null;
  676. //var getLookupAction = function(callback){
  677. // if (!lookupAction){
  678. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  679. // lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  680. // lookupAction.getActions = function(actionCallback){
  681. // this.actions = {
  682. // "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  683. // "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  684. // };
  685. // if (actionCallback) actionCallback();
  686. // }
  687. // if (callback) callback();
  688. // }.bind(this));
  689. // }else{
  690. // if (callback) callback();
  691. // }
  692. //};
  693. //
  694. //this.view = {
  695. // "lookup": function(view, callback){
  696. // getLookupAction(function(){
  697. // lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  698. // var data = {
  699. // "grid": json.data.grid,
  700. // "groupGrid": json.data.groupGrid
  701. // };
  702. // if (callback) callback(data);
  703. // }.bind(this)});
  704. // }.bind(this));
  705. // },
  706. // "select": function(view, callback, options){
  707. // if (view.view){
  708. // var viewJson = {
  709. // "application": view.application || "",
  710. // "viewName": view.view || "",
  711. // "isTitle": view.isTitle || "yes",
  712. // "select": view.select || "multi",
  713. // "title": view.title || "Select View"
  714. // };
  715. // if (!options) options = {};
  716. // var width = options.width || "700";
  717. // var height = options.height || "400";
  718. //
  719. // if (layout.mobile){
  720. // var size = document.body.getSize();
  721. // width = size.x;
  722. // height = size.y;
  723. // options.style = "viewmobile";
  724. // }
  725. // width = width.toInt();
  726. // height = height.toInt();
  727. //
  728. // var size = _form.app.content.getSize();
  729. // var x = (size.x-width)/2;
  730. // var y = (size.y-height)/2;
  731. // if (x<0) x = 0;
  732. // if (y<0) y = 0;
  733. // if (layout.mobile){
  734. // x = 20;
  735. // y = 0;
  736. // }
  737. //
  738. // var _self = this;
  739. // MWF.require("MWF.xDesktop.Dialog", function(){
  740. // var dlg = new MWF.xDesktop.Dialog({
  741. // "title": options.title || "select View",
  742. // "style": options.style || "view",
  743. // "top": y,
  744. // "left": x-20,
  745. // "fromTop":y,
  746. // "fromLeft": x-20,
  747. // "width": width,
  748. // "height": height,
  749. // "html": "<div style='height: 100%;'></div>",
  750. // "maskNode": _form.app.content,
  751. // "container": _form.app.content,
  752. // "buttonList": [
  753. // {
  754. // "text": MWF.LP.process.button.ok,
  755. // "action": function(){
  756. // //if (callback) callback(_self.view.selectedItems);
  757. // if (callback) callback(_self.view.getData());
  758. // this.close();
  759. // }
  760. // },
  761. // {
  762. // "text": MWF.LP.process.button.cancel,
  763. // "action": function(){this.close();}
  764. // }
  765. // ]
  766. // });
  767. // dlg.show();
  768. // if (layout.mobile){
  769. // var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  770. // var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  771. // if (backAction) backAction.addEvent("click", function(e){
  772. // dlg.close();
  773. // }.bind(this));
  774. // if (okAction) okAction.addEvent("click", function(e){
  775. // //if (callback) callback(this.view.selectedItems);
  776. // if (callback) callback(this.view.getData());
  777. // dlg.close();
  778. // }.bind(this));
  779. // }
  780. //
  781. // // MWF.xDesktop.requireApp("cms.Xform", "widget.View", function(){
  782. // // this.view = new MWF.xApplication.cms.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  783. // // }.bind(this));
  784. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  785. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  786. // }.bind(this));
  787. // }.bind(this));
  788. // }
  789. // }
  790. //};
  791. //include 引用脚本
  792. //optionsOrName : {
  793. // type : "", 默认为cms, 可以为 portal process cms
  794. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  795. // name : "" // 脚本名称/别名/id
  796. //}
  797. //或者name: "" // 脚本名称/别名/id
  798. // if( !window.includedScripts ){
  799. // var includedScripts = window.includedScripts = [];
  800. // }else{
  801. // var includedScripts = window.includedScripts;
  802. // }
  803. var includedScripts = [];
  804. this.include = function( optionsOrName , callback ){
  805. var options = optionsOrName;
  806. if( typeOf( options ) == "string" ){
  807. options = { name : options };
  808. }
  809. var name = options.name;
  810. var type = ( options.type && options.application ) ? options.type : "cms";
  811. var application = options.application || _form.json.application;
  812. var key = type +"-" + application + "-" + name;
  813. if (includedScripts.indexOf( key )> -1){
  814. if (callback) callback.apply(this);
  815. return;
  816. }
  817. //if (includedScripts.indexOf( name )> -1){
  818. // if (callback) callback.apply(this);
  819. // return;
  820. //}
  821. var scriptAction;
  822. switch ( type ){
  823. case "portal" :
  824. if( this.scriptActionPortal ){
  825. scriptAction = this.scriptActionPortal;
  826. }else{
  827. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  828. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  829. }
  830. break;
  831. case "process" :
  832. if( this.scriptActionProcess ){
  833. scriptAction = this.scriptActionProcess;
  834. }else{
  835. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  836. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  837. }
  838. break;
  839. case "cms" :
  840. if( this.scriptActionCMS ){
  841. scriptAction = this.scriptActionCMS;
  842. }else{
  843. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  844. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  845. }
  846. break;
  847. }
  848. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  849. if (json.data){
  850. includedScripts.push( key );
  851. //名称、别名、id
  852. json.data.importedList.each( function ( flag ) {
  853. if( type === "portal" ){
  854. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  855. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  856. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  857. }else if( type === "cms" ){
  858. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  859. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  860. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  861. }else if( type === "process" ){
  862. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  863. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  864. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  865. }
  866. });
  867. includedScripts = includedScripts.concat(json.data.importedList);
  868. MWF.CMSMacro.exec(json.data.text, this);
  869. if (callback) callback.apply(this);
  870. }else{
  871. if (callback) callback.apply(this);
  872. }
  873. }.bind(this), null, false);
  874. };
  875. //var includedScripts = [];
  876. //this.include = function(name, callback){
  877. // if (includedScripts.indexOf(name)==-1){
  878. // if (!this.scriptAction){
  879. // MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  880. // this.scriptAction = new MWF.xScript.Actions.CMSScriptActions();
  881. // }
  882. // this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
  883. // includedScripts = includedScripts.concat(json.data.importedList);
  884. // MWF.CMSMacro.exec(json.data.text, this);
  885. // if (callback) callback.apply(this);
  886. // }.bind(this), null, false);
  887. // }else{
  888. // if (callback) callback.apply(this);
  889. // }
  890. //}.bind(this);
  891. this.define = function(name, fun, overwrite){
  892. var over = true;
  893. if (overwrite===false) over = false;
  894. var o = {};
  895. o[name] = {"value": fun, "configurable": over};
  896. MWF.defineProperties(this, o);
  897. }.bind(this);
  898. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  899. //可在调用前执行 var resolve = this.wait();
  900. //在异步调用结束后 执行 resolve.cb();
  901. //目前只有表单的queryload事件支持此方法。
  902. this.wait = function(){
  903. resolve = {};
  904. var setResolve = function(callback){
  905. resolve.cb = callback;
  906. }.bind(this);
  907. this.target.event_resolve = setResolve;
  908. return resolve;
  909. };
  910. //和this.wait配合使用,
  911. //如果没有异步,则resolve.cb方法不存在,
  912. //所以在回调中中使用this.goon();使表单继续加载
  913. this.goon = function(){
  914. this.target.event_resolve = null;
  915. };
  916. //仅前台对象-----------------------------------------
  917. //form
  918. this.form = {
  919. "getInfor": function(){return ev.formInfor;},
  920. "infor": ev.formInfor,
  921. "getApp": function(){return _form.app;},
  922. "app": _form.app,
  923. "node": function(){return _form.node;},
  924. "readonly": _form.options.readonly,
  925. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  926. "getField": function(name){return _forms[name];},
  927. "getAction": function(){return _form.documentAction},
  928. "getData": function(){return new MWF.xScript.CMSJSONData(_form.getData());},
  929. "save": function(callback){
  930. _form.saveDocument(callback);
  931. },
  932. "close": function(){_form.closeDocument();},
  933. "publish": function(option){
  934. _form.publishDocument()
  935. },
  936. //"archive": function(option){
  937. // _form.archiveDocument()
  938. //},
  939. //"redraft": function(option){
  940. // _form.redraftDocument()
  941. //},
  942. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  943. // var p = MWF.getCenter({"x": width, "y": height});
  944. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  945. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  946. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  947. var p = MWF.getCenter({"x": width, "y": height});
  948. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  949. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  950. }else{
  951. e = (arguments.length>1) ? arguments[1] : null;
  952. title = (arguments.length>2) ? arguments[2] : null;
  953. text = (arguments.length>3) ? arguments[3] : null;
  954. width = (arguments.length>4) ? arguments[4] : null;
  955. height = (arguments.length>5) ? arguments[5] : null;
  956. ok = (arguments.length>6) ? arguments[6] : null;
  957. cancel = (arguments.length>7) ? arguments[7] : null;
  958. callback = (arguments.length>8) ? arguments[8] : null;
  959. mask = (arguments.length>9) ? arguments[9] : null;
  960. style = (arguments.length>10) ? arguments[10] : null;
  961. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  962. }
  963. },
  964. //"confirm": function(type, e, title, text, width, height, ok, cancel, callback){
  965. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  966. //},
  967. "notice": function(content, type, target, where, offset, option){
  968. _form.notice(content, type, target, where, offset, option);
  969. },
  970. "addEvent": function(e, f){_form.addEvent(e, f);},
  971. "openWork": function(id, completedId, title, options){
  972. var op = options || {};
  973. op.workId = id;
  974. op.workCompletedId = completedId;
  975. op.docTitle = title;
  976. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  977. return layout.desktop.openApplication(this.event, "process.Work", op);
  978. },
  979. "openJob": function(id, choice, options){
  980. var workData = null;
  981. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  982. if (json.data) workData = json.data;
  983. }.bind(this), null, false);
  984. if (workData){
  985. var len = workData.workList.length + workData.workCompletedList.length;
  986. if (len){
  987. if (len>1 && choice){
  988. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  989. workData.workList.each(function(work){
  990. var workNode = new Element("div", {
  991. "styles": {
  992. "background": "#ffffff",
  993. "border-radius": "10px",
  994. "clear": "both",
  995. "margin-bottom": "10px",
  996. "height": "40px",
  997. "padding": "10px 10px"
  998. }
  999. }).inject(node);
  1000. var html = "<div style='height: 40px; width: 40px; float: left; background: url(../x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
  1001. "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
  1002. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1003. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1004. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1005. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1006. workNode.set("html", html);
  1007. var action = workNode.getElement(".MWFAction");
  1008. action.store("work", work);
  1009. action.addEvent("click", function(e){
  1010. var work = e.target.retrieve("work");
  1011. if (work) this.openWork(work.id, null, work.title, options);
  1012. dlg.close();
  1013. }.bind(this));
  1014. }.bind(this));
  1015. workData.workCompletedList.each(function(work){
  1016. var workNode = new Element("div", {
  1017. "styles": {
  1018. "background": "#ffffff",
  1019. "border-radius": "10px",
  1020. "clear": "both",
  1021. "margin-bottom": "10px",
  1022. "height": "40px",
  1023. "padding": "10px 10px"
  1024. }
  1025. }).inject(node);
  1026. var html = "<div style='height: 40px; width: 40px; float: left; background: url(../x_component_process_Xform/$Form/default/icon/work.png) no-repeat center center'></div>" +
  1027. "<div style='height: 40px; width: 40px; float: right'><div class='MWFAction' style='height: 20px; width: 40px; margin-top: 10px; border: 1px solid #999999; border-radius: 5px;text-align: center; cursor: pointer'>"+o2.LP.widget.open+"</div></div>"+
  1028. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1029. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1030. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1031. workNode.set("html", html);
  1032. var action = workNode.getElement(".MWFAction");
  1033. action.store("work", work);
  1034. action.addEvent("click", function(e){
  1035. var work = e.target.retrieve("work");
  1036. if (work) this.openWork(null, work.id, work.title, options);
  1037. dlg.close();
  1038. }.bind(this));
  1039. }.bind(this));
  1040. var height = node.getSize().y+20;
  1041. if (height>600) height = 600;
  1042. var dlg = o2.DL.open({
  1043. "title": o2.LP.widget.choiceWork,
  1044. "style" : "user",
  1045. "isResize": false,
  1046. "content": node,
  1047. "buttonList": [
  1048. {
  1049. "type" : "cancel",
  1050. "text": o2.LP.widget.close,
  1051. "action": function(){dlg.close();}
  1052. }
  1053. ]
  1054. });
  1055. }else{
  1056. if (workData.workList.length){
  1057. var work = workData.workList[0];
  1058. return this.openWork(work.id, null, work.title, options);
  1059. }else{
  1060. var work = workData.workCompletedList[0];
  1061. return this.openWork(null, work.id, work.title, options);
  1062. }
  1063. }
  1064. }
  1065. }
  1066. },
  1067. "openDocument": function(id, title, options){
  1068. var op = options || {};
  1069. op.documentId = id;
  1070. op.docTitle = title;
  1071. layout.desktop.openApplication(this.event, "cms.Document", op);
  1072. },
  1073. "openPortal": function(name, page, par){
  1074. var action = MWF.Actions.get("x_portal_assemble_surface");
  1075. action.getApplication(name, function(json){
  1076. if (json.data){
  1077. if (page){
  1078. action.getPageByName(page, json.data.id, function(pageJson){
  1079. layout.desktop.openApplication(null, "portal.Portal", {
  1080. "portalId": json.data.id,
  1081. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1082. "parameters": par,
  1083. "appId": "portal.Portal"+json.data.id
  1084. })
  1085. });
  1086. }else{
  1087. layout.desktop.openApplication(null, "portal.Portal", {
  1088. "portalId": json.data.id,
  1089. "parameters": par,
  1090. "appId": "portal.Portal"+json.data.id
  1091. })
  1092. }
  1093. }
  1094. });
  1095. },
  1096. "openCMS": function(name){
  1097. var action = MWF.Actions.get("x_cms_assemble_control");
  1098. action.getColumn(name, function(json){
  1099. if (json.data){
  1100. layout.desktop.openApplication(null, "cms.Module", {
  1101. "columnId": json.data.id,
  1102. "appId": "cms.Module"+json.data.id
  1103. });
  1104. }
  1105. });
  1106. },
  1107. "openProcess": function(name){
  1108. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1109. action.getApplication(name, function(json){
  1110. if (json.data){
  1111. layout.desktop.openApplication(null, "process.Application", {
  1112. "id": json.data.id,
  1113. "appId": "process.Application"+json.data.id
  1114. });
  1115. }
  1116. });
  1117. },
  1118. "openApplication":function(name, options){
  1119. layout.desktop.openApplication(null, name, options);
  1120. },
  1121. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1122. var column = columnOrOptions;
  1123. var onAfterPublish, onPostPublish;
  1124. if (typeOf(columnOrOptions) == "object") {
  1125. column = columnOrOptions.column;
  1126. category = columnOrOptions.category;
  1127. data = columnOrOptions.data;
  1128. identity = columnOrOptions.identity;
  1129. callback = columnOrOptions.callback;
  1130. target = columnOrOptions.target;
  1131. latest = columnOrOptions.latest;
  1132. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1133. ignoreTitle = columnOrOptions.ignoreTitle;
  1134. onAfterPublish = columnOrOptions.onAfterPublish;
  1135. onPostPublish = columnOrOptions.onPostPublish;
  1136. }
  1137. if (target) {
  1138. if (layout.app && layout.app.inBrowser) {
  1139. layout.app.content.empty();
  1140. layout.app = null;
  1141. }
  1142. }
  1143. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1144. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1145. "documentData": data,
  1146. "identity": identity,
  1147. "ignoreTitle": ignoreTitle === true,
  1148. "ignoreDrafted": latest === false,
  1149. "selectColumnEnable": !category || selectColumnEnable === true,
  1150. "restrictToColumn": !!category && selectColumnEnable !== true,
  1151. "categoryFlag": category, //category id or name
  1152. "columnFlag": column, //column id or name,
  1153. "onStarted": function (documentId, data) {
  1154. if (callback) callback();
  1155. },
  1156. "onPostPublish": function () {
  1157. if(onPostPublish)onPostPublish();
  1158. },
  1159. "onAfterPublish": function () {
  1160. if(onAfterPublish)onAfterPublish();
  1161. }
  1162. });
  1163. starter.load();
  1164. })
  1165. },
  1166. "startProcess": function(app, process, data, identity, callback, target, latest){
  1167. if (arguments.length>2){
  1168. for (var i=2; i<arguments.length; i++){
  1169. if (typeOf(arguments[i])=="boolean"){
  1170. target = arguments[i];
  1171. break;
  1172. }
  1173. }
  1174. }
  1175. if (target){
  1176. if (layout.app && layout.app.inBrowser){
  1177. //layout.app.content.empty();
  1178. layout.app.$openWithSelf = true;
  1179. }
  1180. }
  1181. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1182. if (json.data){
  1183. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1184. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1185. "workData": data,
  1186. "identity": identity,
  1187. "latest": latest,
  1188. "onStarted": function(data, title, processName){
  1189. if (data.work){
  1190. var work = data.work;
  1191. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1192. layout.desktop.openApplication(null, "process.Work", options);
  1193. }else{
  1194. var currentTask = [];
  1195. data.each(function(work){
  1196. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1197. }.bind(this));
  1198. if (currentTask.length==1){
  1199. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1200. layout.desktop.openApplication(null, "process.Work", options);
  1201. }else{}
  1202. }
  1203. // var currentTask = [];
  1204. // data.each(function(work){
  1205. // if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1206. // }.bind(this));
  1207. //
  1208. // if (currentTask.length==1){
  1209. // var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1210. // layout.desktop.openApplication(null, "process.Work", options);
  1211. // }else{}
  1212. if (callback) callback(data);
  1213. }.bind(this)
  1214. });
  1215. starter.load();
  1216. }.bind(this));
  1217. }
  1218. });
  1219. }
  1220. };
  1221. this.target = ev.target;
  1222. this.event = ev.event;
  1223. this.status = ev.status;
  1224. this.session = layout.desktop.session;
  1225. this.Actions = o2.Actions;
  1226. this.query = function(option){
  1227. // options = {
  1228. // "name": "statementName",
  1229. // "data": "json data",
  1230. // "firstResult": 1,
  1231. // "maxResults": 100,
  1232. // "success": function(){},
  1233. // "error": function(){},
  1234. // "async": true or false, default is true
  1235. // }
  1236. if (option){
  1237. var json = (option.data) || {};
  1238. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1239. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1240. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1241. }
  1242. };
  1243. this.Table = MWF.xScript.createTable();
  1244. };
  1245. MWF.xScript.createTable = function(){
  1246. return function(name){
  1247. this.name = name;
  1248. this.action = o2.Actions.get("x_query_assemble_surface");
  1249. this.listRowNext = function(id, count, success, error, async){
  1250. this.action.listRowNext(this.name, id, count, success, error, async);
  1251. };
  1252. this.listRowPrev = function(id, count, success, error, async){
  1253. this.action.listRowPrev(this.name, id, count, success, error, async);
  1254. };
  1255. this.listRowPrev = function(id, count, success, error, async){
  1256. this.action.listRowPrev(this.name, id, count, success, error, async);
  1257. };
  1258. this.listRowSelectWhere = function(where, success, error, async){
  1259. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1260. };
  1261. this.listRowCountWhere = function(where, success, error, async){
  1262. this.action.listRowCountWhere(this.name, where, success, error, async);
  1263. };
  1264. this.deleteRow = function(id, success, error, async){
  1265. this.action.deleteRow(this.name, id, success, error, async);
  1266. };
  1267. this.deleteAllRow = function(success, error, async){
  1268. this.action.deleteAllRow(this.name, success, error, async);
  1269. };
  1270. this.getRow = function(id, success, error, async){
  1271. this.action.getRow(this.name, id, success, error, async);
  1272. };
  1273. this.insertRow = function(data, success, error, async){
  1274. this.action.insertRow(this.name, data, success, error, async);
  1275. };
  1276. this.updateRow = function(id, data, success, error, async){
  1277. this.action.updateRow(this.name, id, data, success, error, async);
  1278. };
  1279. }
  1280. };
  1281. MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1282. var getter = function(data, callback, k, _self){
  1283. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1284. };
  1285. var setter = function(data, callback, k, _self){
  1286. return function(v){
  1287. data[k] = v;
  1288. //debugger;
  1289. //this.add(k, v, true);
  1290. if (callback) callback(data, k, _self);
  1291. }
  1292. };
  1293. var define = function(){
  1294. var o = {};
  1295. 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])};
  1296. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1297. MWF.defineProperties(this, o);
  1298. var methods = {
  1299. "getKey": {"value": function(){ return key; }},
  1300. "getParent": {"value": function(){ return parent; }},
  1301. "toString": {"value": function() { return data.toString();}},
  1302. "add": {"value": function(newKey, newValue, overwrite){
  1303. var flag = true;
  1304. var type = typeOf(data);
  1305. if (type==="array"){
  1306. if (arguments.length<2){
  1307. data.push(newKey);
  1308. newValue = newKey;
  1309. newKey = data.length-1;
  1310. }else{
  1311. if (!newKey && newKey!==0){
  1312. data.push(newValue);
  1313. newKey = data.length-1;
  1314. }else{
  1315. flag = false;
  1316. }
  1317. }
  1318. if (flag){
  1319. var o = {};
  1320. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1321. MWF.defineProperties(this, o);
  1322. }
  1323. this[newKey] = newValue;
  1324. }else if (type==="object"){
  1325. if (!this.hasOwnProperty(newKey)){
  1326. data[newKey] = newValue;
  1327. if (flag){
  1328. var o = {};
  1329. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1330. MWF.defineProperties(this, o);
  1331. }
  1332. this[newKey] = newValue;
  1333. }else{
  1334. if (overwrite) this[newKey] = newValue;
  1335. }
  1336. }
  1337. return this[newKey];
  1338. }},
  1339. "del": {"value": function(delKey){
  1340. if (!this.hasOwnProperty(delKey)) return null;
  1341. delete data[delKey];
  1342. delete this[delKey];
  1343. return this;
  1344. }}
  1345. };
  1346. MWF.defineProperties(this, methods);
  1347. //this.getKey = function(){ return key; };
  1348. //this.getParent = function(){ return parent; };
  1349. //this.toString = function() { return data.toString();};
  1350. //this.add = function(newKey, newValue, overwrite){
  1351. // var flag = true;
  1352. // var type = typeOf(data);
  1353. // if (!this.hasOwnProperty(newKey)){
  1354. // if (type=="array"){
  1355. // if (arguments.length<2){
  1356. // data.push(newKey);
  1357. // newValue = newKey;
  1358. // newKey = data.length-1;
  1359. // }else{
  1360. // debugger;
  1361. // if (!newKey && newKey!=0){
  1362. // data.push(newValue);
  1363. // newKey = data.length-1;
  1364. // }else{
  1365. // flag == false;
  1366. // }
  1367. // }
  1368. // }else{
  1369. // data[newKey] = newValue;
  1370. // }
  1371. // //var valueType = typeOf(newValue);
  1372. // //var newValueData = newValue;
  1373. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1374. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1375. // if (flag){
  1376. // var o = {};
  1377. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1378. // MWF.defineProperties(this, o);
  1379. // }
  1380. // this[newKey] = newValue;
  1381. // }else{
  1382. // if (overwrite) this[newKey] = newValue;
  1383. // }
  1384. //
  1385. // //var valueType = typeOf(newValue);
  1386. // //var newValueData = newValue;
  1387. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1388. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1389. // //
  1390. // //this[newKey] = newValueData;
  1391. //
  1392. // return this[newKey];
  1393. //};
  1394. //this.del = function(delKey){
  1395. // if (!this.hasOwnProperty(delKey)) return null;
  1396. // delete data[newKey];
  1397. // delete this[newKey];
  1398. // return this;
  1399. //};
  1400. };
  1401. var type = typeOf(data);
  1402. if (type==="object" || type==="array") define.apply(this);
  1403. };
  1404. //MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1405. // var getter = function(data, callback, k, _self){
  1406. // return function(){return (["array","object"].indexOf(typeOf(data[k]))==-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1407. // }
  1408. // var setter = function(data, callback, k, _self){
  1409. // return function(v){
  1410. // data[k] = v;
  1411. // if (callback) callback(data, k, _self);
  1412. // }
  1413. // }
  1414. // var define = function(){
  1415. // var o = {};
  1416. // for (var k in data) o[k] = {
  1417. // "configurable": true,
  1418. // "get": getter.apply(this, [data, callback, k, this]),
  1419. // "set": setter.apply(this, [data, callback, k, this])
  1420. // };
  1421. // o["length"] = {"get": function(){return Object.keys(data).length;}};
  1422. // MWF.defineProperties(this, o);
  1423. // this.getKey = function(){ return key; };
  1424. // this.getParent = function(){ return parent; };
  1425. // this.toString = function() { return data.toString();};
  1426. // this.add = function(newKey, newValue){
  1427. // var type = typeOf(data);
  1428. // if (!this.hasOwnProperty(newKey)){
  1429. // if (type=="array"){
  1430. // data.push(newValue || {});
  1431. // newKey = data.length-1;
  1432. // }else{
  1433. // data[newKey] = newValue || {};
  1434. // }
  1435. // var o = {};
  1436. // o[newKey] = {"configurable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1437. // MWF.defineProperties(this, o);
  1438. // }
  1439. // this[newKey] = newValue;
  1440. // return this;
  1441. // };
  1442. // this.del = function(delKey){
  1443. // if (!this.hasOwnProperty(delKey)) return null;
  1444. // delete data[newKey];
  1445. // delete this[newKey];
  1446. // return this;
  1447. // };
  1448. // }
  1449. // var type = typeOf(data);
  1450. // if (type=="object" || type=="array") define.apply(this);
  1451. //};
  1452. //MWF.xScript.createCMSDict = function(application){
  1453. // return function(name){
  1454. // var applicationId = application;
  1455. // this.name = name;
  1456. // MWF.require("MWF.xScript.Actions.CMSDictActions", null, false);
  1457. // var action = new MWF.xScript.Actions.CMSDictActions();
  1458. //
  1459. // this.get = function(path, success, failure){
  1460. // var value = null;
  1461. // if( path ){
  1462. // var arr = path.split(/\./g);
  1463. // var ar = arr.map(function(v){
  1464. // return encodeURIComponent(v);
  1465. // });
  1466. // //var p = path.replace(/\./g, "/");
  1467. // var p = ar.join("/");
  1468. // action.getDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1469. // value = json.data;
  1470. // if (success) success(json.data);
  1471. // }, function(xhr, text, error){
  1472. // if (failure) failure(xhr, text, error);
  1473. // }, false);
  1474. // }else{
  1475. // action.getDictWhole(applicationId, encodeURIComponent(this.name), function(json){
  1476. // value = json.data;
  1477. // if (success) success(json.data);
  1478. // }, function(xhr, text, error){
  1479. // if (failure) failure(xhr, text, error);
  1480. // }, false);
  1481. // }
  1482. // return value;
  1483. // };
  1484. //
  1485. // this.set = function(path, value, success, failure){
  1486. // var p = path.replace(/\./g, "/");
  1487. // action.setDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1488. // if (success) success(json.data);
  1489. // }, function(xhr, text, error){
  1490. // if (failure) failure(xhr, text, error);
  1491. // });
  1492. // };
  1493. // this.add = function(path, value, success, failure){
  1494. // var p = path.replace(/\./g, "/");
  1495. // action.addDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1496. // if (success) success(json.data);
  1497. // }, function(xhr, text, error){
  1498. // if (failure) failure(xhr, text, error);
  1499. // });
  1500. // };
  1501. // this["delete"] = function(path, success, failure){
  1502. // var p = path.replace(/\./g, "/");
  1503. // action.deleteDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1504. // if (success) success(json.data);
  1505. // }, function(xhr, text, error){
  1506. // if (failure) failure(xhr, text, error);
  1507. // });
  1508. // };
  1509. // this.destory = this["delete"];
  1510. // }
  1511. //};
  1512. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  1513. MWF.xScript.addDictToCache = function ( options, path, json ) {
  1514. if( !path )path = "root";
  1515. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1516. var type = options.appType || "process";
  1517. var enableAnonymous = options.enableAnonymous || false;
  1518. var appFlagList = [];
  1519. if( options.application )appFlagList.push( options.application );
  1520. if( options.appId )appFlagList.push( options.appId );
  1521. if( options.appName )appFlagList.push( options.appName );
  1522. if( options.appAlias )appFlagList.push( options.appAlias );
  1523. var dictFlagList = [];
  1524. if( options.id )dictFlagList.push( options.id );
  1525. if( options.name )dictFlagList.push( options.name );
  1526. if( options.alias )dictFlagList.push( options.alias );
  1527. var cache = {};
  1528. cache[path] = json;
  1529. for( var i=0; i<appFlagList.length; i++ ){
  1530. for( var j=0; j<dictFlagList.length; j++ ){
  1531. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  1532. if( !MWF.xScript.dictLoaded[k] ){
  1533. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  1534. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  1535. }else if( i===0 && j===0 ){
  1536. MWF.xScript.setDictToCache( k, path ,json );
  1537. var arr = path.split(/\./g);
  1538. var p;
  1539. var cache = MWF.xScript.dictLoaded[k];
  1540. for( var l=0 ; l<arr.length; l++ ){
  1541. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  1542. if( cache[ p ] )break;
  1543. }
  1544. if( p ){
  1545. var mathP = p+".";
  1546. Object.keys( cache ).each( function( path, idx){
  1547. if( path.indexOf( mathP ) === 0 )delete cache[path];
  1548. })
  1549. }
  1550. }
  1551. }
  1552. }
  1553. };
  1554. MWF.xScript.getMatchedDict = function(key, path){
  1555. if( !path )path = "root";
  1556. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1557. var arr = path.split(/\./g);
  1558. if( MWF.xScript.dictLoaded[key] ){
  1559. var dicts = MWF.xScript.dictLoaded[key];
  1560. var list = Array.clone(arr);
  1561. var p;
  1562. var dict;
  1563. for( var i=0 ; i<arr.length; i++ ){
  1564. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  1565. list.shift();
  1566. if( dicts[ p ] ){
  1567. dict = dicts[ p ];
  1568. break;
  1569. }
  1570. }
  1571. return {
  1572. dict : dict,
  1573. unmatchedPathList : list
  1574. }
  1575. }
  1576. return {
  1577. dict : null,
  1578. unmatchedPathList : list
  1579. }
  1580. };
  1581. MWF.xScript.insertDictToCache = function(key, path, json){
  1582. if( MWF.xScript.dictLoaded[key] ){
  1583. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1584. var dict = matchedDict.dict;
  1585. var list = matchedDict.unmatchedPathList;
  1586. if( !dict ){
  1587. MWF.xScript.dictLoaded[key][path] = json;
  1588. }else{
  1589. for( var j=0; j<list.length-1; j++ ){
  1590. if( !dict[ list[j] ] ){
  1591. dict[ list[j] ] = {};
  1592. }
  1593. dict = dict[ list[j] ];
  1594. }
  1595. var lastPath = list[list.length-1];
  1596. if( !dict[lastPath] ){
  1597. dict[lastPath] = json;
  1598. }else if( typeOf( dict[lastPath] ) === "array" ){
  1599. dict[lastPath].push( json );
  1600. }
  1601. }
  1602. }else{
  1603. MWF.xScript.dictLoaded[key] = {};
  1604. MWF.xScript.dictLoaded[key][path] = json;
  1605. }
  1606. };
  1607. MWF.xScript.setDictToCache = function(key, path, json){
  1608. if( MWF.xScript.dictLoaded[key] ){
  1609. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1610. var dict = matchedDict.dict;
  1611. var list = matchedDict.unmatchedPathList;
  1612. if( !dict ){
  1613. MWF.xScript.dictLoaded[key][path] = json;
  1614. }else{
  1615. for( var j=0; j<list.length-1; j++ ){
  1616. if( !dict[ list[j] ] ){
  1617. dict[ list[j] ] = {};
  1618. }
  1619. dict = dict[ list[j] ];
  1620. }
  1621. dict[list[list.length-1]] = json;
  1622. }
  1623. }else{
  1624. MWF.xScript.dictLoaded[key] = {};
  1625. MWF.xScript.dictLoaded[key][path] = json;
  1626. }
  1627. };
  1628. MWF.xScript.getDictFromCache = function( key, path ){
  1629. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1630. var dict = matchedDict.dict;
  1631. var list = matchedDict.unmatchedPathList;
  1632. if( dict ){
  1633. for( var j=0; j<list.length; j++ ){
  1634. dict = dict[ list[j] ];
  1635. if( !dict )return null;
  1636. }
  1637. return dict;
  1638. }
  1639. return null;
  1640. };
  1641. MWF.xScript.deleteDictToCache = function(key, path){
  1642. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1643. var dict = matchedDict.dict;
  1644. var list = matchedDict.unmatchedPathList;
  1645. if( dict){
  1646. for( var j=0; j<list.length-1; j++ ){
  1647. dict = dict[ list[j] ];
  1648. if( !dict )return;
  1649. }
  1650. delete dict[list[list.length-1]];
  1651. }
  1652. };
  1653. MWF.xScript.createCMSDict = function(application){
  1654. //optionsOrName : {
  1655. // type : "", //默认为process, 可以为 process cms
  1656. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1657. // name : "", // 数据字典名称/别名/id
  1658. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1659. //}
  1660. //或者name: "" // 数据字典名称/别名/id
  1661. return function(optionsOrName){
  1662. var options = optionsOrName;
  1663. if( typeOf( options ) == "string" ){
  1664. options = { name : options };
  1665. }
  1666. var name = this.name = options.name;
  1667. var type = ( options.type && options.application ) ? options.type : "cms";
  1668. var applicationId = options.application || application;
  1669. var enableAnonymous = options.enableAnonymous || false;
  1670. var opt = {
  1671. "appType" : type,
  1672. "name" : name,
  1673. "appId" : applicationId,
  1674. "enableAnonymous" : enableAnonymous
  1675. };
  1676. var key = name+type+applicationId+enableAnonymous;
  1677. // if (!dictLoaded[key]) dictLoaded[key] = {};
  1678. // this.dictData = dictLoaded[key];
  1679. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1680. if( type == "cms" ){
  1681. var action = MWF.Actions.get("x_cms_assemble_control");
  1682. }else{
  1683. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1684. }
  1685. var encodePath = function( path ){
  1686. var arr = path.split(/\./g);
  1687. var ar = arr.map(function(v){
  1688. return encodeURIComponent(v);
  1689. });
  1690. return ar.join("/");
  1691. };
  1692. this.get = function(path, success, failure, async, refresh){
  1693. var value = null;
  1694. if (!refresh ){
  1695. var data = MWF.xScript.getDictFromCache( key, path );
  1696. if( data ){
  1697. if (success) success( data );
  1698. return data;
  1699. }
  1700. }
  1701. if (path){
  1702. var p = encodePath( path );
  1703. //var p = path.replace(/\./g, "/");
  1704. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1705. value = json.data;
  1706. // this.dictData[path] = value;
  1707. MWF.xScript.addDictToCache(opt, path, value);
  1708. if (success) success(json.data);
  1709. }.bind(this), function(xhr, text, error){
  1710. if (failure) failure(xhr, text, error);
  1711. }, !!async, false);
  1712. }else{
  1713. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1714. value = json.data;
  1715. // this.dictData["root"] = value;
  1716. MWF.xScript.addDictToCache(opt, path, value);
  1717. if (success) success(json.data);
  1718. }.bind(this), function(xhr, text, error){
  1719. if (failure) failure(xhr, text, error);
  1720. }, !!async);
  1721. }
  1722. return value;
  1723. };
  1724. this.set = function(path, value, success, failure){
  1725. var p = encodePath( path );
  1726. //var p = path.replace(/\./g, "/");
  1727. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1728. MWF.xScript.setDictToCache(key, path, value);
  1729. if (success) success(json.data);
  1730. }, function(xhr, text, error){
  1731. if (failure) failure(xhr, text, error);
  1732. }, false, false);
  1733. };
  1734. this.add = function(path, value, success, failure){
  1735. var p = encodePath( path );
  1736. //var p = path.replace(/\./g, "/");
  1737. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1738. MWF.xScript.insertDictToCache(key, path, value);
  1739. if (success) success(json.data);
  1740. }, function(xhr, text, error){
  1741. if (failure) failure(xhr, text, error);
  1742. }, false, false);
  1743. };
  1744. this["delete"] = function(path, success, failure){
  1745. var p = encodePath( path );
  1746. //var p = path.replace(/\./g, "/");
  1747. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1748. MWF.xScript.deleteDictToCache(key, path);
  1749. if (success) success(json.data);
  1750. }, function(xhr, text, error){
  1751. if (failure) failure(xhr, text, error);
  1752. }, false, false);
  1753. };
  1754. this.destory = this["delete"];
  1755. }
  1756. };
  1757. // var dictLoaded = {};
  1758. // MWF.xScript.createCMSDict = function(application){
  1759. // //optionsOrName : {
  1760. // // type : "", //默认为process, 可以为 process cms
  1761. // // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1762. // // name : "", // 数据字典名称/别名/id
  1763. // // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1764. // //}
  1765. // //或者name: "" // 数据字典名称/别名/id
  1766. // return function(optionsOrName){
  1767. // var options = optionsOrName;
  1768. // if( typeOf( options ) == "string" ){
  1769. // options = { name : options };
  1770. // }
  1771. // var name = this.name = options.name;
  1772. // var type = ( options.type && options.application ) ? options.type : "cms";
  1773. // var applicationId = options.application || application;
  1774. // var enableAnonymous = options.enableAnonymous || false;
  1775. //
  1776. // var key = name+type+applicationId+enableAnonymous
  1777. // if (!dictLoaded[key]) dictLoaded[key] = {};
  1778. // this.dictData = dictLoaded[key];
  1779. //
  1780. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1781. // if( type == "cms" ){
  1782. // var action = MWF.Actions.get("x_cms_assemble_control");
  1783. // }else{
  1784. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1785. // }
  1786. //
  1787. // var encodePath = function( path ){
  1788. // var arr = path.split(/\./g);
  1789. // var ar = arr.map(function(v){
  1790. // return encodeURIComponent(v);
  1791. // });
  1792. // return ar.join("/");
  1793. // };
  1794. //
  1795. // this.get = function(path, success, failure, async, refresh){
  1796. // var value = null;
  1797. // if (path){
  1798. // if ( !refresh && this.dictData[path] ){
  1799. // if (success) success(this.dictData[path]);
  1800. // return this.dictData[path];
  1801. // }
  1802. //
  1803. // var p = encodePath( path );
  1804. // //var p = path.replace(/\./g, "/");
  1805. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1806. // value = json.data;
  1807. // this.dictData[path] = value;
  1808. // if (success) success(json.data);
  1809. // }.bind(this), function(xhr, text, error){
  1810. // if (failure) failure(xhr, text, error);
  1811. // }, !!async, false);
  1812. // }else{
  1813. // if (this.dictData["root"]){
  1814. // if (success) success(this.dictData["root"]);
  1815. // return this.dictData["root"];
  1816. // }
  1817. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1818. // value = json.data;
  1819. // this.dictData["root"] = value;
  1820. // if (success) success(json.data);
  1821. // }.bind(this), function(xhr, text, error){
  1822. // if (failure) failure(xhr, text, error);
  1823. // }, !!async);
  1824. // }
  1825. //
  1826. // return value;
  1827. // };
  1828. //
  1829. // this.set = function(path, value, success, failure){
  1830. // var p = encodePath( path );
  1831. // //var p = path.replace(/\./g, "/");
  1832. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1833. // if (success) success(json.data);
  1834. // }, function(xhr, text, error){
  1835. // if (failure) failure(xhr, text, error);
  1836. // }, false, false);
  1837. // };
  1838. // this.add = function(path, value, success, failure){
  1839. // var p = encodePath( path );
  1840. // //var p = path.replace(/\./g, "/");
  1841. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1842. // if (success) success(json.data);
  1843. // }, function(xhr, text, error){
  1844. // if (failure) failure(xhr, text, error);
  1845. // }, false, false);
  1846. // };
  1847. // this["delete"] = function(path, success, failure){
  1848. // var p = encodePath( path );
  1849. // //var p = path.replace(/\./g, "/");
  1850. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1851. // if (success) success(json.data);
  1852. // }, function(xhr, text, error){
  1853. // if (failure) failure(xhr, text, error);
  1854. // }, false, false);
  1855. // };
  1856. // this.destory = this["delete"];
  1857. // }
  1858. // };
  1859. // MWF.xScript.createCMSDict = function(application){
  1860. // //optionsOrName : {
  1861. // // type : "", //默认为cms, 可以为 process cms
  1862. // // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1863. // // name : "", // 数据字典名称/别名/id
  1864. // // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1865. // //}
  1866. // //或者name: "" // 数据字典名称/别名/id
  1867. // return function(optionsOrName){
  1868. // var options = optionsOrName;
  1869. // if( typeOf( options ) == "string" ){
  1870. // options = { name : options };
  1871. // }
  1872. // var name = this.name = options.name;
  1873. // var type = ( options.type && options.application ) ? options.type : "cms";
  1874. // var applicationId = options.application || application;
  1875. // var enableAnonymous = options.enableAnonymous || false;
  1876. //
  1877. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1878. // if( type == "cms" ){
  1879. // var action = MWF.Actions.get("x_cms_assemble_control");
  1880. // }else{
  1881. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1882. // }
  1883. //
  1884. // var encodePath = function( path ){
  1885. // var arr = path.split(/\./g);
  1886. // var ar = arr.map(function(v){
  1887. // return encodeURIComponent(v);
  1888. // });
  1889. // return ar.join("/");
  1890. // };
  1891. //
  1892. // this.get = function(path, success, failure){
  1893. // var value = null;
  1894. // if (path){
  1895. // var p = encodePath( path );
  1896. // //var p = path.replace(/\./g, "/");
  1897. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1898. // value = json.data;
  1899. // if (success) success(json.data);
  1900. // }, function(xhr, text, error){
  1901. // if (failure) failure(xhr, text, error);
  1902. // }, false, false);
  1903. // }else{
  1904. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](encodeURIComponent(this.name), applicationId, function(json){
  1905. // value = json.data;
  1906. // if (success) success(json.data);
  1907. // }, function(xhr, text, error){
  1908. // if (failure) failure(xhr, text, error);
  1909. // }, false);
  1910. // }
  1911. //
  1912. // return value;
  1913. // };
  1914. //
  1915. // this.set = function(path, value, success, failure){
  1916. // var p = encodePath( path );
  1917. // //var p = path.replace(/\./g, "/");
  1918. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1919. // if (success) success(json.data);
  1920. // }, function(xhr, text, error){
  1921. // if (failure) failure(xhr, text, error);
  1922. // }, false, false);
  1923. // };
  1924. // this.add = function(path, value, success, failure){
  1925. // var p = encodePath( path );
  1926. // //var p = path.replace(/\./g, "/");
  1927. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1928. // if (success) success(json.data);
  1929. // }, function(xhr, text, error){
  1930. // if (failure) failure(xhr, text, error);
  1931. // }, false, false);
  1932. // };
  1933. // this["delete"] = function(path, success, failure){
  1934. // var p = encodePath( path );
  1935. // //var p = path.replace(/\./g, "/");
  1936. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1937. // if (success) success(json.data);
  1938. // }, function(xhr, text, error){
  1939. // if (failure) failure(xhr, text, error);
  1940. // }, false, false);
  1941. // };
  1942. // this.destory = this["delete"];
  1943. // }
  1944. // };