CMSEnvironment.js 105 KB

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