From a3a6ff34edae6e3e0ddd68656f9e1003fcad42af Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Sun, 21 Feb 2021 20:44:27 +0100 Subject: [PATCH] wip #4285 @2.5 --- .../cart/fluidbook.cart.grandvision.js | 104 ++++- js/libs/jquery/jquery.multi-select.js | 442 ++++++++++++++++++ style/cart/grandvision.less | 194 +++++++- 3 files changed, 727 insertions(+), 13 deletions(-) create mode 100644 js/libs/jquery/jquery.multi-select.js diff --git a/js/libs/fluidbook/cart/fluidbook.cart.grandvision.js b/js/libs/fluidbook/cart/fluidbook.cart.grandvision.js index a4203253..e4530941 100644 --- a/js/libs/fluidbook/cart/fluidbook.cart.grandvision.js +++ b/js/libs/fluidbook/cart/fluidbook.cart.grandvision.js @@ -3,6 +3,7 @@ function FluidbookCartGrandVision(cart) { this.cart = cart; this.fluidbook = this.cart.fluidbook; this.data = this.fluidbook.settings.basketReferences; + this.filters = {}; this.init(); } @@ -37,7 +38,43 @@ FluidbookCartGrandVision.prototype = { return this.openSelection(cb); }, + updateFilters: function () { + var hasVisible = false; + $('#grandvision-selection .item').each(function () { + var hide = false; + var a = $(this); + $("#grandvision-selection .filters select").each(function () { + var vals = $(this).val(); + if (vals.length === 0) { + return; + } + var name = $(this).attr('name'); + var attrvalues = $(a).attr('data-' + name).split(','); + var inter = vals.filter(function (n) { + return attrvalues.indexOf(n) !== -1; + }); + if (inter.length === 0) { + hide = true; + } + }); + if (hide) { + $(a).hide(); + } else { + hasVisible = true; + $(a).show(); + } + + }); + + if (hasVisible) { + $("#emptyres").hide(); + } else { + $("#emptyres").show(); + } + }, + openSelection: function (cb) { + var $this = this; var res = '
'; res += this.fluidbook.menu.getCaption('', true); @@ -48,17 +85,41 @@ FluidbookCartGrandVision.prototype = { res += '
'; this.fluidbook.menu.viewWrap(res, 'cart-grandvision-selection', 'data-max-width="1200" data-min-width="1200"'); + + $("#grandvision-cart select").each(function () { + var allValues = $this.filters[$(this).attr('name')].values; + $this.filters[$(this).attr('name')].multiselect = $(this).multiSelect({ + 'noneText': $(this).data('label'), + presets: [ + { + name: 'All', + options: allValues, + }, + ] + }).on('change', function () { + $this.updateFilters(); + }); + }); + + if (cb !== undefined) { cb(); } }, + + cartSelection: function () { var $this = this; - var res = '
'; - res += '

My Selection

'; - res += '
'; - res += '
'; + + this.filters = { + brand: {col: 'BRAND', label: 'Brand', values: []}, + category: {col: 'Category', label: 'Category', values: []}, + gender: {col: 'Gender', label: 'Gender', values: []}, + material: {col: 'Material', label: 'Material', values: []} + }; + + var selection = ''; $.each(this.items, function (k, item) { var data = $this.getProductData(item); var infos = ['Brand: ' + data.BRAND, 'Color: ' + data['Color Code']]; @@ -67,13 +128,38 @@ FluidbookCartGrandVision.prototype = { } infos.push('EAN: ' + item); - res += '
'; - res += '
'; - res += '

' + data['Model Code'] + '

'; - res += '
' + infos.join(' | ') + '
'; - res += '
'; + $.each($this.filters, function (fname, filter) { + if ($this.filters[fname].values.indexOf(data[filter.col]) === -1) { + $this.filters[fname].values.push(data[filter.col]); + } + }); + + selection += '
'; + selection += '
'; + if (data.front) { + selection += ''; + } + selection += '
'; + selection += '

' + data['Model Code'] + '

'; + selection += '

' + infos.join(' | ') + '

'; + selection += '
'; }); + + var res = '
'; + res += '

My Selection

'; + res += '
'; + $.each(this.filters, function (name, data) { + res += ''; + }); + res += '
'; + res += '
'; + res += selection; res += '
'; + res += '
No selected item match filters
'; res += '
'; return res; }, diff --git a/js/libs/jquery/jquery.multi-select.js b/js/libs/jquery/jquery.multi-select.js new file mode 100644 index 00000000..8143f30b --- /dev/null +++ b/js/libs/jquery/jquery.multi-select.js @@ -0,0 +1,442 @@ +// jquery.multi-select.js +// by mySociety +// https://github.com/mysociety/jquery-multi-select + +;(function ($) { + + "use strict"; + + var pluginName = "multiSelect", + defaults = { + 'containerHTML': '
', + 'menuHTML': '
', + 'buttonHTML': '', + 'menuItemsHTML': '
', + 'menuItemHTML': '