SettingModuleUI.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. MWF.xDesktop.requireApp("Selector", "package", null, false);
  2. MWF.require("MWF.widget.O2Identity", null,false);
  3. MWF.xApplication.Setting.UIModuleDocument = new Class({
  4. Extends: MWF.xApplication.Common.Main,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default"
  8. },
  9. initialize: function(explorer, content, options){
  10. this.setOptions(options);
  11. this.path = "/x_component_Setting/$SettingModuleUI/";
  12. this.cssPath =this.path+this.options.style+"/css.wcss";
  13. this._loadCss();
  14. this.content = content;
  15. this.explorer = explorer;
  16. this.app = this.explorer.app;
  17. this.lp = this.app.lp.module;
  18. this.actions = MWF.Actions.get("x_component_assemble_control");
  19. this.load();
  20. },
  21. "destroy": function(){
  22. this.appDeploymentContent.destroy();
  23. this.content.empty();
  24. if (this.setContentHeightFun) this.app.removeEvent("resize", this.setContentHeightFun);
  25. MWF.release(this);
  26. },
  27. load: function(){
  28. this.components = [];
  29. this.loadTitle();
  30. this.appDeploymentContent = new Element("div", {"styles": this.css.appDeploymentContent}).inject(this.content);
  31. this.componentsContent = new Element("div", {"styles": this.css.componentsContent}).inject(this.appDeploymentContent);
  32. MWF.require("MWF.widget.Tab", function(){
  33. this.tab = new MWF.widget.Tab(this.content, {"style": "processlayout"});
  34. this.tab.load();
  35. this.appPage = this.tab.addTab(this.appDeploymentContent, "已部署组件", false);
  36. this.appPage.showIm();
  37. this.setContentHeight();
  38. this.setContentHeightFun = this.setContentHeight.bind(this);
  39. this.app.addEvent("resize", this.setContentHeightFun);
  40. }.bind(this));
  41. this.loadApplicationContent();
  42. },
  43. loadTitle: function(){
  44. // this.titleBar = new Element("div", {"styles": this.css.titleBar}).inject(this.content);
  45. // this.taskTitleTextNode = new Element("div", {"styles": this.css.titleTextNode,"text": this.lp.title}).inject(this.titleBar);
  46. },
  47. loadApplicationContent: function(){
  48. this.loadApps(function(){
  49. if (MWF.AC.isAdministrator()) this.loadNewApp();
  50. }.bind(this));
  51. },
  52. getComponentCatalogue: function(callback){
  53. var url = MWF.defaultPath+"/xDesktop/$Layout/components.json";
  54. MWF.getJSON(url, function(json){
  55. if (callback) callback(json);
  56. }.bind(this));
  57. },
  58. loadApps: function(callback){
  59. this.getComponentCatalogue(function(json){
  60. json.each(function(value, key){
  61. //this.createComponentItem(value, key);
  62. this.components.push(new MWF.xApplication.Setting.UIModuleDocument.Component(value, this));
  63. }.bind(this));
  64. this.actions.listComponent(function(json){
  65. json.data.each(function(value, key){
  66. this.components.push(new MWF.xApplication.Setting.UIModuleDocument.UserComponent(value, this));
  67. }.bind(this));
  68. if (callback) callback();
  69. }.bind(this));
  70. }.bind(this));
  71. },
  72. loadNewApp: function(){
  73. var node = new Element("div", {"styles": this.css.componentItemNode}).inject(this.componentsContent);
  74. node.setStyles({
  75. "background-color": "#FFF"
  76. });
  77. var contentNode = new Element("div", {"styles": this.css.contentNode}).inject(node);
  78. var titleNode = new Element("div", {"styles": this.css.titleNode}).inject(contentNode);
  79. //contentNode.setStyles({"height": "30px"});
  80. var iconNode = new Element("div", {"styles": this.css.addIconNode}).inject(node);
  81. iconNode.addEvents({
  82. "mouseover": function(){iconNode.setStyles(this.css.addIconNode_over); titleNode.setStyle("color", "#3498db");}.bind(this),
  83. "mouseout": function(){iconNode.setStyles(this.css.addIconNode); titleNode.setStyle("color", "#999");}.bind(this),
  84. "click": function(e){
  85. this.createNewDeploy(e);
  86. }.bind(this)
  87. });
  88. var actionAreaNode = new Element("div", {"styles": this.css.actionAreaNode}).inject(node);
  89. titleNode.set("text", this.lp.add);
  90. titleNode.setStyle("color", "#999");
  91. },
  92. createNewDeploy: function(){
  93. new MWF.xApplication.Setting.UIModuleDocument.Deploy(this);
  94. },
  95. deployApp: function(){
  96. var inputs = this.appContentNode.getElements("input");
  97. var nameInput = inputs[0];
  98. var tileInput = inputs[1];
  99. var fileInput = inputs[2];
  100. var name = nameInput.get("value");
  101. var title = tileInput.get("value");
  102. if (!name || !title){
  103. this.app.notice("请输入应用名称和应用标题", "error", this.appContentNode);
  104. }else if (!fileInput.files.length){
  105. this.app.notice("请上传文件的ZIP包", "error", this.appContentNode);
  106. }else{
  107. var formData = new FormData();
  108. formData.append('file', fileInput.files[0]);
  109. formData.append('name', name);
  110. formData.append('title', title);
  111. formData.append('path', "/res/mwf4/package/xApplication");
  112. var xhr = new COMMON.Browser.Request();
  113. xhr.open("POST", "jaxrs/application", false);
  114. var onreadystatechange= function(){
  115. if (xhr.readyState != 4) return;
  116. var status = xhr.status;
  117. status = (status == 1223) ? 204 : status;
  118. if ((status >= 200 && status < 300)) {
  119. this.app.notice("部署成功", "success", this.appContentNode);
  120. this.appListNode.empty();
  121. this.loadApps();
  122. };
  123. }.bind(this);
  124. xhr.onreadystatechange = onreadystatechange;
  125. xhr.send(formData);
  126. }
  127. },
  128. setContentHeight: function(node){
  129. var size = this.content.getSize();
  130. //var titleSize = this.titleBar.getSize();
  131. var tabSize = this.tab.tabNodeContainer.getSize();
  132. var height = size.y-tabSize.y;
  133. this.tab.pages.each(function(page){
  134. page.contentNodeArea.setStyles({"height": ""+height+"px", "overflow": "auto"})
  135. });
  136. //this.appDeploymentContent.setStyle("height", height);
  137. }
  138. });
  139. MWF.xApplication.Setting.UIModuleDocument.Component = new Class({
  140. initialize: function(value, deployment, inset){
  141. this.data = value;
  142. this.deployment = deployment;
  143. this.css = this.deployment.css;
  144. this.content = this.deployment.componentsContent;
  145. this.load(inset);
  146. },
  147. reload: function(data){
  148. this.data = data;
  149. this.node.empty();
  150. this.load();
  151. },
  152. load: function(inset){
  153. if (!this.node){
  154. this.node = new Element("div", {"styles": this.css.componentItemNode});
  155. if (inset){
  156. var tmpNode = this.content.getLast("div");
  157. this.node.inject(tmpNode, "before");
  158. }else{
  159. this.node.inject(this.content);
  160. }
  161. }
  162. this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.node);
  163. this.titleNode = new Element("div", {"styles": this.css.titleNode}).inject(this.contentNode);
  164. this.nameNode = new Element("div", {"styles": this.css.nameNode}).inject(this.contentNode);
  165. this.iconNode = new Element("div", {"styles": this.css.iconNode}).inject(this.node);
  166. this.actionAreaNode = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.node);
  167. var icon = "/x_component_"+this.data.path.replace(/\./g, "_")+"/$Main/"+this.data.iconPath;
  168. this.iconNode.setStyle("background-image", "url("+icon+")");
  169. this.titleNode.set("text", this.data.title);
  170. this.nameNode.set("text", this.data.name);
  171. this.addAction();
  172. this.loadSystemFlag();
  173. },
  174. addAction: function(){
  175. if (this.data.visible){
  176. var user = layout.session.user;
  177. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  178. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  179. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  180. var isAllow = true;
  181. if (this.data.allowList) isAllow = (this.data.allowList.length) ? (this.data.allowList.isIntersect(currentNames)) : true;
  182. var isDeny = false;
  183. if (this.data.denyList) isDeny = (this.data.denyList.length) ? (this.data.denyList.isIntersect(currentNames)) : false;
  184. if ((!isDeny && isAllow) || MWF.AC.isAdministrator()){
  185. this.openAction = new Element("div", {"styles": this.css.actionNode, "text": this.deployment.lp.open}).inject(this.actionAreaNode);
  186. this.openAction.addEvents({
  187. "mouseover": function(){this.openAction.setStyles(this.css.actionNode_over);}.bind(this),
  188. "mouseout": function(){this.openAction.setStyles(this.css.actionNode);}.bind(this),
  189. "click": function(e){
  190. this.deployment.app.desktop.openApplication(e, this.data.path);
  191. }.bind(this)
  192. });
  193. }
  194. }else{
  195. }
  196. },
  197. loadSystemFlag: function(){
  198. //this.flagNode = new Element("div", {"styles": this.css.flagNode}).inject(this.node);
  199. }
  200. });
  201. MWF.xApplication.Setting.UIModuleDocument.UserComponent = new Class({
  202. Extends: MWF.xApplication.Setting.UIModuleDocument.Component,
  203. createOpenAction: function(style){
  204. this.openAction = new Element("div", {"styles": this.css[style], "text": this.deployment.lp.open}).inject(this.actionAreaNode);
  205. this.openAction.addEvents({
  206. "mouseover": function(){this.openAction.setStyles(this.css.actionNode_over);}.bind(this),
  207. "mouseout": function(){this.openAction.setStyles(this.css[style]);}.bind(this),
  208. "click": function(e){
  209. this.deployment.app.desktop.openApplication(e, this.data.path);
  210. }.bind(this)
  211. });
  212. },
  213. createEditAction: function(style){
  214. this.editAction = new Element("div", {"styles": this.css[style], "text": this.deployment.lp.edit}).inject(this.actionAreaNode);
  215. this.editAction.addEvents({
  216. "mouseover": function(){this.editAction.setStyles(this.css.actionNode_over);}.bind(this),
  217. "mouseout": function(){this.editAction.setStyles(this.css[style]);}.bind(this),
  218. "click": function(e){
  219. this.editComponent();
  220. }.bind(this)
  221. });
  222. },
  223. createRemoveAction: function(style){
  224. this.removeAction = new Element("div", {"styles": this.css[style], "text": this.deployment.lp.remove}).inject(this.actionAreaNode);
  225. this.removeAction.addEvents({
  226. "mouseover": function(){this.removeAction.setStyles(this.css.actionNode_over);}.bind(this),
  227. "mouseout": function(){this.removeAction.setStyles(this.css[style]);}.bind(this),
  228. "click": function(e){
  229. var _self = this;
  230. var text = this.deployment.lp.removeComponent.replace(/{name}/, this.data.title);
  231. this.deployment.app.confirm("warn", e, this.deployment.lp.removeComponentTitle, text, 300, 130, function(){
  232. _self.removeComponent();
  233. this.close();
  234. }, function(){
  235. this.close();
  236. }, null, this.deployment.content);
  237. }.bind(this)
  238. });
  239. },
  240. addAction: function(){
  241. this.node.setStyles(this.css.userComponentItemNode);
  242. var user = layout.session.user;
  243. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  244. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  245. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  246. var isAdministrator = this.checkAdministrator();
  247. if (isAdministrator && this.data.visible){
  248. this.createOpenAction("action2Node");
  249. this.createEditAction("action2Node");
  250. this.createRemoveAction("action3Node");
  251. }else if (!isAdministrator && this.data.visible){
  252. var isAllow = (this.data.allowList.length) ? (this.data.allowList.isIntersect(currentNames)) : true;
  253. var isDeny = (this.data.denyList.length) ? (this.data.denyList.isIntersect(currentNames)) : false;
  254. if ((!isDeny && isAllow) || MWF.AC.isAdministrator()){
  255. this.createOpenAction("actionNode");
  256. }
  257. }else if (isAdministrator && !this.data.visible){
  258. this.createEditAction("action4Node");
  259. this.createRemoveAction("action5Node");
  260. }
  261. },
  262. checkAdministrator: function(){
  263. if (MWF.AC.isAdministrator()) return true;
  264. var user = this.deployment.desktop.session.user;
  265. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  266. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  267. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  268. if (this.data.controllerList.isIntersect(currentNames)) return true;
  269. return false;
  270. },
  271. loadSystemFlag: function(){},
  272. editComponent: function(){
  273. new MWF.xApplication.Setting.UIModuleDocument.DeployEdit(this.data, this, this.deployment);
  274. },
  275. removeComponent: function(){
  276. this.deployment.actions.removeComponent(this.data.id, function(){
  277. this.deployment.app.notice(this.deployment.lp.removeComponentOk, "success");
  278. this.deployment.components.erase(this);
  279. this.node.destroy();
  280. MWF.release(this);
  281. }.bind(this));
  282. }
  283. });
  284. MWF.xApplication.Setting.UIModuleDocument.Deploy = new Class({
  285. initialize: function(deployment){
  286. this.deployment = deployment;
  287. this.css = this.deployment.css;
  288. this.tab = this.deployment.tab;
  289. this.lp = this.deployment.lp;
  290. this.load(this.lp.add);
  291. },
  292. createLine: function(title){
  293. var lineNode = new Element("div", {"styles": this.css.deployLineNode}).inject(this.content);
  294. var titleNode = new Element("div", {"styles": this.css.deployTitleNode, "text": title}).inject(lineNode);
  295. var valueNode = new Element("div", {"styles": this.css.deployvalueNode}).inject(lineNode);
  296. return new Element("input", {"styles": this.css.deployInputNode, "type": "text"}).inject(valueNode);
  297. },
  298. createLineSelect: function(title, defaultValue){
  299. var lineNode = new Element("div", {"styles": this.css.deployLineNode}).inject(this.content);
  300. var titleNode = new Element("div", {"styles": this.css.deployTitleNode, "text": title}).inject(lineNode);
  301. var valueNode = new Element("div", {"styles": this.css.deployvalueNode}).inject(lineNode);
  302. var selectNode = new Element("select").inject(valueNode);
  303. new Element("option", {"text": this.lp.yes, "value":"yes"}).inject(selectNode);
  304. new Element("option", {"text": this.lp.no, "value":"no", "checked": ((defaultValue=="no") ? true : false)}).inject(selectNode);
  305. return selectNode;
  306. },
  307. load: function(title){
  308. this.node = new Element("div", {"styles": this.css.newDeployNode});
  309. this.content = new Element("div", {"styles": this.css.deployContentNode}).inject(this.node);
  310. this.nameInputNode = this.createLine(this.lp.name);
  311. this.titleInputNode = this.createLine(this.lp.componentTitle);
  312. this.pathInputNode = this.createLine(this.lp.path);
  313. this.visibleInputNode = this.createLineSelect(this.lp.isVisible);
  314. // this.widgetNameInputNode = this.createLine(this.lp.widgetName);
  315. // this.widgetTitleInputNode = this.createLine(this.lp.widgetTitle);
  316. // this.widgetStartInputNode = this.createLineSelect(this.lp.widgetStart, "no");
  317. // this.widgetVisibleInputNode = this.createLineSelect(this.lp.widgetVisible);
  318. this.allowList = new MWF.xApplication.Setting.UIModuleDocument.Deploy.Select(this.deployment, this.content, this.lp.allowList);
  319. this.denyList = new MWF.xApplication.Setting.UIModuleDocument.Deploy.Select(this.deployment, this.content, this.lp.denyList);
  320. //this.controllerList = new MWF.xApplication.Setting.UIModuleDocument.Deploy.Select(this.deployment, this.content, this.lp.controllerList);
  321. this.okAction = new Element("div", {"styles": this.css.deployOkAction, "text": this.lp.add}).inject(this.content);
  322. this.okAction.addEvent("click", function(){
  323. var data = this.getComponentData();
  324. if ((!data.name) || (!data.title) || (!data.path)){
  325. this.deployment.app.notice(this.lp.noInputInfor, "error");
  326. return false;
  327. }else{
  328. this.deployment.actions.createComponent(data, function(){
  329. this.deployment.app.notice(this.lp.deploySuccess, "success");
  330. this.page.closeTab();
  331. this.deployment.appPage.showTabIm();
  332. this.deployment.components.push(new MWF.xApplication.Setting.UIModuleDocument.UserComponent(data, this.deployment, true));
  333. }.bind(this));
  334. }
  335. }.bind(this));
  336. this.page = this.tab.addTab(this.node, title, true);
  337. this.page.showTabIm();
  338. },
  339. getComponentData: function(){
  340. var visible = this.visibleInputNode.options[this.visibleInputNode.selectedIndex].value;
  341. // var widgetStart = this.widgetStartInputNode.options[this.widgetStartInputNode.selectedIndex].value;
  342. // var widgetVisible = this.widgetVisibleInputNode.options[this.widgetVisibleInputNode.selectedIndex].value;
  343. // var data = {
  344. // "name": this.nameInputNode.get("value"),
  345. // "title": this.titleInputNode.get("value"),
  346. // "path": this.pathInputNode.get("value"),
  347. // "visible": (visible=="yes") ? true : false,
  348. // "iconPath": "appicon.png",
  349. // "widgetName": this.widgetNameInputNode.get("value"),
  350. // "widgetTitle": this.widgetTitleInputNode.get("value"),
  351. // "widgetIconPath": "widgeticon.png",
  352. // "widgetStart": (widgetStart=="yes") ? true : false,
  353. // "widgetVisible": (widgetVisible=="yes") ? true : false,
  354. //
  355. // "allowList": this.allowList.list,
  356. // "denyList": this.denyList.list,
  357. // "controllerList": this.controllerList.list
  358. // };
  359. var data = {
  360. "name": this.nameInputNode.get("value"),
  361. "title": this.titleInputNode.get("value"),
  362. "path": this.pathInputNode.get("value"),
  363. "visible": (visible=="yes") ? true : false,
  364. "iconPath": "appicon.png",
  365. "widgetName": "",
  366. "widgetTitle": "",
  367. "widgetIconPath": "",
  368. "widgetStart": false,
  369. "widgetVisible": false,
  370. "allowList": this.allowList.list,
  371. "denyList": this.denyList.list,
  372. "controllerList": []
  373. };
  374. return data;
  375. }
  376. });
  377. MWF.xApplication.Setting.UIModuleDocument.DeployEdit = new Class({
  378. Extends: MWF.xApplication.Setting.UIModuleDocument.Deploy,
  379. initialize: function(data, component, deployment){
  380. this.deployment = deployment;
  381. this.component = component;
  382. this.css = this.deployment.css;
  383. this.tab = this.deployment.tab;
  384. this.lp = this.deployment.lp;
  385. this.data = data;
  386. this.load(this.lp.modify);
  387. this.setValues();
  388. },
  389. setValues: function(){
  390. this.nameInputNode.set("value", this.data.name);
  391. this.titleInputNode.set("value", this.data.title);
  392. this.pathInputNode.set("value", this.data.path);
  393. if (this.data.visible){
  394. this.visibleInputNode.getFirst("option").set("checked", true);
  395. }else{
  396. this.visibleInputNode.getLast("option").set("checked", true);
  397. }
  398. // this.widgetNameInputNode.set("value", this.data.widgetName);
  399. // this.widgetTitleInputNode.set("value", this.data.widgetTitle);
  400. this.allowList.setList(this.data.allowList);
  401. this.denyList.setList(this.data.denyList);
  402. //this.controllerList.setList(this.data.controllerList);
  403. this.okAction.set("text", this.lp.modify);
  404. this.okAction.removeEvents("click");
  405. this.okAction.addEvent("click", function(){
  406. var data = this.getComponentData();
  407. if ((!data.name) || (!data.title) || (!data.path)){
  408. this.deployment.app.notice(this.lp.noInputInfor, "error");
  409. return false;
  410. }else{
  411. this.deployment.actions.updateComponent(this.data.id, data, function(){
  412. this.deployment.app.notice(this.lp.modifySuccess, "success");
  413. this.page.closeTab();
  414. this.deployment.appPage.showTabIm();
  415. data.id = this.data.id;
  416. this.component.reload(data);
  417. }.bind(this));
  418. }
  419. }.bind(this));
  420. }
  421. });
  422. MWF.xApplication.Setting.UIModuleDocument.Deploy.Select = new Class({
  423. initialize: function(deployment, content, title){
  424. this.deployment = deployment;
  425. this.css = this.deployment.css;
  426. this.list = [];
  427. var lineNode = new Element("div", {"styles": this.css.deployLineNode}).inject(content);
  428. lineNode.setStyle("height", "40px");
  429. var titleNode = new Element("div", {"styles": this.css.deployTitleNode, "text": title}).inject(lineNode);
  430. var valueNode = new Element("div", {"styles": this.css.deployvalueNode}).inject(lineNode);
  431. this.listNode = new Element("div", {"styles": {"float": "left"}}).inject(valueNode);
  432. var actionNode = new Element("div", {"styles": this.css.actionNode, "text": this.deployment.lp.selPerson}).inject(valueNode);
  433. actionNode.setStyles({"margin-top": "10px", "float": "left"});
  434. actionNode.addEvent("click", function(){
  435. var options = {
  436. "type": "",
  437. "types": ["person", "group", "role"],
  438. "values": this.list,
  439. "count": 0,
  440. "onComplete": function(items){
  441. this.list = [];
  442. items.each(function(item){
  443. this.list.push(item.data.distinguishedName);
  444. }.bind(this));
  445. this.listNode.empty();
  446. this.list.each(function(personName){
  447. if (personName){
  448. var t = personName.substr(personName.length-1, 1);
  449. switch (t){
  450. case "G":
  451. new MWF.widget.O2Group({"name": personName}, this.listNode, {"style": "application"});
  452. break;
  453. case "R":
  454. new MWF.widget.O2Role({"name": personName}, this.listNode, {"style": "application"});
  455. break;
  456. default:
  457. new MWF.widget.O2Person({"name": personName}, this.listNode, {"style": "application"});
  458. }
  459. }
  460. }.bind(this));
  461. }.bind(this)
  462. };
  463. var selector = new MWF.O2Selector(this.deployment.app.content, options);
  464. }.bind(this));
  465. },
  466. setList: function(data){
  467. this.list = data;
  468. this.list.each(function(personName){
  469. if (personName) new MWF.widget.O2Person({"name": personName}, this.listNode, {"style": "application"});
  470. }.bind(this));
  471. }
  472. });