CMSEnvironment.js 105 KB

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