Main.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. //MWF.xDesktop.requireApp("Deployment", "Actions.RestActions", null, false);
  2. MWF.require("MWF.xAction.org.express.RestActions", null,false);
  3. MWF.xDesktop.requireApp("Selector", "package", null, false);
  4. //MWF.xDesktop.requireApp("Deployment", "Actions.RestActions", null, false);
  5. MWF.require("MWF.widget.O2Identity", 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 = MWF.Actions.get("x_component_assemble_control");
  20. //this.actions = new MWF.xApplication.Deployment.Actions.RestActions();
  21. var personActions = new MWF.xAction.org.express.RestActions();
  22. this.explorer = {"actions": personActions,"app": {"lp": this.lp}};
  23. },
  24. loadApplication: function(callback){
  25. this.components = [];
  26. this.loadTitle();
  27. this.appDeploymentContent = new Element("div", {"styles": this.css.appDeploymentContent}).inject(this.content);
  28. this.componentsContent = new Element("div", {"styles": this.css.componentsContent}).inject(this.appDeploymentContent);
  29. MWF.require("MWF.widget.Tab", function(){
  30. this.tab = new MWF.widget.Tab(this.content, {"style": "processlayout"});
  31. this.tab.load();
  32. this.appPage = this.tab.addTab(this.appDeploymentContent, this.lp.deployedComponent, false);
  33. this.appPage.showIm();
  34. this.setContentHeight();
  35. this.addEvent("resize", function(){this.setContentHeight();}.bind(this));
  36. }.bind(this));
  37. this.loadApplicationContent();
  38. },
  39. loadTitle: function(){
  40. this.titleBar = new Element("div", {"styles": this.css.titleBar}).inject(this.content);
  41. this.taskTitleTextNode = new Element("div", {"styles": this.css.titleTextNode,"text": this.lp.title}).inject(this.titleBar);
  42. },
  43. loadApplicationContent: function(){
  44. this.loadApps(function(){
  45. if (MWF.AC.isAdministrator()) this.loadNewApp();
  46. }.bind(this));
  47. },
  48. getComponentCatalogue: function(callback){
  49. var url = MWF.defaultPath+"/xDesktop/$Layout/components.json";
  50. MWF.getJSON(url, function(json){
  51. if (callback) callback(json);
  52. }.bind(this));
  53. },
  54. loadApps: function(callback){
  55. this.getComponentCatalogue(function(json){
  56. json.each(function(value, key){
  57. //this.createComponentItem(value, key);
  58. this.components.push(new MWF.xApplication.Deployment.Component(value, this));
  59. }.bind(this));
  60. this.actions.listComponent(function(json){
  61. json.data.each(function(value, key){
  62. this.components.push(new MWF.xApplication.Deployment.UserComponent(value, this));
  63. }.bind(this));
  64. if (callback) callback();
  65. }.bind(this));
  66. }.bind(this));
  67. },
  68. loadNewApp: function(){
  69. var node = new Element("div", {"styles": this.css.componentItemNode}).inject(this.componentsContent);
  70. node.setStyles({
  71. "background-color": "#FFF"
  72. });
  73. var contentNode = new Element("div", {"styles": this.css.contentNode}).inject(node);
  74. var titleNode = new Element("div", {"styles": this.css.titleNode}).inject(contentNode);
  75. //contentNode.setStyles({"height": "30px"});
  76. var iconNode = new Element("div", {"styles": this.css.addIconNode}).inject(node);
  77. iconNode.addEvents({
  78. "mouseover": function(){iconNode.setStyles(this.css.addIconNode_over); titleNode.setStyle("color", "#3498db");}.bind(this),
  79. "mouseout": function(){iconNode.setStyles(this.css.addIconNode); titleNode.setStyle("color", "#999");}.bind(this),
  80. "click": function(e){
  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( this.lp.inputNameAndTitle , "error", this.appContentNode);
  100. }else if (!fileInput.files.length){
  101. this.notice( this.lp.uploadZipFile, "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( this.lp.deploySuccess, "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. var user = this.deployment.desktop.session.user;
  173. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  174. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  175. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  176. var isAllow = true;
  177. if (this.data.allowList) isAllow = (this.data.allowList.length) ? (this.data.allowList.isIntersect(currentNames)) : true;
  178. var isDeny = false;
  179. if (this.data.denyList) isDeny = (this.data.denyList.length) ? (this.data.denyList.isIntersect(currentNames)) : false;
  180. if ((!isDeny && isAllow) || MWF.AC.isAdministrator()){
  181. this.openAction = new Element("div", {"styles": this.css.actionNode, "text": this.deployment.lp.open}).inject(this.actionAreaNode);
  182. this.openAction.addEvents({
  183. "mouseover": function(){this.openAction.setStyles(this.css.actionNode_over);}.bind(this),
  184. "mouseout": function(){this.openAction.setStyles(this.css.actionNode);}.bind(this),
  185. "click": function(e){
  186. this.deployment.desktop.openApplication(e, this.data.path);
  187. }.bind(this)
  188. });
  189. }
  190. }else{
  191. }
  192. },
  193. loadSystemFlag: function(){
  194. //this.flagNode = new Element("div", {"styles": this.css.flagNode}).inject(this.node);
  195. }
  196. });
  197. MWF.xApplication.Deployment.UserComponent = new Class({
  198. Extends: MWF.xApplication.Deployment.Component,
  199. createOpenAction: function(style){
  200. this.openAction = new Element("div", {"styles": this.css[style], "text": this.deployment.lp.open}).inject(this.actionAreaNode);
  201. this.openAction.addEvents({
  202. "mouseover": function(){this.openAction.setStyles(this.css.actionNode_over);}.bind(this),
  203. "mouseout": function(){this.openAction.setStyles(this.css[style]);}.bind(this),
  204. "click": function(e){
  205. this.deployment.desktop.openApplication(e, this.data.path);
  206. }.bind(this)
  207. });
  208. },
  209. createEditAction: function(style){
  210. this.editAction = new Element("div", {"styles": this.css[style], "text": this.deployment.lp.edit}).inject(this.actionAreaNode);
  211. this.editAction.addEvents({
  212. "mouseover": function(){this.editAction.setStyles(this.css.actionNode_over);}.bind(this),
  213. "mouseout": function(){this.editAction.setStyles(this.css[style]);}.bind(this),
  214. "click": function(e){
  215. this.editComponent();
  216. }.bind(this)
  217. });
  218. },
  219. createRemoveAction: function(style){
  220. this.removeAction = new Element("div", {"styles": this.css[style], "text": this.deployment.lp.remove}).inject(this.actionAreaNode);
  221. this.removeAction.addEvents({
  222. "mouseover": function(){this.removeAction.setStyles(this.css.actionNode_over);}.bind(this),
  223. "mouseout": function(){this.removeAction.setStyles(this.css[style]);}.bind(this),
  224. "click": function(e){
  225. var _self = this;
  226. var text = this.deployment.lp.removeComponent.replace(/{name}/, this.data.title)
  227. this.deployment.confirm("warn", e, this.deployment.lp.removeComponentTitle, text, 300, 130, function(){
  228. _self.removeComponent();
  229. this.close();
  230. }, function(){
  231. this.close();
  232. }, null, this.deployment.content);
  233. }.bind(this)
  234. });
  235. },
  236. addAction: function(){
  237. this.node.setStyles(this.css.userComponentItemNode);
  238. var user = this.deployment.desktop.session.user;
  239. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  240. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  241. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  242. var isAdministrator = this.checkAdministrator();
  243. if (isAdministrator && this.data.visible){
  244. this.createOpenAction("action2Node");
  245. this.createEditAction("action2Node");
  246. this.createRemoveAction("action3Node");
  247. }else if (!isAdministrator && this.data.visible){
  248. var isAllow = (this.data.allowList.length) ? (this.data.allowList.isIntersect(currentNames)) : true;
  249. var isDeny = (this.data.denyList.length) ? (this.data.denyList.isIntersect(currentNames)) : false;
  250. if ((!isDeny && isAllow) || MWF.AC.isAdministrator()){
  251. this.createOpenAction("actionNode");
  252. }
  253. }else if (isAdministrator && !this.data.visible){
  254. this.createEditAction("action4Node");
  255. this.createRemoveAction("action5Node");
  256. }
  257. },
  258. checkAdministrator: function(){
  259. if (MWF.AC.isAdministrator()) return true;
  260. var user = this.deployment.desktop.session.user;
  261. var currentNames = [user.name, user.distinguishedName, user.id, user.unique];
  262. if (user.roleList) currentNames = currentNames.concat(user.roleList);
  263. if (user.groupList) currentNames = currentNames.concat(user.groupList);
  264. if (this.data.controllerList.isIntersect(currentNames)) return true;
  265. return false;
  266. },
  267. loadSystemFlag: function(){},
  268. editComponent: function(){
  269. new MWF.xApplication.Deployment.DeployEdit(this.data, this, this.deployment);
  270. },
  271. removeComponent: function(){
  272. this.deployment.actions.removeComponent(this.data.id, function(){
  273. this.deployment.notice(this.deployment.lp.removeComponentOk, "success");
  274. this.deployment.components.erase(this);
  275. this.node.destroy();
  276. MWF.release(this);
  277. }.bind(this));
  278. }
  279. });
  280. MWF.xApplication.Deployment.Deploy = new Class({
  281. initialize: function(deployment){
  282. this.deployment = deployment;
  283. this.css = this.deployment.css;
  284. this.tab = this.deployment.tab;
  285. this.lp = this.deployment.lp;
  286. this.load(this.lp.add);
  287. },
  288. createLine: function(title){
  289. var lineNode = new Element("div", {"styles": this.css.deployLineNode}).inject(this.content);
  290. var titleNode = new Element("div", {"styles": this.css.deployTitleNode, "text": title}).inject(lineNode);
  291. var valueNode = new Element("div", {"styles": this.css.deployvalueNode}).inject(lineNode);
  292. return new Element("input", {"styles": this.css.deployInputNode, "type": "text"}).inject(valueNode);
  293. },
  294. createLineSelect: function(title, defaultValue){
  295. var lineNode = new Element("div", {"styles": this.css.deployLineNode}).inject(this.content);
  296. var titleNode = new Element("div", {"styles": this.css.deployTitleNode, "text": title}).inject(lineNode);
  297. var valueNode = new Element("div", {"styles": this.css.deployvalueNode}).inject(lineNode);
  298. var selectNode = new Element("select").inject(valueNode);
  299. new Element("option", {"text": this.lp.yes, "value":"yes"}).inject(selectNode);
  300. new Element("option", {"text": this.lp.no, "value":"no", "checked": ((defaultValue=="no") ? true : false)}).inject(selectNode);
  301. return selectNode;
  302. },
  303. load: function(title){
  304. this.node = new Element("div", {"styles": this.css.newDeployNode});
  305. this.content = new Element("div", {"styles": this.css.deployContentNode}).inject(this.node);
  306. this.nameInputNode = this.createLine(this.lp.name);
  307. this.titleInputNode = this.createLine(this.lp.componentTitle);
  308. this.pathInputNode = this.createLine(this.lp.path);
  309. this.visibleInputNode = this.createLineSelect(this.lp.isVisible);
  310. this.widgetNameInputNode = this.createLine(this.lp.widgetName);
  311. this.widgetTitleInputNode = this.createLine(this.lp.widgetTitle);
  312. this.widgetStartInputNode = this.createLineSelect(this.lp.widgetStart, "no");
  313. this.widgetVisibleInputNode = this.createLineSelect(this.lp.widgetVisible);
  314. this.allowList = new MWF.xApplication.Deployment.Deploy.Select(this.deployment, this.content, this.lp.allowList);
  315. this.denyList = new MWF.xApplication.Deployment.Deploy.Select(this.deployment, this.content, this.lp.denyList);
  316. this.controllerList = new MWF.xApplication.Deployment.Deploy.Select(this.deployment, this.content, this.lp.controllerList);
  317. this.okAction = new Element("div", {"styles": this.css.deployOkAction, "text": this.lp.add}).inject(this.content);
  318. this.okAction.addEvent("click", function(){
  319. var data = this.getComponentData();
  320. if ((!data.name) || (!data.title) || (!data.path)){
  321. this.deployment.notice(this.lp.noInputInfor, "error");
  322. return false;
  323. }else{
  324. this.deployment.actions.createComponent(data, function(){
  325. this.deployment.notice(this.lp.deploySuccess, "success");
  326. this.page.closeTab();
  327. this.deployment.appPage.showTabIm();
  328. this.deployment.components.push(new MWF.xApplication.Deployment.UserComponent(data, this.deployment, true));
  329. }.bind(this));
  330. }
  331. }.bind(this));
  332. this.page = this.tab.addTab(this.node, title, true);
  333. this.page.showTabIm();
  334. },
  335. getComponentData: function(){
  336. var visible = this.visibleInputNode.options[this.visibleInputNode.selectedIndex].value;
  337. var widgetStart = this.widgetStartInputNode.options[this.widgetStartInputNode.selectedIndex].value;
  338. var widgetVisible = this.widgetVisibleInputNode.options[this.widgetVisibleInputNode.selectedIndex].value;
  339. var data = {
  340. "name": this.nameInputNode.get("value"),
  341. "title": this.titleInputNode.get("value"),
  342. "path": this.pathInputNode.get("value"),
  343. "visible": (visible=="yes") ? true : false,
  344. "iconPath": "appicon.png",
  345. "widgetName": this.widgetNameInputNode.get("value"),
  346. "widgetTitle": this.widgetTitleInputNode.get("value"),
  347. "widgetIconPath": "widgeticon.png",
  348. "widgetStart": (widgetStart=="yes") ? true : false,
  349. "widgetVisible": (widgetVisible=="yes") ? true : false,
  350. "allowList": this.allowList.list,
  351. "denyList": this.denyList.list,
  352. "controllerList": this.controllerList.list
  353. };
  354. return data;
  355. }
  356. });
  357. MWF.xApplication.Deployment.DeployEdit = new Class({
  358. Extends: MWF.xApplication.Deployment.Deploy,
  359. initialize: function(data, component, deployment){
  360. this.deployment = deployment;
  361. this.component = component;
  362. this.css = this.deployment.css;
  363. this.tab = this.deployment.tab;
  364. this.lp = this.deployment.lp;
  365. this.data = data;
  366. this.load(this.lp.modify);
  367. this.setValues();
  368. },
  369. setValues: function(){
  370. this.nameInputNode.set("value", this.data.name);
  371. this.titleInputNode.set("value", this.data.title);
  372. this.pathInputNode.set("value", this.data.path);
  373. if (this.data.visible){
  374. this.visibleInputNode.getFirst("option").set("checked", true);
  375. }else{
  376. this.visibleInputNode.getLast("option").set("checked", true);
  377. }
  378. this.widgetNameInputNode.set("value", this.data.widgetName);
  379. this.widgetTitleInputNode.set("value", this.data.widgetTitle);
  380. this.allowList.setList(this.data.allowList);
  381. this.denyList.setList(this.data.denyList);
  382. this.controllerList.setList(this.data.controllerList);
  383. this.okAction.set("text", this.lp.modify);
  384. this.okAction.removeEvents("click");
  385. this.okAction.addEvent("click", function(){
  386. var data = this.getComponentData();
  387. if ((!data.name) || (!data.title) || (!data.path)){
  388. this.deployment.notice(this.lp.noInputInfor, "error");
  389. return false;
  390. }else{
  391. this.deployment.actions.updateComponent(this.data.id, data, function(){
  392. this.deployment.notice(this.lp.modifySuccess, "success");
  393. this.page.closeTab();
  394. this.deployment.appPage.showTabIm();
  395. data.id = this.data.id;
  396. this.component.reload(data);
  397. }.bind(this));
  398. }
  399. }.bind(this));
  400. }
  401. });
  402. MWF.xApplication.Deployment.Deploy.Select = new Class({
  403. initialize: function(deployment, content, title){
  404. this.deployment = deployment;
  405. this.css = this.deployment.css;
  406. this.list = [];
  407. var lineNode = new Element("div", {"styles": this.css.deployLineNode}).inject(content);
  408. lineNode.setStyle("height", "40px");
  409. var titleNode = new Element("div", {"styles": this.css.deployTitleNode, "text": title}).inject(lineNode);
  410. var valueNode = new Element("div", {"styles": this.css.deployvalueNode}).inject(lineNode);
  411. this.listNode = new Element("div", {"styles": {"float": "left"}}).inject(valueNode);
  412. var actionNode = new Element("div", {"styles": this.css.actionNode, "text": this.deployment.lp.selPerson}).inject(valueNode);
  413. actionNode.setStyles({"margin-top": "10px", "float": "left"});
  414. actionNode.addEvent("click", function(){
  415. var options = {
  416. "type": "person",
  417. "values": this.list,
  418. "count": 0,
  419. "onComplete": function(items){
  420. this.list = [];
  421. items.each(function(item){
  422. this.list.push(item.data.distinguishedName);
  423. }.bind(this));
  424. this.listNode.empty();
  425. this.list.each(function(personName){
  426. if (personName) new MWF.widget.O2Person({"name": personName}, this.listNode, {"style": "application"});
  427. }.bind(this));
  428. }.bind(this)
  429. };
  430. var selector = new MWF.O2Selector(this.deployment.content, options);
  431. }.bind(this));
  432. },
  433. setList: function(data){
  434. this.list = data;
  435. this.list.each(function(personName){
  436. if (personName) new MWF.widget.O2Person({"name": personName}, this.listNode, {"style": "application"});
  437. }.bind(this));
  438. }
  439. });