소스 검색

Fix IE issues with Excel import.
Fix blank worksheet errors in Excel import.

Andrew Klopper 8 년 전
부모
커밋
e6d553ce42
3개의 변경된 파일38개의 추가작업 그리고 2개의 파일을 삭제
  1. 7 0
      base/static/js/tour.js
  2. 1 0
      base/templates/layouts/base.html
  3. 30 2
      feed_content/templates/feed_content/feed_category_import_excel.html

+ 7 - 0
base/static/js/tour.js

@@ -251,6 +251,13 @@ var feed_logs_tour = new Tour({
251 251
 	]
252 252
 });
253 253
 
254
+if (! String.prototype.startsWith) {
255
+  String.prototype.startsWith = function(searchString, position) {
256
+    position = position || 0;
257
+    return this.indexOf(searchString, position) === position;
258
+  };
259
+}
260
+
254 261
 if (document.location.pathname.startsWith('/feed_content/')) {
255 262
 	feed_content_tour.init();
256 263
 }

+ 1 - 0
base/templates/layouts/base.html

@@ -1,3 +1,4 @@
1
+<!DOCTYPE html>
1 2
 {% load staticfiles %}
2 3
 <html class="no-js" lang="en">
3 4
 <head>

+ 30 - 2
feed_content/templates/feed_content/feed_category_import_excel.html

@@ -88,6 +88,28 @@
88 88
 <script>
89 89
   'use strict';
90 90
 
91
+  if (FileReader.prototype.readAsBinaryString === undefined) {
92
+    FileReader.prototype.readAsBinaryString = function (fileData) {
93
+      var binary = "";
94
+      var pt = this;
95
+      var reader = new FileReader();
96
+      reader.onload = function (e) {
97
+        var bytes = new Uint8Array(reader.result);
98
+        var length = bytes.byteLength;
99
+        for (var i = 0; i < length; i++) {
100
+          binary += String.fromCharCode(bytes[i]);
101
+        }
102
+        //pt.result  - readonly so assign content to another property
103
+        pt.content = binary;
104
+        $(pt).trigger('onload');
105
+      }
106
+      reader.readAsArrayBuffer(fileData);
107
+    }
108
+  }
109
+</script>
110
+<script>
111
+  'use strict';
112
+
91 113
   var workbook = null;
92 114
   var messages_to_import = null;
93 115
 
@@ -132,6 +154,11 @@
132 154
       var sheet_name = workbook.SheetNames[index];
133 155
       var sheet = workbook.Sheets[sheet_name];
134 156
       $('.sheet-name').text(sheet_name);
157
+      if (! ('!ref' in sheet)) {
158
+	      $('#sheet_contents').text('Sheet is empty.');
159
+	      set_status_error('Sheet is empty.');
160
+	      return;
161
+      }
135 162
       $('#sheet_contents').html(XLSX.utils.sheet_to_html(sheet));
136 163
       $('#sheet_contents table').addClass('table table-bordered table-striped table-hover');
137 164
       var sheet_range = XLSX.utils.decode_range(sheet['!ref']);
@@ -177,7 +204,7 @@
177 204
           cell = sheet[cell_address];
178 205
           var message_text = (cell != null) && (cell.t == 's') ? cell.v.trim() : '';
179 206
           if (message_text == '') {
180
-            set_status_error('No message text found for day ' + day + ' in cell ' + cell_address);
207
+            set_status_error('No message text found for day ' + day + ' in cell ' + cell_address + '.<br>If you want to import everything before this day, please delete this day number or insert a blank row into the sheet directly above it.');
181 208
             return;
182 209
           }
183 210
 
@@ -222,8 +249,9 @@
222 249
       var reader = new FileReader();
223 250
       reader.readAsBinaryString(file);
224 251
       reader.onload = function(e) {
252
+        var data = e ? e.target.result : reader.content;
225 253
         try {
226
-          workbook = XLSX.read(e.target.result, {type: 'binary'});
254
+          workbook = XLSX.read(data, {type: 'binary'});
227 255
           workbook_changed();
228 256
         }
229 257
         catch (err) {