From 33e07276774841fdab3a898e76cfbb7b49eadf2b Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Fri, 13 Nov 2020 11:50:46 +0100 Subject: [PATCH] wip #4047 @0.5 --- js/libs/fluidbook/cart/fluidbook.cart.mif.js | 198 +++++++++++++++++++ js/libs/fluidbook/fluidbook.links.js | 17 +- style/fluidbook.less | 3 + 3 files changed, 212 insertions(+), 6 deletions(-) create mode 100644 js/libs/fluidbook/cart/fluidbook.cart.mif.js diff --git a/js/libs/fluidbook/cart/fluidbook.cart.mif.js b/js/libs/fluidbook/cart/fluidbook.cart.mif.js new file mode 100644 index 00000000..7c059865 --- /dev/null +++ b/js/libs/fluidbook/cart/fluidbook.cart.mif.js @@ -0,0 +1,198 @@ +function FluidbookCartMIF(cart) { + var $this = this; + this.cart = cart; + this.fluidbook = this.cart.fluidbook; + this.data = this.fluidbook.settings.basketReferences; + this.init(); +} + +FluidbookCartMIF.prototype = { + init: function () { + var $this = this; + this.items = this.fluidbook.cache.get('cart', []); + $(document).on('click', '.exportCartPDF', function () { + $this.exportPDF(); + return false; + }); + $(document).on('click', '.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 true; + }, + + removeFromCart: function (key) { + this.items.splice(key, 1); + this.save(); + }, + + save: function () { + this.fluidbook.cache.set('cart', this.items); + this.fluidbook.cart.updateLinks(); + }, + getItemsReferences: function () { + return this.items; + }, + getItemsNumbers: function () { + return this.items.length; + }, + getAllQuantities: function () { + return this.getItemsNumbers(); + }, + + updateCart: function () { + if ($('#mifcart').length > 0) { + $('#mifcart .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('my cart', this.getCartContent(), function () { + callback(); + }); + }, + + getCartContent: function () { + if (this.getItemsNumbers() == 0) { + return '
' + this.fluidbook.l10n.__('your cart is empty') + '
'; + } + + var $this = this; + var content = ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + $.each(this.items, function (i, ref) { + var item = $this.data[ref]; + if (item === undefined) { + return; + } + content += ''; + content += ''; + content += ''; + content += ''; + content += ''; + var image = ''; + if (item['zoom_image']) { + image = ''; + } else { + image = '-'; + } + content += ''; + content += ''; + content += ''; + }); + content += ''; + content += '
CatégorieMarqueNom du produitPrixImage
' + item.Categorie + '' + item.Marque + '' + item.Produit + '' + item.Prix + '' + image + '' + getSpriteIcon('interface-close') + '
'; + content += ''; + + return content; + }, + + sendCartAsEmail: function () { + var $this = this; + + var subject = 'Ma liste de Noël' + var body = 'Ma liste de Noël : ' + "\n\n"; + + $.each(this.items, function (i, ref) { + var item = $this.fluidbook.settings.basketReferences[ref]; + if (item === undefined) { + return; + } + body += item.Produit + ' (' + item.Marque + ') - ' + item.Prix + " :\n"; + body += item.Lien + "\n\n"; + }); + window.location.href = 'mailto:?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body); + }, + + exportPDF: function () { + + var element = $('#mifcarttable').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 1200; + }, + + 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.links.js b/js/libs/fluidbook/fluidbook.links.js index 8268ad99..e65c7e27 100644 --- a/js/libs/fluidbook/fluidbook.links.js +++ b/js/libs/fluidbook/fluidbook.links.js @@ -87,18 +87,18 @@ FluidbookLinks.prototype = { }); - $(document).on('click', 'a', function () { + $(document).on('click', 'a, [data-pseudolink-href]', function () { + console.log(this); if ($(this).is('#wopen')) { return true; } - var target = $(this).attr('target'); + var target = $(this).is('[data-pseudolink-href]') ? $(this).data('pseudolink-target') : $(this).attr('target'); if (!target) { target = '_self'; } + var href = $(this).is('[data-pseudolink-href]') ? $(this).data('pseudolink-href') : $(this).attr('href'); - - var href = $(this).attr('href'); if (href === undefined) { return true; } @@ -228,7 +228,8 @@ FluidbookLinks.prototype = { }, handleExternalHref: function (link) { - var href = $(link).attr('href'); + var href = $(link).is('[data-pseudolink-href]') ? $(link).data('pseudolink-href') : $(link).attr('href'); + ; var change = false; if (this.fluidbook.stats.relay_url_params !== '' && !$(link).hasClass('relay_appended')) { $(link).addClass('relay_appended'); @@ -243,7 +244,11 @@ FluidbookLinks.prototype = { } if (change) { - $(link).attr('href', href); + if ($(link).is('[data-pseudolink-href]')) { + $(link).attr('[data-pseudolink-href]', href).data('pseudolink-href', href); + } else { + $(link).attr('href', href); + } } return href; diff --git a/style/fluidbook.less b/style/fluidbook.less index 4601d69a..03ebb41d 100644 --- a/style/fluidbook.less +++ b/style/fluidbook.less @@ -234,6 +234,9 @@ body, html { } } +[data-pseudolink-href]{ + cursor: pointer; +} #links { .container { -- 2.39.5