CMSEnvironment.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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, document.id, jData);
  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.require("MWF.xScript.Actions.OrgActions", null, false);
  50. orgActions = new MWF.xScript.Actions.OrgActions();
  51. }
  52. };
  53. this.org = {
  54. //options = {
  55. // "name": "职务名称",
  56. // "departmentName": "部门名称",
  57. // "identityName": "身份名称",
  58. // "level": "1",
  59. //
  60. //}
  61. //获取部门指定职务
  62. "getDepartmentDuty": function(options){
  63. getOrgActions();
  64. var v;
  65. orgActions.getDepartmentDutyBydepartmentName(options.name, options.departmentName, function(json){
  66. if (json.data) v = json.data.identityList;
  67. }, null, false);
  68. return v;
  69. },
  70. //"getPersonInfo": function(options){
  71. // getOrgActions();
  72. // var v,p;
  73. // orgActions.getPersonInfo(options.name, function(json){
  74. // if (json.data){
  75. // v = json.data;
  76. // p = v[options.attribute];
  77. // }
  78. // }, null, false);
  79. // return p;
  80. //},
  81. //获取个人基本信息
  82. "getPersonInfo": function(options){
  83. getOrgActions();
  84. var v,p;
  85. orgActions.getPersonInfo(options.name, function(json){
  86. if (json.data){
  87. v = json.data;
  88. p = v[options.attribute];
  89. }
  90. }, null, false);
  91. return p;
  92. },
  93. //获取个人属性
  94. "getPersonAttribute": function(options){
  95. getOrgActions();
  96. var v;
  97. orgActions.getPersonAttribute(options.name, options.personName, function(json){
  98. if (json.data) v = json.data.attributeList;
  99. }, null, false);
  100. return v;
  101. },
  102. //根据个人身份获取部门
  103. "getDepartmentByIdentity": function(options){
  104. getOrgActions();
  105. var v;
  106. orgActions.getDepartmentByIdentity(options.personIdentity, function(json){
  107. v = json.data.name;
  108. }, null, false);
  109. return v;
  110. },
  111. //修改当前人的属性
  112. "updatePersonAttribute": function(options){
  113. getOrgActions();
  114. var attributeList = {"attributeList":options.attributeList};
  115. orgActions.updatePersonAttribute(options.name, attributeList, function(json){
  116. if (success) success(json.data);
  117. }, function(xhr, text, error){
  118. if (failure) failure(xhr, text, error);
  119. }, false);
  120. },
  121. //修改他人属性
  122. "setPersonAttribute": function(options){
  123. getOrgActions();
  124. var attributeList = {"attributeList":options.attributeList};
  125. orgActions.setPersonAttribute(options.name, options.personName, attributeList, function(json){
  126. if (success) success(json.data);
  127. }, function(xhr, text, error){
  128. if (failure) failure(xhr, text, error);
  129. }, false);
  130. },
  131. //获取指定部门的所有上级部门
  132. "listSupDepartmentNested": function(options){
  133. getOrgActions();
  134. var v;
  135. orgActions.listSupDepartmentNested(options.departmentName, function(json){
  136. v = json.data;
  137. }, null, false);
  138. return v;
  139. },
  140. //获取个人所有属性(返回json对象数组)
  141. "listPersonAttribute": function(options){
  142. getOrgActions();
  143. var v;
  144. orgActions.listPersonAttribute(options.personName, function(json){
  145. v = json.data;
  146. }, null, false);
  147. return v;
  148. },
  149. //获取公司(多个)根据人名,返回列表
  150. "listCompanyByPerson": function(options){
  151. getOrgActions();
  152. var v;
  153. orgActions.listCompanyByPerson(options.personName, function(json){
  154. debugger;
  155. v = json.data;
  156. }, null, false);
  157. return v;
  158. },
  159. //获取公司根据身份
  160. "getCompanyByIdentity": function(options){
  161. getOrgActions();
  162. var v;
  163. orgActions.getCompanyByIdentity(options.personIdentity, function(json){
  164. v = json.data.name;
  165. }, null, false);
  166. return v;
  167. },
  168. //列出公司所有属性
  169. "listCompanyAttribute": function(options){
  170. getOrgActions();
  171. var v;
  172. orgActions.listCompanyAttribute(options.compName, function(json){
  173. v = json.data;
  174. }, null, false);
  175. return v;
  176. },
  177. //获取公司指定属性
  178. "getCompanyAttribute": function(options){
  179. getOrgActions();
  180. var v;
  181. orgActions.getCompanyAttribute(options.name, options.compName, function(json){
  182. if (json.data) v = json.data.attributeList;
  183. }, null, false);
  184. return v;
  185. },
  186. //列出公司所有职务
  187. "listCompanyDuty": function(options){
  188. getOrgActions();
  189. var v;
  190. orgActions.listCompanyDuty(options.compName, function(json){
  191. v = json.data;
  192. }, null, false);
  193. return v;
  194. },
  195. //获取公司指定职务
  196. "getCompanyDuty": function(options){
  197. getOrgActions();
  198. var v;
  199. orgActions.getCompanyDuty(options.name, options.compName, function(json){
  200. if (json.data) v = json.data.identityList;
  201. }, null, false);
  202. return v;
  203. },
  204. //列出部门所有属性
  205. "listDepartmentAttribute": function(options){
  206. getOrgActions();
  207. var v;
  208. orgActions.listDepartmentAttribute(options.deptName, function(json){
  209. v = json.data;
  210. }, null, false);
  211. return v;
  212. },
  213. //获取部门指定属性
  214. "getDepartmentAttribute": function(options){
  215. getOrgActions();
  216. var v;
  217. orgActions.getDepartmentAttribute(options.name, options.deptName, function(json){
  218. if (json.data) v = json.data.attributeList;
  219. }, null, false);
  220. return v;
  221. },
  222. //列出部门所有职务
  223. "listDepartmentDuty": function(options){
  224. getOrgActions();
  225. var v;
  226. orgActions.listDepartmentDuty(options.deptName, function(json){
  227. v = json.data;
  228. }, null, false);
  229. return v;
  230. },
  231. //获取部门指定职务
  232. //"getDepartmentDuty": function(options){
  233. // getOrgActions();
  234. // var v;
  235. // orgActions.getDepartmentDuty(options.name, options.deptName, function(json){
  236. // if (json.data) v = json.data.identityList;
  237. // }, null, false);
  238. // return v;
  239. //},
  240. //列出指定部门下的所有身份(直接成员)
  241. "listIdentity": function(options){
  242. getOrgActions();
  243. var v;
  244. orgActions.listIdentity(options.deptName, function(json){
  245. v = json.data;
  246. }, null, false);
  247. return v;
  248. },
  249. //列出指定部门下的所有身份(包括所有下级部门成员)
  250. "listIdentityNested": function(options){
  251. getOrgActions();
  252. var v;
  253. orgActions.listIdentityNested(options.deptName, function(json){
  254. v = json.data;
  255. }, null, false);
  256. return v;
  257. },
  258. //获取指定部门的上级部门
  259. "getSupDepartmentDirect": function(options){
  260. getOrgActions();
  261. var v;
  262. orgActions.getSupDepartmentDirect(options.deptName, function(json){
  263. if (json.data) v = json.data.name;
  264. }, null, false);
  265. return v;
  266. },
  267. //获取指定人员所在的部门
  268. "listDepartmentByPerson": function(options){
  269. getOrgActions();
  270. var v;
  271. orgActions.listDepartmentByPerson(options.personName, function(json){
  272. v = json.data;
  273. }, null, false);
  274. return v;
  275. }
  276. };
  277. this.service = {
  278. "jaxwsClient": {},
  279. "jaxrsClient":{}
  280. };
  281. var lookupAction = null;
  282. var getLookupAction = function(callback){
  283. if (!lookupAction){
  284. MWF.require("MWF.xDesktop.Actions.RestActions", function(){
  285. lookupAction = new MWF.xDesktop.Actions.RestActions("", "x_cms_assemble_control", "");
  286. lookupAction.getActions = function(actionCallback){
  287. this.actions = {
  288. "lookup": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}/execute", "method":"PUT"},
  289. "getView": {"uri": "/jaxrs/queryview/flag/{view}/application/flag/{application}"}
  290. };
  291. if (actionCallback) actionCallback();
  292. }
  293. if (callback) callback();
  294. }.bind(this));
  295. }else{
  296. if (callback) callback();
  297. }
  298. };
  299. this.view = {
  300. "lookup": function(view, callback){
  301. getLookupAction(function(){
  302. lookupAction.invoke({"name": "lookup","async": true, "parameter": {"view": view.view, "application": view.application},"success": function(json){
  303. var data = {
  304. "grid": json.data.grid,
  305. "groupGrid": json.data.groupGrid
  306. };
  307. if (callback) callback(data);
  308. }.bind(this)});
  309. }.bind(this));
  310. },
  311. "select": function(view, callback, options){
  312. if (view.view){
  313. var viewJson = {
  314. "application": view.application || "",
  315. "viewName": view.view || "",
  316. "isTitle": view.isTitle || "yes",
  317. "select": view.select || "multi"
  318. };
  319. if (!options) options = {};
  320. var width = options.width || "700";
  321. var height = options.height || "400";
  322. if (layout.mobile){
  323. var size = document.body.getSize();
  324. width = size.x;
  325. height = size.y;
  326. options.style = "viewmobile";
  327. }
  328. width = width.toInt();
  329. height = height.toInt();
  330. var size = _form.app.content.getSize();
  331. var x = (size.x-width)/2;
  332. var y = (size.y-height)/2;
  333. if (x<0) x = 0;
  334. if (y<0) y = 0;
  335. if (layout.mobile){
  336. x = 20;
  337. y = 0;
  338. }
  339. var _self = this;
  340. MWF.require("MWF.xDesktop.Dialog", function(){
  341. var dlg = new MWF.xDesktop.Dialog({
  342. "title": options.title || "select View",
  343. "style": options.style || "view",
  344. "top": y,
  345. "left": x-20,
  346. "fromTop":y,
  347. "fromLeft": x-20,
  348. "width": width,
  349. "height": height,
  350. "html": "<div></div>",
  351. "maskNode": _form.app.content,
  352. "container": _form.app.content,
  353. "buttonList": [
  354. {
  355. "text": MWF.LP.process.button.ok,
  356. "action": function(){
  357. //if (callback) callback(_self.view.selectedItems);
  358. if (callback) callback(_self.view.getData());
  359. this.close();
  360. }
  361. },
  362. {
  363. "text": MWF.LP.process.button.cancel,
  364. "action": function(){this.close();}
  365. }
  366. ]
  367. });
  368. dlg.show();
  369. if (layout.mobile){
  370. var backAction = dlg.node.getElement(".MWF_dialod_Action_back");
  371. var okAction = dlg.node.getElement(".MWF_dialod_Action_ok");
  372. if (backAction) backAction.addEvent("click", function(e){
  373. dlg.close();
  374. }.bind(this));
  375. if (okAction) okAction.addEvent("click", function(e){
  376. //if (callback) callback(this.view.selectedItems);
  377. if (callback) callback(this.view.getData());
  378. dlg.close();
  379. }.bind(this));
  380. }
  381. MWF.xDesktop.requireApp("cms.Xform", "widget.View", function(){
  382. this.view = new MWF.xApplication.cms.Xform.widget.View(dlg.content.getFirst(), viewJson, {"style": "select"});
  383. }.bind(this));
  384. }.bind(this));
  385. }
  386. }
  387. };
  388. //include 引用脚本
  389. var includedScripts = [];
  390. this.include = function(name, callback){
  391. if (includedScripts.indexOf(name)==-1){
  392. if (!this.scriptAction){
  393. MWF.require("MWF.xScript.Actions.CMSScriptActions", null, false);
  394. this.scriptAction = new MWF.xScript.Actions.CMSScriptActions();
  395. }
  396. this.scriptAction.getScriptByName(_form.json.application, name, includedScripts, function(json){
  397. includedScripts = includedScripts.concat(json.data.importedList);
  398. MWF.Macro.exec(json.data.text, this);
  399. if (callback) callback.apply(this);
  400. }.bind(this), null, false);
  401. }else{
  402. if (callback) callback.apply(this);
  403. }
  404. }.bind(this);
  405. this.define = function(name, fun, overwrite){
  406. var over = true;
  407. if (overwrite===false) over = false;
  408. var o = {};
  409. o[name] = {"value": fun, "configurable": over};
  410. MWF.defineProperties(this, o);
  411. }.bind(this);
  412. //仅前台对象-----------------------------------------
  413. //form
  414. this.form = {
  415. "get": function(name){return _form.all[name];},
  416. "getField": function(name){return _forms[name];},
  417. "getData": function(){return new MWF.xScript.CMSJSONData(_form.getData());},
  418. "save": function(callback){
  419. _form.saveDocument(callback);
  420. },
  421. "close": function(){_form.closeDocument();},
  422. "publish": function(option){
  423. _form.publishDocument()
  424. },
  425. //"archive": function(option){
  426. // _form.archiveDocument()
  427. //},
  428. //"redraft": function(option){
  429. // _form.redraftDocument()
  430. //},
  431. "confirm": function(type, e, title, text, width, height, ok, cancel, callback){
  432. _form.confirm(type, e, title, text, width, height, ok, cancel, callback);
  433. },
  434. "notice": function(content, type, target, where){
  435. _form.notice(content, type, target, where);
  436. },
  437. "addEvent": function(e, f){_form.addEvent(e, f);}
  438. };
  439. this.target = ev.target;
  440. this.event = ev.event;
  441. this.status = ev.status;
  442. this.session = layout.desktop.session;
  443. };
  444. MWF.xScript.CMSJSONData = function(data, callback, key, parent){
  445. var getter = function(data, callback, k, _self){
  446. return function(){return (["array","object"].indexOf(typeOf(data[k]))==-1) ? data[k] : new MWF.xScript.CMSJSONData(data[k], callback, k, _self);};
  447. }
  448. var setter = function(data, callback, k, _self){
  449. return function(v){
  450. data[k] = v;
  451. if (callback) callback(data, k, _self);
  452. }
  453. }
  454. var define = function(){
  455. var o = {};
  456. for (var k in data) o[k] = {"configurable": true, "get": getter.apply(this, [data, callback, k, this]),"set": setter.apply(this, [data, callback, k, this])};
  457. o["length"] = {"get": function(){return Object.keys(data).length;}};
  458. MWF.defineProperties(this, o);
  459. this.getKey = function(){ return key; };
  460. this.getParent = function(){ return parent; };
  461. this.toString = function() { return data.toString();};
  462. this.add = function(newKey, newValue){
  463. var type = typeOf(data);
  464. if (!this.hasOwnProperty(newKey)){
  465. if (type=="array"){
  466. data.push(newValue || {});
  467. newKey = data.length-1;
  468. }else{
  469. data[newKey] = newValue || {};
  470. }
  471. var o = {};
  472. o[newKey] = {"configurable": true, "get": getter.apply(this, [data, callback, newKey, this]),"set": setter.apply(this, [data, callback, newKey, this])};
  473. MWF.defineProperties(this, o);
  474. }
  475. this[newKey] = newValue;
  476. return this;
  477. };
  478. this.del = function(delKey){
  479. if (!this.hasOwnProperty(delKey)) return null;
  480. delete data[newKey];
  481. delete this[newKey];
  482. return this;
  483. };
  484. }
  485. var type = typeOf(data);
  486. if (type=="object" || type=="array") define.apply(this);
  487. };
  488. MWF.xScript.createCMSDict = function(application){
  489. return function(name){
  490. var applicationId = application;
  491. this.name = name;
  492. MWF.require("MWF.xScript.Actions.CMSDictActions", null, false);
  493. var action = new MWF.xScript.Actions.CMSDictActions();
  494. this.get = function(path, success, failure){
  495. var p = path.replace(/\./g, "/");
  496. var value = null;
  497. action.getDict(applicationId, encodeURIComponent(this.name), p, function(json){
  498. value = json.data;
  499. if (success) success(json.data);
  500. }, function(xhr, text, error){
  501. if (failure) failure(xhr, text, error);
  502. }, false);
  503. return value;
  504. };
  505. this.set = function(path, value, success, failure){
  506. var p = path.replace(/\./g, "/");
  507. action.setDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  508. if (success) success(json.data);
  509. }, function(xhr, text, error){
  510. if (failure) failure(xhr, text, error);
  511. });
  512. };
  513. this.add = function(path, value, success, failure){
  514. var p = path.replace(/\./g, "/");
  515. action.addDict(applicationId, encodeURIComponent(this.name), p, value, function(json){
  516. if (success) success(json.data);
  517. }, function(xhr, text, error){
  518. if (failure) failure(xhr, text, error);
  519. });
  520. };
  521. this.delete = function(path, success, failure){
  522. var p = path.replace(/\./g, "/");
  523. action.deleteDict(applicationId, encodeURIComponent(this.name), p, function(json){
  524. if (success) success(json.data);
  525. }, function(xhr, text, error){
  526. if (failure) failure(xhr, text, error);
  527. });
  528. };
  529. }
  530. };