CMSEnvironment.js 93 KB

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