]> _ Git - fluidbook-html5.git/commitdiff
wait #5534
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 Oct 2022 16:43:22 +0000 (18:43 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 25 Oct 2022 16:43:22 +0000 (18:43 +0200)
js/libs/fluidbook/cart/fluidbook.cart.puma.js

index 923e3384f0fea0110fe3b75e5403e78271ce3fae..26216aa7d5b8b63bad5105f65f4e752fee476ba1 100644 (file)
@@ -3,6 +3,7 @@ function FluidbookCartPuma(cart) {
     this.cart = cart;
     this.fluidbook = this.cart.fluidbook;
     this.data = this.fluidbook.settings.basketReferences;
+    this.exportFileName = '';
     this.init();
 }
 
@@ -11,13 +12,17 @@ FluidbookCartPuma.prototype = {
         var $this = this;
         this.items = this.fluidbook.cache.get('cart', []);
         $(document).on(this.fluidbook.input.clickEvent, '.exportCartPDF', function () {
-            $this.exportPDF();
+            $this.chooseFileName(function () {
+                $this.exportPDF();
+            });
             return false;
         });
 
         $(document).on(this.fluidbook.input.clickEvent, '.exportCartXLS', function () {
             try {
-                $this.exportXLS();
+                $this.chooseFileName(function () {
+                    $this.exportXLS();
+                });
             } catch (err) {
                 console.log(err);
             }
@@ -25,7 +30,9 @@ FluidbookCartPuma.prototype = {
         });
         $(document).on(this.fluidbook.input.clickEvent, '.exportEANXLS', function () {
             try {
-                $this.exportEANXLS();
+                $this.chooseFileName(function () {
+                    $this.exportEANXLS();
+                });
             } catch (err) {
                 console.log(err);
             }
@@ -224,12 +231,12 @@ FluidbookCartPuma.prototype = {
         }, 2000);
     },
 
-    getExportFileName: function (label) {
-        if (label === undefined) {
-            label = 'Cart';
+    getExportFileName: function () {
+        if (this.exportFileName !== '') {
+            return this.exportFileName;
         }
         var date = new Date();
-        return this.fluidbook.settings.title + ' - ' + label + ' - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
+        return this.fluidbook.settings.title + ' - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDate();
     },
 
     exportEANXLS: function () {
@@ -280,12 +287,47 @@ FluidbookCartPuma.prototype = {
             const url = window.URL.createObjectURL(blob);
             const anchor = document.createElement('a');
             anchor.href = url;
-            anchor.download = $this.getExportFileName('EAN') + '.xlsx';
+            anchor.download = $this.getExportFileName() + '.xlsx';
             anchor.click();
             window.URL.revokeObjectURL(url);
         });
     },
 
+    chooseFileName: function (callback) {
+        var $this = this;
+        $.confirm({
+            title: 'Name your file',
+            content: '' +
+                '<form action="" class="formName">' +
+                '<div class="form-group">' +
+                '<input type="text" value="' + this.getExportFileName() + '" placeholder="File name" class="name form-control" required />' +
+                '</div>' +
+                '</form>',
+            buttons: {
+                formSubmit: {
+                    text: 'Submit',
+                    btnClass: 'btn-ok',
+                    action: function () {
+                        $this.exportFileName = this.$content.find('.name').val();
+                        callback();
+                    }
+                },
+                cancel: function () {
+                    //close
+                },
+            },
+            onContentReady: function () {
+                // bind to events
+                var jc = this;
+                this.$content.find('form').on('submit', function (e) {
+                    // if the user submits the form by pressing enter in the field.
+                    e.preventDefault();
+                    jc.$$formSubmit.trigger('click'); // reference the button and click it
+                });
+            }
+        });
+    },
+
     exportXLS: function () {
         var $this = this;
         const workbook = new ExcelJS.Workbook();