From 13bc752f885ccb05c58c8e9bb416164509d28c55 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 12 May 2021 17:12:36 +0200 Subject: [PATCH] wip #4447 @2 --- .../fluidbook/cart/fluidbook.cart.flexipan.js | 182 ++++++++++++++++++ js/libs/fluidbook/fluidbook.cart.js | 4 +- js/libs/fluidbook/fluidbook.nav.js | 4 +- style/cart/flexipan.less | 157 +++++++++++++++ 4 files changed, 344 insertions(+), 3 deletions(-) create mode 100644 js/libs/fluidbook/cart/fluidbook.cart.flexipan.js create mode 100644 style/cart/flexipan.less diff --git a/js/libs/fluidbook/cart/fluidbook.cart.flexipan.js b/js/libs/fluidbook/cart/fluidbook.cart.flexipan.js new file mode 100644 index 00000000..a8c23d0e --- /dev/null +++ b/js/libs/fluidbook/cart/fluidbook.cart.flexipan.js @@ -0,0 +1,182 @@ +function FluidbookCartFlexipan(cart) { + var $this = this; + this.cart = cart; + this.fluidbook = this.cart.fluidbook; + this.data = this.fluidbook.settings.basketReferences; + this.init(); +} + +FluidbookCartFlexipan.prototype = { + init: function () { + var $this = this; + this.items = this.fluidbook.cache.get('cart', []); + $(document).on('click', '.exportCartPDF', function () { + $this.exportPDF(); + return false; + }); + }, + + addToCart: function (ref, quantity) { + if (this.items.indexOf(ref) === -1) { + this.items.push(ref); + this.save(); + } + + return true; + }, + + removeFromCart: function (key) { + this.items.splice(key, 1); + this.save(); + }, + + save: function () { + this.fluidbook.cache.set('cart', this.getItems()); + this.updateIcon(); + this.fluidbook.cart.updateLinks(); + }, + + 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; + }, + + + getItemsReferences: function () { + return this.getItems(); + }, + getItemsNumbers: function () { + return this.getItems().length; + }, + getAllQuantities: function () { + return this.getItemsNumbers(); + }, + + updateCart: function () { + if ($('#flexipancart').length > 0) { + $('#flexipancart .content').html(this.getCartContent()); + } + }, + + updateIcon: function () { + $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()}); + }, + + openMenu: function (p1, p2, callback) { + this.fluidbook.menu.quickCloseView(); + return this.openCart(p2, callback); + }, + + openCart: function (p2, callback) { + this._endMenu('Ma sélection', this.getCartContent(), function () { + callback(); + }); + }, + + getCartContent: function () { + if (this.getItemsNumbers() == 0) { + return '
Votre sélection est vide
'; + } + + var $this = this; + var content = ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + $.each(this.getItems(), function (i, ref) { + var item = $this.data[ref]; + if (item === undefined) { + return; + } + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + }); + content += ''; + content += '
Dénomination produitCode produitGammeCatégorie
' + item.Denomination + '' + ref + '' + item.Gamme + '' + item.Categorie + '' + getSpriteIcon('interface-close') + '
'; + content += ''; + + return content; + }, + + exportPDF: function () { + + var element = $('#flexipancarttable').get(0); + var options = { + margin: 15, + filename: this.getExportFileName() + '.pdf', + image: {type: 'jpeg', quality: 0.98}, + html2canvas: {dpi: 150, scale: 2, letterRendering: true}, + jsPDF: {unit: 'mm', format: 'A4', orientation: 'portrait'} + }; + $(element).addClass('print') + html2pdf().set(options).from(element).save().then(function () { + $(element).removeClass('print'); + }); + + setTimeout(function () { + $(element).removeClass('print'); + }, 2000); + }, + + getExportFileName: function () { + var date = new Date(); + return this.fluidbook.settings.title + ' - Cart - ' + date.getFullYear() + '-' + date.getMonth() + '-' + date.getDay(); + }, + + _endMenu: function (title, content, callback) { + var view = '
'; + view += this.fluidbook.menu.getCaption(title); + view += '
'; + view += "" + content; + view += '
'; + view += '
'; + this.fluidbook.menu.viewWrap(view, 'cart'); + callback(); + }, + + getMenuWidth: function () { + return 900; + }, + + parseFloat: function (s) { + if (typeof s === 'number') { + return s; + } + if (s === undefined || s === null || s === '') { + return 0; + } + s = s.replace(/\s/g, ''); + return parseFloat(s); + }, + + parseInt: function (s) { + if (typeof s === 'number') { + return Math.round(s); + } + if (s === undefined || s === null || s === '') { + return 0; + } + s = s.replace(/\s/g, ''); + return parseInt(s); + }, +}; \ No newline at end of file diff --git a/js/libs/fluidbook/fluidbook.cart.js b/js/libs/fluidbook/fluidbook.cart.js index 76aa28e5..356629b0 100644 --- a/js/libs/fluidbook/fluidbook.cart.js +++ b/js/libs/fluidbook/fluidbook.cart.js @@ -50,7 +50,7 @@ FluidbookCart.prototype = { setTimeout(function () { $this.fluidbook.tooltip.hideTooltip(); }, 2500); - }catch (e){ + } catch (e) { } @@ -98,6 +98,8 @@ FluidbookCart.prototype = { return new FluidbookCartPuma(this); case 'MIF': return new FluidbookCartMIF(this); + case 'Flexipan': + return new FluidbookCartFlexipan(this); case 'GrandVision': return new FluidbookCartGrandVision(this); default: diff --git a/js/libs/fluidbook/fluidbook.nav.js b/js/libs/fluidbook/fluidbook.nav.js index fc41b19e..bd0ece2b 100644 --- a/js/libs/fluidbook/fluidbook.nav.js +++ b/js/libs/fluidbook/fluidbook.nav.js @@ -469,9 +469,9 @@ FluidbookNav.prototype = { } else if (icon === 'basket' && this.fluidbook.cart !== undefined && this.fluidbook.cart.enabled) { // __('basket') link = this.addLink(navType, this.fluidbook.settings.cartIcon, '#/cart', 'cart', 'basket', 'basket', 'Control+Alt+C'); - $(this.fluidbook).on('fluidbook.cart.updateIcon', {link: $(link).attr('id')}, function (e, data) { + $(this.fluidbook).on('fluidbook.cart.updateIcon', {link:link},function (e, data) { var n = data.number; - var l = $("#" + e.data.link); + var l = $("#" +$(e.data.link).attr('id')); if (n === 0) { $(l).find('span.number').remove(); diff --git a/style/cart/flexipan.less b/style/cart/flexipan.less new file mode 100644 index 00000000..96c2f88c --- /dev/null +++ b/style/cart/flexipan.less @@ -0,0 +1,157 @@ +#flexipancart { + background-color: #fff; + + .caption { + color: #000; + margin-top: 0px; + position: relative; + top: 0px; + text-transform: uppercase; + + #mview-dialog-title{ + margin-top: 10px; + } + + a.button.back { + color: #fff; + } + } + + .cart-empty{ + color:#000; + } +} + +[data-type="7"] { + svg { + pointer-events: none; + + + } + + .on { + visibility: hidden; + } + + .off { + visibility: visible; + } + + &.active { + .off { + visibility: hidden; + } + + .on { + visibility: visible; + } + } +} + + +#flexipancarttable { + [data-cart-delete], [data-cart-view] { + color: #fff; + background-color: @menu-button-background; + padding: 5px 6px 7px 6px; + width: 23px; + height: 23px; + display: block; + position: relative; + left: 20px; + } + + [data-cart-view] { + padding: 0; + } + + tr.print-header { + display: none; + font-size: 0; + + td { + padding: 0; + display: table-cell !important; + + img { + max-width: 100%; + } + } + } + + padding: 0; + border-collapse: collapse; + margin: 20px 30px 40px; + width: ~"calc(100% - 60px)"; + max-width: none; + + &.print { + tr.print-header { + display: table-row !important; + } + + span { + text-decoration: none; + } + + margin: 0; + font-size: 8px; + width: 100%; + + td, th { + vertical-align: top; + padding: 5px; + + &:last-child { + display: none; + } + } + + [data-cart-delete], [data-cart-view] { + display: none; + } + } + + td, th { + padding: 20px 0 20px 30px; + font-size: 11px; + text-align: center; + + span { + display: block; + max-width: 120px; + white-space: normal; + margin: 0 auto; + } + + img { + max-width: 80px; + } + + &:last-child { + padding-right: 30px; + padding-left: 0px; + } + } + + thead { + th { + text-transform: uppercase; + color: #fff; + background-color: @menu-button-background; + font-weight: normal; + } + } + + tbody { + td { + //border-top: 1px solid #000; + } + + tr { + background-color: #fff; + color: #000 + } + + } +} \ No newline at end of file -- 2.39.5