Import.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. MWF.xApplication = MWF.xApplication || {};
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.FormDesigner = MWF.xApplication.cms.FormDesigner || {};
  4. MWF.xDesktop.requireApp("portal.PageDesigner", "Import", null, false);
  5. MWF.xApplication.cms.FormDesigner.Import = MWF.CMSFormImport = new Class({
  6. Extends : MWF.FormImport
  7. });
  8. MWF.CMSFormImport.O2 = new Class({
  9. Extends: MWF.FormImport.O2
  10. });
  11. MWF.CMSFormImport.Html = new Class({
  12. Extends: MWF.FormImport.Html,
  13. parseImplodeCSS: function(css, doc, callback){
  14. var rex = /(url\(.*\))/g;
  15. var match;
  16. while ((match = rex.exec(css)) !== null) {
  17. var pic = match[0];
  18. var len = pic.length;
  19. var s = pic.substring(pic.length-2, pic.length-1);
  20. var n = (s==="'" || s==="\"") ? 2 : 1;
  21. pic = pic.substring(pic.lastIndexOf("/")+1, pic.length-n);
  22. //var root = (this.options.type==="portal") ? "x_portal_assemble_surface" : "x_processplatform_assemble_surface";
  23. var root = "x_cms_assemble_control";
  24. var url = root + o2.Actions.get(root).action.actions.readFile.uri;
  25. url = url.replace("{flag}", pic);
  26. url = url.replace("{applicationFlag}", this.form.json.application || this.form.json.portal);
  27. url = "url('"+url+"')";
  28. var len2 = url.length;
  29. css = css.substring(0, match.index) + url + css.substring(rex.lastIndex, css.length);
  30. rex.lastIndex = rex.lastIndex + (len2-len);
  31. }
  32. return css;
  33. },
  34. convertImgNode: function(subNode, moduleList){
  35. this.getImplodeModuleJson(moduleList, "Image", (subNode.get("id") || "image"), subNode, function(id, moduleData){
  36. debugger;
  37. var src = subNode.get("src");
  38. if (src){
  39. //var root = (this.options.type==="portal") ? "x_portal_assemble_surface" : "x_processplatform_assemble_surface";
  40. var root = "x_cms_assemble_control";
  41. var pic = src.substring(src.lastIndexOf("/")+1, src.length);
  42. var url = root + o2.Actions.get(root).action.actions.readFile.uri;
  43. url = url.replace("{flag}", pic);
  44. url = url.replace("{applicationFlag}", this.form.json.application || this.form.json.portal);
  45. moduleData.properties.src = url;
  46. subNode.set("src", url);
  47. }
  48. subNode.set({"mwftype": "img", "id": id});
  49. }.bind(this));
  50. return subNode;
  51. }
  52. });
  53. MWF.CMSFormImport.Office = new Class({
  54. Extends: MWF.CMSFormImport.Html,
  55. options: {
  56. "stylePath": "../x_component_portal_PageDesigner/$Import/{style}/style_office.css"
  57. },
  58. init: function(){
  59. this.inforText = this.form.designer.lp.importOffice_infor;
  60. this.inforText2 = this.form.designer.lp.importOffice_infor2;
  61. this.panelTitle = this.form.designer.lp.importOffice;
  62. this.panelWidth = 800;
  63. this.panelHeight = 240;
  64. this.editorMode = "html";
  65. },
  66. loadEditor: function(){
  67. //this.contentHtml
  68. if (this.contentCss) this.contentCss.destroy();
  69. if (this.inforText2Node) this.inforText2Node.destroy();
  70. this.file = new Element("input.importFile", {
  71. "type": "file",
  72. "accept": ".doc,.docx,.xls,.xlsx"
  73. }).inject(this.contentHtml);
  74. },
  75. loadEvent: function(){
  76. this.cancelNode.addEvent("click", function(){
  77. this.implodePanel.closePanel();
  78. }.bind(this));
  79. this.okNode.addEvent("click", function(e){
  80. var files = this.file.files;
  81. if (!files.length){
  82. this.form.designer.notice(this.form.designer.lp.implodeOfficeEmpty, "error", this.node);
  83. return false;
  84. }
  85. var _self = this;
  86. this.form.designer.confirm("warn", e, this.form.designer.lp.implodeConfirmTitle, this.form.designer.lp.implodeConfirmText, 400, 100, function(){
  87. _self.implodeOffice(files);
  88. this.close();
  89. }, function(){
  90. this.close();
  91. });
  92. }.bind(this));
  93. },
  94. implodeOffice: function(files){
  95. var file = files.item(0);
  96. var formData = new FormData();
  97. formData.append('file', file);
  98. MWF.Actions.get("x_general_assemble_control").convertHtml(formData, file, function(json){
  99. var html = json.data.value;
  100. this.implode(html);
  101. }.bind(this));
  102. }
  103. });
  104. MWF.CMSFormImport.create = function(type, form, options){
  105. return new MWF.CMSFormImport[type.capitalize()](form, options);
  106. };