MWF.xApplication.AppCenter = MWF.xApplication.AppCenter || {}; MWF.xDesktop.requireApp("AppCenter", "lp."+MWF.language, null, false); MWF.xApplication.AppCenter.Main = new Class({ Extends: MWF.xApplication.Common.Main, Implements: [Options, Events], options: { "style": "default", "name": "AppCenter", "icon": "icon.png", "width": "1000", "height": "700", "title": MWF.xApplication.AppCenter.LP.title }, onQueryLoad: function(){ this.lp = MWF.xApplication.AppCenter.LP; this.actions = MWF.Actions.get("x_program_center"); }, loadApplication: function(callback){ this.components = []; //this.node = new Element("div", {"styles": {"width": "100%", "height": "100%", "overflow": "hidden"}}).inject(this.content); this.loadTitle(); this.contentNode = new Element("div", {"styles": this.css.contentNode}).inject(this.content); this.contentModuleArea = new Element("div", {"styles": this.css.contentModuleArea}).inject(this.contentNode); this.setContentSize(); this.addEvent("resize", this.setContentSize); this.loadModuleContent(); }, loadTitle: function(){ this.titleBar = new Element("div", {"styles": this.css.titleBar}).inject(this.content); if (MWF.AC.isProcessPlatformCreator()){ this.createApplicationNode = new Element("div", { "styles": this.css.createApplicationNode, "title": this.lp.export }).inject(this.titleBar); this.createApplicationNode.addEvent("click", function(){ this.createApplication(); }.bind(this)); this.importApplicationNode = new Element("div", { "styles": this.css.setupApplicationNode, "title": this.lp.setup }).inject(this.titleBar); this.importApplicationNode.addEvent("click", function(){ this.implodeLocal(); }.bind(this)); } this.taskTitleTextNode = new Element("div", {"styles": this.css.titleTextNode,"text": this.lp.title}).inject(this.titleBar); }, implodeLocal: function(){ if (!this.uploadFileAreaNode){ this.uploadFileAreaNode = new Element("div"); var html = ""; this.uploadFileAreaNode.set("html", html); this.fileUploadNode = this.uploadFileAreaNode.getFirst(); this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this)); }else{ if (this.fileUploadNode) this.fileUploadNode.destroy(); this.uploadFileAreaNode.empty(); var html = ""; this.uploadFileAreaNode.set("html", html); this.fileUploadNode = this.uploadFileAreaNode.getFirst(); this.fileUploadNode.addEvent("change", this.implodeLocalFile.bind(this)); } this.fileUploadNode.click(); }, implodeLocalFile: function(){ var files = this.fileUploadNode.files; if (files.length){ var file = files[0]; var position = this.titleBar.getPosition(this.content); var size = this.contentNode.getSize(); var width = size.x*0.9; if (width>600) width = 600; var height = size.y*0.9; var x = (size.x-width)/2; var y = (size.y-height)/2; var setupModule = null; MWF.require("MWF.xDesktop.Dialog", function(){ var dlg = new MWF.xDesktop.Dialog({ "title": this.lp.setupTitle, "style": "appMarket", "top": y+20, "left": x, "fromTop":position.y, "fromLeft": position.x, "width": width, "height": height, "html": "", "maskNode": this.content, "container": this.content, "buttonList": [ { "text": this.lp.ok, "action": function(){ if (setupModule) setupModule.setup(); this.close(); } }, { "text": this.lp.cancel, "action": function(){this.close();} } ] }); dlg.show(); setupModule = new MWF.xApplication.AppCenter.Module.SetupLocal(file, dlg, this); }.bind(this)); } }, setContentSize: function(){ var size = this.content.getSize(); var titleSize = this.titleBar.getSize(); var height = size.y-titleSize.y; this.contentNode.setStyles({"height": ""+height+"px", "overflow": "auto"}); var max = size.x*0.98; var n = (size.x/320).toInt(); var x = n*320; while (x>max){ n--; x = n*320; } this.contentModuleArea.setStyle("width", ""+x+"px"); }, loadModuleContent: function(){ this.actions.listStructure(function(json){ this.moduleList = json.data; if (this.moduleList.length){ this.moduleList.each(function(module){ if( module && module.id ){ new MWF.xApplication.AppCenter.Module(this, module); } }.bind(this)); }else{ this.createEmptyElement(); } }.bind(this)); }, createEmptyElement: function(){ this.emptyNode = new Element("div", {"styles": this.css.emptyNode}).inject(this.contentModuleArea); if (MWF.AC.isProcessPlatformCreator()){ this.emptyNode.set("text", this.lp.emptyModuleManagerInfo); this.emptyNode.addEvent("click", function(){ this.createApplication(); }.bind(this)); }else{ this.emptyNode.set("text", this.lp.emptyModuleInfo); } }, createApplication: function(target,id){ if(id) this.curAppId = id; if(target) this.content = target; new MWF.xApplication.AppCenter.Exporter(this); } }); MWF.xApplication.AppCenter.Module = new Class({ initialize: function(app, data){ this.app = app; this.data = data; this.json = JSON.decode(this.data.data); if (!this.json) this.json = {}; this.json.structure = this.data.id; this.lp = this.app.lp; this.css = this.app.css; this.content = this.app.contentModuleArea; this.load(); }, load: function(){ this.node = new Element("div", {"styles": this.css.moduleNode}).inject(this.content); this.iconNode = new Element("div", {"styles": this.css.moduleIconNode}).inject(this.node); this.contentNode = new Element("div", {"styles": this.css.moduleContentNode}).inject(this.node); this.nameNode = new Element("div", {"styles": this.css.moduleNameNode}).inject(this.contentNode); this.categoryNode = new Element("div", {"styles": this.css.moduleCategoryNode}).inject(this.contentNode); this.descriptionNode = new Element("div", {"styles": this.css.moduleDescriptionNode}).inject(this.contentNode); this.actionNode = new Element("div", {"styles": this.css.moduleActionNode}).inject(this.contentNode); this.viewActionNode = new Element("div", {"styles": this.css.moduleActionNode}).inject(this.contentNode); this.deleteActionNode = new Element("div", {"styles": this.css.moduleDeleteActionNode}).inject(this.contentNode); this.deleteActionNode.set("text", this.lp.delete); this.nameNode.set("text", this.data.name); this.categoryNode.set("text", this.data.createTime); this.descriptionNode.set("text", this.data.description); this.actionNode.set("text", this.lp.output); this.viewActionNode.set("text", this.lp.outputView); this.viewActionNode.setStyle("margin-left", "10px"); this.loadEvent(); }, loadEvent: function(){ this.actionNode.addEvent("click", function(e){ var uri = this.app.actions.action.actions["download"].uri; uri = uri.replace("{flag}", this.json.structure); window.open(o2.filterUrl(this.app.actions.action.address+uri)); }.bind(this)); this.viewActionNode.addEvent("click", function(e){ this.outputApp(); e.stopPropagation(); }.bind(this)); this.node.addEvent("click", function(){ this.openApp(); }.bind(this)); var _self = this; this.deleteActionNode.addEvent("click",function (e) { this.app.confirm("warn", e, "tip", "confirm delete?", 300, 120, function(){ this.structureRes = _self.app.actions.removeStructure(_self.json.structure,function(json){ _self.app.notice("success"); _self.node.destroy(); }.bind(this)); this.close(); }, function(){ this.close(); }, null); }.bind(this)); }, outputApp: function(){ new MWF.xApplication.AppCenter.Exporter(this.app, this.json) }, openApp: function(){ } }); MWF.xApplication.AppCenter.Exporter = new Class({ initialize: function(app, selectData){ this.app = app; this.lp = this.app.lp; this.css = this.app.css; this.structure = null; this.dlg = null; this.selectData = selectData || { "structure": "", "name": "", "description": "", "processPlatformList": [], "portalList": [], "queryList": [], "serviceModuleList": [], "cmsList": [] }; this.setp = 1; this.load(); }, loadStructure: function(){ this.structureRes = this.app.actions.outputStructure(function(json){ if(this.app.curAppId){ var cmsList = json.data.cmsList; var portalList = json.data.portalList; var processPlatformList = json.data.processPlatformList; var queryList = json.data.queryList; var serviceModuleList = json.data.serviceModuleList; var curAppData = { "portalList":[], "cmsList":[], "processPlatformList":[], "queryList":[], "serviceModuleList":[] }; cmsList.each(function (cms) { if(cms.id===this.app.curAppId) { curAppData.cmsList.push(cms); } }.bind(this)); portalList.each(function (portal) { if(portal.id === this.app.curAppId){ curAppData.portalList.push(portal); } }.bind(this)); processPlatformList.each(function (processPlatform) { if(processPlatform.id===this.app.curAppId){ curAppData.processPlatformList.push(processPlatform) } }.bind(this)); queryList.each(function (query) { if(query.id===this.app.curAppId) { curAppData.queryList.push(query); } }.bind(this)); serviceModuleList.each(function (service) { if(service.id===this.app.curAppId) { curAppData.serviceModuleList.push(service); } }.bind(this)); this.structure = curAppData; }else{ this.structure = json.data; } this.createContent(); }.bind(this)); }, showDlg: function(callback){ var position = this.app.createApplicationNode.getPosition(this.app.content); var size = this.app.content.getSize(); var width = size.x*0.9; if (width>600) width = 600; var height = size.y*0.8; var x = (size.x-width)/2; var y = (size.y-height)/2; if (y<80) y = 80; var _self = this; MWF.require("MWF.xDesktop.Dialog", function(){ this.dlg = new MWF.xDesktop.Dialog({ "title": this.lp.exportTitle, "style": "appCenter", "top": y+20, "left": x, "fromTop":position.y, "fromLeft": position.x, "width": width, "height": height, "html": "", "maskNode": this.app.content, "container": this.app.content, "buttonList": [ { "text": this.lp.next, "action": function(){ _self.next(); //this.close(); } }, { "text": this.lp.prev, "action": function(){ _self.prev(); //this.close(); } }, { "text": this.lp.ok, "action": function(){ _self.output(); //this.close(); } }, { "text": this.lp.cancel, "action": function(){ this.close(); if (_self.structureRes && _self.structureRes.res){ if (_self.structureRes.res.isRunning()){_self.structureRes.res.cancel();} _self.structureRes = null; } } } ], "onPostShow": function(){ if (callback) callback(); }.bind(this), "onPostClose": function() { if(_self.app){ _self.app.fireEvent("exporterClose"); } MWF.release(_self); } }); this.dlg.show(); }.bind(this)); }, checkInput: function(){ var name = this.moduleNameInput.get("value"); var category = this.moduleCategoryInput.get("value"); var description = this.moduleDescriptionInput.get("value"); if (!name){ this.app.notice(this.lp.noNameError, "error"); return false; } if (!this.selectData.processPlatformList.length && !this.selectData.portalList.length && !this.selectData.queryList.length && !this.selectData.serviceModuleList.length && !this.selectData.cmsList.length){ this.app.notice(this.lp.noModuleError, "error"); return false; } this.selectData.name = name; this.selectData.category = category; this.selectData.description = description; return true; }, next: function(){ if (this.setp==1){ if (this.checkInput()) this.showStatus(); } }, prev: function(){ if (this.step==2){ if (this.statusContentNode){ this.statusContentNode.destroy(); this.statusContentNode = null; } this.contentNode.setStyle("display", "block"); this.okBut.setStyle("display", "none"); this.prevBut.setStyle("display", "nonde"); this.nextBut.setStyle("display", "inline"); } }, output: function(){ if (this.step==2){ if (this.checkInput()){ MWF.require("o2.widget.Mask", function(){ this.mask = new o2.widget.Mask(); this.mask.loadNode(this.dlg.node); this.app.actions.output(this.selectData, function(json){ var uri = this.app.actions.action.actions["download"].uri; uri = uri.replace("{flag}", json.data.flag); if (this.mask) this.mask.hide(); this.dlg.close(); window.open(o2.filterUrl(this.app.actions.action.address+uri)); this.app.fireEvent("exporterClose"); MWF.release(this); }.bind(this), function(xhr, text, error){ if (xhr.status!=0){ var errorText = error; if (xhr){ var json = JSON.decode(xhr.responseText); if (json){ errorText = json.message.trim() || "request json error"; }else{ errorText = "request json error: "+xhr.responseText; } } MWF.xDesktop.notice("error", {x: "right", y:"top"}, errorText); } if (this.mask) this.mask.hide(); }.bind(this)); }.bind(this)); } } }, showStatus: function(){ this.statusContentNode = new Element("div", {"styles": this.css.moduleSelectContentAreaNode}).inject(this.contentNode, "after"); this.statusTitleNode = new Element("div", {"styles": this.css.moduleSelectTitleNode, "text": this.lp.selected}).inject(this.statusContentNode); this.statusInfoNode = new Element("div", {"styles": this.css.moduleSelectContentNode}).inject(this.statusContentNode); var size = this.contentNode.getSize(); var position = this.contentNode.getPosition(this.contentNode.getOffsetParent()); var css = { "height": ""+size.y+"px", "width": ""+size.x+"px", "top": ""+position.y+"px", "left": ""+position.x+"px", "background-color": "#eeeeee" }; this.statusContentNode.setStyles(css); var titleSize = this.statusTitleNode.getSize(); var h = size.y-titleSize.y-20; this.statusInfoNode.setStyle("height", ""+h+"px"); this.showStatusList(); this.contentNode.setStyle("display", "none"); this.okBut.setStyle("display", "inline"); this.prevBut.setStyle("display", "inline"); this.nextBut.setStyle("display", "none"); this.step = 2; }, showStatusList: function(){ this.showStatusItemList("processPlatformList", ["processList", "formList", "applicationDictList", "scriptList", "fileList"]); this.showStatusItemList("portalList", ["pageList", "scriptList", "widgetList", "applicationDictList","fileList"]); this.showStatusItemList("cmsList", ["categoryInfoList", "formList", "appDictList", "scriptList"]); this.showStatusItemList("queryList", ["viewList", "statList", "tableList", "statementList", "importModelList"]); this.showStatusItemList("serviceModuleList", ["agentList", "invokeList", "scriptList", "dictList"]); }, showStatusItemList: function(listName, subList){ this.selectData[listName].each(function(app){ new Element("div", {"styles": this.css.moduleStatusInforNode1, "text": "["+this.lp[listName]+"] "+(app.name || app.appName)}).inject(this.statusInfoNode); subList.each(function(name){ if (app[name] && app[name].length) app[name].each(function(process){ new Element("div", {"styles": this.css.moduleStatusInforNode2, "text": "["+this.lp[name]+"] "+(process.name || process.categoryName)}).inject(this.statusInfoNode); }.bind(this)); }.bind(this)); }.bind(this)); }, load: function(){ this.showDlg(function(){ this.createLayout(); this.loadStructure(); }.bind(this)); }, createLayout: function(){ this.nextBut = this.dlg.button.getFirst("input"); this.prevBut = this.nextBut.getNext("input"); this.okBut = this.prevBut.getNext("input"); if (this.setp==1){ this.okBut.setStyle("display", "none"); this.prevBut.setStyle("display", "none"); } this.node = new Element("div", {"styles": this.css.moduleSetupContentNode}).inject(this.dlg.content); this.titleNode = new Element("div", {"styles": this.css.moduleSetupTitleNode}).inject(this.node); var iconNode = new Element("div", {"styles": this.css.moduleIconNode}).inject(this.titleNode); var contentNode = new Element("div", {"styles": this.css.moduleSetupTitleContentNode}).inject(this.titleNode); var nameNode = new Element("div", {"styles": this.css.moduleSetupNameNode}).inject(contentNode); var categoryNode = new Element("div", {"styles": this.css.moduleSetupCategoryNode}).inject(contentNode); categoryNode.hide(); var descriptionNode = new Element("div", {"styles": this.css.moduleSetupDescriptionNode}).inject(contentNode); var nameTitleNode = new Element("div", {"styles": this.css.moduleInputTitleNode, "text": this.lp.moduleName}).inject(nameNode); var nameContentNode = new Element("div", {"styles": this.css.moduleInputContentNode}).inject(nameNode); this.moduleNameInput = new Element("input", {"styles": this.css.moduleInputNode}).inject(nameContentNode); var categoryTitleNode = new Element("div", {"styles": this.css.moduleInputTitleNode, "text": this.lp.moduleCategory}).inject(categoryNode); var categoryContentNode = new Element("div", {"styles": this.css.moduleInputContentNode}).inject(categoryNode); this.moduleCategoryInput = new Element("input", {"styles": this.css.moduleInputNode}).inject(categoryContentNode); var descriptionTitleNode = new Element("div", {"styles": this.css.moduleInputTitleNode, "text": this.lp.moduleDescription}).inject(descriptionNode); var descriptionContentNode = new Element("div", {"styles": this.css.moduleInputContentNode}).inject(descriptionNode); this.moduleDescriptionInput = new Element("input", {"styles": this.css.moduleInputNode}).inject(descriptionContentNode); this.moduleNameInput.set("value", this.selectData.name); this.moduleCategoryInput.set("value", this.selectData.category); this.moduleDescriptionInput.set("value", this.selectData.description); this.contentNode = new Element("div", {"styles": this.css.moduleSetupCompareContentNode}).inject(this.node); this.setListContentSize(); this.createLoading(this.contentNode); }, setListContentSize: function(){ var size = this.dlg.content.getSize(); var h = size.y; var titleH = this.titleNode.getSize().y+10; var contentH = h-titleH-10; this.contentNode.setStyle("height", ""+contentH+"px"); }, createLoading: function(node){ //this.okBut.setStyle("display", "none"); this.nextBut.setStyle("display", "none"); this.loadingAreaNode = new Element("div", {"styles": this.css.moduleLoadingAreaNode}).inject(node); var img = new Element("img", { "styles": this.css.moduleLoadingImgNode, "src": this.app.path+this.app.options.style+"/icon/loading.gif" }).inject(this.loadingAreaNode); }, clearLoading: function(){ if (this.loadingAreaNode){ this.loadingAreaNode.destroy(); this.loadingAreaNode = null; } //this.okBut.setStyle("display", "inline"); this.nextBut.setStyle("display", "inline"); }, createContent: function(){ this.clearLoading(); this.createListArea(); this.loadProcessList(); this.loadPortalList(); this.loadCMSList(); this.loadQueryList(); this.loadServiceList(); //this.structure }, createListArea: function(){ this.contentAreaNode = new Element("div").inject(this.contentNode); // this.contentInforNode = new Element("div", {"styles": this.css.moduleSetupContentInforNode, "text": this.lp.selectModules}).inject(this.contentAreaNode); // //this.processArea = new Element("div", {"styles": this.css.moduleSetupListAreaNode}).inject(this.contentNode); // // this.listAreaNode = new Element("div").inject(this.contentAreaNode); this.processAreaTitle = new Element("div.moduleSetupListAreaTitle", {"styles": this.css.moduleSetupListAreaTitleNode, "text": this.lp.process, "data-type":"process"}).inject(this.contentAreaNode); this.processAreaContent = new Element("div.", {"styles": this.css.moduleSetupListAreaContentNode}).inject(this.contentAreaNode); this.portalAreaTitle = new Element("div.moduleSetupListAreaTitle", {"styles": this.css.moduleSetupListAreaTitleNode, "text": this.lp.portal, "data-type":"portal"}).inject(this.contentAreaNode); this.portalAreaContent = new Element("div", {"styles": this.css.moduleSetupListAreaContentNode}).inject(this.contentAreaNode); this.cmsAreaTitle = new Element("div.moduleSetupListAreaTitle", {"styles": this.css.moduleSetupListAreaTitleNode, "text": this.lp.cms, "data-type":"cms"}).inject(this.contentAreaNode); this.cmsAreaContent = new Element("div", {"styles": this.css.moduleSetupListAreaContentNode}).inject(this.contentAreaNode); this.queryAreaTitle = new Element("div.moduleSetupListAreaTitle", {"styles": this.css.moduleSetupListAreaTitleNode, "text": this.lp.query, "data-type":"query"}).inject(this.contentAreaNode); this.queryAreaContent = new Element("div", {"styles": this.css.moduleSetupListAreaContentNode}).inject(this.contentAreaNode); this.serviceAreaTitle = new Element("div.moduleSetupListAreaTitle", {"styles": this.css.moduleSetupListAreaTitleNode, "text": this.lp.service, "data-type":"service"}).inject(this.contentAreaNode); this.serviceAreaContent = new Element("div", {"styles": this.css.moduleSetupListAreaContentNode}).inject(this.contentAreaNode); this.contentAreaNode.getElements(".moduleSetupListAreaTitle").each(function (node){ debugger; var spanNode = new Element("div",{ styles: { "float": "left", "padding-right": "10px", "cursor": "pointer", "width": "24px", "height": "30px", "background": "url("+this.app.path+this.app.options.style+"/icon/arrow_down.png) center center no-repeat" } }).inject(node, "top"); spanNode.addEvent("click",function (ev){ if(spanNode.retrieve("collapse")){ node.getNext().show(); spanNode.store("collapse", false); spanNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/arrow_down.png)"); }else { node.getNext().hide(); spanNode.store("collapse", true); spanNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/arrow_up.png)"); } ev.stopPropagation(); }.bind(this)); node.addEvent("click",function (){ if(spanNode.retrieve("collapse")){ node.getNext().show(); spanNode.store("collapse", false); spanNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/arrow_down.png)"); }else { node.getNext().hide(); spanNode.store("collapse", true); spanNode.setStyle("background-image", "url("+this.app.path+this.app.options.style+"/icon/arrow_up.png)"); } }.bind(this)); var inverseAction = new Element("div", {"styles": this.css.moduleSelectContentTitleButtonActionNode, "text": this.lp.inverse}).inject(node); inverseAction.addEvent("click", function(ev){ var type = node.get("data-type"); this[type+"ListNodes"].each(function( element ){ element.selectAll( false ); }.bind(this)); ev.stopPropagation(); }.bind(this)); var selectAllAction = new Element("div", {"styles": this.css.moduleSelectContentTitleButtonActionNode, "text": this.lp.selectAll}).inject(node); selectAllAction.addEvent("click", function(ev){ var type = node.get("data-type"); this[type+"ListNodes"].each(function( element ){ element.selectAll( true ); }.bind(this)); ev.stopPropagation(); }.bind(this)); }.bind(this)); }, loadProcessList: function(){ this.processListNodes = []; this.structure.processPlatformList.each(function(item){ var postData = null; for (var i=0; i"; options += ""; options += ""; this.action.set("html", options); // this.action.addEvent("change", function(e){ // // }.bind(this)); }else{ this.action = new Element("select", {"styles": this.css.moduleSetupListActionSelectNode}).inject(this.actionNode); var options = ""; options += ""; this.action.set("html", options); //this.inforNode.set("text", this.lp.setup); } }, getNameContent: function(){ return { "title": this.lp.name+": "+this.data.name+" "+this.lp.id+": "+this.data.id, "text": this.data.name } } }); MWF.xApplication.AppCenter.Module.Setup.ProcessElement = new Class({ Extends: MWF.xApplication.AppCenter.Module.Setup.Element }); MWF.xApplication.AppCenter.Module.Setup.PortalElement = new Class({ Extends: MWF.xApplication.AppCenter.Module.Setup.Element }); MWF.xApplication.AppCenter.Module.Setup.CmsElement = new Class({ Extends: MWF.xApplication.AppCenter.Module.Setup.Element }); MWF.xApplication.AppCenter.Module.Setup.QueryElement = new Class({ Extends: MWF.xApplication.AppCenter.Module.Setup.Element }); MWF.xApplication.AppCenter.Module.Setup.ServiceElement = new Class({ Extends: MWF.xApplication.AppCenter.Module.Setup.Element });