Import.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.portal = MWF.xApplication.portal || {};
  3. MWF.xApplication.portal.PageDesigner = MWF.xApplication.portal.PageDesigner || {};
  4. MWF.xApplication.portal.PageDesigner.Import = MWF.FormImport = MWF.PageImport = new Class({
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "type": "portal",
  9. "stylePath": "../x_component_portal_PageDesigner/$Import/{style}/style.css",
  10. "viewPath": "../x_component_portal_PageDesigner/$Import/{style}/view.html"
  11. },
  12. initialize: function(form, options){
  13. this.setOptions(options);
  14. this.path = "../x_component_portal_PageDesigner/$Import/";
  15. this.stylePath = this.options.stylePath.replace("{style}", this.options.style);
  16. this.viewPath = this.options.viewPath.replace("{style}", this.options.style);
  17. this.form = form;
  18. this.init();
  19. this.loadView();
  20. },
  21. init: function(){
  22. this.inforText = this.form.designer.lp.importO2_infor;
  23. this.panelTitle = this.form.designer.lp.importO2;
  24. this.panelWidth = 800;
  25. this.panelHeight = 660;
  26. this.editorMode = "json";
  27. },
  28. loadView: function(){
  29. MWF.require("MWF.widget.Panel", function(){
  30. this.node = new Element("div.importNode");
  31. this.node.set("load", {"onSuccess": function(){
  32. this.inforNode = this.node.getElement(".importInfor");
  33. this.contentNode = this.node.getElement(".importContent");
  34. this.bottomNode = this.node.getElement(".importBottom");
  35. this.okNode = this.node.getElement(".importOkButton");
  36. this.cancelNode = this.node.getElement(".importCancelButton");
  37. o2.loadCss(this.stylePath, this.node, function(){
  38. this.load();
  39. }.bind(this));
  40. }.bind(this)}).load(this.viewPath);
  41. var node = this.form.designer.pageNode || this.form.designer.formNode;
  42. var position = node.getPosition(node.getOffsetParent());
  43. this.implodePanel = new MWF.widget.Panel(this.node, {
  44. "style": "wizard",
  45. "isResize": false,
  46. "isMax": false,
  47. "title": this.panelTitle,
  48. "width": this.panelWidth,
  49. "height": this.panelHeight,
  50. "top": position.y,
  51. "left": position.x+3,
  52. "isExpand": false,
  53. "target": this.form.designer.node
  54. });
  55. this.implodePanel.load();
  56. }.bind(this));
  57. },
  58. load: function(){
  59. this.loadContent();
  60. this.loadEditor();
  61. this.loadEvent();
  62. },
  63. loadContent: function(){
  64. this.inforNode.set("html", this.inforText);
  65. this.okNode.set("text", this.form.designer.lp.import_ok);
  66. this.cancelNode.set("text", this.form.designer.lp.import_cancel);
  67. },
  68. loadEditor: function(){
  69. MWF.require("MWF.widget.ScriptArea", function(){
  70. this.scriptArea = new MWF.widget.ScriptArea(this.contentNode, {
  71. "isload": true,
  72. "style": "page",
  73. "isbind": false,
  74. "mode": this.editorMode
  75. });
  76. this.scriptArea.load({"code": ""});
  77. //cssArea.loadEditor(cssContent);
  78. }.bind(this));
  79. },
  80. loadEvent: function(){
  81. this.cancelNode.addEvent("click", function(){
  82. this.implodePanel.closePanel();
  83. }.bind(this));
  84. this.okNode.addEvent("click", function(e){
  85. var str = this.scriptArea.editor.getValue();
  86. if (!str){
  87. this.form.designer.notice(this.form.designer.lp.implodeEmpty, "error", this.node);
  88. return false;
  89. }
  90. var _self = this;
  91. this.form.designer.confirm("warn", e, this.form.designer.lp.implodeConfirmTitle, this.form.designer.lp.implodeConfirmText, 400, 100, function(){
  92. _self.implode(str);
  93. this.close();
  94. }, function(){
  95. this.close();
  96. });
  97. }.bind(this));
  98. },
  99. implode: function(str){
  100. if (str){
  101. var data = JSON.decode(str);
  102. if (data && data.json && data.html){
  103. var json = data.json;
  104. data.id = this.form.data.id;
  105. data.isNewPage = this.form.data.isNewPage;
  106. json.id = this.form.json.id;
  107. json.name = this.form.json.name;
  108. json.application = this.form.json.application;
  109. json.applicationName = this.form.json.applicationName;
  110. this.form.reload(data);
  111. this.implodePanel.closePanel();
  112. this.fireEvent("implode");
  113. }else{
  114. this.form.designer.notice(this.designer.lp.implodeError, "error", this.node);
  115. }
  116. }else{
  117. this.form.designer.notice(this.designer.lp.implodeEmpty, "error", this.node);
  118. }
  119. }
  120. });
  121. MWF.FormImport.O2 = new Class({
  122. Extends: MWF.FormImport
  123. });
  124. MWF.FormImport.Html = new Class({
  125. Extends: MWF.FormImport,
  126. options: {
  127. "stylePath": "../x_component_portal_PageDesigner/$Import/{style}/style_html.css",
  128. "viewPath": "../x_component_portal_PageDesigner/$Import/{style}/view_html.html"
  129. },
  130. init: function(){
  131. this.inforText = this.form.designer.lp.importHTML_infor;
  132. this.inforText2 = this.form.designer.lp.importHTML_infor2;
  133. this.panelTitle = this.form.designer.lp.importHTML;
  134. this.panelWidth = 800;
  135. this.panelHeight = 700;
  136. this.editorMode = "html";
  137. },
  138. loadContent: function(){
  139. this.inforTextNode = this.node.getElement(".importInforText");
  140. this.inforOptionsNode = this.node.getElement(".importInforOption");
  141. this.inforTextNode.set("html", this.inforText);
  142. this.inforText2Node = this.node.getElement(".importInforText2");
  143. this.inforText2Node.set("html", this.inforText2);
  144. this.contentHtml = this.node.getElement(".importContentHtml");
  145. this.contentCss = this.node.getElement(".importContentCss");
  146. var html = "<input type='checkbox'>"+this.form.designer.lp.import_option1;
  147. html += "<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><input type='checkbox'>"+this.form.designer.lp.import_option2;
  148. this.inforOptionsNode.set("html", html);
  149. var inputs = this.inforOptionsNode.getElements("input");
  150. this.option1 = inputs[0];
  151. this.option2 = inputs[1];
  152. this.okNode.set("text", this.form.designer.lp.import_ok);
  153. this.cancelNode.set("text", this.form.designer.lp.import_cancel);
  154. },
  155. loadEditor: function(){
  156. MWF.require("MWF.widget.ScriptArea", function(){
  157. this.scriptArea = new MWF.widget.ScriptArea(this.contentHtml, {
  158. "isload": true,
  159. "style": "page",
  160. "isbind": false,
  161. "mode": this.editorMode
  162. });
  163. this.scriptArea.load({"code": ""});
  164. //cssArea.loadEditor(cssContent);
  165. }.bind(this));
  166. MWF.require("MWF.widget.ScriptArea", function(){
  167. this.cssArea = new MWF.widget.ScriptArea(this.contentCss, {
  168. "isload": true,
  169. "style": "page",
  170. "isbind": false,
  171. "mode": "css"
  172. });
  173. this.cssArea.load({"code": ""});
  174. //cssArea.loadEditor(cssContent);
  175. }.bind(this));
  176. },
  177. implode: function(str){
  178. MWF.require("MWF.widget.Mask", null, false);
  179. var maxIndex = this.implodePanel.container.getStyle("z-index").toInt();
  180. var mask = new MWF.widget.Mask({"zIndex": maxIndex});
  181. mask.loadNode(this.form.designer.content);
  182. try{
  183. var iframe = new Element("iframe").inject(document.body);
  184. var doc = iframe.contentWindow.document;
  185. debugger;
  186. o2.load("mootools", {"doc": doc}, function(){
  187. debugger;
  188. var oldNodeHtml = this.form.node.get("html");
  189. var oldModuleList = this.form.json.moduleList;
  190. var oldHtml = this.form.data.html;
  191. try{
  192. doc.body.set("html", str);
  193. doc.body.normalize();
  194. var moduleList = {};
  195. var readyDeleteNodes = [];
  196. var styleNodes = doc.body.getElements("style");
  197. if (styleNodes) this.loadStyles(styleNodes);
  198. var css = "";
  199. if (this.cssArea){
  200. css = this.cssArea.editor.getValue();
  201. if (css) this.form.json.css.code += this.parseImplodeCSS(css, doc);
  202. //if (css) this.form.json.css.code += css;
  203. }
  204. this.parseImplodeHTML(doc.body, moduleList, doc, readyDeleteNodes);
  205. while (readyDeleteNodes.length){
  206. readyDeleteNodes.shift().destroy();
  207. }
  208. var html = doc.body.get("html");
  209. this.form.node.empty();
  210. var formHtml = this.form.node.outerHTML;
  211. var arr = formHtml.split(/\>\s*\</);
  212. html = arr[0]+">"+html+"<"+arr[1];
  213. this.form.json.moduleList = moduleList;
  214. this.form.data.html = html;
  215. this.form.reload(this.form.data);
  216. iframe.destroy();
  217. this.implodePanel.closePanel();
  218. this.fireEvent("implode");
  219. mask.hide();
  220. }catch(e){
  221. this.form.designer.notice(e.message, "error", this.node);
  222. this.form.node.set("html", oldNodeHtml);
  223. this.form.json.moduleList = oldModuleList;
  224. this.form.data.html = oldHtml;
  225. this.form.reload(this.form.data);
  226. this.fireEvent("implode");
  227. mask.hide();
  228. }finally{
  229. oldNodeHtml = null;
  230. oldModuleList = null;
  231. oldModuleList = null;
  232. }
  233. }.bind(this));
  234. }catch(e){
  235. this.form.designer.notice(e.message, "error", this.node);
  236. mask.hide();
  237. }
  238. },
  239. parseImplodeCSS: function(css, doc, callback){
  240. var rex = /(url\(.*\))/g;
  241. var match;
  242. while ((match = rex.exec(css)) !== null) {
  243. var pic = match[0];
  244. var len = pic.length;
  245. var s = pic.substring(pic.length-2, pic.length-1);
  246. var n = (s==="'" || s==="\"") ? 2 : 1;
  247. pic = pic.substring(pic.lastIndexOf("/")+1, pic.length-n);
  248. var root = (this.options.type==="portal") ? "x_portal_assemble_surface" : "x_processplatform_assemble_surface";
  249. var url = root + o2.Actions.get(root).action.actions.readFile.uri;
  250. url = url.replace("{flag}", pic);
  251. url = url.replace("{applicationFlag}", this.form.json.application || this.form.json.portal);
  252. url = "url('"+url+"')";
  253. var len2 = url.length;
  254. css = css.substring(0, match.index) + url + css.substring(rex.lastIndex, css.length);
  255. rex.lastIndex = rex.lastIndex + (len2-len);
  256. }
  257. return css;
  258. },
  259. loadStyles: function(styleNodes){
  260. var cssText = "";
  261. styleNodes.each(function(node){
  262. cssText+=node.get("text");
  263. }.bind(this));
  264. styleNodes.destroy();
  265. this.form.json.css.code = cssText;
  266. },
  267. "getInnerStyles": function(node){
  268. var styles = {};
  269. style = node.get("style");
  270. if (style){
  271. var styleArr = style.split(/\s*\;\s*/g);
  272. styleArr.each(function(s){
  273. if (s){
  274. var sarr = s.split(/\s*\:\s*/g);
  275. styles[sarr[0]] = (sarr.length>1) ? sarr[1]: ""
  276. }
  277. }.bind(this));
  278. }
  279. return styles;
  280. },
  281. "getInnerProperties": function(node){
  282. var properties = {};
  283. if (node.attributes.length){
  284. for (var i=0; i<node.attributes.length; i++){
  285. var k = node.attributes[i].nodeName.toString().toLowerCase();
  286. if (k!=="mwftype" && k!=="id" && k!=="style") properties[k] = node.attributes[i].nodeValue;
  287. }
  288. }
  289. return properties;
  290. },
  291. getImplodeModuleJson: function(moduleList, className, moduleId, node, callback){
  292. var id = moduleId;
  293. var className = className;
  294. this.form.getTemplateData(className, function(data){
  295. var moduleData = Object.clone(data);
  296. var n = 1;
  297. while (moduleList[id]){
  298. id = moduleId+"_"+n;
  299. n++;
  300. }
  301. if (node.nodeType===Node.ELEMENT_NODE){
  302. moduleData.styles = this.getInnerStyles(node);
  303. moduleData.properties = this.getInnerProperties(node);
  304. }else if (node.nodeType===Node.TEXT_NODE){
  305. moduleData.styles.display = "inline";
  306. }
  307. if (className==="Label") moduleData.styles.display = "inline";
  308. moduleData.id = id;
  309. moduleList[id] = moduleData;
  310. if (callback) callback(id, moduleData);
  311. }.bind(this), false);
  312. },
  313. convertTextLabelNode: function(subNode, moduleList){
  314. if (subNode.nodeValue.trim()){
  315. this.getImplodeModuleJson(moduleList, "Label", "label", subNode, function(id, moduleData){
  316. moduleData.text = subNode.nodeValue;
  317. var textNode = new Element("div#"+id, {"mwftype": "label", "text": moduleData.text});
  318. if (subNode.replaceWith){
  319. subNode.replaceWith(textNode);
  320. }else if (subNode.replaceNode){
  321. subNode.replaceNode(textNode);
  322. }
  323. subNode = textNode;
  324. }.bind(this));
  325. }
  326. return subNode;
  327. },
  328. convertLabelNode: function(subNode, moduleList, tag){
  329. this.getImplodeModuleJson(moduleList, "Label", (subNode.get("id") || "label"), subNode, function(id, moduleData){
  330. moduleData.text = subNode.get("text");
  331. if (tag!=="div"){
  332. var node = new Element("div#"+id, {"mwftype": "label", "text": moduleData.text}).inject(subNode, "before");
  333. subNode.destroy();
  334. subNode = node;
  335. }else{
  336. subNode.set({"mwftype": "label", "id": id});
  337. }
  338. }.bind(this));
  339. return subNode;
  340. },
  341. convertDivNode: function(subNode, moduleList, tag){
  342. this.getImplodeModuleJson(moduleList, "Div", (subNode.get("id") || "div"), subNode, function(id, moduleData){
  343. if (tag==="p"){
  344. var node = new Element("div#"+id, {"mwftype": "div"}).inject(subNode, "before");
  345. node.set("html", subNode.get("html"));
  346. node.set("MWFOriginalTag", "p");
  347. subNode.destroy();
  348. subNode = node;
  349. }else{
  350. subNode.set({"mwftype": "div", "id": id});
  351. }
  352. }.bind(this));
  353. return subNode;
  354. },
  355. convertTableNode: function(subNode, moduleList){
  356. this.getImplodeModuleJson(moduleList, "Table", (subNode.get("id") || "table"), subNode, function(id, moduleData){
  357. moduleData.styles.display = "table";
  358. var tableNode = new Element("div#"+id, {"mwftype": "table"}).inject(subNode, "before");
  359. subNode.inject(tableNode);
  360. //subNode.set({"mwftype": "table", "id": id});
  361. }.bind(this));
  362. return subNode;
  363. },
  364. convertTdNode: function(subNode, moduleList){
  365. this.getImplodeModuleJson(moduleList, "Table$Td", (subNode.get("id") || "table$Td"), subNode, function(id){
  366. subNode.set({"mwftype": "table$Td", "id": id});
  367. }.bind(this));
  368. return subNode;
  369. },
  370. convertImgNode: function(subNode, moduleList){
  371. this.getImplodeModuleJson(moduleList, "Image", (subNode.get("id") || "image"), subNode, function(id, moduleData){
  372. debugger;
  373. var src = subNode.get("src");
  374. if (src){
  375. var root = (this.options.type==="portal") ? "x_portal_assemble_surface" : "x_processplatform_assemble_surface";
  376. var pic = src.substring(src.lastIndexOf("/")+1, src.length);
  377. var url = root + o2.Actions.get(root).action.actions.readFile.uri;
  378. url = url.replace("{flag}", pic);
  379. url = url.replace("{applicationFlag}", this.form.json.application || this.form.json.portal);
  380. moduleData.properties.src = url;
  381. subNode.set("src", url);
  382. }
  383. subNode.set({"mwftype": "img", "id": id});
  384. }.bind(this));
  385. return subNode;
  386. },
  387. convertInputImgNode: function(subNode, moduleList){
  388. this.getImplodeModuleJson(moduleList, "Img", (subNode.get("id") || "img"), subNode, function(id){
  389. var imgNode = new Element("img#"+id, {"mwftype": "img"}).inject(subNode, "before");
  390. //subNode.set({"mwftype": "img", "id": id});
  391. subNode.destroy();
  392. subNode = imgNode;
  393. }.bind(this));
  394. return subNode;
  395. },
  396. convertButtonNode: function(subNode, moduleList){
  397. this.getImplodeModuleJson(moduleList, "Button", (subNode.get("id") || "button"), subNode, function(id, moduleData){
  398. var value = subNode.get("value");
  399. if (value) moduleData.name = value;
  400. delete moduleData.properties.type;
  401. delete moduleData.properties.name;
  402. var buttonNode = new Element("div#"+id, {"mwftype": "button"}).inject(subNode, "before");
  403. subNode.inject(buttonNode);
  404. }.bind(this));
  405. return subNode;
  406. },
  407. convertIframeNode: function(subNode, moduleList){
  408. this.getImplodeModuleJson(moduleList, "Iframe", (subNode.get("id") || "iframe"), subNode, function(id, moduleData){
  409. if (moduleData.properties.src){
  410. moduleData.src = moduleData.properties.src;
  411. delete moduleData.properties.src;
  412. }
  413. var iframeNode = new Element("div#"+id, {"mwftype": "iframe"}).inject(subNode, "before");
  414. subNode.destroy();
  415. subNode = iframeNode;
  416. }.bind(this));
  417. return subNode
  418. },
  419. convertTextareaNode: function(subNode, moduleList){
  420. this.getImplodeModuleJson(moduleList, "Textarea", (subNode.get("id") || "textarea"), subNode, function(id, moduleData){
  421. var value = subNode.get("text");
  422. if (value){
  423. if (!moduleData.defaultValue) moduleData.defaultValue = {"code": "", "html": ""};
  424. var v = value.replace(/\"/g, "\\\"");
  425. moduleData.defaultValue.code = "return \""+v+"\"";
  426. }
  427. var textareaNode = new Element("div#"+id, {"mwftype": "textarea"}).inject(subNode, "before");
  428. subNode.destroy();
  429. subNode = textareaNode;
  430. }.bind(this));
  431. return subNode;
  432. },
  433. convertSelectNode: function(subNode, moduleList){
  434. this.getImplodeModuleJson(moduleList, "Select", (subNode.get("id") || "select"), subNode, function(id, moduleData){
  435. var options = subNode.getElements("option");
  436. moduleData.itemValues = [];
  437. options.each(function(op){
  438. var text = op.get("text");
  439. var value = op.get("value") || text;
  440. moduleData.itemValues.push(text+"|"+value);
  441. }.bind(this));
  442. var selectNode = new Element("div#"+id, {"mwftype": "select"}).inject(subNode, "before");
  443. subNode.destroy();
  444. subNode = selectNode;
  445. }.bind(this));
  446. return subNode;
  447. },
  448. convertTextfieldNode: function(subNode, moduleList){
  449. this.getImplodeModuleJson(moduleList, "Textfield", (subNode.get("id") || "textfield"), subNode, function(id, moduleData){
  450. var value = subNode.get("value");
  451. if (value){
  452. if (!moduleData.defaultValue) moduleData.defaultValue = {"code": "", "html": ""};
  453. var v = moduleData.properties.value.replace(/\"/g, "\\\"");
  454. moduleData.defaultValue.code = "return \""+v+"\"";
  455. }
  456. delete moduleData.properties.type;
  457. delete moduleData.properties.name;
  458. var fieldNode = new Element("div#"+id, {"mwftype": "textfield"}).inject(subNode, "before");
  459. subNode.destroy();
  460. subNode = fieldNode;
  461. }.bind(this));
  462. return subNode;
  463. },
  464. convertNumberNode: function(subNode, moduleList){
  465. this.getImplodeModuleJson(moduleList, "Number", (subNode.get("id") || "number"), subNode, function(id, moduleData){
  466. var value = subNode.get("value");
  467. if (value){
  468. if (!moduleData.defaultValue) moduleData.defaultValue = {"code": "", "html": ""};
  469. var v = moduleData.properties.value.replace(/\"/g, "\\\"");
  470. moduleData.defaultValue.code = "return \""+v+"\"";
  471. }
  472. delete moduleData.properties.type;
  473. delete moduleData.properties.name;
  474. var fieldNode = new Element("div#"+id, {"mwftype": "number"}).inject(subNode, "before");
  475. subNode.destroy();
  476. subNode = fieldNode;
  477. }.bind(this));
  478. return subNode;
  479. },
  480. convertCalendarNode: function(subNode, moduleList){
  481. this.getImplodeModuleJson(moduleList, "Calendar", (subNode.get("id") || "calendar"), subNode, function(id, moduleData){
  482. var value = subNode.get("value");
  483. if (value){
  484. if (!moduleData.defaultValue) moduleData.defaultValue = {"code": "", "html": ""};
  485. var v = moduleData.properties.value.replace(/\"/g, "\\\"");
  486. moduleData.defaultValue.code = "return \""+v+"\"";
  487. }
  488. if (t==="date") moduleData.selectType = "date";
  489. if (t==="time") moduleData.selectType = "time";
  490. delete moduleData.properties.type;
  491. delete moduleData.properties.name;
  492. var fieldNode = new Element("div#"+id, {"mwftype": "calendar"}).inject(subNode, "before");
  493. subNode.destroy();
  494. subNode = fieldNode;
  495. }.bind(this));
  496. return subNode;
  497. },
  498. convertRadioNode: function(subNode, moduleList){
  499. this.getImplodeModuleJson(moduleList, "Radio", (subNode.get("id") || "radio"), subNode, function(id, moduleData){
  500. moduleData.itemValues = [];
  501. var textNode = subNode.nextSibling;
  502. if (textNode && textNode.nodeType===Node.TEXT_NODE){
  503. text = textNode.nodeValue;
  504. if (textNode.remove){
  505. textNode.remove();
  506. }else if(textNode.removeNode){
  507. textNode.removeNode();
  508. }
  509. }
  510. var value = subNode.get("value");
  511. moduleData.itemValues.push(text+"|"+value);
  512. delete moduleData.properties.type;
  513. delete moduleData.properties.name;
  514. delete moduleData.properties.value;
  515. var fieldNode = new Element("div#"+id, {"mwftype": "radio"}).inject(subNode, "before");
  516. subNode.destroy();
  517. subNode = fieldNode;
  518. }.bind(this));
  519. return subNode;
  520. },
  521. convertCheckboxNode: function(subNode, moduleList){
  522. this.getImplodeModuleJson(moduleList, "Checkbox", (subNode.get("id") || "checkbox"), subNode, function(id, moduleData){
  523. moduleData.itemValues = [];
  524. var textNode = subNode.nextSibling;
  525. if (textNode && textNode.nodeType===Node.TEXT_NODE){
  526. text = textNode.nodeValue;
  527. if (textNode.remove){
  528. textNode.remove();
  529. }else if(textNode.removeNode){
  530. textNode.removeNode();
  531. }
  532. }
  533. var value = subNode.get("value");
  534. moduleData.itemValues.push(text+"|"+value);
  535. delete moduleData.properties.type;
  536. delete moduleData.properties.name;
  537. delete moduleData.properties.value;
  538. var fieldNode = new Element("div#"+id, {"mwftype": "checkbox"}).inject(subNode, "before");
  539. subNode.destroy();
  540. subNode = fieldNode;
  541. }.bind(this));
  542. return subNode;
  543. },
  544. convertCommonTextNode: function(subNode, moduleList, tag){
  545. this.getImplodeModuleJson(moduleList, "Common", (subNode.get("id") || "common"), subNode, function(id, moduleData){
  546. //moduleData.styles.display = subNode.getStyle("display");
  547. moduleData.innerHTML = subNode.get("text");
  548. moduleData.tagName = tag;
  549. subNode.set({"mwftype": "common", "id": id});
  550. subNode.empty();
  551. }.bind(this));
  552. return subNode;
  553. },
  554. convertCommonNode: function(subNode, moduleList, tag){
  555. this.getImplodeModuleJson(moduleList, "Common", (subNode.get("id") || "common"), subNode, function(id, moduleData){
  556. moduleData.tagName = tag;
  557. subNode.set({"mwftype": "common", "id": id});
  558. }.bind(this));
  559. return subNode;
  560. },
  561. checkNodeEmpty: function(node){
  562. if (node.nodeType===Node.TEXT_NODE){
  563. if (node.nodeValue.trim()) return false;
  564. return true;
  565. }
  566. if (node.nodeType===Node.ELEMENT_NODE){
  567. if (node.getElements("input").length) return false;
  568. if (node.getElements("img").length) return false;
  569. if (node.getElements("button").length) return false;
  570. if (node.getElements("audio").length) return false;
  571. if (node.getElements("canvas").length) return false;
  572. if (node.getElements("iframe").length) return false;
  573. if (node.getElements("object").length) return false;
  574. if (node.getElements("select").length) return false;
  575. if (node.getElements("video").length) return false;
  576. if (node.get("text").trim()) return false;
  577. return true;
  578. }
  579. return false;
  580. },
  581. parseImplodeHTML: function(node, moduleList, doc, readyDeleteNodes){
  582. if (!node) return ;
  583. var nodes = node.childNodes;
  584. for (var i = 0; i<nodes.length; i++){
  585. var subNode = nodes[i];
  586. if (!subNode) continue;
  587. subNode.normalize();
  588. var nextNode = true;
  589. if (subNode.nodeType===Node.TEXT_NODE){
  590. subNode = this.convertTextLabelNode(subNode, moduleList);
  591. nextNode = false;
  592. }
  593. if (subNode.nodeType===Node.ELEMENT_NODE){
  594. var tag = subNode.tagName.toString().toLowerCase();
  595. if (this.option2.checked){
  596. if (!(tag==="table" || tag==="td" || tag==="th" || tag==="tr" || tag==="tbody" || tag==="thead" || tag==="tfoot" ||
  597. tag==="input" || tag==="img" || tag==="button" || tag==="audio" || tag==="canvas" || tag==="iframe" ||
  598. tag==="object" || tag==="select" || tag==="video")){
  599. if (this.checkNodeEmpty(subNode)){
  600. subNode.readyDelete = true;
  601. readyDeleteNodes.push(subNode);
  602. // if (subNode.destroy){
  603. // subNode.destroy();
  604. // }else if (subNode.remove){
  605. // subNode.remove();
  606. // }
  607. // subNode = null;
  608. }
  609. }
  610. }
  611. if (subNode.readyDelete) continue;
  612. switch (tag){
  613. //case "figure":
  614. //case "figcaption":
  615. //case "p":
  616. case "div":
  617. if (subNode.childNodes.length===1 && subNode.childNodes[0].nodeType===Node.TEXT_NODE && subNode.childNodes[0].nodeValue.trim()){
  618. subNode = this.convertLabelNode(subNode, moduleList, tag);
  619. nextNode = false;
  620. }else{
  621. subNode = this.convertDivNode(subNode, moduleList, tag);
  622. }
  623. break;
  624. case "table":
  625. subNode = this.convertTableNode(subNode, moduleList);
  626. break;
  627. //case "caption":
  628. case "colgroup":
  629. case "col":
  630. case "br":
  631. case "tr": break;
  632. case "th":
  633. case "td":
  634. if (this.option1.checked){
  635. if (this.checkNodeEmpty(subNode)){
  636. new Element("input", {"tyep": "text"}).inject(subNode);
  637. }
  638. }
  639. //subNode = this.convertTdNode(subNode, moduleList);
  640. break;
  641. case "img":
  642. subNode = this.convertImgNode(subNode, moduleList);
  643. nextNode = false;
  644. break;
  645. case "button":
  646. subNode = this.convertButtonNode(subNode, moduleList);
  647. nextNode = false;
  648. break;
  649. case "iframe":
  650. subNode = this.convertIframeNode(subNode, moduleList);
  651. nextNode = false;
  652. break;
  653. case "textarea":
  654. subNode = this.convertTextareaNode(subNode, moduleList);
  655. nextNode = false;
  656. break;
  657. case "select":
  658. subNode = this.convertSelectNode(subNode, moduleList);
  659. nextNode = false;
  660. break;
  661. case "input":
  662. var t = subNode.get("type").toString().toLowerCase();
  663. switch (t){
  664. case "text":
  665. subNode = this.convertTextfieldNode(subNode, moduleList);
  666. break;
  667. case "number":
  668. subNode = this.convertNumberNode(subNode, moduleList);
  669. break;
  670. case "reset":
  671. case "submit":
  672. case "button":
  673. subNode = this.convertCommonNode(subNode, moduleList, tag);
  674. //subNode = this.convertButtonNode(subNode, moduleList);
  675. break;
  676. case "datetime":
  677. case "datetime-local":
  678. case "time":
  679. case "date":
  680. subNode = this.convertCalendarNode(subNode, moduleList);
  681. break;
  682. case "radio":
  683. subNode = this.convertRadioNode(subNode, moduleList);
  684. break;
  685. case "checkbox":
  686. subNode = this.convertCheckboxNode(subNode, moduleList);
  687. break;
  688. case "file":
  689. break;
  690. case "image":
  691. subNode = this.convertInputImgNode(subNode, moduleList);
  692. break;
  693. default:
  694. subNode = this.convertTextfieldNode(subNode, moduleList);
  695. }
  696. nextNode = false;
  697. break;
  698. case "base":
  699. case "tbody":
  700. case "thead":
  701. case "tfoot": break;
  702. default:
  703. debugger;
  704. if (subNode.childNodes.length===1 && subNode.childNodes[0].nodeType===Node.TEXT_NODE && subNode.childNodes[0].nodeValue.trim()){
  705. subNode = this.convertCommonTextNode(subNode, moduleList, tag);
  706. nextNode = false;
  707. }else{
  708. subNode = this.convertCommonNode(subNode, moduleList, tag);
  709. }
  710. }
  711. }
  712. if (nextNode) this.parseImplodeHTML(subNode, moduleList, doc, readyDeleteNodes);
  713. }
  714. }
  715. });
  716. MWF.FormImport.Office = new Class({
  717. Extends: MWF.FormImport.Html,
  718. options: {
  719. "stylePath": "../x_component_portal_PageDesigner/$Import/{style}/style_office.css"
  720. },
  721. init: function(){
  722. this.inforText = this.form.designer.lp.importOffice_infor;
  723. this.inforText2 = this.form.designer.lp.importOffice_infor2;
  724. this.panelTitle = this.form.designer.lp.importOffice;
  725. this.panelWidth = 800;
  726. this.panelHeight = 240;
  727. this.editorMode = "html";
  728. },
  729. loadEditor: function(){
  730. //this.contentHtml
  731. if (this.contentCss) this.contentCss.destroy();
  732. if (this.inforText2Node) this.inforText2Node.destroy();
  733. this.file = new Element("input.importFile", {
  734. "type": "file",
  735. "accept": ".doc,.docx,.xls,.xlsx"
  736. }).inject(this.contentHtml);
  737. },
  738. loadEvent: function(){
  739. this.cancelNode.addEvent("click", function(){
  740. this.implodePanel.closePanel();
  741. }.bind(this));
  742. this.okNode.addEvent("click", function(e){
  743. var files = this.file.files;
  744. if (!files.length){
  745. this.form.designer.notice(this.form.designer.lp.implodeOfficeEmpty, "error", this.node);
  746. return false;
  747. }
  748. var _self = this;
  749. this.form.designer.confirm("warn", e, this.form.designer.lp.implodeConfirmTitle, this.form.designer.lp.implodeConfirmText, 400, 100, function(){
  750. _self.implodeOffice(files);
  751. this.close();
  752. }, function(){
  753. this.close();
  754. });
  755. }.bind(this));
  756. },
  757. implodeOffice: function(files){
  758. var file = files.item(0);
  759. var formData = new FormData();
  760. formData.append('file', file);
  761. MWF.Actions.get("x_general_assemble_control").convertHtml(formData, file, function(json){
  762. var html = json.data.value;
  763. this.implode(html);
  764. }.bind(this));
  765. }
  766. });
  767. MWF.FormImport.create = function(type, form, options){
  768. return new MWF.FormImport[type.capitalize()](form, options);
  769. };