From e7fae25c2a3ab8d2ea87b46625281e326f97e33f Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 22 Sep 2021 19:35:58 +0200 Subject: [PATCH] wait #4696 @2 --- .../cart/fluidbook.cart.joueclub2021.js | 217 ++++++++++++++++++ js/libs/fluidbook/fluidbook.cart.js | 2 + style/cart/joueclub2021.less | 184 +++++++++++++++ 3 files changed, 403 insertions(+) create mode 100644 js/libs/fluidbook/cart/fluidbook.cart.joueclub2021.js create mode 100644 style/cart/joueclub2021.less diff --git a/js/libs/fluidbook/cart/fluidbook.cart.joueclub2021.js b/js/libs/fluidbook/cart/fluidbook.cart.joueclub2021.js new file mode 100644 index 00000000..a4ca078e --- /dev/null +++ b/js/libs/fluidbook/cart/fluidbook.cart.joueclub2021.js @@ -0,0 +1,217 @@ +function FluidbookCartJoueClub2021(cart) { + this.cart = cart; + this.fluidbook = this.cart.fluidbook; + this.data = this.fluidbook.settings.basketReferences; + this.init(); +} + +FluidbookCartJoueClub2021.prototype = { + init: function () { + var $this = this; + 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, '.sendAsEmail', function () { + try { + $this.sendCartAsEmail(); + } catch (err) { + console.log(err); + } + return false; + }); + }, + + addToCart: function (ref, quantity) { + if (this.items.indexOf(ref) === -1) { + this.items.push(ref); + this.save(); + } + return "Le jouet a été ajouté à votre liste de cadeaux"; + }, + + removeFromCart: function (key) { + console.log('remove from cart ' + key); + this.items.splice(key, 1); + this.save(); + }, + + save: function () { + this.fluidbook.cache.set('cart', this.getItems()); + 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 ($('#jc2021cart').length > 0) { + $('#jc2021cart .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 wishlist', this.getCartContent(), function () { + callback(); + }); + }, + + getCartContent: function () { + + + var $this = this; + var content = '
'; + if (this.getItemsNumbers() == 0) { + content += '
Votre liste de cadeaux est vide
'; + return content; + } + + content += ''; + content += ''; + 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 += ''; + content += ''; + }); + content += ''; + content += '
Nom du jouetRéférenceMarquePrix
' + item['Nom du jouet'] + '' + ref + '' + item.Marque + '' + item.Prix + '€' + getSpriteIcon('interface-close') + '
'; + content += ''; + + return content; + }, + + sendCartAsEmail: function () { + var $this = this; + + var subject = 'Catalogue Jouéclub Noël 2021 - Ma liste de cadeaux' + var body = ''; + + $.each(this.getItems(), function (i, ref) { + var item = $this.fluidbook.settings.basketReferences[ref]; + if (item === undefined) { + return; + } + body += item['Nom du jouet'] + ' : ' + item.Prix + '€' + "\n"; + body += 'Marque : ' + item.Marque + "\n"; + body += 'Référence : ' + ref + "\n\n----\n\n"; + }); + window.location.href = 'mailto:?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body); + }, + + exportPDF: function () { + + var element = $('#jc2021cartprint').get(0); + var options = { + margin: 5, + 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 + ' - Liste de cadeaux'; + }, + + _endMenu: function (title, content, callback) { + var view = '
'; + view += this.fluidbook.menu.getCaption(); + + view += '
'; + view += "" + content; + view += '
'; + view += '
'; + this.fluidbook.menu.viewWrap(view, 'cart'); + callback(); + }, + + getMenuWidth: function () { + return 1060; + }, + + 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 571bf13c..67188370 100644 --- a/js/libs/fluidbook/fluidbook.cart.js +++ b/js/libs/fluidbook/fluidbook.cart.js @@ -102,6 +102,8 @@ FluidbookCart.prototype = { return new FluidbookCartGrandPavois(this); case 'Flexipan': return new FluidbookCartFlexipan(this); + case 'JoueclubWishlist2021': + return new FluidbookCartJoueClub2021(this); case 'GrandVision': return new FluidbookCartGrandVision(this); default: diff --git a/style/cart/joueclub2021.less b/style/cart/joueclub2021.less new file mode 100644 index 00000000..9db59c49 --- /dev/null +++ b/style/cart/joueclub2021.less @@ -0,0 +1,184 @@ +#jc2021cart { + background-color: #fff; + + .caption { + margin-top: 0px; + padding: 0; + height: 0; + text-transform: uppercase; + + .back { + background-color: #e30613; + top: 10px; + right: 10px; + width: 50px; + height: 50px; + padding: 14px; + border-radius: 50%; + } + } + + .cart-empty { + color: #000; + } +} + +.mview #jc2021cart .fonctions a { + background-color: #26348b; + border-radius: 8px; +} + +[data-type="7"] { + svg { + pointer-events: none; + } + + .on { + visibility: hidden; + } + + .off { + visibility: visible; + } + + &.active { + .off { + visibility: hidden; + } + + .on { + visibility: visible; + } + } +} + +#jc2021cartprint { + + + &.print { + font-size: 8px; + + + #jc2021header { + height: auto; + + img { + width: 100%; + } + } + + .ps__rail-y, .ps__rail-x { + display: none; + } + + #jc2021carttable { + + span { + text-decoration: none; + } + + margin: 20px 0 0 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; + } + } + + .fonctions { + display: none; + } + } +} + +#jc2021header { + height: 245px; + + img { + width: 1060px; + } +} + +#jc2021carttable { + + + [data-cart-delete], [data-cart-view] { + color: #fff; + background-color: #e30613; + padding: 5px 6px 7px 6px; + width: 23px; + height: 23px; + display: block; + position: relative; + left: 20px; + border-radius: 50%; + } + + padding: 0; + border-collapse: collapse; + margin: 0 0 40px !important; + width: 100%; + max-width: none; + + + td, th { + padding: 20px 0 20px 30px; + font-size: 11px; + text-align: center; + font-weight: 600; + text-transform: uppercase; + + span { + display: block; + white-space: normal; + + img { + width: 80px; + } + } + + &.margin { + width: 30px; + } + + + &:last-child { + padding-right: 30px; + padding-left: 0px; + } + } + + thead { + th { + text-transform: uppercase; + color: #fff; + background-color: #26348b; + } + } + + tbody { + td { + border-top: 1px solid #f2f2f2; + + &.margin { + border-color: #fff; + } + } + + tr { + background-color: #fff; + color: #000 + } + + } +} \ No newline at end of file -- 2.39.5