]> _ Git - fluidbook-html5.git/commitdiff
wip #4286 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 23 Feb 2021 14:09:39 +0000 (15:09 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 23 Feb 2021 14:09:39 +0000 (15:09 +0100)
js/libs/fluidbook/cart/fluidbook.cart.grandvision.js

index 1a3905dc952885d022229af992ef0bda8471941b..fcbe2eec7a67e07558e38b3f4327439a39e69fd9 100644 (file)
@@ -12,7 +12,7 @@ FluidbookCartGrandVision.prototype = {
         var $this = this;
         this.items = this.fluidbook.cache.get('cart', []);
         this.boxes = this.fluidbook.cache.get('boxes', [{name: 'Box 1', refs: []}]);
-        if (this.boxes===undefined || this.boxes===null || this.boxes.length === 0) {
+        if (typeof this.boxes === "string" || this.boxes === undefined || this.boxes === null || this.boxes.length === 0) {
             this.boxes = [{name: 'Box 1', refs: []}];
         }
         this.boxIndex = Math.max(0, Math.min(this.boxes.length - 1, parseInt(this.fluidbook.cache.get('boxindex', '0'))));
@@ -45,7 +45,13 @@ FluidbookCartGrandVision.prototype = {
         });
 
         $(document).on('change', 'select[name="box"]', function () {
-            $this.boxIndex = parseInt($(this).find('option[value="' + $(this).val() + '"]').data('i'));
+            var val = $(this).val();
+            var opt = $(this).find('option[value="' + val + '"]');
+            var i = $(opt).data('index');
+            console.log(val, opt, i);
+            $this.boxIndex = parseInt(i);
+            $this.fluidbook.cache.set('boxindex', $this.boxIndex);
+            $this.setBox();
             return true;
         });
 
@@ -68,10 +74,18 @@ FluidbookCartGrandVision.prototype = {
             $this.updateBoxesSelector();
             return false;
         });
+
+        $(document).on('click', '[data-action="export"]', function () {
+           $this.exportBoxes();
+        });
+    },
+
+    exportBoxes:function(){
+
     },
 
-    addNewBox:function(){
-        this.boxes.push({name: 'Box ' + (this.boxes.length + 2), refs: []});
+    addNewBox: function () {
+        this.boxes.push({name: 'Box ' + (this.boxes.length + 1), refs: []});
         this.boxIndex = this.boxes.length - 1;
 
         this.fluidbook.cache.set('boxes', this.boxes);
@@ -94,7 +108,6 @@ FluidbookCartGrandVision.prototype = {
 
         this.updateBoxesSelector();
         this.setBox();
-
     },
 
     removeFromCart: function (ref) {
@@ -284,7 +297,7 @@ FluidbookCartGrandVision.prototype = {
         var $this = this;
         $.each(this.boxes, function (k, b) {
             var selected = (k === $this.boxIndex) ? ' selected ' : '';
-            res += '<option data-index="' + k + '"' + selected + '>' + b.name + '</option>';
+            res += '<option data-index="' + k + '"' + selected + ' value="' + b.name + '">' + b.name + '</option>';
         });
         $("select[name='box']").html(res);
     },