Просмотр исходного кода

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

Andrew Klopper лет назад: 8
Родитель
Сommit
e6d553ce42

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

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
 if (document.location.pathname.startsWith('/feed_content/')) {
261
 if (document.location.pathname.startsWith('/feed_content/')) {
255
 	feed_content_tour.init();
262
 	feed_content_tour.init();
256
 }
263
 }

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

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

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

88
 <script>
88
 <script>
89
   'use strict';
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
   var workbook = null;
113
   var workbook = null;
92
   var messages_to_import = null;
114
   var messages_to_import = null;
93
 
115
 
132
       var sheet_name = workbook.SheetNames[index];
154
       var sheet_name = workbook.SheetNames[index];
133
       var sheet = workbook.Sheets[sheet_name];
155
       var sheet = workbook.Sheets[sheet_name];
134
       $('.sheet-name').text(sheet_name);
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
       $('#sheet_contents').html(XLSX.utils.sheet_to_html(sheet));
162
       $('#sheet_contents').html(XLSX.utils.sheet_to_html(sheet));
136
       $('#sheet_contents table').addClass('table table-bordered table-striped table-hover');
163
       $('#sheet_contents table').addClass('table table-bordered table-striped table-hover');
137
       var sheet_range = XLSX.utils.decode_range(sheet['!ref']);
164
       var sheet_range = XLSX.utils.decode_range(sheet['!ref']);
177
           cell = sheet[cell_address];
204
           cell = sheet[cell_address];
178
           var message_text = (cell != null) && (cell.t == 's') ? cell.v.trim() : '';
205
           var message_text = (cell != null) && (cell.t == 's') ? cell.v.trim() : '';
179
           if (message_text == '') {
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
             return;
208
             return;
182
           }
209
           }
183
 
210
 
222
       var reader = new FileReader();
249
       var reader = new FileReader();
223
       reader.readAsBinaryString(file);
250
       reader.readAsBinaryString(file);
224
       reader.onload = function(e) {
251
       reader.onload = function(e) {
252
+        var data = e ? e.target.result : reader.content;
225
         try {
253
         try {
226
-          workbook = XLSX.read(e.target.result, {type: 'binary'});
254
+          workbook = XLSX.read(data, {type: 'binary'});
227
           workbook_changed();
255
           workbook_changed();
228
         }
256
         }
229
         catch (err) {
257
         catch (err) {