]> _ Git - fluidbook-html5.git/commitdiff
wip #1927 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 11 Apr 2018 18:10:12 +0000 (20:10 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 11 Apr 2018 18:10:12 +0000 (20:10 +0200)
js/libs/fluidbook/cart/fluidbook.cart.remarkable.js
js/libs/fluidbook/fluidbook.menu.js
js/libs/fluidbook/fluidbook.nav.js

index 8142a785f3485e4f3589053661fcdeb3d7bce7d8..2c309ec34804e6f1e1249aeb00f188f63d181aaf 100644 (file)
@@ -1,7 +1,21 @@
 function FluidbookCartRemarkable(cart) {
+    var $this = this;
     this.cart = cart;
     this.fluidbook = this.cart.fluidbook;
     this.items = {};
+    this.database;
+    $.each(this.fluidbook.datas.basketReferences, function (k, v) {
+        $this.database = {};
+        $.each(v, function (index, line) {
+            $this.database[line[0]] = {
+                ref: line[0],
+                name: line[1],
+                price: parseFloat(line[2]),
+                tax: parseFloat(line[3]) / 100
+            }
+        });
+        return true;
+    });
     this.init();
 }
 
@@ -46,4 +60,67 @@ FluidbookCartRemarkable.prototype = {
         $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()});
     },
 
+    openMenu: function (p1, p2, callback) {
+        if (p1 == 'shipping') {
+            return this.openShipping(p2, callback);
+        } else if (p1 == 'confirm') {
+            return this.openConfirm(p2, callback);
+        } else {
+            return this.openCart(p2, callback);
+        }
+    },
+
+    openCart: function (p2, callback) {
+        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="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 + '</tr>';
+        });
+        content + '</table>';
+        this._endMenu(this.fluidbook.l10n.__('your cart'), content, callback);
+    },
+
+    formatPrice: function (price, currency, suffix) {
+        if (suffix == undefined) {
+            suffix = '';
+        }
+
+        return price.toLocaleString("fr-FR", {style: "currency", currency: "EUR"}) + ' ' + suffix;
+    },
+
+    getItemData: function (ref) {
+        return this.database[ref];
+    },
+
+
+    openShipping: function (p2, callback) {
+        var content = '';
+        this._endMenu(this.fluidbook.l10n.__('your contact details'), content, callback);
+    },
+
+    openConfirm: function (p2, callback) {
+        var content = '';
+        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">';
+        view += "" + content;
+        view += '</div>';
+        $("#view").append('<div class="mview" data-menu="cart">' + view + '</div>');
+        callback();
+    }
+
 };
\ No newline at end of file
index a86b891eaf6898fe83836ec06933c15260367880..10135ca826e5ac2d8cf6417a30cb2ee14050742c 100644 (file)
@@ -247,8 +247,11 @@ FluidbookMenu.prototype = {
         if (callback != undefined) {
             callback();
         }
-    }
-    ,
+    },
+
+    openCart: function (p1, p2, callback) {
+        this.fluidbook.cart.instance.openMenu(p1, p2, callback);
+    },
     openShare: function (p1, p2, callback) {
         this.fluidbook.share.openShare(p1, p2, callback);
     },
@@ -398,6 +401,9 @@ FluidbookMenu.prototype = {
             case 'locales':
                 w = 300;
                 break;
+            case 'cart':
+                w = 1024;
+                break;
             case 'bookmarks':
                 var max = Math.floor((ww * 0.8) / 120) * 120 + 40;
                 w = Math.min(max, Math.max(m.find('.doubleThumb').length, 4) * 120 + 40);
@@ -487,19 +493,36 @@ FluidbookMenu.prototype = {
                         h = nh * s;
                     }
 
-                    x = (w - (nw * s)  ) / 2;
+                    x = (w - (nw * s)) / 2;
                     y = (h - (nh * s)) / 2;
                 }
 
 
                 if (s < 1) {
-                    var css = {overflow: 'hidden', width: nw * s, height: nh * s, top: y, left: x, position: 'absolute'};
+                    var css = {
+                        overflow: 'hidden',
+                        width: nw * s,
+                        height: nh * s,
+                        top: y,
+                        left: x,
+                        position: 'absolute'
+                    };
                     m.find('.multimediaHolder').css(css);
                 } else {
-                    m.find('.multimediaHolder').css({position: "", overflow: '', width: '', height: '', top: '', left: ''});
+                    m.find('.multimediaHolder').css({
+                        position: "",
+                        overflow: '',
+                        width: '',
+                        height: '',
+                        top: '',
+                        left: ''
+                    });
                 }
 
-                m.find('.multimediaScale').css({width: nw, height: nh, overflow: 'hidden'}).transform({scale: [s, s], origin: [0, 0]}).css('text-align', 'left');
+                m.find('.multimediaScale').css({width: nw, height: nh, overflow: 'hidden'}).transform({
+                    scale: [s, s],
+                    origin: [0, 0]
+                }).css('text-align', 'left');
                 break;
             default:
                 break;
index 68a873fd10c4fb0824212d81a11c31248d7a908a..794e64a76b35dd5062f2c07225e6d6f7a23daecf 100644 (file)
@@ -393,7 +393,7 @@ FluidbookNav.prototype = {
             } else if (icon == 'print' && this.fluidbook.datas.print) {
                 link = this.addLink(navType, 'nav-print', '#', 'print', 'print', 'print');
             } else if (icon == 'basket' && this.fluidbook.cart.enabled) {
-                link = this.addLink(navType, 'nav-basket', '#', 'cart', 'basket', 'basket');
+                link = this.addLink(navType, 'nav-basket', '#/cart', 'cart', 'basket', 'basket');
                 $(this.fluidbook).on('fluidbook.cart.updateIcon', {link: link.attr('id')}, function (e, data) {
                     var n = data.number;
                     var l = $("#" + e.data.link);