CMSEnvironment.js 95 KB

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