Import.js 32 KB

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