MWF.xApplication.portal.PageDesigner.Module = MWF.xApplication.portal.PageDesigner.Module || {}; MWF.require("MWF.widget.Common", null, false); MWF.xApplication.portal.PageDesigner.Module.Page = MWF.PCPage = new Class({ Extends: MWF.widget.Common, Implements: [Options, Events], options: { "style": "default", "propertyPath": "../x_component_portal_PageDesigner/Module/Page/page.html", "mode": "PC", "fields": [ "Calendar", "Checkbox", "Datagrid", "Datagrid$Title", "Datagrid$Data", "Datatable", "Datatable$Title", "Datatable$Data", "Datatemplate","Htmleditor", "TinyMCEEditor","Number", "Currency", "Office", "Orgfield", "Org", "Personfield", "Radio", "Select", "Textarea", "Textfield","Address","Combox", "Elcascader", "Elcheckbox", "Elcolorpicker", "Eldate", "Eldatetime", "Elinput", "Elnumber", "Elradio", "Elrate", "Elselect", "Elslider", "Elswitch", "ElTime" ], "injectActions" : [ { "name" : "top", "styles" : "injectActionTop", "event" : "click", "action" : "injectTop", "title": MWF.APPPOD.LP.formAction["insertTop"] }, { "name" : "bottom", "styles" : "injectActionBottom", "event" : "click", "action" : "injectBottom", "title": MWF.APPPOD.LP.formAction["insertBottom"] } ] }, initializeBase: function(options){ this.setOptions(options); this.path = "../x_component_portal_PageDesigner/Module/Page/"; this.cssPath = "../x_component_portal_PageDesigner/Module/Page/"+this.options.style+"/css.wcss"; this._loadCss(); }, initialize: function(designer, container, options){ this.initializeBase(options); this.container = null; this.page = this; this.form = this; this.moduleType = "page"; this.moduleList = []; this.moduleNodeList = []; this.moduleContainerNodeList = []; this.moduleElementNodeList = []; this.moduleComponentNodeList = []; // this.moduleContainerList = []; this.dataTemplate = {}; this.designer = designer; this.container = container; this.selectedModules = []; }, reload: function(data){ this.moduleList.each(function(module){ if (module.property){ module.property.destroy(); } }.bind(this)); if (this.property) this.property.destroy(); this.property = null; this.moduleList = []; this.moduleNodeList = []; this.moduleContainerNodeList = []; this.moduleElementNodeList = []; this.moduleComponentNodeList = []; this.dataTemplate = {}; this.selectedModules = []; this.container.empty(); this.widgetList = null; if(this.options.parentpageIdList)this.options.parentpageIdList = null; if (this.treeNode){ this.domTree.empty(); this.domTree.node.destroy(); this.domTree = null; this.treeNode = null; } if( this.history ){ this.history.destroy(); this.history = null; } this.currentSelectedModule = null; this.propertyMultiTd = null; if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID); this.load(data); }, load : function(data){ this.data = data; this.json = data.json; this.html = data.html; this.json.mode = this.options.mode; if (!this.json.css) this.json.css = {"code":""}; this.isNewPage = (this.json.id) ? false : true; if (this.isNewPage) this.checkUUID(); if(this.designer.application) this.data.json.applicationName = this.designer.application.name; if(this.designer.application) this.data.json.application = this.designer.application.id; this.container.set("html", this.html); this.loadStylesList(function(){ var oldStyleValue = ""; if ((!this.json.pageStyleType) || !this.stylesList[this.json.pageStyleType]) this.json.pageStyleType="blue-simple"; if (this.options.mode=="Mobile"){ if (this.json.pageStyleType != "defaultMobile"){ oldStyleValue = this.json.pageStyleType; this.json.pageStyleType = "defaultMobile"; } } this.templateStyles = (this.stylesList && this.json.pageStyleType) ? this.stylesList[this.json.pageStyleType] : null; this.loadDomModules(); if (this.json.pageStyleType){ if (this.stylesList[this.json.pageStyleType]){ if (this.stylesList[this.json.pageStyleType]["page"]){ this.setTemplateStyles(this.stylesList[this.json.pageStyleType]["page"]); } } } this.setCustomStyles(); this.node.setProperties(this.json.properties); this.setNodeEvents(); if (this.options.mode=="Mobile"){ if (oldStyleValue) this._setEditStyle("pageStyleType", null, oldStyleValue); } this.selected(); this.autoSave(); this.designer.addEvent("queryClose", function(){ if (this.autoSaveTimerID) window.clearInterval(this.autoSaveTimerID); }.bind(this)); this.loadHistory(); this.fireEvent("postLoad"); }.bind(this)); }, removeStyles: function(from, to){ if (this.json[to]){ Object.each(from, function(style, key){ if (this.json[to][key] && this.json[to][key]==style){ delete this.json[to][key]; } }.bind(this)); } }, copyStyles: function(from, to){ if (!this.json[to]) this.json[to] = {}; Object.each(from, function(style, key){ if (!this.json[to][key]) this.json[to][key] = style; }.bind(this)); }, clearTemplateStyles: function(styles){ if (styles){ if (styles.styles) this.removeStyles(styles.styles, "styles"); if (styles.properties) this.removeStyles(styles.properties, "properties"); } }, setTemplateStyles: function(styles){ if (styles.styles) this.copyStyles(styles.styles, "styles"); if (styles.properties) this.copyStyles(styles.properties, "properties"); }, loadStylesList: function(callback){ var stylesUrl = "../x_component_portal_PageDesigner/Module/Page/template/"+((this.options.mode=="Mobile") ? "styles": "styles")+".json"; MWF.getJSON(stylesUrl,{ "onSuccess": function(responseJSON){ this.stylesList= responseJSON; if (callback) callback(this.stylesList); }.bind(this), "onRequestFailure": function(){ this.stylesList = {}; if (callback) callback(this.stylesList); }.bind(this), "onError": function(){ this.stylesList = {}; if (callback) callback(this.stylesList); }.bind(this) } ); }, autoSave: function(){ this.autoSaveCheckNode = this.designer.pageToolbarNode.getElement("#MWFPageAutoSaveCheck"); if (this.autoSaveCheckNode){ this.autoSaveTimerID = window.setInterval(function(){ if (this.autoSaveCheckNode.get("checked")){ this.save(); } }.bind(this), 60000); } }, loadHistory: function(){ o2.xDesktop.requireApp("process.FormDesigner", "History", function () { this.history = new MWF.xApplication.process.FormDesigner.History(this, this.designer.currentHistoryNode); this.history.load(); }.bind(this)); }, checkPropertyHistory: function(name, oldValue, newValue, notSetEditStyle, compareName, force){ if( !this.history )return null; var log = { "type": "property", "force": force, "moduleId": "form", "moduleType": "form", "notSetEditStyle": notSetEditStyle, "changeList": [ { "name": name, "compareName": compareName, "fromValue": oldValue, "toValue": newValue || this.json[name] } ] }; this.history.checkProperty(log, this); }, checkMultiPropertyHistory: function(name, oldValueList, newValue, modules){ if( !this.history )return null; var log = { "type": "multiProperty", "moduleId": "form", "changeList": modules.map(function (module, i) { return { "module": module, "name": name, "fromValue": oldValueList[i], "toValue": newValue || module.json[name] } }) }; this.history.checkMultiProperty(log, modules); }, checkUUID: function(){ this.designer.actions.getUUID(function(id){ this.json.id = id; }.bind(this)); }, loadDomModules: function(){ this.node = this.container.getFirst(); this.node.set("id", this.json.id); this.node.setStyles(this.css.pageNode); this.node.store("module", this); var id = this.json.id.replace(/\-/g, ""); ( this.node.get("class") || "" ).split(" ").each(function(className){ if( className.indexOf("css") === 0 && className.length === 35 ){ this.node.removeClass(className); } }.bind(this)); this.node.addClass("css"+id); this.reloadCss(); var y = this.container.getStyle("height"); y = (y) ? y.toInt()-2 : this.container.getSize().y-2; this.node.setStyle("min-height", ""+y+"px"); this.designer.addEvent("resize", function(){ var y = this.container.getStyle("height"); y = (y) ? y.toInt()-2 : this.container.getSize().y-2; this.node.setStyle("min-height", ""+y+"px"); }.bind(this)); this.loadDomTree(); }, loadDomTree: function(){ MWF.require("MWF.widget.Tree", function(){ this.domTree = new MWF.widget.Tree(this.designer.propertyDomArea, {"style": "domtree"}); this.domTree.load(); this.createPageTreeNode(); this.parseModules(this, this.node); }.bind(this)); }, createPageTreeNode: function(){ var text = "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] "; var o = { "expand": true, "title": this.json.id, "text": "<"+this.json.type+"> "+this.json.name+" ["+this.options.mode+"] ", "icon": (this.options.mode=="Mobile") ? "mobile.png": "pc.png" }; o.action = function(){ if (this.module) this.module.selected(); }; this.treeNode = this.domTree.appendChild(o); this.treeNode.setText(text); this.treeNode.module = this; }, getModuleNodes: function (dom, ignoreMultipleModule) { var moduleNodes = []; var subDom = dom.getFirst(); while (subDom) { var mwftype = subDom.get("MWFtype") || subDom.get("mwftype"); if (mwftype) { if( ignoreMultipleModule ){ var type = mwftype; if ( type.indexOf("$") === -1)moduleNodes.push(subDom); }else{ moduleNodes.push(subDom); } moduleNodes = moduleNodes.concat(this.getModuleNodes(subDom)); } else { moduleNodes = moduleNodes.concat(this.getModuleNodes(subDom)); } subDom = subDom.getNext(); } return moduleNodes; }, // parseModules: function(parent, dom){ // var tmpDom = null; // var subDom = dom.getFirst(); // while (subDom){ // if (subDom.get("MWFtype")){ // var json = this.getDomjson(subDom); // if (json) module = this.loadModule(json, subDom, parent); // } // if (!json) tmpDom = subDom; // subDom = subDom.getNext(); // // if (tmpDom){ // tmpDom.destroy(); // tmpDom = null; // } // } // }, parseModules: function(parent, dom){ var moduleNodes = []; var subDom = dom.getFirst(); while (subDom){ if (subDom.get("MWFtype")){ var json = this.getDomjson(subDom); var moduleNode = subDom; moduleNodes.push({"dom": moduleNode, "json": json}); } subDom = subDom.getNext(); } moduleNodes.each(function(obj){ module = this.loadModule(obj.json, obj.dom, parent); }.bind(this)); }, getDomjson: function(dom){ var mwfType = dom.get("MWFtype"); switch (mwfType) { case "page": return this.json; case "": return null; default: var id = dom.get("id"); if (id){ return this.json.moduleList[id]; }else{ return null; } } }, loadModule: function(json, dom, parent){ var module; if (json) { if( json.events ){ module = new MWF["PC" + json.type](this); module.load(json, dom, parent); }else{ var className = json.type.capitalize(); this.getTemplateData(className, function(data){ json.events = Object.clone(data.events); module = new MWF["PC" + json.type](this); module.load(json, dom, parent); }.bind(this), false); } } return module; }, setNodeEvents: function(){ this.node.addEvent("click", function(e){ this.selected(); }.bind(this)); }, createModuleImmediately: function( className, parentModule, relativeNode, position, selectDisabled, async ){ var module; this.getTemplateData(className, function(data){ var moduleData = Object.clone(data); module = new MWF["PC"+className](this); if( parentModule ){ module.onDragModule = parentModule; if (!parentModule.Component) module.inContainer = parentModule; module.parentContainer = parentModule; module.nextModule = null; } module.createImmediately(moduleData, relativeNode, position, selectDisabled); }.bind(this), async); return module; }, createModule: function(className, e){ this.getTemplateData(className, function(data){ var moduleData = Object.clone(data); var newTool = new MWF["PC"+className](this); newTool.create(moduleData, e); }.bind(this)); }, getTemplateData: function(className, callback, async){ debugger; if (this.dataTemplate[className]){ if (callback) callback(this.dataTemplate[className]); }else{ var modulePath = ( MWF["PC"+className] && MWF["PC"+className].templateJsonPath ) || "../x_component_portal_PageDesigner/Module/"; var templateUrl = modulePath + className+"/template.json"; MWF.getJSON(templateUrl, function(responseJSON, responseText){ this.dataTemplate[className] = responseJSON; if (callback) callback(responseJSON); }.bind(this), async); } }, selected: function(){ if (this.currentSelectedModule){ if (this.currentSelectedModule==this){ return true; }else{ this.currentSelectedModule.unSelected(); } } if (this.propertyMultiTd){ this.propertyMultiTd.hide(); this.propertyMultiTd = null; } this.unSelectedMulti(); this.currentSelectedModule = this; if (this.treeNode){ this.treeNode.selectNode(); } this.showProperty(); // this.isFocus = true; }, unSelectedMulti: function(){ while (this.selectedModules.length){ this.selectedModules[0].unSelectedMulti(); } if (this.multimoduleActionsArea) this.multimoduleActionsArea.setStyle("display", "none"); }, unSelectAll: function(){ }, _beginSelectMulti: function(){ if (this.currentSelectedModule) this.currentSelectedModule.unSelected(); this.unSelectedMulti(); this.noSelected = true; }, _completeSelectMulti: function(){ if (this.selectedModules.length<2){ this.selectedModules[0].selected(); }else{ this._showMultiActions(); } }, createMultimoduleActionsArea: function(){ this.multimoduleActionsArea = new Element("div", { styles: { "display": "none", // "width": 18*this.options.actions.length, "position": "absolute", "background-color": "#F1F1F1", "padding": "1px", "padding-right": "0px", "border": "1px solid #AAA", "box-shadow": "0px 2px 5px #999", "z-index": 10001 } }).inject(this.page.container, "after"); }, _showMultiActions: function(){ if (!this.multimoduleActionsArea) this.createMultimoduleActionsArea(); var firstModule = this._getFirstMultiSelectedModule(); if (firstModule){ // var module = firstModule.module; var y = firstModule.position.y-25; var x = firstModule.position.x; this.multimoduleActionsArea.setPosition({"x": x, "y": y}); this.multimoduleActionsArea.setStyle("display", "block"); } }, _getFirstMultiSelectedModule: function(){ var firstModule = null; this.selectedModules.each(function(module){ var position = module.node.getPosition(module.form.node.getOffsetParent()); if (!firstModule){ firstModule = {"module": module, "position": position}; }else{ if (position.y "+title+" ["+this.options.mode+"] "); } if (name=="id"){ if (!this.json.name) this.treeNode.setText("<"+this.json.type+"> "+this.json.id+" ["+this.options.mode+"] "); this.treeNode.setTitle(this.json.id); this.node.set("id", this.json.id); } if (name=="pageStyleType"){ this.templateStyles = (this.stylesList && this.json.pageStyleType) ? this.stylesList[this.json.pageStyleType] : null; if (oldValue) { var oldTemplateStyles = this.stylesList[oldValue]; if (oldTemplateStyles){ if (oldTemplateStyles["page"]) this.clearTemplateStyles(oldTemplateStyles["page"]); } } if (this.templateStyles){ if (this.templateStyles["page"]) this.setTemplateStyles(this.templateStyles["page"]); } this.setAllStyles(); this.moduleList.each(function(module){ if (oldTemplateStyles){ module.clearTemplateStyles(oldTemplateStyles[module.moduleName]); } module.setStyleTemplate(); module.setAllStyles(); }.bind(this)); } if (name==="css"){ this.reloadCss(); } this._setEditStyle_custom(name, obj, oldValue); }, parseCSS: function(css){ var rex = /(url\(.*\))/g; var match; while ((match = rex.exec(css)) !== null) { var pic = match[0]; var len = pic.length; var s = pic.substring(pic.length-2, pic.length-1); var n0 = (s==="'" || s==="\"") ? 5 : 4; var n1 = (s==="'" || s==="\"") ? 2 : 1; pic = pic.substring(n0, pic.length-n1); if ((pic.indexOf("x_processplatform_assemble_surface")!=-1 || pic.indexOf("x_portal_assemble_surface")!=-1)){ var host1 = MWF.Actions.getHost("x_processplatform_assemble_surface"); var host2 = MWF.Actions.getHost("x_portal_assemble_surface"); if (pic.indexOf("/x_processplatform_assemble_surface")!==-1){ pic = pic.replace("/x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface"); }else if (pic.indexOf("x_processplatform_assemble_surface")!==-1){ pic = pic.replace("x_processplatform_assemble_surface", host1+"/x_processplatform_assemble_surface"); } if (pic.indexOf("/x_portal_assemble_surface")!==-1){ pic = pic.replace("/x_portal_assemble_surface", host2+"/x_portal_assemble_surface"); }else if (pic.indexOf("x_portal_assemble_surface")!==-1){ pic = pic.replace("x_portal_assemble_surface", host2+"/x_portal_assemble_surface"); } pic = o2.filterUrl(pic); } pic = "url('"+pic+"')"; var len2 = pic.length; css = css.substring(0, match.index) + pic + css.substring(rex.lastIndex, css.length); rex.lastIndex = rex.lastIndex + (len2-len); } return css; }, reloadCss: function(){ var cssText = (this.json.css) ? this.json.css.code : ""; //var head = (document.head || document.getElementsByTagName("head")[0] || document.documentElement); var styleNode = $("design_style"+this.json.id); if (styleNode) styleNode.destroy(); if (cssText){ //删除注释 cssText = cssText.replace(/\/\*[\s\S]*?\*\/\n|([^:]|^)\/\/.*\n$/g, '').replace(/\\n/, ''); cssText = this.parseCSS(cssText); var rex = new RegExp("(.+)(?=\\{)", "g"); var match; var id = this.json.id.replace(/\-/g, ""); var prefix = ".css" + id + " "; while ((match = rex.exec(cssText)) !== null) { var rulesStr = match[0]; var startWith = rulesStr.substring(0, 1); if (startWith === "@" || startWith === ":" || rulesStr.indexOf("%") !== -1) { }else if (rulesStr.trim()==='from' || rulesStr.trim()==='to'){ } else { if (rulesStr.indexOf(",")!=-1){ //var rules = rulesStr.split(/\s*,\s*/g); var rules = rulesStr.split(/,/g); rules = rules.map(function(r){ return prefix + r; }); var rule = rules.join(","); cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length); rex.lastIndex = rex.lastIndex + (prefix.length*rules.length); }else{ var rule = prefix + match[0]; cssText = cssText.substring(0, match.index) + rule + cssText.substring(rex.lastIndex, cssText.length); rex.lastIndex = rex.lastIndex + prefix.length; } } } var styleNode = document.createElement("style"); styleNode.setAttribute("type", "text/css"); styleNode.id="design_style"+this.json.id; styleNode.inject(this.container, "before"); if(styleNode.styleSheet){ var setFunc = function(){ styleNode.styleSheet.cssText = cssText; }; if(styleNode.styleSheet.disabled){ setTimeout(setFunc, 10); }else{ setFunc(); } }else{ var cssTextNode = document.createTextNode(cssText); styleNode.appendChild(cssTextNode); } } }, setAllStyles: function(){ this.setPropertiesOrStyles("styles"); this.setPropertiesOrStyles("properties"); this.reloadMaplist(); }, reloadMaplist: function(){ if (this.property) Object.each(this.property.maplists, function(map, name){ map.reload(this.json[name]);}.bind(this)); }, _setEditStyle_custom: function(){ }, saveAsTemplete: function(){ }, checkModuleId: function(id, type, currentSubform){ var fieldConflict = false; var elementConflict = false; if (this.json.moduleList[id]){ elementConflict = true; if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(this.json.moduleList[id].type)!=-1){ fieldConflict = true; } return {"fieldConflict": fieldConflict, "elementConflict": elementConflict}; } // if (this.subformList){ // Object.each(this.subformList, function(subform){ // if (!currentSubform || currentSubform!=subform.id){ // if (subform.moduleList[id]){ // elementConflict = true; // if (this.options.fields.indexOf(type)!=-1 || this.options.fields.indexOf(subform.moduleList[id].type)!=-1){ // fieldConflict = true; // } // } // } // }.bind(this)); // } return {"fieldConflict": fieldConflict, "elementConflict": elementConflict}; }, //脚本附签上的脚本编辑器 addScriptJsEditor: function (propertyName, jsEditor) { if( !this.scriptJsEditors )this.scriptJsEditors = {}; this.scriptJsEditors[propertyName] = jsEditor; }, getScriptJsEditor: function (propertyName) { if( !this.scriptJsEditors ){ return null; }else{ return this.scriptJsEditors[propertyName]; } }, showFormVersion: function(){ this.versionNode = new Element("div"); this.dlg = o2.DL.open({ "title": MWF.APPFD.LP.version["title"], "content": this.versionNode, "offset": {"y": -100}, "isMax": false, "width": 500, "height": 300, "buttonList": [ { "type": "cancel", "text": MWF.APPFD.LP.version["close"], "action": function(){ this.close(); } } ], "onPostShow": function(){ this.loadVersionList(); }.bind(this), "onPostClose": function(){ this.dlg = null; }.bind(this) }); }, loadVersionList : function(){ var tableHtml = "" + "" + "" + "" + "" + "
"+MWF.APPPOD.LP.version["no"]+""+MWF.APPPOD.LP.version["person"]+""+MWF.APPPOD.LP.version["updateTime"]+""+MWF.APPPOD.LP.version["op"]+"
"; this.versionNode.set("html", tableHtml); this.versionTable = this.versionNode.getElement("table"); o2.Actions.load("x_portal_assemble_designer").PageVersionAction.listWithPage(this.form.json.id, function(json){ this.versionList = json.data; this.versionList.sort(function (a, b) { return new Date(b.updateTime) - new Date(a.updateTime) }); this.versionList.each(function (version,index) { var node = new Element("tr").inject(this.versionTable); var html = ""+(index+1)+"" + ""+version.person+"" + ""+version.updateTime+"" + ""; node.set("html", html); var actionNode = new Element("div",{"styles":{ "width": "60px", "padding": "0px 3px", "border-radius": "20px", "cursor" : "pointer", "color": "#ffffff", "background-color": "#4A90E2", "float": "left", "margin-right": "2px", "text-align": "center", "font-weight": "100" }}).inject(node.getLast("td")); actionNode.set("text", MWF.APPPOD.LP.version["resume"]); actionNode.addEvent("click",function (e) { var _self = this; this.designer.confirm("warn", e, MWF.APPPOD.LP.version["resumeConfirm"], MWF.APPPOD.LP.version["resumeInfo"], 460, 120, function(){ _self.resumeForm(version); this.close(); }, function(){ this.close(); }); }.bind(this)); }.bind(this)) }.bind(this)); }, resumeForm : function(version){ o2.Actions.load("x_portal_assemble_designer").PageVersionAction.get(version.id, function( json ){ var formData = JSON.parse(json.data.data); //this.action.FormAction.update(version.form, formData,function( json ){ this.designer.notice(MWF.APPPOD.LP.version["resumeSuccess"]); var data = JSON.decode(MWF.decodeJsonString(formData.data)); data.isNewForm = false; this.reload(data); this.dlg.close(); //}.bind(this), null, false); }.bind(this), null, false); } });