Import.js 34 KB

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