]> _ Git - fluidbook-html5.git/commitdiff
wip #7898 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Jan 2026 18:32:17 +0000 (19:32 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 13 Jan 2026 18:32:17 +0000 (19:32 +0100)
js/libs/fluidbook/cart/fluidbook.cart.kimplay.js
js/libs/fluidbook/fluidbook.cart.js
style/cart/kimplay.less

index 56e78a91201cda2f3e1ee38654ea6300173f8415..03e32446c69bf33c27fa1bc382dadc8ddf5dc65b 100644 (file)
@@ -1,23 +1,43 @@
 function FluidbookCartKimplay(cart) {
-    var $this = this;
     this.cart = cart;
     this.fluidbook = this.cart.fluidbook;
     this.data = this.fluidbook.settings.basketReferences;
     this.showAddToCartTooltips = false;
+    this.items = {};
     this.init();
 }
 
 FluidbookCartKimplay.prototype = {
     init: function () {
         var $this = this;
-        this.items = this.fluidbook.cache.get('cart', []);
+        this.items = this.fluidbook.cache.get('cart', {});
         $(document).on(this.fluidbook.input.clickEvent, '.exportCartPDF', function () {
             $this.exportPDF();
             return false;
         });
+
+        $(document).on(this.fluidbook.input.clickEvent, '#kimplay-additem button', function () {
+            let form = $(this).closest('#kimplay-additem');
+            $this.items['' + $(this).data('ref')] = {
+                quantity: $(form).find('[name=qty]').val(),
+                comment: $(form).find('[name=comment]').val()
+            };
+            $this.fluidbook.tooltip.displayTooltipDuring($this.fluidbook.l10n.__("the item has been added to your cart"), 2500);
+            $this.fluidbook.menu.closeView();
+            $this.save();
+        });
     },
 
-    addToCart: function (ref, quantity) {
+    addToCart: function (ref) {
+        let quantity, comment;
+
+        if (this.items[ref] === undefined) {
+            quantity = 1;
+            comment = '';
+        } else {
+            quantity = this.items[ref].quantity;
+            comment = this.items[ref].comment;
+        }
 
         let view = `<div id="kimplay-additem">
     ${this.fluidbook.menu.getCaption("", 'small')}
@@ -30,23 +50,14 @@ FluidbookCartKimplay.prototype = {
                                 Quantité souhaitée :<br>
                                 <input type="text" name="qty" value="${quantity}"><br>
                                 Commentaire (facultatif)
-                                <textarea name="commentaire"></textarea><br>
-                                <button>Ajouter à ma sélection</button>
+                                <textarea name="comment">${comment}</textarea><br>
+                                <button data-ref="${ref}">Ajouter à ma sélection</button>
                             </div>
                         </div>
                     </div>`;
         this.fluidbook.menu.openCustomView(view, 'cart-kimplay-qty');
     },
 
-    _addToCart: function (ref, quantity) {
-        if (this.items.indexOf(ref) === -1) {
-            this.items.push(ref);
-            this.save();
-        }
-
-        return this.fluidbook.l10n.__("the item has been added to your selection");
-    },
-
     removeFromCart: function (key) {
         this.items.splice(key, 1);
         this.save();
@@ -59,23 +70,31 @@ FluidbookCartKimplay.prototype = {
     },
 
     getItems: function () {
-        var res = [];
-        var $this = this;
-        $(this.items).each(function (i, ref) {
-            if ($this.data[ref] !== undefined && $this.data[ref] !== null) {
-                res.push(ref);
-            }
-        });
-        return res;
+        return this.items;
     },
 
+    hasItem: function (ref) {
+        return this.items[ref] !== undefined;
+    },
 
     getItemsReferences: function () {
-        return this.getItems();
-    }, getItemsNumbers: function () {
+        let res = [];
+        $.each(this.getItems(), function (i, item) {
+            res.push(i);
+        });
+        return res;
+    },
+
+    getItemsNumbers: function () {
         return this.getItems().length;
-    }, getAllQuantities: function () {
-        return this.getItemsNumbers();
+    },
+
+    getAllQuantities: function () {
+        let res = 0;
+        $.each(this.getItems(), function (i, item) {
+            res += parseInt(item.quantity);
+        });
+        return res;
     },
 
     updateCart: function () {
index b937635171026d0ba29e88ce9d32f8e8b3b31538..6d470492b1e75cfce045fc64974c08c1b7141ba8 100644 (file)
@@ -49,13 +49,13 @@ FluidbookCart.prototype = {
                             }
                             if (refs.indexOf(r) === -1) {
                                 refs.push(r);
-                                if ($this.instance.getItems().indexOf(r) === -1) {
+                                if ($this.hasItem(r) === -1) {
                                     force = true;
                                 }
                             }
                         });
                     } else {
-                        force = $this.instance.getItems().indexOf(ref) === -1;
+                        force = $this.hasItem(ref) === -1;
                         refs = [ref];
                     }
 
@@ -92,7 +92,7 @@ FluidbookCart.prototype = {
                         $this.fluidbook.tooltip.displayTooltipDuring(tooltip, 2500, tooltipStyle);
                     }
                 } catch (e) {
-
+                    console.log(e);
                 }
 
                 return false;
@@ -104,6 +104,13 @@ FluidbookCart.prototype = {
         });
     },
 
+    hasItem: function (ref) {
+        if (this.instance.hasItem !== undefined) {
+            return this.instance.hasItem(ref);
+        }
+        return this.instance.getItems().indexOf(ref)
+    },
+
     updateLinks: function () {
 
         $('a[data-cart-ref]').removeClass('active');
index dd74e93d1ccd9428d5aeb11c1e99994373cda431..1e2627fef9c316de16d0ef380430573a1fc634e0 100644 (file)
@@ -1,3 +1,7 @@
+.link a.active[data-cart-ref] {
+  background-color: rgba(0, 255, 0, 0.5);
+}
+
 .mview[data-menu="cart-kimplay-qty"] {
   background-color: #fff;
   color: #000;
@@ -6,7 +10,7 @@
 
   .caption {
     height: 30px;
-    padding:0;
+    padding: 0;
   }
 
   .caption a.back {
 
     input, textarea {
       border: 2px solid #000;
-      margin-bottom: 30px;
+      margin-bottom: 20px;
       padding: 2px;
       font-size: 16px;
+      font-family: @font;
     }
 
     textarea {
       max-width: 100%;
       height: 58px;
       max-height: 58px;
+      padding: 5px;
     }
 
     input {
-      width: 50px;
+      width: 70px;
       background-color: #fff;
+      text-align: center;
     }
 
     button {
       color: #fff;
       text-transform: uppercase;
       text-align: center;
-      padding: 10px 0;
+      padding: 14px 0;
       display: block;
       width: 100%;
       font-weight: bold;
+      cursor: pointer;
     }
   }
 }
\ No newline at end of file