From: Vincent Vanwaelscappel Date: Tue, 19 Dec 2023 19:05:31 +0000 (+0100) Subject: wip #6554 @3 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=0ea1ddc8b17c0f0e7a5a329114ab152e54b881c6;p=fluidbook-html5.git wip #6554 @3 --- diff --git a/js/libs/fluidbook/cart/fluidbook.cart.puma-se.js b/js/libs/fluidbook/cart/fluidbook.cart.puma-se.js index f1d76e2b..7fbcc2d3 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.puma-se.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.puma-se.js @@ -4,6 +4,8 @@ function FluidbookCartPumaSE(cart) { this.fluidbook = this.cart.fluidbook; this.data = this.fluidbook.settings.basketReferences; this.exportFileName = ''; + this.base64URL = {}; + this.base64Loading = 0; this.init(); } @@ -233,6 +235,7 @@ FluidbookCartPumaSE.prototype = { value = $this.formatPrice(value, '€'); } else if (v.type === 'image') { if ($this.data[ref] && $this.data[ref]['zoom_image']) { + $this.setBase64URL(ref); value = ''; } else { value = '-'; @@ -261,6 +264,33 @@ FluidbookCartPumaSE.prototype = { return content; }, + setBase64URL: function (ref) { + if (this.base64URL[ref] !== undefined && this.base64URL[ref] !== null) { + return; + } + this.base64URL[ref] = '__LOADING__'; + this.base64Loading++; + let $this = this; + this.toDataURL(this.data[ref]['zoom_image'], function (dataUrl) { + $this.base64URL[ref] = dataUrl; + this.base64Loading--; + }); + }, + + toDataURL: function (url, callback) { + var xhr = new XMLHttpRequest(); + xhr.onload = function () { + var reader = new FileReader(); + reader.onloadend = function () { + callback(reader.result); + } + reader.readAsDataURL(xhr.response); + }; + xhr.open('GET', url); + xhr.responseType = 'blob'; + xhr.send(); + }, + exportPDF: function () { @@ -436,7 +466,8 @@ FluidbookCartPumaSE.prototype = { // $.each(this.getItems(), function (i, ref) { var img = workbook.addImage({ - base64: 'data:image/jpeg;base64,' + $this.data[ref]['zoom_url'], extension: 'jpeg', + base64: $this.base64URL[ref], + extension: 'jpeg', }); sheet.addImage(img, {tl: {col: 0, row: i + 1}, br: {col: 1, row: i + 2}, editAs: 'twoCell'}); }); diff --git a/js/libs/fluidbook/cart/fluidbook.cart.puma.js b/js/libs/fluidbook/cart/fluidbook.cart.puma.js index 1c77912c..7c028bb3 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.puma.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.puma.js @@ -4,6 +4,8 @@ function FluidbookCartPuma(cart) { this.fluidbook = this.cart.fluidbook; this.data = this.fluidbook.settings.basketReferences; this.exportFileName = ''; + this.base64URL = {}; + this.base64Loading = 0; this.init(); } @@ -28,6 +30,7 @@ FluidbookCartPuma.prototype = { } return false; }); + $(document).on(this.fluidbook.input.clickEvent, '.exportEANXLS', function () { try { $this.chooseFileName(function () { @@ -46,13 +49,10 @@ FluidbookCartPuma.prototype = { content: 'Are you sure you want to empty your cart?', buttons: { confirm: { - text: 'Confirm', - btnClass: 'btn-ok', - action: function () { + text: 'Confirm', btnClass: 'btn-ok', action: function () { $this.emptyCart(); }, - }, - cancel: function () { + }, cancel: function () { }, } @@ -68,12 +68,15 @@ FluidbookCartPuma.prototype = { resize(); }, - addToCart: function (ref, quantity) { - if (this.getItems().indexOf(ref) === -1) { + addToCart: function (ref, quantity, force) { + let inCart = this.getItems().indexOf(ref) >= 0; + let add = (force === undefined) ? !inCart : force; + if (add && !inCart) { this.items.push(ref); this.save(); return this.fluidbook.l10n.__("the item has been added to your cart"); - } else { + } + if (!add && inCart) { this.removeFromCartByRef(ref); return this.fluidbook.l10n.__("the item has been removed from your cart"); } @@ -183,7 +186,9 @@ FluidbookCartPuma.prototype = { if (v === 'PVC' || v === 'Tarif') { value = $this.formatPrice(value, '€'); } else if (v === 'Image') { + if ($this.data[ref] && $this.data[ref]['zoom_image']) { + $this.setBase64URL(ref); value = ''; } else { value = '-'; @@ -213,6 +218,33 @@ FluidbookCartPuma.prototype = { return content; }, + setBase64URL: function (ref) { + if (this.base64URL[ref] !== undefined && this.base64URL[ref] !== null) { + return; + } + this.base64URL[ref] = '__LOADING__'; + this.base64Loading++; + let $this = this; + this.toDataURL(this.data[ref]['zoom_image'], function (dataUrl) { + $this.base64URL[ref] = dataUrl; + this.base64Loading--; + }); + }, + + toDataURL: function (url, callback) { + var xhr = new XMLHttpRequest(); + xhr.onload = function () { + var reader = new FileReader(); + reader.onloadend = function () { + callback(reader.result); + } + reader.readAsDataURL(xhr.response); + }; + xhr.open('GET', url); + xhr.responseType = 'blob'; + xhr.send(); + }, + exportPDF: function () { @@ -243,15 +275,10 @@ FluidbookCartPuma.prototype = { }, formatDate: function (date) { - var d = new Date(date), - month = '' + (d.getMonth() + 1), - day = '' + d.getDate(), - year = d.getFullYear(); + var d = new Date(date), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear(); - if (month.length < 2) - month = '0' + month; - if (day.length < 2) - day = '0' + day; + if (month.length < 2) month = '0' + month; + if (day.length < 2) day = '0' + day; return [year, month, day].join('-'); }, @@ -260,9 +287,7 @@ FluidbookCartPuma.prototype = { var $this = this; const workbook = new ExcelJS.Workbook(); const sheet = workbook.addWorksheet(this.fluidbook.settings.title); - sheet.views = [ - {state: 'frozen', xSplit: 0, ySplit: 1, topLeftCell: 'A2', activeCell: 'A2'} - ]; + sheet.views = [{state: 'frozen', xSplit: 0, ySplit: 1, topLeftCell: 'A2', activeCell: 'A2'}]; sheet.properties.defaultRowHeight = 15; var columnsLabels = ['Reference', 'Size Description', 'EAN13', 'Season Description', 'Rbu', 'Family', 'Article', 'Model Id', 'Color Id', 'Units']; var columns = []; @@ -314,22 +339,14 @@ FluidbookCartPuma.prototype = { var $this = this; $.confirm({ title: 'Name your file', - content: '' + - '
' + - '
' + - '' + - '
' + - '
', + content: '' + '
' + '
' + '' + '
' + '
', buttons: { formSubmit: { - text: 'Submit', - btnClass: 'btn-ok', - action: function () { + text: 'Submit', btnClass: 'btn-ok', action: function () { $this.exportFileName = this.$content.find('.name').val(); callback(); } - }, - cancel: function () { + }, cancel: function () { //close }, }, @@ -349,9 +366,7 @@ FluidbookCartPuma.prototype = { var $this = this; const workbook = new ExcelJS.Workbook(); const sheet = workbook.addWorksheet(this.fluidbook.settings.title); - sheet.views = [ - {state: 'frozen', xSplit: 0, ySplit: 1, topLeftCell: 'A2', activeCell: 'A2'} - ]; + sheet.views = [{state: 'frozen', xSplit: 0, ySplit: 1, topLeftCell: 'A2', activeCell: 'A2'}]; sheet.properties.defaultRowHeight = 15; var columnsLabels = this.getExcelColumns(); var columns = []; @@ -414,10 +429,10 @@ FluidbookCartPuma.prototype = { sheet.getColumn(k + 1).numFmt = fmt[v]; }); // + $.each(this.getItems(), function (i, ref) { var img = workbook.addImage({ - base64: 'data:image/jpeg;base64,' + $this.data[ref]['zoom_url'], - extension: 'jpeg', + base64: $this.base64URL[ref], extension: 'jpeg', }); sheet.addImage(img, {tl: {col: 0, row: i + 1}, br: {col: 1, row: i + 2}, editAs: 'twoCell'}); }); @@ -443,10 +458,7 @@ FluidbookCartPuma.prototype = { } var res = price.toLocaleString("fr-FR", { - style: "currency", - currency: "EUR", - minimumFractionDigits: 2, - maximumFractionDigits: 2 + style: "currency", currency: "EUR", minimumFractionDigits: 2, maximumFractionDigits: 2 }); if (res.indexOf(suffix) === -1) { res += ' ' + suffix; diff --git a/js/libs/fluidbook/fluidbook.cart.js b/js/libs/fluidbook/fluidbook.cart.js index 815cb674..34970f72 100644 --- a/js/libs/fluidbook/fluidbook.cart.js +++ b/js/libs/fluidbook/fluidbook.cart.js @@ -1,4 +1,6 @@ // this.fluidbook.l10n.__("remove from cart") +// this.fluidbook.l10n.__('remove all page products from cart') +// this.fluidbook.l10n.__('add all page products to cart') function FluidbookCart(fluidbook) { this.fluidbook = fluidbook; @@ -37,8 +39,42 @@ FluidbookCart.prototype = { } var ref = $(this).data('cart-ref'); + let refs = []; + if (ref === 'auto:all_in_page') { + $('#links [data-cart-ref]').each(function () { + let r = $(this).data('cart-ref'); + if (r.indexOf('auto:') === 0) { + return; + } + if (refs.indexOf(r) === -1) { + refs.push(r); + } + }); + } else { + refs = [ref]; + } - $this.fluidbook.stats.track(15, $this.fluidbook.currentPage, ref); + let force = $this.instance.getItems().indexOf(refs[0]) === -1; + + var tooltip; + $.each(refs, function (k, ref) { + $this.fluidbook.stats.track(15, $this.fluidbook.currentPage, ref); + $this.instance.addToCart(ref, qty, force); + }); + + if (refs.length > 1) { + if (force) { + tooltip = $this.fluidbook.l10n.__("the items have been added to your cart"); + } else { + tooltip = $this.fluidbook.l10n.__("the items have been removed from your cart"); + } + } else { + if (force) { + tooltip = $this.fluidbook.l10n.__("the item has been added to your cart"); + } else { + tooltip = $this.fluidbook.l10n.__("the item has been removed from your cart"); + } + } var tooltipStyle = ''; try { @@ -46,10 +82,7 @@ FluidbookCart.prototype = { } catch (e) { } - var tooltip = $this.instance.addToCart(ref, qty); - if (tooltip === undefined || tooltip === null || !tooltip || tooltip === true || tooltip === false || tooltip === 'true' || tooltip === 'false') { - tooltip = $this.fluidbook.l10n.__("the item has been added to your cart"); - } + $this.fluidbook.tooltip.displayTooltip(tooltip, tooltipStyle); setTimeout(function () { $this.fluidbook.tooltip.hideTooltip(); @@ -79,6 +112,10 @@ FluidbookCart.prototype = { } catch (err) { } + if ($("#links a[data-cart-ref]").not('[data-cart-ref="auto:all_in_page"]').eq(0).hasClass('active')) { + $('[data-cart-ref="auto:all_in_page"]').addClass('active'); + } + if (this.fluidbook.settings.cartLinkAppearance === 'overlay') { $('a[data-cart-ref]').each(function () { var c = []; @@ -131,8 +168,7 @@ FluidbookCart.prototype = { var paddingTop = 0.5 * ($(this).outerHeight() - bh); var paddingLeft = 0.5 * ($(this).outerWidth() - bw); $(this).attr('data-tooltip', null).addClass('overlay').css({ - paddingTop: paddingTop, - paddingLeft: paddingLeft + paddingTop: paddingTop, paddingLeft: paddingLeft }).html('
' + getSpriteIcon('link-cart-remove') + getSpriteIcon('link-cart-remove-hover') + '
' + getSpriteIcon('link-cart-add') + getSpriteIcon('link-cart-add-hover') + '
' + getSpriteIcon('link-cart-info') + '
'); }); } @@ -149,11 +185,9 @@ FluidbookCart.prototype = { getSavedData: function () { return this.fluidbook.cache.get('cart', {}) - }, - saveData: function (data) { + }, saveData: function (data) { this.fluidbook.cache.set('cart', data); - }, - createInstance: function () { + }, createInstance: function () { switch (this.fluidbook.settings.basketManager) { case "Remarkable": return new FluidbookCartRemarkable(this); @@ -234,8 +268,7 @@ FluidbookCart.prototype = { this.element.val(this.normalize()); this.inited = true; - }, - normalize: function (v) { + }, normalize: function (v) { var origV; if (v === undefined) { v = this.element.val(); @@ -260,8 +293,7 @@ FluidbookCart.prototype = { } return v; - }, - increment: function (i) { + }, increment: function (i) { var v = this.normalize(); var v1 = v; v += i;