CMSEnvironment.js 102 KB

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