Applications.min.js 5.4 KB

1
  1. MWF.xApplication.Setting.applications=MWF.xApplication.Setting.applications||{};MWF.require("MWF.widget.Mask",null,false);MWF.xApplication.Setting.applications.Applications=new Class({Extends:MWF.widget.Common,Implements:[Options,Events],initialize:function(t){this.explorer=t;this.app=this.explorer.app;this.actions=this.app.actions;this.css=this.app.css;this.applications=[];this.content=this.explorer.applicationsContent;this.load()},load:function(){this.mask=new MWF.widget.Mask({style:"desktop"});this.mask.loadNode(this.explorer.contentAreaNode);this.actions.listApplications(function(t){Object.each(t.data,function(t,i){this.applications.push(new MWF.xApplication.Setting.applications.Application(this,t,i))}.bind(this));if(this.mask)this.mask.hide()}.bind(this))},destroy:function(){this.applications.each(function(t){t.destroy()}.bind(this));this.content.destroy();MWF.release(this)}});MWF.xApplication.Setting.applications.Application=new Class({Implements:[Events],initialize:function(t,i,e){this.list=t;this.explorer=this.list.explorer;this.app=this.list.explorer.app;this.json=i;this.key=e;this.container=this.list.content;this.css=this.app.css;this.servers=[];this.load()},load:function(){this.node=new Element("div",{styles:this.css.applicationNode}).inject(this.container);this.nameNode=new Element("div",{styles:this.css.applicationNameNode}).inject(this.node);this.iconNode=new Element("div",{styles:this.css.applicationNameIconNode}).inject(this.nameNode);this.textNode=new Element("div",{styles:this.css.applicationNameTextNode}).inject(this.nameNode);this.textNode.set("text",this.key);this.serverListNode=new Element("div",{styles:this.css.applicationServerListNode}).inject(this.node);this.weight=0;var t=0;this.json.each(function(i,e){if(i.weight){this.weight+=i.weight.toFloat();t++}}.bind(this));var i=100;if(t>0){i=this.weight/t}if(t<this.json.length){this.json.each(function(t,e){if(!t.weight)this.weight+=i}.bind(this))}this.json.each(function(t,e){if(!t.weight)t.weight=i;this.servers.push(new MWF.xApplication.Setting.applications.Application.Server(this,t))}.bind(this))},destroy:function(){this.servers.each(function(t){t.destroy()}.bind(this));this.node.destroy();MWF.release(this)}});MWF.xApplication.Setting.applications.Application.Server=new Class({initialize:function(t,i){this.application=t;this.list=this.application.list;this.explorer=this.application.explorer;this.app=this.application.explorer.app;this.json=i;this.container=this.application.serverListNode;this.css=this.app.css;this.load()},load:function(){this.node=new Element("div",{styles:this.css.applicationInServerNode}).inject(this.container);this.tableNode=new Element("div",{styles:this.css.applicationInServerTableNode}).inject(this.node);var t="<table width='100%' cellSpacing='0' cellPadding='0'><tr>"+"<td width='40px'></td>"+"<td style='padding: 0px 5px'>"+this.json.applicationServer+"</td>"+"<td style='padding: 0px 5px'>"+this.json.host+"</td>"+"<td style='padding: 0px 5px'>"+this.json.port+"</td>"+"<td style='padding: 0px 5px'>"+this.json.context+"</td>"+"<td width='80px' style='padding: 0px 5px'>"+this.json.weight+"</td>"+"<td width='40px'></td>"+"</tr></table>";this.tableNode.set("html",t);tds=this.tableNode.getElements("td");tds[0].setStyles(this.css.applicationInServerIconNode);this.editTd=tds[tds.length-1];this.editTd.setStyles(this.css.applicationInServerEditNode);this.jsonNode=new Element("div",{styles:this.css.applicationInServerJsonNode}).inject(this.node);this.jsonButtonNode=new Element("div",{styles:this.css.applicationInServerJsonButtonNode}).inject(this.node);var i=JSON.stringify(this.json,null,"\t");jsonHtml=i.replace(/\n|\r/g,"<br>");jsonHtml=jsonHtml.replace(/\t/g,"<font>&nbsp;&nbsp;&nbsp;&nbsp;</font>");this.jsonNode.set("html",jsonHtml);this.editTd.addEvent("click",function(){if(this.status=="edit"){this.saveWeight()}else{this.editWeight()}}.bind(this));this.jsonButtonNode.addEvent("click",function(){if(this.jsonNode.getStyle("display")=="none"){this.jsonNode.setStyle("display","block");this.jsonButtonNode.setStyle("background","url(/x_component_Setting/$Main/default/icon/up.png) no-repeat center center")}else{this.jsonNode.setStyle("display","none");this.jsonButtonNode.setStyle("background","url(/x_component_Setting/$Main/default/icon/down.png) no-repeat center center")}}.bind(this))},editWeight:function(){tds=this.tableNode.getElements("td");this.editTd.setStyles(this.css.applicationInServerSaveNode);weightTd=tds[tds.length-2];weightTd.empty();this.weightInput=new Element("input",{styles:this.css.applicationInServerWeightInputNode,type:"text"}).inject(weightTd);this.weightInput.set("value",this.json.weight);this.status="edit"},saveWeight:function(){var t=this.weightInput.get("value");t=t.toFloat();if(isNaN(t)){this.app.notice(this.app.lp.saveWeightError,"error");return false}if(t!=this.json.weight){this.json.weight=t;this.app.actions.getAppServer(this.json.applicationServer,function(i){serverJson=i.data;thisAppName=this.json.context.substr(1,this.json.context.lenght);serverJson.planList.each(function(i){if(i.name==thisAppName){i.weight=t}}.bind(this));this.app.actions.updateAppServer(serverJson.name,serverJson,function(){this.saveWeightCompleted()}.bind(this))}.bind(this))}else{this.saveWeightCompleted()}},saveWeightCompleted:function(){tds=this.tableNode.getElements("td");this.editTd.setStyles(this.css.applicationInServerEditNode);weightTd=tds[tds.length-2];weightTd.empty();weightTd.set("text",this.json.weight);this.status="read"},destroy:function(){this.node.destroy();MWF.release(this)}});