From f73a9030b6d728ed067e979d3b2937e8eef2f95e Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 11 Apr 2018 20:10:12 +0200 Subject: [PATCH] wip #1927 @1 --- .../cart/fluidbook.cart.remarkable.js | 77 +++++++++++++++++++ js/libs/fluidbook/fluidbook.menu.js | 35 +++++++-- js/libs/fluidbook/fluidbook.nav.js | 2 +- 3 files changed, 107 insertions(+), 7 deletions(-) diff --git a/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js b/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js index 8142a785..2c309ec3 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.remarkable.js @@ -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 = ''; + $.each(this.items, function (ref, quantity) { + var item = $this.getItemData(ref); + + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + + content + ''; + }); + content + '
' + item.name + '' + quantity + '' + $this.formatPrice(item.price, 'HT') + '' + $this.formatPrice(item.price * quantity, 'HT') + '' + $this.formatPrice((item.price * quantity) * (1 + item.tax), 'TTC') + '
'; + 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 = '
' + this.fluidbook.menu.closeButton() + '

' + title + '

'; + view += '
'; + view += "" + content; + view += '
'; + $("#view").append('
' + view + '
'); + callback(); + } + }; \ No newline at end of file diff --git a/js/libs/fluidbook/fluidbook.menu.js b/js/libs/fluidbook/fluidbook.menu.js index a86b891e..10135ca8 100644 --- a/js/libs/fluidbook/fluidbook.menu.js +++ b/js/libs/fluidbook/fluidbook.menu.js @@ -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; diff --git a/js/libs/fluidbook/fluidbook.nav.js b/js/libs/fluidbook/fluidbook.nav.js index 68a873fd..794e64a7 100644 --- a/js/libs/fluidbook/fluidbook.nav.js +++ b/js/libs/fluidbook/fluidbook.nav.js @@ -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); -- 2.39.5