ExcelForm.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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", "$ExcelForm.lp."+MWF.language, null, false);
  5. //MWF.xDesktop.requireApp("cms.Module", "Actions.RestActions", null, false);
  6. MWF.xApplication.cms.Module.ImportForm = new Class({
  7. Extends: MPopupForm,
  8. Implements: [Options, Events],
  9. options: {
  10. "style": "cms",
  11. "width": "650",
  12. "height": "300",
  13. "hasTop": true,
  14. "hasIcon": false,
  15. "draggable": true,
  16. "title" : MWF.xApplication.cms.Module.ExcelForm.lp.importData
  17. },
  18. initialize: function (explorer, data, options, para) {
  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 : this.lp.downloadTemplate }, //"下载模板"
  46. file: { type : "button", value : this.lp.selectExcelFile ,text : this.lp.selectFile, 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. if( file.name.indexOf(" ") > -1 ){
  76. this.app.notice("上传的文件不能带空格", "error");
  77. return false;
  78. }
  79. this.file = file;
  80. this.formData = new FormData();
  81. this.formData.append('file', this.file);
  82. var fileNameDiv = this.formTableArea.getElement("[item='filename']");
  83. fileNameDiv.set("text",file.name);
  84. }
  85. }.bind(this));
  86. }
  87. var fileNode = this.uploadFileAreaNode.getFirst();
  88. fileNode.click();
  89. },
  90. ok: function( callback ){
  91. if( !this.formData ){
  92. this.app.notice( this.lp.selectExcelFileNotice, "error" ); //"请先选择Excel文件"
  93. }else{
  94. this.action.importDocumentFormExcel(this.data.id, function () {
  95. this.formData = null;
  96. this.file = null;
  97. }.bind(this), null, this.formData, this.file);
  98. }
  99. }
  100. });
  101. MWF.xApplication.cms.Module.ExportForm = new Class({
  102. Extends: MPopupForm,
  103. Implements: [Options, Events],
  104. options: {
  105. "style": "cms",
  106. "width": "850",
  107. "height": "700",
  108. "maxAction" : true,
  109. "hasTop": true,
  110. "hasIcon": false,
  111. "hasBottom": true,
  112. "draggable": true,
  113. "title" : MWF.xApplication.cms.Module.ExcelForm.lp.exportData
  114. },
  115. initialize: function (explorer, data, options, para) {
  116. MWF.xDesktop.requireApp("cms.Module", "$ExcelForm.lp."+MWF.language, null, false);
  117. this.lp = MWF.xApplication.cms.Module.ExcelForm.lp;
  118. this.setOptions(options);
  119. this.data = data;
  120. this.explorer = explorer;
  121. this.app = this.explorer.app;
  122. this.container = this.app.content;
  123. this.action = MWF.Actions.get("x_cms_assemble_control"); //new MWF.xApplication.cms.Module.Actions.RestActions();
  124. this.path = "../x_component_cms_Module/$ExcelForm/";
  125. this.cssPath = "../x_component_Template/$MPopupForm/"+this.options.style+"/css.wcss";
  126. this.load();
  127. //this.orgAction = new MWF.xAction.org.express.RestActions();
  128. },
  129. _setCustom: function(){
  130. //this.formTableContainer.setStyles({
  131. // "margin-left" : "60px",
  132. // "width" : "520px"
  133. //});
  134. //
  135. //this.formBottomNode.setStyles({
  136. // "padding-right" : "195px",
  137. // "padding-bottom" : "20px"
  138. //});
  139. },
  140. _createTableContent: function(){
  141. //var filter = null;
  142. //if (this.json.filterList && this.json.filterList.length){
  143. // filter = [];
  144. // this.json.filterList.each(function(entry){
  145. // entry.value = this.form.Macro.exec(entry.code.code, this);
  146. // //delete entry.code;
  147. // filter.push(entry);
  148. // }.bind(this));
  149. //}
  150. this.formTableArea.setStyles({
  151. "margin-left":"20px",
  152. "margin-right":"20px"
  153. });
  154. var viewJson = {
  155. //"application": this.json.queryView.appName,
  156. "application" : this.data.importViewAppId,
  157. "viewName": this.data.importViewId, //this.data.importViewId, //this.json.queryView.name
  158. "isTitle": "yes",
  159. "select": "multi"
  160. //"isTitle": this.json.isTitle || "yes",
  161. //"select": this.json.select || "none",
  162. //"titleStyles": this.json.titleStyles,
  163. //"itemStyles": this.json.itemStyles,
  164. //"isExpand": this.json.isExpand || "no",
  165. //"filter": filter
  166. };
  167. MWF.xDesktop.requireApp("query.Query", "Viewer", function(){
  168. this.view = new MWF.xApplication.query.Query.Viewer(this.formTableArea, viewJson, {
  169. //"resizeNode": (this.node.getStyle("height").toString().toLowerCase()!=="auto" && this.node.getStyle("height").toInt()>0),
  170. "onSelect": function(){
  171. this.fireEvent("select");
  172. }.bind(this)
  173. }, this.app);
  174. }.bind(this));
  175. },
  176. _setNodesSize : function(width, height, formContentHeight, formTableHeight){
  177. this.formTableArea.setStyles({
  178. "height" : formTableHeight + "px"
  179. });
  180. if(this.view && this.view.node && this.view.viewAreaNode )this.view.setContentHeight();
  181. }
  182. });