]> _ Git - fluidbook-html5.git/commitdiff
wip #1927 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 12 Apr 2018 17:25:47 +0000 (19:25 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 12 Apr 2018 17:25:47 +0000 (19:25 +0200)
js/libs/fluidbook/cart/fluidbook.cart.remarkable.js
js/libs/fluidbook/fluidbook.cache.js
js/libs/fluidbook/fluidbook.cart.js
js/libs/fluidbook/fluidbook.nav.js
js/libs/fluidbook/fluidbook.tooltip.js
style/fluidbook.less

index 2c309ec34804e6f1e1249aeb00f188f63d181aaf..566c5802469525a62305ed097e3230483d50f790 100644 (file)
@@ -2,7 +2,7 @@ function FluidbookCartRemarkable(cart) {
     var $this = this;
     this.cart = cart;
     this.fluidbook = this.cart.fluidbook;
-    this.items = {};
+    this.items = this.cart.getSavedData();
     this.database;
     $.each(this.fluidbook.datas.basketReferences, function (k, v) {
         $this.database = {};
@@ -21,7 +21,11 @@ function FluidbookCartRemarkable(cart) {
 
 FluidbookCartRemarkable.prototype = {
     init: function () {
-
+        var $this = this;
+        $(document).on('change', '[data-menu="cart"] .input-number', function () {
+            $this.updateCart();
+            return true;
+        });
     },
     addToCart: function (ref, quantity) {
         this.setQuantity(ref, quantity, 'add');
@@ -51,6 +55,7 @@ FluidbookCartRemarkable.prototype = {
         } else {
             this.items[ref] = q;
         }
+        this.cart.saveData(this.items);
         this.updateIcon();
     },
     getItemsNumbers: function () {
@@ -71,26 +76,40 @@ FluidbookCartRemarkable.prototype = {
     },
 
     openCart: function (p2, callback) {
+        var $this = this;
+        this._endMenu(this.fluidbook.l10n.__('your cart'), this.getCartContent(), function () {
+            $('input[type="number"]').inputNumber();
+
+            callback();
+        });
+    },
+
+    getCartContent: function () {
         var $this = this;
         var content = '<table class="cart-items">';
         $.each(this.items, function (ref, quantity) {
             var item = $this.getItemData(ref);
-
             content += '<tr>';
             content += '<td class="name">' + item.name + '</td>';
-            content += '<td class="quantity">' + quantity + '</td>';
+            content += '<td class="quantity"><input name="' + ref + '" class="cartqty" type="number" min="0" max="100" value="' + quantity + '" step="1" /></td>';
             content += '<td class="price_unit">' + $this.formatPrice(item.price, 'HT') + '</td>';
             content += '<td class="price_excluding_taxes">' + $this.formatPrice(item.price * quantity, 'HT') + '</td>';
             content += '<td class="price">' + $this.formatPrice((item.price * quantity) * (1 + item.tax), 'TTC') + '</td>';
-            content += '<td class="delete"></td>';
+            content += '<td class="delete"><a href="#" data-cart-delete="' + ref + '"></a></td>';
+            content += '</tr>';
+        });
+        content += '</table>';
+        return content;
+    },
 
-            content + '</tr>';
+    updateCart: function () {
+        var $this = this;
+        $(".cartqty").each(function () {
+            $this.setQuantity($(this).attr('name'), parseInt($(this).val()), 'set');
         });
-        content + '</table>';
-        this._endMenu(this.fluidbook.l10n.__('your cart'), content, callback);
     },
 
-    formatPrice: function (price, currency, suffix) {
+    formatPrice: function (price, suffix) {
         if (suffix == undefined) {
             suffix = '';
         }
@@ -102,7 +121,6 @@ FluidbookCartRemarkable.prototype = {
         return this.database[ref];
     },
 
-
     openShipping: function (p2, callback) {
         var content = '';
         this._endMenu(this.fluidbook.l10n.__('your contact details'), content, callback);
@@ -113,7 +131,6 @@ FluidbookCartRemarkable.prototype = {
         this._endMenu(this.fluidbook.l10n.__('confirmation'), content, callback);
     },
 
-
     _endMenu: function (title, content, callback) {
         var view = '<div class="caption">' + this.fluidbook.menu.closeButton() + '<h2>' + title + '</h2></div>';
         view += '<div class="content">';
index fd757ce74c9938b5db69d732f321119a2169599a..22651a415a073df8b91bae37248bf638b751854d 100644 (file)
@@ -35,13 +35,19 @@ FluidbookCache.prototype = {
             return this._cache[key] != null;
         }
     },
-    get: function (key) {
+    get: function (key, defaultValue) {
+        if (defaultValue === undefined) {
+            defaultValue = null;
+        }
         var res;
         if (this._support) {
             res = localStorage.getItem(this._prefix + key);
         } else {
             res = this._cache[key];
         }
+        if (!this.isset(key)) {
+            return defaultValue;
+        }
         var f = res.substr(0, 1);
         if (f == '[' || f == '{') {
             res = json_parse(res);
@@ -60,7 +66,7 @@ FluidbookCache.prototype = {
     },
     checkValidity: function () {
         if (!this.isset('validity') || this.get('validity') != this._date) {
-            this.clear();
+            //this.clear();
             this.set('validity', this._date);
         }
     }
index 22b43185e7156b44a659c93301a176fa5ce210fc..67df20e8c563bec83f4432b9a4443c2faf8e18f8 100644 (file)
@@ -16,9 +16,16 @@ FluidbookCart.prototype = {
 
         $(document).on('click', '[data-cart-ref]', function () {
             $this.instance.addToCart($(this).data('cart-ref'));
+            $this.fluidbook.tooltip.displayTooltip($this.fluidbook.l10n.__("the item has been added to your cart"));
             return false;
         });
     },
+    getSavedData: function () {
+        return this.fluidbook.cache.get('cart', {})
+    },
+    saveData: function (data) {
+        this.fluidbook.cache.set('cart', data);
+    },
     createInstance: function () {
         switch (this.fluidbook.datas.basketManager) {
             case "Remarkable":
@@ -27,4 +34,101 @@ FluidbookCart.prototype = {
                 return null;
         }
     },
-}
\ No newline at end of file
+};
+
+(function ($) {
+    function JQinputNumber(element) {
+        this.element = element;
+        this.positive = false;
+        this.integer = false;
+        this.step = 1;
+        this.inited = false;
+
+        var istep = parseFloat(this.element.attr('step'));
+        this.min = undefined !== this.element.attr('min') ? parseFloat(this.element.attr('min')) : Number.NEGATIVE_INFINITY;
+        this.max = undefined !== this.element.attr('max') ? parseFloat(this.element.attr('max')) : Number.POSITIVE_INFINITY;
+        this.errorMax = this.element.data('max-error');
+
+        this.integer = (!isNaN(istep) && istep % 1 === 0);
+        this.positive = (this.min > 0);
+
+        if (!isNaN(istep)) {
+            this.step = istep;
+        }
+        this.init();
+    }
+
+    JQinputNumber.prototype = {
+        init: function () {
+            var $this = this;
+
+            this.element.attr('novalidate', 'novalidate');
+            this.element.prop('type', 'text');
+            this.element.wrap('<div class="input-number"></div>');
+            this.wrapper = this.element.parent('.input-number');
+            this.wrapper.prepend('<a href="#" class="minus">-</a>');
+            this.wrapper.append('<a href="#" class="plus">+</a>');
+
+            this.wrapper.on('click', 'a', function () {
+                if ($(this).hasClass('minus')) {
+                    $this.increment(-1 * $this.step);
+                } else if ($(this).hasClass('plus')) {
+                    $this.increment($this.step);
+                }
+                return false;
+            });
+
+            this.element.on('change', function () {
+                $this.element.val($this.normalize());
+                $this.wrapper.trigger('change');
+            });
+
+            this.element.val(this.normalize());
+            this.inited = true;
+        },
+        normalize: function (v) {
+            var origV;
+            if (v === undefined) {
+                v = this.element.val();
+            }
+            if (typeof v !== "number") {
+
+                if (this.integer) {
+                    v = parseInt(v);
+                } else {
+                    v = parseFloat(v);
+                }
+
+            }
+            if (isNaN(v)) {
+                v = 0;
+            }
+            origV = v;
+            v = Math.max(v, this.min);
+            v = Math.min(v, this.max);
+            v = Math.round(v / this.step) * this.step;
+            if (v < origV && this.errorMax !== null) {
+                alert(this.errorMax);
+            }
+            return v;
+        },
+        increment: function (i) {
+            var v = this.normalize();
+            var v1 = v;
+            v += i;
+            v = this.normalize(v);
+            if (v === v1) {
+                return;
+            }
+            this.element.val(v);
+            this.wrapper.trigger('change');
+        }
+    };
+
+    jQuery.fn.inputNumber = function () {
+        return this.each(function () {
+            var $this = $(this);
+            $(this).data('inputNumber', new JQinputNumber($this));
+        });
+    };
+})(jQuery);
\ No newline at end of file
index 794e64a76b35dd5062f2c07225e6d6f7a23daecf..8aabeeab2e5803d3324c8e23453210b2fdd19189 100644 (file)
@@ -408,6 +408,7 @@ FluidbookNav.prototype = {
                         $(l).find('span.number').text(n);
                     }
                 });
+                this.fluidbook.cart.instance.updateIcon();
             } else if (icon == 'lang' && this.fluidbook.l10n.multilangEnabled) {
                 // Note: the "!" at the beginning of the title/help parameters means that we don't want these strings translated
                 link = this.addLink(navType, 'nav-locales', '#/locales', 'locales', '!' + this.fluidbook.l10n.getCurrentLanguageName(), '!Select Language');
index bb86822b2491b6c260bd5149db87b696a119d45e..c426ac7456a9d995ca21839d393b8b493fa8d0f8 100644 (file)
@@ -104,7 +104,6 @@ FluidbookTooltip.prototype = {
         }
 
         this.displayTooltip(text);
-        this.updateTooltipPosition();
         return false;
     },
 
@@ -129,7 +128,7 @@ FluidbookTooltip.prototype = {
             });
             return false;
         }
-
+        this.updateTooltipPosition();
         return true;
     },
     hideTooltip: function () {
index c4d2a9ba3eed8de53297a2fc3a79563f75d20a20..4fec0b546d35aa70e0ab6ce5ee5099072b0d5432 100644 (file)
@@ -859,6 +859,49 @@ a.bookmark {
        }
 }
 
+[data-menu="cart"] {
+       table {
+               width: 1004px;
+               margin-left: 10px;
+               td {
+                       padding: 15px;
+                       text-align: left;
+                       vertical-align: middle;
+                       white-space: nowrap;
+                       &.name {
+                               white-space: normal;
+                       }
+                       &.price {
+                               font-weight: 700;
+                       }
+               }
+               .input-number {
+                       position: relative;
+                       width: 160px;
+                       height: 44px;
+                       input {
+                               height: 44px;
+                               width: 60px;
+                               display: inline-block;
+                               margin: 0 2px;
+                               border: 0;
+                               vertical-align: top;
+                               padding: 20px;
+                               text-align: center;
+                       }
+                       a {
+                               display: inline-block;
+                               height: 44px;
+                               width: 44px;
+                               background-color: @menu-button-background;
+                               text-align: center;
+                               font-weight: 700;
+                               font-size: 30px;
+                       }
+               }
+       }
+}
+
 // Hack for #1433
 html.ios body.portrait #interface {
        -moz-transition: none;