From 785096a53060a9d8afa0168b55dc7d95d6c6bd91 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 22 Apr 2024 11:14:41 +0200 Subject: [PATCH] wip #6875 @1 --- .../cart/fluidbook.cart.bastide-resah.js | 106 +---- style/cart/bastide-resah-cart.less | 401 ++++++++++++++++++ 2 files changed, 417 insertions(+), 90 deletions(-) create mode 100644 style/cart/bastide-resah-cart.less diff --git a/js/libs/fluidbook/cart/fluidbook.cart.bastide-resah.js b/js/libs/fluidbook/cart/fluidbook.cart.bastide-resah.js index 2f24544f..dad3fdd8 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.bastide-resah.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.bastide-resah.js @@ -2,7 +2,7 @@ function FluidbookCartBastideResah(cart) { this.cart = cart; this.fluidbook = this.cart.fluidbook; this.data = this.fluidbook.settings.basketReferences; - this.form_endpoint = this.fluidbook.service.getBaseURL()+'bastide'; // Where cart form is processed + this.form_endpoint = this.fluidbook.service.getBaseURL() + 'bastide'; // Where cart form is processed this.init(); } @@ -28,7 +28,7 @@ FluidbookCartBastideResah.prototype = { }); // Handle "Valider ma sélection" button in cart - $(document).on(this.fluidbook.input.clickEvent, '#Bastide_cart [data-validate-cart]', function(event) { + $(document).on(this.fluidbook.input.clickEvent, '#Bastide_cart [data-validate-cart]', function (event) { event.preventDefault(); // Use the built-in HTML5 validation to make sure all fields are valid in the cart @@ -42,80 +42,6 @@ FluidbookCartBastideResah.prototype = { window.location.hash = '/cart/validate'; } }); - - // Handle details form validation and submission - $(document).on(this.fluidbook.input.clickEvent, '#Bastide_user_details [data-send-cart]', function(event) { - event.preventDefault(); - - let form = $('#Bastide_user_details form:visible'); - - if (!form.length) { - console.warn('Error finding form...'); - return false; - } - - // Get the form name so that we can look up the field labels later - let form_name = form.data('name'); - let forms = $this.getForms(); - - // Get the user's details from the form... - let user_data = new FormData(form[0]); - let user_details = {}; // Restructured user data to send to the endpoint - - user_data.forEach(function(value, key) { - user_details[key] = { - label: forms[form_name][key]['label'], - value: value, - }; - }); - - // Prepare the main form data for sending - let data = new FormData(); - - // To make our endpoint more flexible, we need to give it some extra details - data.append('action', 'process-cart'); // There could be other actions handled by the endpoint - data.append('fluidbook_id', $this.fluidbook.settings.id); // In case we need special treatment per Fluidbook - - // Now add the user details to the main form data... - data.append('user_details', JSON.stringify(user_details)); - - // Get data from the cart summary that can be used to generate the XLS - // This is passed as a JSON string to make it easier to handle in the FormData - data.append('cart_items', JSON.stringify($this.getItemsForXLS())); - data.append('column_headings', JSON.stringify($this.getColumnsForXLS())); - - // It's also possible that the Fluidbook will include a querystring parameter (?a=xxxxx) to determine who - // the e-mail should be sent to. This is needs to be passed to the endpoint for handling - let querystring = (new URL(document.location)).searchParams; - data.append('recipient_code', querystring.get('a')); // If the querystring isn't set, it will return null - - // Next, make sure the form is valid. Uses the built-in HTML5 validation - if (form[0].reportValidity()) { - $.ajax({ - url: $this.form_endpoint, - cache: false, - data: data, - processData: false, - contentType: false, - method: 'post', - dataType: 'json', - success: function (data) { - - if (!data.success) { - console.warn('Error processing request', data); - } - - let container = $('#Bastide_user_details'); - // Hide the form and footer content, then show the message from the endpoint - container.find('.details-form, .details-footer').hide(); - container.find('.server-response').text(data.message).show(); - } - }); - } - - event.preventDefault(); - }); - }, // emptyCart: function () { @@ -125,7 +51,7 @@ FluidbookCartBastideResah.prototype = { // resize(); // }, - getCartItemIndex: function(reference) { + getCartItemIndex: function (reference) { let cartItems = this.getItems(); for (let i = 0; i < cartItems.length; i++) { if (cartItems[i].reference === reference) { @@ -201,7 +127,7 @@ FluidbookCartBastideResah.prototype = { $.each($this.getColumnsForXLS(), function (key, title) { - switch(key) { + switch (key) { case 'QUANTITY': item[key] = cart_item['quantity']; break; @@ -291,7 +217,7 @@ FluidbookCartBastideResah.prototype = { // The columns should be the same as for the cart except we skip "DELETE" let columns = {}; - $.each(this.getColumns(), function(key, title) { + $.each(this.getColumns(), function (key, title) { if (key === 'DELETE') return; @@ -338,22 +264,22 @@ FluidbookCartBastideResah.prototype = { getCartContent: function () { if (this.getItemCount() === 0) { - return `
${ this.fluidbook.l10n.__('your cart is empty') }
`; + return `
${this.fluidbook.l10n.__('your cart is empty')}
`; } let $this = this; let columns = this.getColumns(); let content = - `
+ `
${Object.entries(columns) - .map(heading => ``) - .join('') - } + .map(heading => ``) + .join('') + } `; @@ -368,7 +294,7 @@ FluidbookCartBastideResah.prototype = { let value = data[key] || '—'; // Fallback for missing values let output = ''; - switch(key) { + switch (key) { case 'PRIX': output += $this.formatPrice(value); @@ -376,7 +302,7 @@ FluidbookCartBastideResah.prototype = { case 'QUANTITY': let min_quantity = 1; - output = `
`; + output = `
`; output += `
${heading[1]}${heading[1]}