LP#1721557 Fix Vandelay export within web client
authorRemington Steed <rjs7@calvin.edu>
Thu, 5 Oct 2017 13:26:39 +0000 (09:26 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Wed, 11 Oct 2017 16:06:12 +0000 (12:06 -0400)
Triggering a file download from dojo pages within the web client
requires a new technique. This commit borrows from the acq lineitem
table export (acq/common/li_table.js) and applies the technique to the
vandelay feature.

Signed-off-by: Remington Steed <rjs7@calvin.edu>
Signed-off-by: Cesar Velez <cesar.velez@equinoxinitiative.org>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Open-ILS/src/templates/vandelay/vandelay.tt2
Open-ILS/web/js/ui/default/vandelay/vandelay.js

index 2002efc..9a7a72a 100644 (file)
@@ -2,6 +2,7 @@
 [% ctx.page_title = l('MARC Import/Export') %]
 
 <script type="text/javascript" src='[% ctx.media_prefix %]/js/ui/default/vandelay/vandelay.js'> </script>
+<script type="text/javascript" src='[% ctx.media_prefix %]/js/file-saver/FileSaver.min.js'> </script>
 <link rel='stylesheet' type='text/css' href='[% ctx.media_prefix %]/css/skin/[% ctx.skin %]/vandelay.css'/>
 <link rel='stylesheet' type='text/css' href='[% ctx.media_prefix %]/css/theme/[% ctx.skin %]/vandelay.css'/>
 
index 8726153..b60cab0 100644 (file)
@@ -577,13 +577,24 @@ function vlExportRecordQueue(opts) {
     req.onreadystatechange = function () {
         if (req.readyState == 4) {
             var file_tag = opts.nonimported ? '_nonimported' : '';
-            openils.XUL.contentToFileSaveDialog(req.responseText, null, {
-                defaultString : currentQueueName + file_tag + '.mrc',
-                defaultExtension : '.mrc',
-                filterName : 'MARC21',
-                filterExtension : '*.mrc',
-                filterAll : true
-            } );
+            var filename = currentQueueName + file_tag + '.mrc';
+
+            try {
+                if (window.IAMBROWSER) {
+                    var blob = new Blob([req.responseText], {type: "application/octet-stream"});
+                    saveAs(blob, filename);
+                } else {
+                    openils.XUL.contentToFileSaveDialog(req.responseText, null, {
+                        defaultString : filename,
+                        defaultExtension : '.mrc',
+                        filterName : 'MARC21',
+                        filterExtension : '*.mrc',
+                        filterAll : true
+                    } );
+                }
+            } catch (E) {
+                alert(E);
+            }
         }
     }
 }