Main.js 20 KB

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