CMSEnvironment.js 104 KB

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