ExcelForm.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. MWF.xDesktop.requireApp("Template", "MPopupForm", null, false);
  2. MWF.xApplication.cms = MWF.xApplication.cms || {};
  3. MWF.xApplication.cms.Module = MWF.xApplication.cms.Module || {};
  4. //MWF.xDesktop.requireApp("cms.Module", "Actions.RestActions", null, false);
  5. MWF.xApplication.cms.Module.ImportForm = new Class({
  6. Extends: MPopupForm,
  7. Implements: [Options, Events],
  8. options: {
  9. "style": "cms",
  10. "width": "650",
  11. "height": "300",
  12. "hasTop": true,
  13. "hasIcon": false,
  14. "draggable": true,
  15. "title" : "数据导入"
  16. },
  17. initialize: function (explorer, data, options, para) {
  18. MWF.xDesktop.requireApp("cms.Module", "$ExcelForm.lp."+MWF.language, null, false);
  19. this.lp = MWF.xApplication.cms.Module.ExcelForm.lp;
  20. this.setOptions(options);
  21. this.data = data;
  22. this.explorer = explorer;
  23. this.app = this.explorer.app;
  24. this.container = this.app.content;
  25. this.action = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Module.Actions.RestActions();
  26. this.path = "/x_component_cms_Module/$ExcelForm/";
  27. this.cssPath = "/x_component_Template/$MPopupForm/"+this.options.style+"/css.wcss";
  28. this.load();
  29. //this.orgAction = new MWF.xAction.org.express.RestActions();
  30. },
  31. _createTableContent: function () {
  32. var html = "<table width='100%' bordr='0' cellpadding='7' cellspacing='0' styles='formTable' style='margin-top: 20px; '>" +
  33. "<tr><td styles='formTableTitle' lable='url' width='20%'></td>" +
  34. " <td styles='formTableValue' item='url' colspan='3' width='80%'></td></tr>" +
  35. "<tr><td styles='formTableTitle' lable='file' ></td>" +
  36. " <td styles='formTableValue' colspan='3'><div item='filename'></div><div item='file'></div></td></tr>" +
  37. "</table>";
  38. this.formTableArea.set("html", html);
  39. MWF.xDesktop.requireApp("Template", "MForm", null, false);
  40. this.form = new MForm(this.formTableArea, {}, {
  41. isEdited: true,
  42. style : "cms",
  43. hasColon : true,
  44. itemTemplate: {
  45. url: { text : "下载模板" },
  46. file: { type : "button", value : "选择Excel文件",text : "选择文件", event :{
  47. click : function(){
  48. this.selectFile();
  49. }.bind(this)
  50. } }
  51. }
  52. }, this.app);
  53. this.form.load();
  54. },
  55. _setCustom: function(){
  56. this.formTableContainer.setStyles({
  57. "margin-left" : "60px",
  58. "width" : "520px"
  59. });
  60. this.formBottomNode.setStyles({
  61. "padding-right" : "195px",
  62. "padding-bottom" : "20px"
  63. });
  64. },
  65. selectFile: function () {
  66. if (!this.uploadFileAreaNode) {
  67. this.uploadFileAreaNode = new Element("div");
  68. var html = "<input name=\"file\" type=\"file\" accept=\"csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel\" />";
  69. this.uploadFileAreaNode.set("html", html);
  70. this.fileUploadNode = this.uploadFileAreaNode.getFirst();
  71. this.fileUploadNode.addEvent("change", function () {
  72. var files = fileNode.files;
  73. if (files.length) {
  74. var file = files.item(0);
  75. this.file = file;
  76. this.formData = new FormData();
  77. this.formData.append('file', this.file);
  78. var fileNameDiv = this.formTableArea.getElement("[item='filename']");
  79. fileNameDiv.set("text",file.name);
  80. }
  81. }.bind(this));
  82. }
  83. var fileNode = this.uploadFileAreaNode.getFirst();
  84. fileNode.click();
  85. },
  86. ok: function( callback ){
  87. if( !this.formData ){
  88. this.app.notice( "请先选择Excel文件", "error" );
  89. }else{
  90. this.action.importDocumentFormExcel(this.data.id, function () {
  91. this.formData = null;
  92. this.file = null;
  93. }.bind(this), null, this.formData, this.file);
  94. }
  95. }
  96. });
  97. MWF.xApplication.cms.Module.ExportForm = new Class({
  98. Extends: MPopupForm,
  99. Implements: [Options, Events],
  100. options: {
  101. "style": "cms",
  102. "width": "850",
  103. "height": "700",
  104. "maxAction" : true,
  105. "hasTop": true,
  106. "hasIcon": false,
  107. "hasBottom": true,
  108. "draggable": true,
  109. "title" : "数据导出"
  110. },
  111. initialize: function (explorer, data, options, para) {
  112. MWF.xDesktop.requireApp("cms.Module", "$ExcelForm.lp."+MWF.language, null, false);
  113. this.lp = MWF.xApplication.cms.Module.ExcelForm.lp;
  114. this.setOptions(options);
  115. this.data = data;
  116. this.explorer = explorer;
  117. this.app = this.explorer.app;
  118. this.container = this.app.content;
  119. this.action = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Module.Actions.RestActions();
  120. this.path = "/x_component_cms_Module/$ExcelForm/";
  121. this.cssPath = "/x_component_Template/$MPopupForm/"+this.options.style+"/css.wcss";
  122. this.load();
  123. //this.orgAction = new MWF.xAction.org.express.RestActions();
  124. },
  125. _setCustom: function(){
  126. //this.formTableContainer.setStyles({
  127. // "margin-left" : "60px",
  128. // "width" : "520px"
  129. //});
  130. //
  131. //this.formBottomNode.setStyles({
  132. // "padding-right" : "195px",
  133. // "padding-bottom" : "20px"
  134. //});
  135. },
  136. _createTableContent: function(){
  137. //var filter = null;
  138. //if (this.json.filterList && this.json.filterList.length){
  139. // filter = [];
  140. // this.json.filterList.each(function(entry){
  141. // entry.value = this.form.Macro.exec(entry.code.code, this);
  142. // //delete entry.code;
  143. // filter.push(entry);
  144. // }.bind(this));
  145. //}
  146. this.formTableArea.setStyles({
  147. "margin-left":"20px",
  148. "margin-right":"20px"
  149. });
  150. var viewJson = {
  151. //"application": this.json.queryView.appName,
  152. "application" : this.data.importViewAppId,
  153. "viewName": this.data.importViewId, //this.data.importViewId, //this.json.queryView.name
  154. "isTitle": "yes",
  155. "select": "multi"
  156. //"isTitle": this.json.isTitle || "yes",
  157. //"select": this.json.select || "none",
  158. //"titleStyles": this.json.titleStyles,
  159. //"itemStyles": this.json.itemStyles,
  160. //"isExpand": this.json.isExpand || "no",
  161. //"filter": filter
  162. };
  163. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  164. this.view = new MWF.xApplication.query.Query.Viewer(this.formTableArea, viewJson, {
  165. //"resizeNode": (this.node.getStyle("height").toString().toLowerCase()!=="auto" && this.node.getStyle("height").toInt()>0),
  166. "onSelect": function(){
  167. this.fireEvent("select");
  168. }.bind(this)
  169. });
  170. }.bind(this));
  171. },
  172. _setNodesSize : function(width, height, formContentHeight, formTableHeight){
  173. this.formTableArea.setStyles({
  174. "height" : formTableHeight + "px"
  175. });
  176. if(this.view && this.view.node && this.view.viewAreaNode )this.view.setContentHeight();
  177. }
  178. });