CMSEnvironment.js 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596
  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);
  670. }.bind(this));
  671. }.bind(this));
  672. }
  673. }
  674. };
  675. //var lookupAction = null;
  676. //var getLookupAction = function(callback){
  677. // if (!lookupAction){
  678. // MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  679. // lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  680. // lookupAction.getActions = function(actionCallback){
  681. // this.actions = {
  682. // "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  683. // "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  684. // };
  685. // if (actionCallback) actionCallback();
  686. // }
  687. // if (callback) callback();
  688. // }.bind(this));
  689. // }else{
  690. // if (callback) callback();
  691. // }
  692. //};
  693. //
  694. //this.view = {
  695. // "lookup": function(view, callback){
  696. // getLookupAction(function(){
  697. // lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  698. // var data = {
  699. // "grid": json.data.grid,
  700. // "groupGrid": json.data.groupGrid
  701. // };
  702. // if (callback) callback(data);
  703. // }.bind(this)});
  704. // }.bind(this));
  705. // },
  706. // "select": function(view, callback, options){
  707. // if (view.view){
  708. // var viewJson = {
  709. // "application": view.application || "",
  710. // "viewName": view.view || "",
  711. // "isTitle": view.isTitle || "yes",
  712. // "select": view.select || "multi",
  713. // "title": view.title || "Select View"
  714. // };
  715. // if (!options) options = {};
  716. // var width = options.width || "700";
  717. // var height = options.height || "400";
  718. //
  719. // if (layout.mobile){
  720. // var size = document.body.getSize();
  721. // width = size.x;
  722. // height = size.y;
  723. // options.style = "viewmobile";
  724. // }
  725. // width = width.toInt();
  726. // height = height.toInt();
  727. //
  728. // var size = _form.app.content.getSize();
  729. // var x = (size.x-width)/2;
  730. // var y = (size.y-height)/2;
  731. // if (x<0) x = 0;
  732. // if (y<0) y = 0;
  733. // if (layout.mobile){
  734. // x = 20;
  735. // y = 0;
  736. // }
  737. //
  738. // var _self = this;
  739. // MWF.require("MWF.xDesktop.Dialog", function(){
  740. // var dlg = new MWF.xDesktop.Dialog({
  741. // "title": options.title || "select View",
  742. // "style": options.style || "view",
  743. // "top": y,
  744. // "left": x-20,
  745. // "fromTop":y,
  746. // "fromLeft": x-20,
  747. // "width": width,
  748. // "height": height,
  749. // "html": "<div style='height: 100%;'></div>",
  750. // "maskNode": _form.app.content,
  751. // "container": _form.app.content,
  752. // "buttonList": [
  753. // {
  754. // "text": MWF.LP.process.button.ok,
  755. // "action": function(){
  756. // //if (callback) callback(_self.view.selectedItems);
  757. // if (callback) callback(_self.view.getData());
  758. // this.close();
  759. // }
  760. // },
  761. // {
  762. // "text": MWF.LP.process.button.cancel,
  763. // "action": function(){this.close();}
  764. // }
  765. // ]
  766. // });
  767. // dlg.show();
  768. // if (layout.mobile){
  769. // var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  770. // var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  771. // if (backAction) backAction.addEvent("click", function(e){
  772. // dlg.close();
  773. // }.bind(this));
  774. // if (okAction) okAction.addEvent("click", function(e){
  775. // //if (callback) callback(this.view.selectedItems);
  776. // if (callback) callback(this.view.getData());
  777. // dlg.close();
  778. // }.bind(this));
  779. // }
  780. //
  781. // // MWF.xDesktop.requireApp("cms.Xform", "widget.View", function(){
  782. // // this.view = new MWF.xApplication.cms.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  783. // // }.bind(this));
  784. // MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  785. // this.view = new MWF.xApplication.query.Query.Viewer(dlg.content.getFirst(), viewJson, {"style": "select"});
  786. // }.bind(this));
  787. // }.bind(this));
  788. // }
  789. // }
  790. //};
  791. //include 引用脚本
  792. //optionsOrName : {
  793. // type : "", 默认为cms, 可以为 portal process cms
  794. // application : "", 门户/流程/CMS的名称/别名/id, 默认为当前应用
  795. // name : "" // 脚本名称/别名/id
  796. //}
  797. //或者name: "" // 脚本名称/别名/id
  798. // if( !window.includedScripts ){
  799. // var includedScripts = window.includedScripts = [];
  800. // }else{
  801. // var includedScripts = window.includedScripts;
  802. // }
  803. var includedScripts = [];
  804. this.include = function( optionsOrName , callback ){
  805. var options = optionsOrName;
  806. if( typeOf( options ) == "string" ){
  807. options = { name : options };
  808. }
  809. var name = options.name;
  810. var type = ( options.type && options.application ) ? options.type : "cms";
  811. var application = options.application || _form.json.application;
  812. var key = type +"-" + application + "-" + name;
  813. if (includedScripts.indexOf( key )> -1){
  814. if (callback) callback.apply(this);
  815. return;
  816. }
  817. //if (includedScripts.indexOf( name )> -1){
  818. // if (callback) callback.apply(this);
  819. // return;
  820. //}
  821. var scriptAction;
  822. switch ( type ){
  823. case "portal" :
  824. if( this.scriptActionPortal ){
  825. scriptAction = this.scriptActionPortal;
  826. }else{
  827. MWF.require("MWF.xScript.Actions.PortalScriptActions", null, false);
  828. scriptAction = this.scriptActionPortal = new MWF.xScript.Actions.PortalScriptActions();
  829. }
  830. break;
  831. case "process" :
  832. if( this.scriptActionProcess ){
  833. scriptAction = this.scriptActionProcess;
  834. }else{
  835. MWF.require("MWF.xScript.Actions.ScriptActions", null, false);
  836. scriptAction = this.scriptActionProcess = new MWF.xScript.Actions.ScriptActions();
  837. }
  838. break;
  839. case "cms" :
  840. if( this.scriptActionCMS ){
  841. scriptAction = this.scriptActionCMS;
  842. }else{
  843. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  844. scriptAction = this.scriptActionCMS = new MWF.xScript.Actions.CMSScriptActions();
  845. }
  846. break;
  847. }
  848. scriptAction.getScriptByName( application, name, includedScripts, function(json){
  849. if (json.data){
  850. includedScripts.push( key );
  851. includedScripts = includedScripts.concat(json.data.importedList);
  852. MWF.Macro.exec(json.data.text, this);
  853. if (callback) callback.apply(this);
  854. }else{
  855. if (callback) callback.apply(this);
  856. }
  857. }.bind(this), null, false);
  858. };
  859. //var includedScripts = [];
  860. //this.include = function(name, callback){
  861. // if (includedScripts.indexOf(name)==-1){
  862. // if (!this.scriptAction){
  863. // MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  864. // this.scriptAction = new MWF.xScript.Actions.CMSScriptActions();
  865. // }
  866. // this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
  867. // includedScripts = includedScripts.concat(json.data.importedList);
  868. // MWF.Macro.exec(json.data.text, this);
  869. // if (callback) callback.apply(this);
  870. // }.bind(this), null, false);
  871. // }else{
  872. // if (callback) callback.apply(this);
  873. // }
  874. //}.bind(this);
  875. this.define = function(name, fun, overwrite){
  876. var over = true;
  877. if (overwrite===false) over = false;
  878. var o = {};
  879. o[name] = {"value": fun, "configurable": over};
  880. MWF.defineProperties(this, o);
  881. }.bind(this);
  882. //仅前台对象-----------------------------------------
  883. //form
  884. this.form = {
  885. "getInfor": function(){return ev.formInfor;},
  886. "infor": ev.formInfor,
  887. "getApp": function(){return _form.app;},
  888. "app": _form.app,
  889. "node": function(){return _form.node;},
  890. "readonly": _form.options.readonly,
  891. "get": function(name){return (_form.all) ? _form.all[name] : null;},
  892. "getField": function(name){return _forms[name];},
  893. "getAction": function(){return _form.documentAction},
  894. "getData": function(){return new MWF.xScript.CMSJSONData(_form.getData());},
  895. "save": function(callback){
  896. _form.saveDocument(callback);
  897. },
  898. "close": function(){_form.closeDocument();},
  899. "publish": function(option){
  900. _form.publishDocument()
  901. },
  902. //"archive": function(option){
  903. // _form.archiveDocument()
  904. //},
  905. //"redraft": function(option){
  906. // _form.redraftDocument()
  907. //},
  908. "confirm": function(type, title, text, width, height, ok, cancel, callback, mask, style){
  909. // var p = MWF.getCenter({"x": width, "y": height});
  910. // e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  911. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  912. if ((arguments.length<=1) || o2.typeOf(arguments[1])==="string"){
  913. var p = MWF.getCenter({"x": width, "y": height});
  914. e = {"event": {"clientX": p.x,"x": p.x,"clientY": p.y,"y": p.y}};
  915. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  916. }else{
  917. e = (arguments.length>1) ? arguments[1] : null;
  918. title = (arguments.length>2) ? arguments[2] : null;
  919. text = (arguments.length>3) ? arguments[3] : null;
  920. width = (arguments.length>4) ? arguments[4] : null;
  921. height = (arguments.length>5) ? arguments[5] : null;
  922. ok = (arguments.length>6) ? arguments[6] : null;
  923. cancel = (arguments.length>7) ? arguments[7] : null;
  924. callback = (arguments.length>8) ? arguments[8] : null;
  925. mask = (arguments.length>9) ? arguments[9] : null;
  926. style = (arguments.length>10) ? arguments[10] : null;
  927. _form.confirm(type, e, title, text, width, height, ok, cancel, callback, mask, style);
  928. }
  929. },
  930. //"confirm": function(type, e, title, text, width, height, ok, cancel, callback){
  931. // _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  932. //},
  933. "notice": function(content, type, target, where, offset, option){
  934. _form.notice(content, type, target, where, offset, option);
  935. },
  936. "addEvent": function(e, f){_form.addEvent(e, f);},
  937. "openWork": function(id, completedId, title, options){
  938. var op = options || {};
  939. op.workId = id;
  940. op.workCompletedId = completedId;
  941. op.docTitle = title;
  942. op.appId = "process.Work"+(op.workId || op.workCompletedId);
  943. return layout.desktop.openApplication(this.event, "process.Work", op);
  944. },
  945. "openJob": function(id, choice, options){
  946. var workData = null;
  947. o2.Actions.get("x_processplatform_assemble_surface").listWorkByJob(id, function(json){
  948. if (json.data) workData = json.data;
  949. }.bind(this), null, false);
  950. if (workData){
  951. var len = workData.workList.length + workData.workCompletedList.length;
  952. if (len){
  953. if (len>1 && choice){
  954. var node = new Element("div", {"styles": {"padding": "20px", "width": "500px"}}).inject(_form.node);
  955. workData.workList.each(function(work){
  956. var workNode = new Element("div", {
  957. "styles": {
  958. "background": "#ffffff",
  959. "border-radius": "10px",
  960. "clear": "both",
  961. "margin-bottom": "10px",
  962. "height": "40px",
  963. "padding": "10px 10px"
  964. }
  965. }).inject(node);
  966. 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>" +
  967. "<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>"+
  968. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  969. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+work.activityName+"</div>" +
  970. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.activityArrivedTime+"</div>" +
  971. "<div style='color:#999999; float: left; margin-right: 10px'>"+(work.manualTaskIdentityText || "")+"</div></div>";
  972. workNode.set("html", html);
  973. var action = workNode.getElement(".MWFAction");
  974. action.store("work", work);
  975. action.addEvent("click", function(e){
  976. var work = e.target.retrieve("work");
  977. if (work) this.openWork(work.id, null, work.title, options);
  978. dlg.close();
  979. }.bind(this));
  980. }.bind(this));
  981. workData.workCompletedList.each(function(work){
  982. var workNode = new Element("div", {
  983. "styles": {
  984. "background": "#ffffff",
  985. "border-radius": "10px",
  986. "clear": "both",
  987. "margin-bottom": "10px",
  988. "height": "40px",
  989. "padding": "10px 10px"
  990. }
  991. }).inject(node);
  992. 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>" +
  993. "<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>"+
  994. "<div style='height: 20px; line-height: 20px; margin: 0px 40px'>"+work.title+"</div>" +
  995. "<div style='margin: 0px 40px'><div style='color:#999999; float: left; margin-right: 10px'>"+o2.LP.widget.workcompleted+"</div>" +
  996. "<div style='color:#999999; float: left; margin-right: 10px'>"+work.completedTime+"</div>";
  997. workNode.set("html", html);
  998. var action = workNode.getElement(".MWFAction");
  999. action.store("work", work);
  1000. action.addEvent("click", function(e){
  1001. var work = e.target.retrieve("work");
  1002. if (work) this.openWork(null, work.id, work.title, options);
  1003. dlg.close();
  1004. }.bind(this));
  1005. }.bind(this));
  1006. var height = node.getSize().y+20;
  1007. if (height>600) height = 600;
  1008. var dlg = o2.DL.open({
  1009. "title": o2.LP.widget.choiceWork,
  1010. "style" : "user",
  1011. "isResize": false,
  1012. "content": node,
  1013. "buttonList": [
  1014. {
  1015. "type" : "cancel",
  1016. "text": o2.LP.widget.close,
  1017. "action": function(){dlg.close();}
  1018. }
  1019. ]
  1020. });
  1021. }else{
  1022. if (workData.workList.length){
  1023. var work = workData.workList[0];
  1024. return this.openWork(work.id, null, work.title, options);
  1025. }else{
  1026. var work = workData.workCompletedList[0];
  1027. return this.openWork(null, work.id, work.title, options);
  1028. }
  1029. }
  1030. }
  1031. }
  1032. },
  1033. "openDocument": function(id, title, options){
  1034. var op = options || {};
  1035. op.documentId = id;
  1036. op.docTitle = title;
  1037. layout.desktop.openApplication(this.event, "cms.Document", op);
  1038. },
  1039. "openPortal": function(name, page, par){
  1040. var action = MWF.Actions.get("x_portal_assemble_surface");
  1041. action.getApplication(name, function(json){
  1042. if (json.data){
  1043. if (page){
  1044. action.getPageByName(page, json.data.id, function(pageJson){
  1045. layout.desktop.openApplication(null, "portal.Portal", {
  1046. "portalId": json.data.id,
  1047. "pageId": (pageJson.data) ? pageJson.data.id : "",
  1048. "parameters": par,
  1049. "appId": "portal.Portal"+json.data.id
  1050. })
  1051. });
  1052. }else{
  1053. layout.desktop.openApplication(null, "portal.Portal", {
  1054. "portalId": json.data.id,
  1055. "parameters": par,
  1056. "appId": "portal.Portal"+json.data.id
  1057. })
  1058. }
  1059. }
  1060. });
  1061. },
  1062. "openCMS": function(name){
  1063. var action = MWF.Actions.get("x_cms_assemble_control");
  1064. action.getColumn(name, function(json){
  1065. if (json.data){
  1066. layout.desktop.openApplication(null, "cms.Module", {
  1067. "columnId": json.data.id,
  1068. "appId": "cms.Module"+json.data.id
  1069. });
  1070. }
  1071. });
  1072. },
  1073. "openProcess": function(name){
  1074. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1075. action.getApplication(name, function(json){
  1076. if (json.data){
  1077. layout.desktop.openApplication(null, "process.Application", {
  1078. "id": json.data.id,
  1079. "appId": "process.Application"+json.data.id
  1080. });
  1081. }
  1082. });
  1083. },
  1084. "openApplication":function(name, options){
  1085. layout.desktop.openApplication(null, name, options);
  1086. },
  1087. "createDocument" : function(columnOrOptions, category, data, identity, callback, target, latest, selectColumnEnable, ignoreTitle){
  1088. var column = columnOrOptions;
  1089. if( typeOf( columnOrOptions ) == "object" ){
  1090. column = columnOrOptions.column;
  1091. category = columnOrOptions.category;
  1092. data = columnOrOptions.data;
  1093. identity = columnOrOptions.identity;
  1094. callback = columnOrOptions.callback;
  1095. target = columnOrOptions.target;
  1096. latest = columnOrOptions.latest;
  1097. selectColumnEnable = columnOrOptions.selectColumnEnable;
  1098. ignoreTitle = columnOrOptions.ignoreTitle;
  1099. }
  1100. if (target){
  1101. if (layout.app && layout.app.inBrowser){
  1102. layout.app.content.empty();
  1103. layout.app = null;
  1104. }
  1105. }
  1106. MWF.xDesktop.requireApp("cms.Index", "Newer", function(){
  1107. var starter = new MWF.xApplication.cms.Index.Newer(null, null, _form.app, null, {
  1108. "documentData": data,
  1109. "identity": identity,
  1110. "ignoreTitle" : ignoreTitle === true,
  1111. "ignoreDrafted" : latest === false,
  1112. "selectColumnEnable" : !category || selectColumnEnable === true,
  1113. "restrictToColumn" : !!category && selectColumnEnable !== true,
  1114. "categoryFlag" : category, //category id or name
  1115. "columnFlag" : column, //column id or name,
  1116. "onStarted" : function( documentId, data ){
  1117. if(callback)callback();
  1118. },
  1119. "onPostLoad" : function(){
  1120. },
  1121. "onPostPublish" : function(){
  1122. }
  1123. });
  1124. starter.load();
  1125. })
  1126. },
  1127. "startProcess": function(app, process, data, identity, callback, target, latest){
  1128. if (arguments.length>2){
  1129. for (var i=2; i<arguments.length; i++){
  1130. if (typeOf(arguments[i])=="boolean"){
  1131. target = arguments[i];
  1132. break;
  1133. }
  1134. }
  1135. }
  1136. if (target){
  1137. if (layout.app && layout.app.inBrowser){
  1138. //layout.app.content.empty();
  1139. layout.app.$openWithSelf = true;
  1140. }
  1141. }
  1142. var action = MWF.Actions.get("x_processplatform_assemble_surface").getProcessByName(process, app, function(json){
  1143. if (json.data){
  1144. MWF.xDesktop.requireApp("process.TaskCenter", "ProcessStarter", function(){
  1145. var starter = new MWF.xApplication.process.TaskCenter.ProcessStarter(json.data, _form.app, {
  1146. "workData": data,
  1147. "identity": identity,
  1148. "latest": latest,
  1149. "onStarted": function(data, title, processName){
  1150. var currentTask = [];
  1151. data.each(function(work){
  1152. if (work.currentTaskIndex != -1) currentTask.push(work.taskList[work.currentTaskIndex].work);
  1153. }.bind(this));
  1154. if (currentTask.length==1){
  1155. var options = {"workId": currentTask[0], "appId": currentTask[0]};
  1156. layout.desktop.openApplication(null, "process.Work", options);
  1157. }else{}
  1158. if (callback) callback(data);
  1159. }.bind(this)
  1160. });
  1161. starter.load();
  1162. }.bind(this));
  1163. }
  1164. });
  1165. }
  1166. };
  1167. this.target = ev.target;
  1168. this.event = ev.event;
  1169. this.status = ev.status;
  1170. this.session = layout.desktop.session;
  1171. this.Actions = o2.Actions;
  1172. this.query = function(option){
  1173. // options = {
  1174. // "name": "statementName",
  1175. // "data": "json data",
  1176. // "firstResult": 1,
  1177. // "maxResults": 100,
  1178. // "success": function(){},
  1179. // "error": function(){},
  1180. // "async": true or false, default is true
  1181. // }
  1182. if (option){
  1183. var json = (option.data) || {};
  1184. if (option.firstResult) json.firstResult = option.firstResult.toInt();
  1185. if (option.maxResults) json.maxResults = option.maxResults.toInt();
  1186. o2.Actions.get("x_query_assemble_surface").executeStatement(option.name, json, success, error, options.async);
  1187. }
  1188. };
  1189. this.Table = MWF.xScript.createTable();
  1190. };
  1191. MWF.xScript.createTable = function(){
  1192. return function(name){
  1193. this.name = name;
  1194. this.action = o2.Actions.get("x_query_assemble_surface");
  1195. this.listRowNext = function(id, count, success, error, async){
  1196. this.action.listRowNext(this.name, id, count, success, error, async);
  1197. };
  1198. this.listRowPrev = function(id, count, success, error, async){
  1199. this.action.listRowPrev(this.name, id, count, success, error, async);
  1200. };
  1201. this.listRowPrev = function(id, count, success, error, async){
  1202. this.action.listRowPrev(this.name, id, count, success, error, async);
  1203. };
  1204. this.listRowSelectWhere = function(where, success, error, async){
  1205. this.action.listRowSelectWhere(this.name, where, success, error, async);
  1206. };
  1207. this.listRowCountWhere = function(where, success, error, async){
  1208. this.action.listRowCountWhere(this.name, where, success, error, async);
  1209. };
  1210. this.deleteRow = function(id, success, error, async){
  1211. this.action.deleteRow(this.name, id, success, error, async);
  1212. };
  1213. this.deleteAllRow = function(success, error, async){
  1214. this.action.deleteAllRow(this.name, success, error, async);
  1215. };
  1216. this.getRow = function(id, success, error, async){
  1217. this.action.getRow(this.name, id, success, error, async);
  1218. };
  1219. this.insertRow = function(data, success, error, async){
  1220. this.action.insertRow(this.name, data, success, error, async);
  1221. };
  1222. this.updateRow = function(id, data, success, error, async){
  1223. this.action.updateRow(this.name, id, data, success, error, async);
  1224. };
  1225. }
  1226. };
  1227. MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1228. var getter = function(data, callback, k, _self){
  1229. return function(){return (["array","object"].indexOf(typeOf(data[k]))===-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1230. };
  1231. var setter = function(data, callback, k, _self){
  1232. return function(v){
  1233. data[k] = v;
  1234. //debugger;
  1235. //this.add(k, v, true);
  1236. if (callback) callback(data, k, _self);
  1237. }
  1238. };
  1239. var define = function(){
  1240. var o = {};
  1241. 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])};
  1242. o["length"] = {"get": function(){return Object.keys(data).length;}};
  1243. MWF.defineProperties(this, o);
  1244. var methods = {
  1245. "getKey": {"value": function(){ return key; }},
  1246. "getParent": {"value": function(){ return parent; }},
  1247. "toString": {"value": function() { return data.toString();}},
  1248. "add": {"value": function(newKey, newValue, overwrite){
  1249. var flag = true;
  1250. var type = typeOf(data);
  1251. if (type==="array"){
  1252. if (arguments.length<2){
  1253. data.push(newKey);
  1254. newValue = newKey;
  1255. newKey = data.length-1;
  1256. }else{
  1257. if (!newKey && newKey!==0){
  1258. data.push(newValue);
  1259. newKey = data.length-1;
  1260. }else{
  1261. flag = false;
  1262. }
  1263. }
  1264. if (flag){
  1265. var o = {};
  1266. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1267. MWF.defineProperties(this, o);
  1268. }
  1269. this[newKey] = newValue;
  1270. }else if (type==="object"){
  1271. if (!this.hasOwnProperty(newKey)){
  1272. data[newKey] = newValue;
  1273. if (flag){
  1274. var o = {};
  1275. o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1276. MWF.defineProperties(this, o);
  1277. }
  1278. this[newKey] = newValue;
  1279. }else{
  1280. if (overwrite) this[newKey] = newValue;
  1281. }
  1282. }
  1283. return this[newKey];
  1284. }},
  1285. "del": {"value": function(delKey){
  1286. if (!this.hasOwnProperty(delKey)) return null;
  1287. delete data[delKey];
  1288. delete this[delKey];
  1289. return this;
  1290. }}
  1291. };
  1292. MWF.defineProperties(this, methods);
  1293. //this.getKey = function(){ return key; };
  1294. //this.getParent = function(){ return parent; };
  1295. //this.toString = function() { return data.toString();};
  1296. //this.add = function(newKey, newValue, overwrite){
  1297. // var flag = true;
  1298. // var type = typeOf(data);
  1299. // if (!this.hasOwnProperty(newKey)){
  1300. // if (type=="array"){
  1301. // if (arguments.length<2){
  1302. // data.push(newKey);
  1303. // newValue = newKey;
  1304. // newKey = data.length-1;
  1305. // }else{
  1306. // debugger;
  1307. // if (!newKey && newKey!=0){
  1308. // data.push(newValue);
  1309. // newKey = data.length-1;
  1310. // }else{
  1311. // flag == false;
  1312. // }
  1313. // }
  1314. // }else{
  1315. // data[newKey] = newValue;
  1316. // }
  1317. // //var valueType = typeOf(newValue);
  1318. // //var newValueData = newValue;
  1319. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1320. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1321. // if (flag){
  1322. // var o = {};
  1323. // o[newKey] = {"configurable": true, "enumerable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1324. // MWF.defineProperties(this, o);
  1325. // }
  1326. // this[newKey] = newValue;
  1327. // }else{
  1328. // if (overwrite) this[newKey] = newValue;
  1329. // }
  1330. //
  1331. // //var valueType = typeOf(newValue);
  1332. // //var newValueData = newValue;
  1333. // //if (valueType=="object" || valueType=="array") newValueData = new MWF.xScript.JSONData(newValue, callback, newKey, this);
  1334. // //if (valueType=="null") newValueData = new MWF.xScript.JSONData({}, callback, newKey, this);
  1335. // //
  1336. // //this[newKey] = newValueData;
  1337. //
  1338. // return this[newKey];
  1339. //};
  1340. //this.del = function(delKey){
  1341. // if (!this.hasOwnProperty(delKey)) return null;
  1342. // delete data[newKey];
  1343. // delete this[newKey];
  1344. // return this;
  1345. //};
  1346. };
  1347. var type = typeOf(data);
  1348. if (type==="object" || type==="array") define.apply(this);
  1349. };
  1350. //MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  1351. // var getter = function(data, callback, k, _self){
  1352. // return function(){return (["array","object"].indexOf(typeOf(data[k]))==-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  1353. // }
  1354. // var setter = function(data, callback, k, _self){
  1355. // return function(v){
  1356. // data[k] = v;
  1357. // if (callback) callback(data, k, _self);
  1358. // }
  1359. // }
  1360. // var define = function(){
  1361. // var o = {};
  1362. // for (var k in data) o[k] = {
  1363. // "configurable": true,
  1364. // "get": getter.apply(this, [data, callback, k, this]),
  1365. // "set": setter.apply(this, [data, callback, k, this])
  1366. // };
  1367. // o["length"] = {"get": function(){return Object.keys(data).length;}};
  1368. // MWF.defineProperties(this, o);
  1369. // this.getKey = function(){ return key; };
  1370. // this.getParent = function(){ return parent; };
  1371. // this.toString = function() { return data.toString();};
  1372. // this.add = function(newKey, newValue){
  1373. // var type = typeOf(data);
  1374. // if (!this.hasOwnProperty(newKey)){
  1375. // if (type=="array"){
  1376. // data.push(newValue || {});
  1377. // newKey = data.length-1;
  1378. // }else{
  1379. // data[newKey] = newValue || {};
  1380. // }
  1381. // var o = {};
  1382. // o[newKey] = {"configurable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  1383. // MWF.defineProperties(this, o);
  1384. // }
  1385. // this[newKey] = newValue;
  1386. // return this;
  1387. // };
  1388. // this.del = function(delKey){
  1389. // if (!this.hasOwnProperty(delKey)) return null;
  1390. // delete data[newKey];
  1391. // delete this[newKey];
  1392. // return this;
  1393. // };
  1394. // }
  1395. // var type = typeOf(data);
  1396. // if (type=="object" || type=="array") define.apply(this);
  1397. //};
  1398. //MWF.xScript.createCMSDict = function(application){
  1399. // return function(name){
  1400. // var applicationId = application;
  1401. // this.name = name;
  1402. // MWF.require("MWF.xScript.Actions.CMSDictActions", null, false);
  1403. // var action = new MWF.xScript.Actions.CMSDictActions();
  1404. //
  1405. // this.get = function(path, success, failure){
  1406. // var value = null;
  1407. // if( path ){
  1408. // var arr = path.split(/\./g);
  1409. // var ar = arr.map(function(v){
  1410. // return encodeURIComponent(v);
  1411. // });
  1412. // //var p = path.replace(/\./g, "/");
  1413. // var p = ar.join("/");
  1414. // action.getDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1415. // value = json.data;
  1416. // if (success) success(json.data);
  1417. // }, function(xhr, text, error){
  1418. // if (failure) failure(xhr, text, error);
  1419. // }, false);
  1420. // }else{
  1421. // action.getDictWhole(applicationId, encodeURIComponent(this.name), function(json){
  1422. // value = json.data;
  1423. // if (success) success(json.data);
  1424. // }, function(xhr, text, error){
  1425. // if (failure) failure(xhr, text, error);
  1426. // }, false);
  1427. // }
  1428. // return value;
  1429. // };
  1430. //
  1431. // this.set = function(path, value, success, failure){
  1432. // var p = path.replace(/\./g, "/");
  1433. // action.setDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1434. // if (success) success(json.data);
  1435. // }, function(xhr, text, error){
  1436. // if (failure) failure(xhr, text, error);
  1437. // });
  1438. // };
  1439. // this.add = function(path, value, success, failure){
  1440. // var p = path.replace(/\./g, "/");
  1441. // action.addDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  1442. // if (success) success(json.data);
  1443. // }, function(xhr, text, error){
  1444. // if (failure) failure(xhr, text, error);
  1445. // });
  1446. // };
  1447. // this["delete"] = function(path, success, failure){
  1448. // var p = path.replace(/\./g, "/");
  1449. // action.deleteDict(applicationId, encodeURIComponent(this.name), p, function(json){
  1450. // if (success) success(json.data);
  1451. // }, function(xhr, text, error){
  1452. // if (failure) failure(xhr, text, error);
  1453. // });
  1454. // };
  1455. // this.destory = this["delete"];
  1456. // }
  1457. //};
  1458. MWF.xScript.createCMSDict = function(application){
  1459. //optionsOrName : {
  1460. // type : "", //默认为cms, 可以为 process cms
  1461. // application : "", //流程/CMS的名称/别名/id, 默认为当前应用
  1462. // name : "", // 数据字典名称/别名/id
  1463. // enableAnonymous : false //允许在未登录的情况下读取CMS的数据字典
  1464. //}
  1465. //或者name: "" // 数据字典名称/别名/id
  1466. return function(optionsOrName){
  1467. var options = optionsOrName;
  1468. if( typeOf( options ) == "string" ){
  1469. options = { name : options };
  1470. }
  1471. var name = this.name = options.name;
  1472. var type = ( options.type && options.application ) ? options.type : "cms";
  1473. var applicationId = options.application || application;
  1474. var enableAnonymous = options.enableAnonymous || false;
  1475. //MWF.require("MWF.xScript.Actions.DictActions", null, false);
  1476. if( type == "cms" ){
  1477. var action = MWF.Actions.get("x_cms_assemble_control");
  1478. }else{
  1479. var action = MWF.Actions.get("x_processplatform_assemble_surface");
  1480. }
  1481. var encodePath = function( path ){
  1482. var arr = path.split(/\./g);
  1483. var ar = arr.map(function(v){
  1484. return encodeURIComponent(v);
  1485. });
  1486. return ar.join("/");
  1487. };
  1488. this.get = function(path, success, failure){
  1489. var value = null;
  1490. if (path){
  1491. var p = encodePath( path );
  1492. //var p = path.replace(/\./g, "/");
  1493. action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, function(json){
  1494. value = json.data;
  1495. if (success) success(json.data);
  1496. }, function(xhr, text, error){
  1497. if (failure) failure(xhr, text, error);
  1498. }, false, false);
  1499. }else{
  1500. action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](encodeURIComponent(this.name), applicationId, function(json){
  1501. value = json.data;
  1502. if (success) success(json.data);
  1503. }, function(xhr, text, error){
  1504. if (failure) failure(xhr, text, error);
  1505. }, false);
  1506. }
  1507. return value;
  1508. };
  1509. this.set = function(path, value, success, failure){
  1510. var p = encodePath( path );
  1511. //var p = path.replace(/\./g, "/");
  1512. action.setDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1513. if (success) success(json.data);
  1514. }, function(xhr, text, error){
  1515. if (failure) failure(xhr, text, error);
  1516. }, false, false);
  1517. };
  1518. this.add = function(path, value, success, failure){
  1519. var p = encodePath( path );
  1520. //var p = path.replace(/\./g, "/");
  1521. action.addDictData(encodeURIComponent(this.name), applicationId, p, value, function(json){
  1522. if (success) success(json.data);
  1523. }, function(xhr, text, error){
  1524. if (failure) failure(xhr, text, error);
  1525. }, false, false);
  1526. };
  1527. this["delete"] = function(path, success, failure){
  1528. var p = encodePath( path );
  1529. //var p = path.replace(/\./g, "/");
  1530. action.deleteDictData(encodeURIComponent(this.name), applicationId, p, function(json){
  1531. if (success) success(json.data);
  1532. }, function(xhr, text, error){
  1533. if (failure) failure(xhr, text, error);
  1534. }, false, false);
  1535. };
  1536. this.destory = this["delete"];
  1537. }
  1538. };