CMSEnvironment.js 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169
  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 parameter = this.parseParameter(statement.parameter);
  678. var filterList = this.parseFilter(statement.filter, parameter);
  679. var obj = {
  680. "filterList": filterList,
  681. "parameter" : parameter
  682. };
  683. MWF.Actions.load("x_query_assemble_surface").StatementAction.executeV2(
  684. statement.name, statement.mode || "data", statement.page || 1, statement.pageSize || 20, obj,
  685. function (json) {
  686. if (callback) callback(json);
  687. }, null, async);
  688. },
  689. parseFilter : function( filter, parameter ){
  690. if( typeOf(filter) !== "array" )return [];
  691. var filterList = [];
  692. ( filter || [] ).each( function (d) {
  693. var parameterName = d.path.replace(/\./g, "_");
  694. var value = d.value;
  695. if( d.comparison === "like" || d.comparison === "notLike" ){
  696. if( value.substr(0, 1) !== "%" )value = "%"+value;
  697. if( value.substr(value.length-1,1) !== "%" )value = value+"%";
  698. parameter[ parameterName ] = value; //"%"+value+"%";
  699. }else{
  700. if( d.formatType === "dateTimeValue" || d.formatType === "datetimeValue"){
  701. value = "{ts '"+value+"'}"
  702. }else if( d.formatType === "dateValue" ){
  703. value = "{d '"+value+"'}"
  704. }else if( d.formatType === "timeValue" ){
  705. value = "{t '"+value+"'}"
  706. }
  707. parameter[ parameterName ] = value;
  708. }
  709. d.value = parameterName;
  710. filterList.push( d );
  711. }.bind(this));
  712. return filterList;
  713. },
  714. parseParameter : function( obj ){
  715. if( typeOf(obj) !== "object" )return {};
  716. var parameter = {};
  717. //传入的参数
  718. for( var p in obj ){
  719. var value = obj[p];
  720. if( typeOf( value ) === "date" ){
  721. value = "{ts '"+value.format("db")+"'}"
  722. }
  723. parameter[ p ] = value;
  724. }
  725. return parameter;
  726. },
  727. "select": function (statement, callback, options) {
  728. if (statement.name) {
  729. // var parameter = this.parseParameter(statement.parameter);
  730. // var filterList = this.parseFilter(statement.filter, parameter);
  731. var statementJson = {
  732. "statementId": statement.name || "",
  733. "isTitle": (statement.isTitle === false) ? "no" : "yes",
  734. "select": (statement.isMulti === false) ? "single" : "multi",
  735. "filter": statement.filter,
  736. "parameter": statement.parameter
  737. };
  738. if (!options) options = {};
  739. options.width = statement.width;
  740. options.height = statement.height;
  741. options.title = statement.caption;
  742. var width = options.width || "700";
  743. var height = options.height || "400";
  744. if (layout.mobile) {
  745. var size = document.body.getSize();
  746. width = size.x;
  747. height = size.y;
  748. options.style = "viewmobile";
  749. }
  750. width = width.toInt();
  751. height = height.toInt();
  752. var size = _form.app.content.getSize();
  753. var x = (size.x - width) / 2;
  754. var y = (size.y - height) / 2;
  755. if (x < 0) x = 0;
  756. if (y < 0) y = 0;
  757. if (layout.mobile) {
  758. x = 20;
  759. y = 0;
  760. }
  761. var _self = this;
  762. MWF.require("MWF.xDesktop.Dialog", function () {
  763. var dlg = new MWF.xDesktop.Dialog({
  764. "title": options.title || "select statement view",
  765. "style": options.style || "view",
  766. "top": y,
  767. "left": x - 20,
  768. "fromTop": y,
  769. "fromLeft": x - 20,
  770. "width": width,
  771. "height": height,
  772. "html": "<div style='height: 100%;'></div>",
  773. "maskNode": _form.app.content,
  774. "container": _form.app.content,
  775. "buttonList": [
  776. {
  777. "text": MWF.LP.process.button.ok,
  778. "action": function () {
  779. //if (callback) callback(_self.view.selectedItems);
  780. if (callback) callback(_self.statement.getData());
  781. this.close();
  782. }
  783. },
  784. {
  785. "text": MWF.LP.process.button.cancel,
  786. "action": function () { this.close(); }
  787. }
  788. ]
  789. });
  790. dlg.show();
  791. if (layout.mobile) {
  792. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  793. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  794. if (backAction) backAction.addEvent("click", function (e) {
  795. dlg.close();
  796. }.bind(this));
  797. if (okAction) okAction.addEvent("click", function (e) {
  798. //if (callback) callback(this.view.selectedItems);
  799. if (callback) callback(this.statement.getData());
  800. dlg.close();
  801. }.bind(this));
  802. }
  803. MWF.xDesktop.requireApp("query.Query", "Statement", function () {
  804. this.statement = new MWF.xApplication.query.Query.Statement(dlg.content.getFirst(), statementJson, { "style": "select" }, _form.app, _form.Macro);
  805. }.bind(this));
  806. }.bind(this));
  807. }
  808. }
  809. };
  810. //var lookupAction = null;
  811. //var getLookupAction = function(callback){
  812. // if (!lookupAction){
  813. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  814. // lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  815. // lookupAction.getActions = function(actionCallback){
  816. // this.actions = {
  817. // "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  818. // "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  819. // };
  820. // if (actionCallback) actionCallback();
  821. // }
  822. // if (callback) callback();
  823. // }.bind(this));
  824. // }else{
  825. // if (callback) callback();
  826. // }
  827. //};
  828. //
  829. //this.view = {
  830. // "lookup": function(view, callback){
  831. // getLookupAction(function(){
  832. // lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  833. // var data = {
  834. // "grid": json.data.grid,
  835. // "groupGrid": json.data.groupGrid
  836. // };
  837. // if (callback) callback(data);
  838. // }.bind(this)});
  839. // }.bind(this));
  840. // },
  841. // "select": function(view, callback, options){
  842. // if (view.view){
  843. // var viewJson = {
  844. // "application": view.application || "",
  845. // "viewName": view.view || "",
  846. // "isTitle": view.isTitle || "yes",
  847. // "select": view.select || "multi",
  848. // "title": view.title || "Select View"
  849. // };
  850. // if (!options) options = {};
  851. // var width = options.width || "700";
  852. // var height = options.height || "400";
  853. //
  854. // if (layout.mobile){
  855. // var size = document.body.getSize();
  856. // width = size.x;
  857. // height = size.y;
  858. // options.style = "viewmobile";
  859. // }
  860. // width = width.toInt();
  861. // height = height.toInt();
  862. //
  863. // var size = _form.app.content.getSize();
  864. // var x = (size.x-width)/2;
  865. // var y = (size.y-height)/2;
  866. // if (x<0) x = 0;
  867. // if (y<0) y = 0;
  868. // if (layout.mobile){
  869. // x = 20;
  870. // y = 0;
  871. // }
  872. //
  873. // var _self = this;
  874. // MWF.require("MWF.xDesktop.Dialog", function(){
  875. // var dlg = new MWF.xDesktop.Dialog({
  876. // "title": options.title || "select View",
  877. // "style": options.style || "view",
  878. // "top": y,
  879. // "left": x-20,
  880. // "fromTop":y,
  881. // "fromLeft": x-20,
  882. // "width": width,
  883. // "height": height,
  884. // "html": "<div style='height: 100%;'></div>",
  885. // "maskNode": _form.app.content,
  886. // "container": _form.app.content,
  887. // "buttonList": [
  888. // {
  889. // "text": MWF.LP.process.button.ok,
  890. // "action": function(){
  891. // //if (callback) callback(_self.view.selectedItems);
  892. // if (callback) callback(_self.view.getData());
  893. // this.close();
  894. // }
  895. // },
  896. // {
  897. // "text": MWF.LP.process.button.cancel,
  898. // "action": function(){this.close();}
  899. // }
  900. // ]
  901. // });
  902. // dlg.show();
  903. // if (layout.mobile){
  904. // var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  905. // var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  906. // if (backAction) backAction.addEvent("click", function(e){
  907. // dlg.close();
  908. // }.bind(this));
  909. // if (okAction) okAction.addEvent("click", function(e){
  910. // //if (callback) callback(this.view.selectedItems);
  911. // if (callback) callback(this.view.getData());
  912. // dlg.close();
  913. // }.bind(this));
  914. // }
  915. //
  916. // // MWF.xDesktop.requireApp("cms.Xform", "widget.View", function(){
  917. // // this.view = new MWF.xApplication.cms.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  918. // // }.bind(this));
  919. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  920. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  921. // }.bind(this));
  922. // }.bind(this));
  923. // }
  924. // }
  925. //};
  926. //include 引用脚本
  927. //optionsOrName : {
  928. // type : "", 默认为cms, 可以为 portal process cms
  929. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  930. // name : "" // 脚本名称/别名/id
  931. //}
  932. //或者name: "" // 脚本名称/别名/id
  933. // if( !window.includedScripts ){
  934. // var includedScripts = window.includedScripts = [];
  935. // }else{
  936. // var includedScripts = window.includedScripts;
  937. // }
  938. var includedScripts = [];
  939. this.include = function( optionsOrName , callback ){
  940. var options = optionsOrName;
  941. if( typeOf( options ) == "string" ){
  942. options = { name : options };
  943. }
  944. var name = options.name;
  945. var type = ( options.type && options.application ) ? options.type : "cms";
  946. var application = options.application || _form.json.application;
  947. var key = type +"-" + application + "-" + name;
  948. if (includedScripts.indexOf( key )> -1){
  949. if (callback) callback.apply(this);
  950. return;
  951. }
  952. //if (includedScripts.indexOf( name )> -1){
  953. // if (callback) callback.apply(this);
  954. // return;
  955. //}
  956. var scriptAction;
  957. switch ( type ){
  958. case "portal" :
  959. if( this.scriptActionPortal ){
  960. scriptAction = this.scriptActionPortal;
  961. }else{
  962. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  963. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  964. }
  965. break;
  966. case "process" :
  967. if( this.scriptActionProcess ){
  968. scriptAction = this.scriptActionProcess;
  969. }else{
  970. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  971. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  972. }
  973. break;
  974. case "cms" :
  975. if( this.scriptActionCMS ){
  976. scriptAction = this.scriptActionCMS;
  977. }else{
  978. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  979. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  980. }
  981. break;
  982. }
  983. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  984. if (json.data){
  985. includedScripts.push( key );
  986. //名称、别名、id
  987. json.data.importedList.each( function ( flag ) {
  988. if( type === "portal" ){
  989. includedScripts.push( type + "-" + json.data.portal + "-" + flag );
  990. if( json.data.portalName )includedScripts.push( type + "-" + json.data.portalName + "-" + flag );
  991. if( json.data.portalAlias )includedScripts.push( type + "-" + json.data.portalAlias + "-" + flag );
  992. }else if( type === "cms" ){
  993. includedScripts.push( type + "-" + json.data.appId + "-" + flag );
  994. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  995. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  996. }else if( type === "process" ){
  997. includedScripts.push( type + "-" + json.data.application + "-" + flag );
  998. if( json.data.appName )includedScripts.push( type + "-" + json.data.appName + "-" + flag );
  999. if( json.data.appAlias )includedScripts.push( type + "-" + json.data.appAlias + "-" + flag );
  1000. }
  1001. });
  1002. includedScripts = includedScripts.concat(json.data.importedList);
  1003. MWF.CMSMacro.exec(json.data.text, this);
  1004. if (callback) callback.apply(this);
  1005. }else{
  1006. if (callback) callback.apply(this);
  1007. }
  1008. }.bind(this), null, false);
  1009. };
  1010. //var includedScripts = [];
  1011. //this.include = function(name, callback){
  1012. // if (includedScripts.indexOf(name)==-1){
  1013. // if (!this.scriptAction){
  1014. // MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  1015. // this.scriptAction = new MWF.xScript.Actions.CMSScriptActions();
  1016. // }
  1017. // this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
  1018. // includedScripts = includedScripts.concat(json.data.importedList);
  1019. // MWF.CMSMacro.exec(json.data.text, this);
  1020. // if (callback) callback.apply(this);
  1021. // }.bind(this), null, false);
  1022. // }else{
  1023. // if (callback) callback.apply(this);
  1024. // }
  1025. //}.bind(this);
  1026. this.define = function(name, fun, overwrite){
  1027. var over = true;
  1028. if (overwrite===false) over = false;
  1029. var o = {};
  1030. o[name] = {"value": fun, "configurable": over};
  1031. MWF.defineProperties(this, o);
  1032. }.bind(this);
  1033. //如果前端事件有异步调用,想要在异步调用结束后继续运行页面加载,
  1034. //可在调用前执行 var resolve = this.wait();
  1035. //在异步调用结束后 执行 resolve.cb();
  1036. //目前只有表单的queryload事件支持此方法。
  1037. this.wait = function(){
  1038. resolve = {};
  1039. var setResolve = function(callback){
  1040. resolve.cb = callback;
  1041. }.bind(this);
  1042. this.target.event_resolve = setResolve;
  1043. return resolve;
  1044. };
  1045. //和this.wait配合使用,
  1046. //如果没有异步,则resolve.cb方法不存在,
  1047. //所以在回调中中使用this.goon();使表单继续加载
  1048. this.goon = function(){
  1049. this.target.event_resolve = null;
  1050. };
  1051. //仅前台对象-----------------------------------------
  1052. //form
  1053. this.form = {
  1054. "getInfor": function(){return ev.formInfor;},
  1055. "infor": ev.formInfor,
  1056. "getApp": function(){return _form.app;},
  1057. "app": _form.app,
  1058. "node": function(){return _form.node;},
  1059. "readonly": _form.options.readonly,
  1060. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  1061. "getField": function(name){return _forms[name];},
  1062. "getAction": function(){return _form.documentAction},
  1063. "getData": function(){return new MWF.xScript.CMSJSONData(_form.getData());},
  1064. "save": function(callback){
  1065. _form.saveDocument(callback);
  1066. },
  1067. "close": function(){_form.closeDocument();},
  1068. "publish": function(option){
  1069. _form.publishDocument()
  1070. },
  1071. //"archive": function(option){
  1072. // _form.archiveDocument()
  1073. //},
  1074. //"redraft": function(option){
  1075. // _form.redraftDocument()
  1076. //},
  1077. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  1078. // var p = MWF.getCenter({"x": width, "y": height});
  1079. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1080. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1081. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  1082. var p = MWF.getCenter({"x": width, "y": height});
  1083. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  1084. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1085. }else{
  1086. e = (arguments.length>1) ? arguments[1] : null;
  1087. title = (arguments.length>2) ? arguments[2] : null;
  1088. text = (arguments.length>3) ? arguments[3] : null;
  1089. width = (arguments.length>4) ? arguments[4] : null;
  1090. height = (arguments.length>5) ? arguments[5] : null;
  1091. ok = (arguments.length>6) ? arguments[6] : null;
  1092. cancel = (arguments.length>7) ? arguments[7] : null;
  1093. callback = (arguments.length>8) ? arguments[8] : null;
  1094. mask = (arguments.length>9) ? arguments[9] : null;
  1095. style = (arguments.length>10) ? arguments[10] : null;
  1096. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  1097. }
  1098. },
  1099. //"confirm": function(type, e, title, text, width, height, ok, cancel, callback){
  1100. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  1101. //},
  1102. "notice": function(content, type, target, where, offset, option){
  1103. _form.notice(content, type, target, where, offset, option);
  1104. },
  1105. "addEvent": function(e, f){_form.addEvent(e, f);},
  1106. "openWork": function(id, completedId, title, options){
  1107. var op = options || {};
  1108. op.workId = id;
  1109. op.workCompletedId = completedId;
  1110. op.docTitle = title;
  1111. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  1112. return layout.desktop.openApplication(this.event, "process.Work", op);
  1113. },
  1114. "openJob": function(id, choice, options){
  1115. var workData = null;
  1116. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  1117. if (json.data) workData = json.data;
  1118. }.bind(this), null, false);
  1119. if (workData){
  1120. var len = workData.workList.length + workData.workCompletedList.length;
  1121. if (len){
  1122. if (len>1 && choice){
  1123. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  1124. workData.workList.each(function(work){
  1125. var workNode = new Element("div", {
  1126. "styles": {
  1127. "background": "#ffffff",
  1128. "border-radius": "10px",
  1129. "clear": "both",
  1130. "margin-bottom": "10px",
  1131. "height": "40px",
  1132. "padding": "10px 10px"
  1133. }
  1134. }).inject(node);
  1135. 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>" +
  1136. "<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>"+
  1137. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1138. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  1139. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  1140. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  1141. workNode.set("html", html);
  1142. var action = workNode.getElement(".MWFAction");
  1143. action.store("work", work);
  1144. action.addEvent("click", function(e){
  1145. var work = e.target.retrieve("work");
  1146. if (work) this.openWork(work.id, null, work.title, options);
  1147. dlg.close();
  1148. }.bind(this));
  1149. }.bind(this));
  1150. workData.workCompletedList.each(function(work){
  1151. var workNode = new Element("div", {
  1152. "styles": {
  1153. "background": "#ffffff",
  1154. "border-radius": "10px",
  1155. "clear": "both",
  1156. "margin-bottom": "10px",
  1157. "height": "40px",
  1158. "padding": "10px 10px"
  1159. }
  1160. }).inject(node);
  1161. 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>" +
  1162. "<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>"+
  1163. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  1164. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  1165. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  1166. workNode.set("html", html);
  1167. var action = workNode.getElement(".MWFAction");
  1168. action.store("work", work);
  1169. action.addEvent("click", function(e){
  1170. var work = e.target.retrieve("work");
  1171. if (work) this.openWork(null, work.id, work.title, options);
  1172. dlg.close();
  1173. }.bind(this));
  1174. }.bind(this));
  1175. var height = node.getSize().y+20;
  1176. if (height>600) height = 600;
  1177. var dlg = o2.DL.open({
  1178. "title": o2.LP.widget.choiceWork,
  1179. "style" : "user",
  1180. "isResize": false,
  1181. "content": node,
  1182. "buttonList": [
  1183. {
  1184. "type" : "cancel",
  1185. "text": o2.LP.widget.close,
  1186. "action": function(){dlg.close();}
  1187. }
  1188. ]
  1189. });
  1190. }else{
  1191. if (workData.workList.length){
  1192. var work = workData.workList[0];
  1193. return this.openWork(work.id, null, work.title, options);
  1194. }else{
  1195. var work = workData.workCompletedList[0];
  1196. return this.openWork(null, work.id, work.title, options);
  1197. }
  1198. }
  1199. }
  1200. }
  1201. },
  1202. "openDocument": function(id, title, options){
  1203. var op = options || {};
  1204. op.documentId = id;
  1205. op.docTitle = title;
  1206. layout.desktop.openApplication(this.event, "cms.Document", op);
  1207. },
  1208. "openPortal": function(name, page, par){
  1209. var action = MWF.Actions.get("x_portal_assemble_surface");
  1210. action.getApplication(name, function(json){
  1211. if (json.data){
  1212. if (page){
  1213. action.getPageByName(page, json.data.id, function(pageJson){
  1214. layout.desktop.openApplication(null, "portal.Portal", {
  1215. "portalId": json.data.id,
  1216. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1217. "parameters": par,
  1218. "appId": "portal.Portal"+json.data.id
  1219. })
  1220. });
  1221. }else{
  1222. layout.desktop.openApplication(null, "portal.Portal", {
  1223. "portalId": json.data.id,
  1224. "parameters": par,
  1225. "appId": "portal.Portal"+json.data.id
  1226. })
  1227. }
  1228. }
  1229. });
  1230. },
  1231. "openCMS": function(name){
  1232. var action = MWF.Actions.get("x_cms_assemble_control");
  1233. action.getColumn(name, function(json){
  1234. if (json.data){
  1235. layout.desktop.openApplication(null, "cms.Module", {
  1236. "columnId": json.data.id,
  1237. "appId": "cms.Module"+json.data.id
  1238. });
  1239. }
  1240. });
  1241. },
  1242. "openProcess": function(name){
  1243. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1244. action.getApplication(name, function(json){
  1245. if (json.data){
  1246. layout.desktop.openApplication(null, "process.Application", {
  1247. "id": json.data.id,
  1248. "appId": "process.Application"+json.data.id
  1249. });
  1250. }
  1251. });
  1252. },
  1253. "openApplication":function(name, options){
  1254. layout.desktop.openApplication(null, name, options);
  1255. },
  1256. "createDocument": function (columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle) {
  1257. var column = columnOrOptions;
  1258. var onAfterPublish, onPostPublish;
  1259. if (typeOf(columnOrOptions) == "object") {
  1260. column = columnOrOptions.column;
  1261. category = columnOrOptions.category;
  1262. data = columnOrOptions.data;
  1263. identity = columnOrOptions.identity;
  1264. callback = columnOrOptions.callback;
  1265. target = columnOrOptions.target;
  1266. latest = columnOrOptions.latest;
  1267. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1268. ignoreTitle = columnOrOptions.ignoreTitle;
  1269. onAfterPublish = columnOrOptions.onAfterPublish;
  1270. onPostPublish = columnOrOptions.onPostPublish;
  1271. }
  1272. if (target) {
  1273. if (layout.app && layout.app.inBrowser) {
  1274. layout.app.content.empty();
  1275. layout.app = null;
  1276. }
  1277. }
  1278. MWF.xDesktop.requireApp("cms.Index", "Newer", function () {
  1279. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1280. "documentData": data,
  1281. "identity": identity,
  1282. "ignoreTitle": ignoreTitle === true,
  1283. "ignoreDrafted": latest === false,
  1284. "selectColumnEnable": !category || selectColumnEnable === true,
  1285. "restrictToColumn": !!category && selectColumnEnable !== true,
  1286. "categoryFlag": category, //category id or name
  1287. "columnFlag": column, //column id or name,
  1288. "onStarted": function (documentId, data) {
  1289. if (callback) callback();
  1290. },
  1291. "onPostPublish": function () {
  1292. if(onPostPublish)onPostPublish();
  1293. },
  1294. "onAfterPublish": function () {
  1295. if(onAfterPublish)onAfterPublish();
  1296. }
  1297. });
  1298. starter.load();
  1299. })
  1300. },
  1301. "startProcess": function(app, process, data, identity, callback, target, latest){
  1302. if (arguments.length>2){
  1303. for (var i=2; i<arguments.length; i++){
  1304. if (typeOf(arguments[i])=="boolean"){
  1305. target = arguments[i];
  1306. break;
  1307. }
  1308. }
  1309. }
  1310. if (target){
  1311. if (layout.app && layout.app.inBrowser){
  1312. //layout.app.content.empty();
  1313. layout.app.$openWithSelf = true;
  1314. }
  1315. }
  1316. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1317. if (json.data){
  1318. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1319. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1320. "workData": data,
  1321. "identity": identity,
  1322. "latest": latest,
  1323. "onStarted": function(data, title, processName){
  1324. if (data.work){
  1325. var work = data.work;
  1326. var options = {"draft": work, "appId": "process.Work"+(new o2.widget.UUID).toString(), "desktopReload": false};
  1327. layout.desktop.openApplication(null, "process.Work", options);
  1328. }else{
  1329. var currentTask = [];
  1330. data.each(function(work){
  1331. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1332. }.bind(this));
  1333. if (currentTask.length==1){
  1334. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1335. layout.desktop.openApplication(null, "process.Work", options);
  1336. }else{}
  1337. }
  1338. // var currentTask = [];
  1339. // data.each(function(work){
  1340. // if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1341. // }.bind(this));
  1342. //
  1343. // if (currentTask.length==1){
  1344. // var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1345. // layout.desktop.openApplication(null, "process.Work", options);
  1346. // }else{}
  1347. if (callback) callback(data);
  1348. }.bind(this)
  1349. });
  1350. starter.load();
  1351. }.bind(this));
  1352. }
  1353. });
  1354. }
  1355. };
  1356. this.target = ev.target;
  1357. this.event = ev.event;
  1358. this.status = ev.status;
  1359. this.session = layout.desktop.session;
  1360. this.Actions = o2.Actions;
  1361. this.query = function(option){
  1362. // options = {
  1363. // "name": "statementName",
  1364. // "data": "json data",
  1365. // "firstResult": 1,
  1366. // "maxResults": 100,
  1367. // "success": function(){},
  1368. // "error": function(){},
  1369. // "async": true or false, default is true
  1370. // }
  1371. if (option){
  1372. var json = (option.data) || {};
  1373. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1374. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1375. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1376. }
  1377. };
  1378. this.Table = MWF.xScript.createTable();
  1379. };
  1380. MWF.xScript.createTable = function(){
  1381. return function(name){
  1382. this.name = name;
  1383. this.action = o2.Actions.get("x_query_assemble_surface");
  1384. this.listRowNext = function(id, count, success, error, async){
  1385. this.action.listRowNext(this.name, id, count, success, error, async);
  1386. };
  1387. this.listRowPrev = function(id, count, success, error, async){
  1388. this.action.listRowPrev(this.name, id, count, success, error, async);
  1389. };
  1390. this.listRowPrev = function(id, count, success, error, async){
  1391. this.action.listRowPrev(this.name, id, count, success, error, async);
  1392. };
  1393. this.listRowSelectWhere = function(where, success, error, async){
  1394. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1395. };
  1396. this.listRowCountWhere = function(where, success, error, async){
  1397. this.action.listRowCountWhere(this.name, where, success, error, async);
  1398. };
  1399. this.deleteRow = function(id, success, error, async){
  1400. this.action.deleteRow(this.name, id, success, error, async);
  1401. };
  1402. this.deleteAllRow = function(success, error, async){
  1403. this.action.deleteAllRow(this.name, success, error, async);
  1404. };
  1405. this.getRow = function(id, success, error, async){
  1406. this.action.getRow(this.name, id, success, error, async);
  1407. };
  1408. this.insertRow = function(data, success, error, async){
  1409. this.action.insertRow(this.name, data, success, error, async);
  1410. };
  1411. this.updateRow = function(id, data, success, error, async){
  1412. this.action.updateRow(this.name, id, data, success, error, async);
  1413. };
  1414. }
  1415. };
  1416. MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1417. var getter = function(data, callback, k, _self){
  1418. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1419. };
  1420. var setter = function(data, callback, k, _self){
  1421. return function(v){
  1422. data[k] = v;
  1423. //debugger;
  1424. //this.add(k, v, true);
  1425. if (callback) callback(data, k, _self);
  1426. }
  1427. };
  1428. var define = function(){
  1429. var o = {};
  1430. 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])};
  1431. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1432. MWF.defineProperties(this, o);
  1433. var methods = {
  1434. "getKey": {"value": function(){ return key; }},
  1435. "getParent": {"value": function(){ return parent; }},
  1436. "toString": {"value": function() { return data.toString();}},
  1437. "add": {"value": function(newKey, newValue, overwrite){
  1438. var flag = true;
  1439. var type = typeOf(data);
  1440. if (type==="array"){
  1441. if (arguments.length<2){
  1442. data.push(newKey);
  1443. newValue = newKey;
  1444. newKey = data.length-1;
  1445. }else{
  1446. if (!newKey && newKey!==0){
  1447. data.push(newValue);
  1448. newKey = data.length-1;
  1449. }else{
  1450. flag = false;
  1451. }
  1452. }
  1453. if (flag){
  1454. var o = {};
  1455. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1456. MWF.defineProperties(this, o);
  1457. }
  1458. this[newKey] = newValue;
  1459. }else if (type==="object"){
  1460. if (!this.hasOwnProperty(newKey)){
  1461. data[newKey] = newValue;
  1462. if (flag){
  1463. var o = {};
  1464. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1465. MWF.defineProperties(this, o);
  1466. }
  1467. this[newKey] = newValue;
  1468. }else{
  1469. if (overwrite) this[newKey] = newValue;
  1470. }
  1471. }
  1472. return this[newKey];
  1473. }},
  1474. "del": {"value": function(delKey){
  1475. if (!this.hasOwnProperty(delKey)) return null;
  1476. delete data[delKey];
  1477. delete this[delKey];
  1478. return this;
  1479. }}
  1480. };
  1481. MWF.defineProperties(this, methods);
  1482. //this.getKey = function(){ return key; };
  1483. //this.getParent = function(){ return parent; };
  1484. //this.toString = function() { return data.toString();};
  1485. //this.add = function(newKey, newValue, overwrite){
  1486. // var flag = true;
  1487. // var type = typeOf(data);
  1488. // if (!this.hasOwnProperty(newKey)){
  1489. // if (type=="array"){
  1490. // if (arguments.length<2){
  1491. // data.push(newKey);
  1492. // newValue = newKey;
  1493. // newKey = data.length-1;
  1494. // }else{
  1495. // debugger;
  1496. // if (!newKey && newKey!=0){
  1497. // data.push(newValue);
  1498. // newKey = data.length-1;
  1499. // }else{
  1500. // flag == false;
  1501. // }
  1502. // }
  1503. // }else{
  1504. // data[newKey] = newValue;
  1505. // }
  1506. // //var valueType = typeOf(newValue);
  1507. // //var newValueData = newValue;
  1508. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1509. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1510. // if (flag){
  1511. // var o = {};
  1512. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1513. // MWF.defineProperties(this, o);
  1514. // }
  1515. // this[newKey] = newValue;
  1516. // }else{
  1517. // if (overwrite) this[newKey] = newValue;
  1518. // }
  1519. //
  1520. // //var valueType = typeOf(newValue);
  1521. // //var newValueData = newValue;
  1522. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1523. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1524. // //
  1525. // //this[newKey] = newValueData;
  1526. //
  1527. // return this[newKey];
  1528. //};
  1529. //this.del = function(delKey){
  1530. // if (!this.hasOwnProperty(delKey)) return null;
  1531. // delete data[newKey];
  1532. // delete this[newKey];
  1533. // return this;
  1534. //};
  1535. };
  1536. var type = typeOf(data);
  1537. if (type==="object" || type==="array") define.apply(this);
  1538. };
  1539. //MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1540. // var getter = function(data, callback, k, _self){
  1541. // return function(){return (["array","object"].indexOf(typeOf(data[k]))==-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1542. // }
  1543. // var setter = function(data, callback, k, _self){
  1544. // return function(v){
  1545. // data[k] = v;
  1546. // if (callback) callback(data, k, _self);
  1547. // }
  1548. // }
  1549. // var define = function(){
  1550. // var o = {};
  1551. // for (var k in data) o[k] = {
  1552. // "configurable": true,
  1553. // "get": getter.apply(this, [data, callback, k, this]),
  1554. // "set": setter.apply(this, [data, callback, k, this])
  1555. // };
  1556. // o["length"] = {"get": function(){return Object.keys(data).length;}};
  1557. // MWF.defineProperties(this, o);
  1558. // this.getKey = function(){ return key; };
  1559. // this.getParent = function(){ return parent; };
  1560. // this.toString = function() { return data.toString();};
  1561. // this.add = function(newKey, newValue){
  1562. // var type = typeOf(data);
  1563. // if (!this.hasOwnProperty(newKey)){
  1564. // if (type=="array"){
  1565. // data.push(newValue || {});
  1566. // newKey = data.length-1;
  1567. // }else{
  1568. // data[newKey] = newValue || {};
  1569. // }
  1570. // var o = {};
  1571. // o[newKey] = {"configurable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1572. // MWF.defineProperties(this, o);
  1573. // }
  1574. // this[newKey] = newValue;
  1575. // return this;
  1576. // };
  1577. // this.del = function(delKey){
  1578. // if (!this.hasOwnProperty(delKey)) return null;
  1579. // delete data[newKey];
  1580. // delete this[newKey];
  1581. // return this;
  1582. // };
  1583. // }
  1584. // var type = typeOf(data);
  1585. // if (type=="object" || type=="array") define.apply(this);
  1586. //};
  1587. //MWF.xScript.createCMSDict = function(application){
  1588. // return function(name){
  1589. // var applicationId = application;
  1590. // this.name = name;
  1591. // MWF.require("MWF.xScript.Actions.CMSDictActions", null, false);
  1592. // var action = new MWF.xScript.Actions.CMSDictActions();
  1593. //
  1594. // this.get = function(path, success, failure){
  1595. // var value = null;
  1596. // if( path ){
  1597. // var arr = path.split(/\./g);
  1598. // var ar = arr.map(function(v){
  1599. // return encodeURIComponent(v);
  1600. // });
  1601. // //var p = path.replace(/\./g, "/");
  1602. // var p = ar.join("/");
  1603. // action.getDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1604. // value = json.data;
  1605. // if (success) success(json.data);
  1606. // }, function(xhr, text, error){
  1607. // if (failure) failure(xhr, text, error);
  1608. // }, false);
  1609. // }else{
  1610. // action.getDictWhole(applicationId, encodeURIComponent(this.name), function(json){
  1611. // value = json.data;
  1612. // if (success) success(json.data);
  1613. // }, function(xhr, text, error){
  1614. // if (failure) failure(xhr, text, error);
  1615. // }, false);
  1616. // }
  1617. // return value;
  1618. // };
  1619. //
  1620. // this.set = function(path, value, success, failure){
  1621. // var p = path.replace(/\./g, "/");
  1622. // action.setDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1623. // if (success) success(json.data);
  1624. // }, function(xhr, text, error){
  1625. // if (failure) failure(xhr, text, error);
  1626. // });
  1627. // };
  1628. // this.add = function(path, value, success, failure){
  1629. // var p = path.replace(/\./g, "/");
  1630. // action.addDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1631. // if (success) success(json.data);
  1632. // }, function(xhr, text, error){
  1633. // if (failure) failure(xhr, text, error);
  1634. // });
  1635. // };
  1636. // this["delete"] = function(path, success, failure){
  1637. // var p = path.replace(/\./g, "/");
  1638. // action.deleteDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1639. // if (success) success(json.data);
  1640. // }, function(xhr, text, error){
  1641. // if (failure) failure(xhr, text, error);
  1642. // });
  1643. // };
  1644. // this.destory = this["delete"];
  1645. // }
  1646. //};
  1647. if( !MWF.xScript.dictLoaded )MWF.xScript.dictLoaded = {};
  1648. MWF.xScript.addDictToCache = function ( options, path, json ) {
  1649. if( !path )path = "root";
  1650. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1651. var type = options.appType || "process";
  1652. var enableAnonymous = options.enableAnonymous || false;
  1653. var appFlagList = [];
  1654. if( options.application )appFlagList.push( options.application );
  1655. if( options.appId )appFlagList.push( options.appId );
  1656. if( options.appName )appFlagList.push( options.appName );
  1657. if( options.appAlias )appFlagList.push( options.appAlias );
  1658. var dictFlagList = [];
  1659. if( options.id )dictFlagList.push( options.id );
  1660. if( options.name )dictFlagList.push( options.name );
  1661. if( options.alias )dictFlagList.push( options.alias );
  1662. var cache = {};
  1663. cache[path] = json;
  1664. for( var i=0; i<appFlagList.length; i++ ){
  1665. for( var j=0; j<dictFlagList.length; j++ ){
  1666. var k = dictFlagList[j] + type + appFlagList[i] + enableAnonymous;
  1667. if( !MWF.xScript.dictLoaded[k] ){
  1668. MWF.xScript.dictLoaded[k] = cache; //指向同一个对象
  1669. // MWF.xScript.dictLoaded[k][path] = json; //指向不同的对象
  1670. }else if( i===0 && j===0 ){
  1671. MWF.xScript.setDictToCache( k, path ,json );
  1672. var arr = path.split(/\./g);
  1673. var p;
  1674. var cache = MWF.xScript.dictLoaded[k];
  1675. for( var l=0 ; l<arr.length; l++ ){
  1676. p = l === 0 ? arr[0] : ( p + "." + arr[l] );
  1677. if( cache[ p ] )break;
  1678. }
  1679. if( p ){
  1680. var mathP = p+".";
  1681. Object.keys( cache ).each( function( path, idx){
  1682. if( path.indexOf( mathP ) === 0 )delete cache[path];
  1683. })
  1684. }
  1685. }
  1686. }
  1687. }
  1688. };
  1689. MWF.xScript.getMatchedDict = function(key, path){
  1690. if( !path )path = "root";
  1691. if( path.indexOf("root") !== 0 )path = "root." + path ;
  1692. var arr = path.split(/\./g);
  1693. if( MWF.xScript.dictLoaded[key] ){
  1694. var dicts = MWF.xScript.dictLoaded[key];
  1695. var list = Array.clone(arr);
  1696. var p;
  1697. var dict;
  1698. for( var i=0 ; i<arr.length; i++ ){
  1699. p = i === 0 ? arr[0] : ( p + "." + arr[i] );
  1700. list.shift();
  1701. if( dicts[ p ] ){
  1702. dict = dicts[ p ];
  1703. break;
  1704. }
  1705. }
  1706. return {
  1707. dict : dict,
  1708. unmatchedPathList : list
  1709. }
  1710. }
  1711. return {
  1712. dict : null,
  1713. unmatchedPathList : list
  1714. }
  1715. };
  1716. MWF.xScript.insertDictToCache = function(key, path, json){
  1717. if( MWF.xScript.dictLoaded[key] ){
  1718. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1719. var dict = matchedDict.dict;
  1720. var list = matchedDict.unmatchedPathList;
  1721. if( !dict ){
  1722. MWF.xScript.dictLoaded[key][path] = json;
  1723. }else{
  1724. for( var j=0; j<list.length-1; j++ ){
  1725. if( !dict[ list[j] ] ){
  1726. dict[ list[j] ] = {};
  1727. }
  1728. dict = dict[ list[j] ];
  1729. }
  1730. var lastPath = list[list.length-1];
  1731. if( !dict[lastPath] ){
  1732. dict[lastPath] = json;
  1733. }else if( typeOf( dict[lastPath] ) === "array" ){
  1734. dict[lastPath].push( json );
  1735. }
  1736. }
  1737. }else{
  1738. MWF.xScript.dictLoaded[key] = {};
  1739. MWF.xScript.dictLoaded[key][path] = json;
  1740. }
  1741. };
  1742. MWF.xScript.setDictToCache = function(key, path, json){
  1743. if( MWF.xScript.dictLoaded[key] ){
  1744. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1745. var dict = matchedDict.dict;
  1746. var list = matchedDict.unmatchedPathList;
  1747. if( !dict ){
  1748. MWF.xScript.dictLoaded[key][path] = json;
  1749. }else{
  1750. for( var j=0; j<list.length-1; j++ ){
  1751. if( !dict[ list[j] ] ){
  1752. dict[ list[j] ] = {};
  1753. }
  1754. dict = dict[ list[j] ];
  1755. }
  1756. dict[list[list.length-1]] = json;
  1757. }
  1758. }else{
  1759. MWF.xScript.dictLoaded[key] = {};
  1760. MWF.xScript.dictLoaded[key][path] = json;
  1761. }
  1762. };
  1763. MWF.xScript.getDictFromCache = function( key, path ){
  1764. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1765. var dict = matchedDict.dict;
  1766. var list = matchedDict.unmatchedPathList;
  1767. if( dict ){
  1768. for( var j=0; j<list.length; j++ ){
  1769. dict = dict[ list[j] ];
  1770. if( !dict )return null;
  1771. }
  1772. return dict;
  1773. }
  1774. return null;
  1775. };
  1776. MWF.xScript.deleteDictToCache = function(key, path){
  1777. var matchedDict = MWF.xScript.getMatchedDict( key, path );
  1778. var dict = matchedDict.dict;
  1779. var list = matchedDict.unmatchedPathList;
  1780. if( dict){
  1781. for( var j=0; j<list.length-1; j++ ){
  1782. dict = dict[ list[j] ];
  1783. if( !dict )return;
  1784. }
  1785. delete dict[list[list.length-1]];
  1786. }
  1787. };
  1788. MWF.xScript.createCMSDict = function(application){
  1789. //optionsOrName : {
  1790. // type : "", //默认为process, 可以为 process cms
  1791. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1792. // name : "", // 数据字典名称/别名/id
  1793. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1794. //}
  1795. //或者name: "" // 数据字典名称/别名/id
  1796. return function(optionsOrName){
  1797. var options = optionsOrName;
  1798. if( typeOf( options ) == "string" ){
  1799. options = { name : options };
  1800. }
  1801. var name = this.name = options.name;
  1802. var type = ( options.type && options.application ) ? options.type : "cms";
  1803. var applicationId = options.application || application;
  1804. var enableAnonymous = options.enableAnonymous || false;
  1805. var opt = {
  1806. "appType" : type,
  1807. "name" : name,
  1808. "appId" : applicationId,
  1809. "enableAnonymous" : enableAnonymous
  1810. };
  1811. var key = name+type+applicationId+enableAnonymous;
  1812. // if (!dictLoaded[key]) dictLoaded[key] = {};
  1813. // this.dictData = dictLoaded[key];
  1814. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1815. if( type == "cms" ){
  1816. var action = MWF.Actions.get("x_cms_assemble_control");
  1817. }else{
  1818. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1819. }
  1820. var encodePath = function( path ){
  1821. var arr = path.split(/\./g);
  1822. var ar = arr.map(function(v){
  1823. return encodeURIComponent(v);
  1824. });
  1825. return ar.join("/");
  1826. };
  1827. this.get = function(path, success, failure, async, refresh){
  1828. var value = null;
  1829. if (!refresh ){
  1830. var data = MWF.xScript.getDictFromCache( key, path );
  1831. if( data ){
  1832. if (success) success( data );
  1833. return data;
  1834. }
  1835. }
  1836. if (path){
  1837. var p = encodePath( path );
  1838. //var p = path.replace(/\./g, "/");
  1839. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1840. value = json.data;
  1841. // this.dictData[path] = value;
  1842. MWF.xScript.addDictToCache(opt, path, value);
  1843. if (success) success(json.data);
  1844. }.bind(this), function(xhr, text, error){
  1845. if (failure) failure(xhr, text, error);
  1846. }, !!async, false);
  1847. }else{
  1848. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1849. value = json.data;
  1850. // this.dictData["root"] = value;
  1851. MWF.xScript.addDictToCache(opt, path, value);
  1852. if (success) success(json.data);
  1853. }.bind(this), function(xhr, text, error){
  1854. if (failure) failure(xhr, text, error);
  1855. }, !!async);
  1856. }
  1857. return value;
  1858. };
  1859. this.set = function(path, value, success, failure){
  1860. var p = encodePath( path );
  1861. //var p = path.replace(/\./g, "/");
  1862. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1863. MWF.xScript.setDictToCache(key, path, value);
  1864. if (success) success(json.data);
  1865. }, function(xhr, text, error){
  1866. if (failure) failure(xhr, text, error);
  1867. }, false, false);
  1868. };
  1869. this.add = function(path, value, success, failure){
  1870. var p = encodePath( path );
  1871. //var p = path.replace(/\./g, "/");
  1872. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1873. MWF.xScript.insertDictToCache(key, path, value);
  1874. if (success) success(json.data);
  1875. }, function(xhr, text, error){
  1876. if (failure) failure(xhr, text, error);
  1877. }, false, false);
  1878. };
  1879. this["delete"] = function(path, success, failure){
  1880. var p = encodePath( path );
  1881. //var p = path.replace(/\./g, "/");
  1882. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1883. MWF.xScript.deleteDictToCache(key, path);
  1884. if (success) success(json.data);
  1885. }, function(xhr, text, error){
  1886. if (failure) failure(xhr, text, error);
  1887. }, false, false);
  1888. };
  1889. this.destory = this["delete"];
  1890. }
  1891. };
  1892. // var dictLoaded = {};
  1893. // MWF.xScript.createCMSDict = function(application){
  1894. // //optionsOrName : {
  1895. // // type : "", //默认为process, 可以为 process cms
  1896. // // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1897. // // name : "", // 数据字典名称/别名/id
  1898. // // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1899. // //}
  1900. // //或者name: "" // 数据字典名称/别名/id
  1901. // return function(optionsOrName){
  1902. // var options = optionsOrName;
  1903. // if( typeOf( options ) == "string" ){
  1904. // options = { name : options };
  1905. // }
  1906. // var name = this.name = options.name;
  1907. // var type = ( options.type && options.application ) ? options.type : "cms";
  1908. // var applicationId = options.application || application;
  1909. // var enableAnonymous = options.enableAnonymous || false;
  1910. //
  1911. // var key = name+type+applicationId+enableAnonymous
  1912. // if (!dictLoaded[key]) dictLoaded[key] = {};
  1913. // this.dictData = dictLoaded[key];
  1914. //
  1915. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1916. // if( type == "cms" ){
  1917. // var action = MWF.Actions.get("x_cms_assemble_control");
  1918. // }else{
  1919. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1920. // }
  1921. //
  1922. // var encodePath = function( path ){
  1923. // var arr = path.split(/\./g);
  1924. // var ar = arr.map(function(v){
  1925. // return encodeURIComponent(v);
  1926. // });
  1927. // return ar.join("/");
  1928. // };
  1929. //
  1930. // this.get = function(path, success, failure, async, refresh){
  1931. // var value = null;
  1932. // if (path){
  1933. // if ( !refresh && this.dictData[path] ){
  1934. // if (success) success(this.dictData[path]);
  1935. // return this.dictData[path];
  1936. // }
  1937. //
  1938. // var p = encodePath( path );
  1939. // //var p = path.replace(/\./g, "/");
  1940. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1941. // value = json.data;
  1942. // this.dictData[path] = value;
  1943. // if (success) success(json.data);
  1944. // }.bind(this), function(xhr, text, error){
  1945. // if (failure) failure(xhr, text, error);
  1946. // }, !!async, false);
  1947. // }else{
  1948. // if (this.dictData["root"]){
  1949. // if (success) success(this.dictData["root"]);
  1950. // return this.dictData["root"];
  1951. // }
  1952. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, function(json){
  1953. // value = json.data;
  1954. // this.dictData["root"] = value;
  1955. // if (success) success(json.data);
  1956. // }.bind(this), function(xhr, text, error){
  1957. // if (failure) failure(xhr, text, error);
  1958. // }, !!async);
  1959. // }
  1960. //
  1961. // return value;
  1962. // };
  1963. //
  1964. // this.set = function(path, value, success, failure){
  1965. // var p = encodePath( path );
  1966. // //var p = path.replace(/\./g, "/");
  1967. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1968. // if (success) success(json.data);
  1969. // }, function(xhr, text, error){
  1970. // if (failure) failure(xhr, text, error);
  1971. // }, false, false);
  1972. // };
  1973. // this.add = function(path, value, success, failure){
  1974. // var p = encodePath( path );
  1975. // //var p = path.replace(/\./g, "/");
  1976. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1977. // if (success) success(json.data);
  1978. // }, function(xhr, text, error){
  1979. // if (failure) failure(xhr, text, error);
  1980. // }, false, false);
  1981. // };
  1982. // this["delete"] = function(path, success, failure){
  1983. // var p = encodePath( path );
  1984. // //var p = path.replace(/\./g, "/");
  1985. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1986. // if (success) success(json.data);
  1987. // }, function(xhr, text, error){
  1988. // if (failure) failure(xhr, text, error);
  1989. // }, false, false);
  1990. // };
  1991. // this.destory = this["delete"];
  1992. // }
  1993. // };
  1994. // MWF.xScript.createCMSDict = function(application){
  1995. // //optionsOrName : {
  1996. // // type : "", //默认为cms, 可以为 process cms
  1997. // // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1998. // // name : "", // 数据字典名称/别名/id
  1999. // // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  2000. // //}
  2001. // //或者name: "" // 数据字典名称/别名/id
  2002. // return function(optionsOrName){
  2003. // var options = optionsOrName;
  2004. // if( typeOf( options ) == "string" ){
  2005. // options = { name : options };
  2006. // }
  2007. // var name = this.name = options.name;
  2008. // var type = ( options.type && options.application ) ? options.type : "cms";
  2009. // var applicationId = options.application || application;
  2010. // var enableAnonymous = options.enableAnonymous || false;
  2011. //
  2012. // //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  2013. // if( type == "cms" ){
  2014. // var action = MWF.Actions.get("x_cms_assemble_control");
  2015. // }else{
  2016. // var action = MWF.Actions.get("x_processplatform_assemble_surface");
  2017. // }
  2018. //
  2019. // var encodePath = function( path ){
  2020. // var arr = path.split(/\./g);
  2021. // var ar = arr.map(function(v){
  2022. // return encodeURIComponent(v);
  2023. // });
  2024. // return ar.join("/");
  2025. // };
  2026. //
  2027. // this.get = function(path, success, failure){
  2028. // var value = null;
  2029. // if (path){
  2030. // var p = encodePath( path );
  2031. // //var p = path.replace(/\./g, "/");
  2032. // action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  2033. // value = json.data;
  2034. // if (success) success(json.data);
  2035. // }, function(xhr, text, error){
  2036. // if (failure) failure(xhr, text, error);
  2037. // }, false, false);
  2038. // }else{
  2039. // action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](encodeURIComponent(this.name), applicationId, function(json){
  2040. // value = json.data;
  2041. // if (success) success(json.data);
  2042. // }, function(xhr, text, error){
  2043. // if (failure) failure(xhr, text, error);
  2044. // }, false);
  2045. // }
  2046. //
  2047. // return value;
  2048. // };
  2049. //
  2050. // this.set = function(path, value, success, failure){
  2051. // var p = encodePath( path );
  2052. // //var p = path.replace(/\./g, "/");
  2053. // action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2054. // if (success) success(json.data);
  2055. // }, function(xhr, text, error){
  2056. // if (failure) failure(xhr, text, error);
  2057. // }, false, false);
  2058. // };
  2059. // this.add = function(path, value, success, failure){
  2060. // var p = encodePath( path );
  2061. // //var p = path.replace(/\./g, "/");
  2062. // action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  2063. // if (success) success(json.data);
  2064. // }, function(xhr, text, error){
  2065. // if (failure) failure(xhr, text, error);
  2066. // }, false, false);
  2067. // };
  2068. // this["delete"] = function(path, success, failure){
  2069. // var p = encodePath( path );
  2070. // //var p = path.replace(/\./g, "/");
  2071. // action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  2072. // if (success) success(json.data);
  2073. // }, function(xhr, text, error){
  2074. // if (failure) failure(xhr, text, error);
  2075. // }, false, false);
  2076. // };
  2077. // this.destory = this["delete"];
  2078. // }
  2079. // };