MWF.xApplication = MWF.xApplication || {};
MWF.xApplication.portal = MWF.xApplication.portal || {};
MWF.xApplication.portal.PageDesigner = MWF.xApplication.portal.PageDesigner || {};
MWF.xApplication.portal.PageDesigner.Import = MWF.FormImport = MWF.PageImport = new Class({
Implements: [Options, Events],
options: {
"style": "default",
"type": "portal",
"stylePath": "../x_component_portal_PageDesigner/$Import/{style}/style.css",
"viewPath": "../x_component_portal_PageDesigner/$Import/{style}/view.html"
},
initialize: function(form, options){
this.setOptions(options);
this.path = "../x_component_portal_PageDesigner/$Import/";
this.stylePath = this.options.stylePath.replace("{style}", this.options.style);
this.viewPath = this.options.viewPath.replace("{style}", this.options.style);
this.form = form;
this.init();
this.loadView();
},
init: function(){
this.inforText = this.form.designer.lp.importO2_infor;
this.panelTitle = this.form.designer.lp.importO2;
this.panelWidth = 800;
this.panelHeight = 660;
this.editorMode = "json";
},
loadView: function(){
MWF.require("MWF.widget.Panel", function(){
this.node = new Element("div.importNode");
this.node.set("load", {"onSuccess": function(){
this.inforNode = this.node.getElement(".importInfor");
this.contentNode = this.node.getElement(".importContent");
this.bottomNode = this.node.getElement(".importBottom");
this.okNode = this.node.getElement(".importOkButton");
this.cancelNode = this.node.getElement(".importCancelButton");
o2.loadCss(this.stylePath, this.node, function(){
this.load();
}.bind(this));
}.bind(this)}).load(this.viewPath);
var node = this.form.designer.pageNode || this.form.designer.formNode;
var position = node.getPosition(node.getOffsetParent());
this.implodePanel = new MWF.widget.Panel(this.node, {
"style": "wizard",
"isResize": false,
"isMax": false,
"title": this.panelTitle,
"width": this.panelWidth,
"height": this.panelHeight,
"top": position.y,
"left": position.x+3,
"isExpand": false,
"target": this.form.designer.node
});
this.implodePanel.load();
}.bind(this));
},
load: function(){
this.loadContent();
this.loadEditor();
this.loadEvent();
},
loadContent: function(){
this.inforNode.set("html", this.inforText);
this.okNode.set("text", this.form.designer.lp.import_ok);
this.cancelNode.set("text", this.form.designer.lp.import_cancel);
},
loadEditor: function(){
MWF.require("MWF.widget.ScriptArea", function(){
this.scriptArea = new MWF.widget.ScriptArea(this.contentNode, {
"isload": true,
"style": "page",
"isbind": false,
"mode": this.editorMode
});
this.scriptArea.load({"code": ""});
//cssArea.loadEditor(cssContent);
}.bind(this));
},
loadEvent: function(){
this.cancelNode.addEvent("click", function(){
this.implodePanel.closePanel();
}.bind(this));
this.okNode.addEvent("click", function(e){
var str = this.scriptArea.editor.getValue();
if (!str){
this.form.designer.notice(this.form.designer.lp.implodeEmpty, "error", this.node);
return false;
}
var _self = this;
this.form.designer.confirm("warn", e, this.form.designer.lp.implodeConfirmTitle, this.form.designer.lp.implodeConfirmText, 400, 100, function(){
_self.implode(str);
this.close();
}, function(){
this.close();
});
}.bind(this));
},
implode: function(str){
if (str){
var data = JSON.decode(str);
if (data && data.json && data.html){
var json = data.json;
data.id = this.form.data.id;
data.isNewPage = this.form.data.isNewPage;
json.id = this.form.json.id;
json.name = this.form.json.name;
json.application = this.form.json.application;
json.applicationName = this.form.json.applicationName;
this.form.reload(data);
this.implodePanel.closePanel();
this.fireEvent("implode");
}else{
this.form.designer.notice(this.designer.lp.implodeError, "error", this.node);
}
}else{
this.form.designer.notice(this.designer.lp.implodeEmpty, "error", this.node);
}
}
});
MWF.FormImport.O2 = new Class({
Extends: MWF.FormImport
});
MWF.FormImport.Html = new Class({
Extends: MWF.FormImport,
options: {
"stylePath": "../x_component_portal_PageDesigner/$Import/{style}/style_html.css",
"viewPath": "../x_component_portal_PageDesigner/$Import/{style}/view_html.html"
},
init: function(){
this.inforText = this.form.designer.lp.importHTML_infor;
this.inforText2 = this.form.designer.lp.importHTML_infor2;
this.panelTitle = this.form.designer.lp.importHTML;
this.panelWidth = 800;
this.panelHeight = 700;
this.editorMode = "html";
},
loadContent: function(){
this.inforTextNode = this.node.getElement(".importInforText");
this.inforOptionsNode = this.node.getElement(".importInforOption");
this.inforTextNode.set("html", this.inforText);
this.inforText2Node = this.node.getElement(".importInforText2");
this.inforText2Node.set("html", this.inforText2);
this.contentHtml = this.node.getElement(".importContentHtml");
this.contentCss = this.node.getElement(".importContentCss");
var html = ""+this.form.designer.lp.import_option1;
html += " "+this.form.designer.lp.import_option2;
this.inforOptionsNode.set("html", html);
var inputs = this.inforOptionsNode.getElements("input");
this.option1 = inputs[0];
this.option2 = inputs[1];
this.okNode.set("text", this.form.designer.lp.import_ok);
this.cancelNode.set("text", this.form.designer.lp.import_cancel);
},
loadEditor: function(){
MWF.require("MWF.widget.ScriptArea", function(){
this.scriptArea = new MWF.widget.ScriptArea(this.contentHtml, {
"isload": true,
"style": "page",
"isbind": false,
"mode": this.editorMode
});
this.scriptArea.load({"code": ""});
//cssArea.loadEditor(cssContent);
}.bind(this));
MWF.require("MWF.widget.ScriptArea", function(){
this.cssArea = new MWF.widget.ScriptArea(this.contentCss, {
"isload": true,
"style": "page",
"isbind": false,
"mode": "css"
});
this.cssArea.load({"code": ""});
//cssArea.loadEditor(cssContent);
}.bind(this));
},
implode: function(str){
MWF.require("MWF.widget.Mask", null, false);
var maxIndex = this.implodePanel.container.getStyle("z-index").toInt();
var mask = new MWF.widget.Mask({"zIndex": maxIndex});
mask.loadNode(this.form.designer.content);
try{
var iframe = new Element("iframe").inject(document.body);
var doc = iframe.contentWindow.document;
debugger;
o2.load("mootools", {"doc": doc}, function(){
debugger;
var oldNodeHtml = this.form.node.get("html");
var oldModuleList = this.form.json.moduleList;
var oldHtml = this.form.data.html;
try{
doc.body.set("html", str);
doc.body.normalize();
var moduleList = {};
var readyDeleteNodes = [];
var styleNodes = doc.body.getElements("style");
if (styleNodes) this.loadStyles(styleNodes);
var css = "";
if (this.cssArea){
css = this.cssArea.editor.getValue();
if (css) this.form.json.css.code += this.parseImplodeCSS(css, doc);
//if (css) this.form.json.css.code += css;
}
this.parseImplodeHTML(doc.body, moduleList, doc, readyDeleteNodes);
while (readyDeleteNodes.length){
readyDeleteNodes.shift().destroy();
}
var html = doc.body.get("html");
this.form.node.empty();
var formHtml = this.form.node.outerHTML;
var arr = formHtml.split(/\>\s*\);
html = arr[0]+">"+html+"<"+arr[1];
this.form.json.moduleList = moduleList;
this.form.data.html = html;
this.form.reload(this.form.data);
iframe.destroy();
this.implodePanel.closePanel();
this.fireEvent("implode");
mask.hide();
}catch(e){
this.form.designer.notice(e.message, "error", this.node);
this.form.node.set("html", oldNodeHtml);
this.form.json.moduleList = oldModuleList;
this.form.data.html = oldHtml;
this.form.reload(this.form.data);
this.fireEvent("implode");
mask.hide();
}finally{
oldNodeHtml = null;
oldModuleList = null;
oldModuleList = null;
}
}.bind(this));
}catch(e){
this.form.designer.notice(e.message, "error", this.node);
mask.hide();
}
},
parseImplodeCSS: function(css, doc, callback){
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 n = (s==="'" || s==="\"") ? 2 : 1;
pic = pic.substring(pic.lastIndexOf("/")+1, pic.length-n);
var root = (this.options.type==="portal") ? "x_portal_assemble_surface" : "x_processplatform_assemble_surface";
var url = root + o2.Actions.get(root).action.actions.readFile.uri;
url = url.replace("{flag}", pic);
url = url.replace("{applicationFlag}", this.form.json.application || this.form.json.portal);
url = "url('"+url+"')";
var len2 = url.length;
css = css.substring(0, match.index) + url + css.substring(rex.lastIndex, css.length);
rex.lastIndex = rex.lastIndex + (len2-len);
}
return css;
},
loadStyles: function(styleNodes){
var cssText = "";
styleNodes.each(function(node){
cssText+=node.get("text");
}.bind(this));
styleNodes.destroy();
this.form.json.css.code = cssText;
},
"getInnerStyles": function(node){
var styles = {};
style = node.get("style");
if (style){
var styleArr = style.split(/\s*\;\s*/g);
styleArr.each(function(s){
if (s){
var sarr = s.split(/\s*\:\s*/g);
styles[sarr[0]] = (sarr.length>1) ? sarr[1]: ""
}
}.bind(this));
}
return styles;
},
"getInnerProperties": function(node){
var properties = {};
if (node.attributes.length){
for (var i=0; i