From c6fa2d5f07da89d987ce1c57f636cd34457b2d11 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 12 Jul 2022 16:37:52 +0200 Subject: add DestroyAccountView --- StoneIsland/www/js/lib/products/ProductView.js | 782 +++++++++++++------------ 1 file changed, 416 insertions(+), 366 deletions(-) (limited to 'StoneIsland/www/js/lib/products/ProductView.js') diff --git a/StoneIsland/www/js/lib/products/ProductView.js b/StoneIsland/www/js/lib/products/ProductView.js index d467fbdd..a6c97e6b 100755 --- a/StoneIsland/www/js/lib/products/ProductView.js +++ b/StoneIsland/www/js/lib/products/ProductView.js @@ -1,7 +1,6 @@ var ProductView = ScrollableView.extend({ - el: "#product", - + events: { "click .fit": "scroll_to_bottom", "click .notAvailableInCanada": "scroll_to_bottom", @@ -14,54 +13,61 @@ var ProductView = ScrollableView.extend({ "click .gallery-left": "gallery_left", "click .gallery-right": "gallery_right", }, - - initialize: function(){ - this.gallery = new GalleryView () - this.scroller = ScrollFactory('#product', app.iscroll_options) - - this.$productHeader = this.$(".product-header") - this.$title = this.$(".title") - this.$type = this.$(".type") - this.$price = this.$(".price") - this.$size = this.$(".size") - this.$sizeSelect = this.$(".size select") - this.$sizeLabel = this.$(".size .label") - this.$color = this.$(".color") - this.$colorSelect = this.$(".color select") - this.$colorLabel = this.$(".color .label") - this.$share = this.$(".share") - this.$body = this.$(".body") - this.$fit = this.$(".fit") - this.$fitHeader = this.$('.fitHeader') - this.$notAvailableInCanada = this.$(".notAvailableInCanada") - this.$extraMessage = this.$(".extraMessage") - this.$sizing = this.$(".sizing") - this.$style = this.$(".style") + + initialize: function () { + this.gallery = new GalleryView(); + this.scroller = ScrollFactory("#product", app.iscroll_options); + + this.$productHeader = this.$(".product-header"); + this.$title = this.$(".title"); + this.$type = this.$(".type"); + this.$price = this.$(".price"); + this.$size = this.$(".size"); + this.$sizeSelect = this.$(".size select"); + this.$sizeLabel = this.$(".size .label"); + this.$color = this.$(".color"); + this.$colorSelect = this.$(".color select"); + this.$colorLabel = this.$(".color .label"); + this.$share = this.$(".share"); + this.$body = this.$(".body"); + this.$fit = this.$(".fit"); + this.$fitHeader = this.$(".fitHeader"); + this.$notAvailableInCanada = this.$(".notAvailableInCanada"); + this.$extraMessage = this.$(".extraMessage"); + this.$sizing = this.$(".sizing"); + this.$style = this.$(".style"); }, - show: function(){ - this.showFooter() - document.body.className = "product" + show: function () { + this.showFooter(); + document.body.className = "product"; }, - - hide: function(){ - app.footer.hide() + + hide: function () { + app.footer.hide(); }, - - showFooter: function(){ - if (this.sold_out) { - console.log("FOOTER: SOLD OUT") - app.footer.show("SOLD OUT") - } - else if (this.isNotAvailable) { - console.log("FOOTER: NOT AVAILABLE") - app.footer.show("NOT AVAILABLE") - } - else { - app.footer.show("ADD TO CART", "BUY NOW") + + showFooter: function () { + var descriptions = this.details ? this.get_descriptions(this.details) : {}; + if ( + (this.sold_out || this.isNotAvailable) && + descriptions["Limited_Edition"] + ) { + // this.$extraMessage.html(stripHTML( descriptions['Limited_Edition'] )) + // this.$extraMessage.show() + console.log("FOOTER: LIMITED EDITION"); + app.footer.show(stripHTML(descriptions["Limited_Edition"])); + } else if (this.sold_out) { + console.log("FOOTER: SOLD OUT"); + app.footer.show("SOLD OUT"); + } else if (this.isNotAvailable) { + console.log("FOOTER: NOT AVAILABLE"); + app.footer.show("NOT AVAILABLE"); + } else { + app.footer.show("ADD TO CART", "BUY NOW"); } }, - + item: null, details: null, size: null, @@ -72,445 +78,489 @@ var ProductView = ScrollableView.extend({ sizes: null, colors: null, - + cache: {}, - - gallery_left: function(){ - app.product.gallery.previous() + + gallery_left: function () { + app.product.gallery.previous(); }, - gallery_right: function(){ - app.product.gallery.next() + gallery_right: function () { + app.product.gallery.next(); }, - - find: function(code, cb){ - data = app.collection.items[code] || {} + + find: function (code, cb) { + data = app.collection.items[code] || {}; if (code in this.cache) { - return cb(data, this.cache[code]) + return cb(data, this.cache[code]); } sdk.product.item({ code: code, - success: function(details){ - this.cache[code] = details - cb(data, details) - }.bind(this) - }) + success: function (details) { + this.cache[code] = details; + cb(data, details); + }.bind(this), + }); }, - load: function(code, data){ - this.gallery.reset() - this.show() + load: function (code, data) { + this.gallery.reset(); + this.show(); if (app.view && app.view.hide) { - app.view.hide() + app.view.hide(); } - app.view = this - app.header.set_back(true) - - if (! app.collection.loaded) { - this.el.className = "loading" - app.collection.afterFetchCallback = this.load.bind(this, code, data) - app.collection.fetch() - return - } - else { - app.collection.afterFetchCallback = null + app.view = this; + app.header.set_back(true); + + if (!app.collection.loaded) { + this.el.className = "loading"; + app.collection.afterFetchCallback = this.load.bind(this, code, data); + app.collection.fetch(); + return; + } else { + app.collection.afterFetchCallback = null; } - window.location.href = "#/store/" + code - + window.location.href = "#/store/" + code; + if (data) { - app.collection.items[code] = data + app.collection.items[code] = data; } - - this.el.className = "loading" - this.find(code, this.populate.bind(this)) + + this.el.className = "loading"; + this.find(code, this.populate.bind(this)); }, - populate: function(data, details){ - this.el.className = "" + populate: function (data, details) { + this.el.className = ""; - console.log(data, details) + console.log(data, details); - var descriptions = this.get_descriptions(details) + var descriptions = this.get_descriptions(details["Item"]); - var title = data['ModelNames'] || "" - var type = title_case( data['MicroCategory'] ) - var price = "$" + data['DiscountedPrice'] + ".00" - var details_description = descriptions['Details'] || "" - var editorial = descriptions['EditorialDescription'] || "" - var body = details_description + " " + editorial + var title = data["ModelNames"] || ""; + var type = title_case(data["MicroCategory"]); + var price = "$" + data["DiscountedPrice"] + ".00"; + var details_description = descriptions["Details"] || ""; + var editorial = descriptions["EditorialDescription"] || ""; + var body = details_description + " " + editorial; // body = body.replace(/
/g, "

").replace(/(
)+$/, "") - var default_color_id = this.populate_selectors(data, details) + var default_color_id = this.populate_selectors(data, details); - var notAvailableInCanada = !! app.store.NotAvailableInCanada - app.product.$notAvailableInCanada.toggle( notAvailableInCanada ) + var notAvailableInCanada = !!app.store.NotAvailableInCanada; + app.product.$notAvailableInCanada.toggle(notAvailableInCanada); - if (! ('Price' in details['Item'])) { - console.log("NO PRICE, IS NOT AVAILABLE") - this.isNotAvailable = true - } - else { - console.log("FOUND PRICE, IS AVAILABLE") - this.isNotAvailable = false + if (!("Price" in details["Item"])) { + console.log("NO PRICE, IS NOT AVAILABLE"); + this.isNotAvailable = true; + } else { + console.log("FOUND PRICE, IS AVAILABLE"); + this.isNotAvailable = false; } + this.$extraMessage.hide(); + if (this.sold_out || this.isNotAvailable) { - this.$style.css("opacity", 0) - this.$color.html("NOT AVAILABLE") - this.$size.hide() - this.gallery.populate( data['Code8'], details['Item']['ImageTypes'] ) - } - else { - this.$style.css("opacity", 1) + this.$style.css("opacity", 0); + this.$color.html("NOT AVAILABLE"); + this.$size.hide(); + this.gallery.populate(data["Code8"], details["Item"]["ImageTypes"]); + } else { + this.$style.css("opacity", 1); - var color = this.colors[default_color_id] - var color_label = color.label - var sizes = this.find_sizes_for_color(default_color_id) - var size = sizes[0] - var size_label = this.sizes[size].label + var color = this.colors[default_color_id]; + var color_label = color.label; + var sizes = this.find_sizes_for_color(default_color_id); + var size = sizes[0]; + var size_label = this.sizes[size].label; - this.gallery.populate( color.code, details['Item']['ImageTypes'] ) + this.gallery.populate(color.code, details["Item"]["ImageTypes"]); - this.color = color - this.size = size + this.color = color; + this.size = size; - this.is_onesize = !! this.sizes[1] - this.set_size_label(size_label) - this.set_color_label(color_label) + this.is_onesize = !!this.sizes[1]; + this.set_size_label(size_label); + this.set_color_label(color_label); } - + // console.log(color, color_label, size, size_label) - this.item = data - this.details = details['Item'] - this.code = data['DefaultCode10'] - - console.log( data['DefaultCode10'] ) + this.item = data; + this.details = details["Item"]; + this.code = data["DefaultCode10"]; + + console.log(data["DefaultCode10"]); // title += "
EXTREME COMPACTING ON NYLON BASE
LIMITED EDITION - NUMBERED 01 TO 100" - if (title.indexOf('
') !== -1) { - var title_lines = title.split('
').map(function(s){ - if (s.indexOf("LIMITED EDITION") !== -1) { - return "" + s + "" - } - return s - }.bind(this)) - title = title_lines.join('

') + '
' + if (title.indexOf("
") !== -1) { + var title_lines = title.split("
").map( + function (s) { + if (s.indexOf("LIMITED EDITION") !== -1) { + return "" + s + ""; + } + return s; + }.bind(this) + ); + title = title_lines.join("

") + "
"; } - this.$title.html(title) - this.$type.html(type) - this.$price.html(price) - this.$body.html(body) - + this.$title.html(title); + this.$type.html(type); + this.$price.html(price); + this.$body.html(body); + // window.FirebasePlugin && window.FirebasePlugin.setScreenName('product:' + code) - - this.$productHeader.toggleClass("wide", title.length > 48) - var fits_large = !!(this.fitLargeCodes[this.code]) + this.$productHeader.toggleClass("wide", title.length > 48); + + var fits_large = !!this.fitLargeCodes[this.code]; - this.showFooter() + this.showFooter(); - console.log(app.store.FitsLarge, app.store.fitsLargeText) + console.log(app.store.FitsLarge, app.store.fitsLargeText); if (fits_large) { - if (app.store.FitsLarge === 'use_alt_text' && (app.store.FitsLargeText || "").length) { - var fit_lines = app.store.FitsLargeText.replace(//g, "&rt;").split('\n').join("
") - this.$fitHeader.html(fit_lines) - this.$fitHeader.show() + if ( + app.store.FitsLarge === "use_alt_text" && + (app.store.FitsLargeText || "").length + ) { + var fit_lines = app.store.FitsLargeText.replace(//g, "&rt;") + .split("\n") + .join("
"); + this.$fitHeader.html(fit_lines); + this.$fitHeader.show(); + } else { + this.$fitHeader.hide(); } - else { - this.$fitHeader.hide() - } - - this.$fit.show() - if (app.store.SizingFooter === 'use_alt_text' && (app.store.SizingFooterText || "").length) { - var sizing_lines = app.store.SizingFooterText.replace(//g, "&rt;").split('\n').join("
") - this.$sizing.html(sizing_lines) - this.$sizing.show() - } else if (app.store.SizingFooter === 'true') { - this.$sizing.show() + this.$fit.show(); + + if ( + app.store.SizingFooter === "use_alt_text" && + (app.store.SizingFooterText || "").length + ) { + var sizing_lines = app.store.SizingFooterText.replace(//g, "&rt;") + .split("\n") + .join("
"); + this.$sizing.html(sizing_lines); + this.$sizing.show(); + } else if (app.store.SizingFooter === "true") { + this.$sizing.show(); } } else { - this.$fitHeader.hide() - this.$fit.hide() - this.$sizing.hide() + this.$fitHeader.hide(); + this.$fit.hide(); + this.$sizing.hide(); } - this.$extraMessage.hide() - if (descriptions['Limited_Edition']) { - this.$extraMessage.html(stripHTML( descriptions['Limited_Edition'] )) - this.$extraMessage.show() - app.footer.show(stripHTML( descriptions['Limited_Edition'] )) - } + this.populate_sizes(); + this.populate_colors(); - this.populate_sizes() - this.populate_colors() - - this.deferScrollToTop() + this.deferScrollToTop(); }, - get_descriptions: function (details){ - var descriptions = {} - details['Item']['Descriptions'].forEach(function(pair){ - descriptions[pair.Key] = pair.Value - }) - return descriptions + get_descriptions: function (details) { + var descriptions = {}; + (details["Descriptions"] || []).forEach(function (pair) { + descriptions[pair.Key] = pair.Value; + }); + return descriptions; }, - find_sizes_for_color: function(color_id){ - return Object.keys( this.colors[color_id].sizes ).sort(function(a,b){ - var ao = SIZE_ORDER[ a.label ], bo = SIZE_ORDER[ b.label ] - return ao