var windowHeight = 0; var windowWidth = 0; var postMade = false; $(window).load(function () { try { //site.fixWebShopProductList(); } catch(e) { //site is not defined } }); $(document).ready(function () { if(!$("#base_summary").hasClass('v2')){ $("#base_summary").addClass('v2'); } if(!$("body").hasClass('v2')){ $("body").addClass('v2'); } if($('#tc_customer_details').length){ return webshop.customerDetails.init(); } webshop.initSwiper(); webshop.setEventHandlers(); webshop.init(); $(window).resize(function () { ResizeHandler(); }); ResizeHandler(); }); function ResizeHandler() { /*If width has changed*/ if (windowWidth != $(window).width()) { //webshop.summary.show(); webshop.initSwiper(); } SaveWindowResolution(); } function SaveWindowResolution () { windowHeight = $(window).height(); windowWidth = $(window).width(); } var webshop = new function () { this.swiperInstances = []; this.initSwiper = function(){ if(site.isSmallOrMediumDevice()) { $(".swiper-container").each(function(index, element){ //some-slider-wrap-in var $this = $(this); $this.addClass('instance').addClass("instance-" + index); //instance need to be unique (ex: some-slider) $this.parent().find(".swiper-pagination").addClass("pagination-" + index); $this.parent().find(".swiper-button-prev").addClass("prev-" + index); //prev must be unique (ex: some-slider-prev) $this.parent().find(".swiper-button-next").addClass("next-" + index); //next must be unique (ex: some-slider-next) webshop.swiperInstances[index] = new Swiper(".instance-" + index, { //instance need to be unique (ex: some-slider) /* slidesPerView: 'auto', freeMode: true, */ direction: 'horizontal', /*spaceBetween: 20,*/ loop: true, pagination: { el: '.pagination-' + index, type: 'bullets', clickable: true }, // Navigation arrows navigation: { nextEl: '.swiper-button-next', prevEl: '.swiper-button-prev', }, /*setWrapperSize:false,*/ slidesPerView: 'auto', /*freeMode: true, freeModeMomentum:true, freeModeMomentumRatio: 1, freeModeMomentumBounce:true, freeModeMomentumBounceRatio: 1, freeModeMomentumVelocityRatio: 1, freeModeSticky:false, freeModeMinimumVelocity: 0.05, */ observer: true, observeParents: true, }); }); } }; this.init = function(){ //set default values var stepInto = 'tc_select_location'; if(!$('#select_location .list-group-item.active').length){ $('#select_location .list-group-item').first().addClass('active'); } if($('#tc_select_location.centers').length){ $('#select_location .list-group-item.active').click(); } $('#select_location button').html($('#select_location .list-group-item.active').data('name') + ' '); webshop.showSection(stepInto); if($('#select_location .list-group-item.active').data('value') || !$('#id_ask_rr_location').length){ webshop.showSection('tc_select_product'); } //select product from cookie if(webshop.product.get()){ var hasOptions = false; var arrProducts = webshop.product.get().split('|'); for (var option in arrProducts) { var productCard = $('.product_card[data-product="' + arrProducts[option] + '"]'); if($(productCard).length) { if($(productCard).data('has-options')){ hasOptions = true; } webshop.product.select($(productCard, false)); if(webshop.swiperInstances.length) { var prodIndex = 0; $('.product_card[data-product-type="product"]').each(function(){ if($(this).data('product') == webshop.product.get()) { webshop.swiperInstances[0].slideTo(prodIndex, false,false); } prodIndex++; }); } } } /* //select payment type from cookie if(webshop.paymentType.get()){ var productCard = $('button.payment_type[data-type="'+webshop.paymentType.get()+'"]'); if($(productCard).length) { stepInto = 'tc_select_payment_type'; webshop.showSection(stepInto); webshop.paymentType.select($(productCard, false)); } } */ if(!hasOptions){ //hide options webshop.hideSection('tc_select_commitMonths'); if($('section[data-name="tc_select_personalTrainer"]').length){ webshop.showSection('tc_select_personalTrainer'); } else { webshop.showSection('checkout'); } } else { webshop.showSection('tc_select_commitMonths'); } webshop.summary.show(); } else { if(!site.isSmallOrMediumDevice()){ webshop.summary.show(); } } site.fixWebShopProductList(45, true, true); webshop.stepInto(stepInto, false); }; this.setEventHandlers = function(){ $('.tc_product_list_v2 .product_card .product_select button.btn').on('click', function(){ if($(this).closest('.product_card').data('product-type') == 'option'){ webshop.option.select($(this).closest('.product_card'), true); } else { webshop.product.select($(this).closest('.product_card'), true); } }); $('.tc_product_list_v2 .product_card .product_select select').on('change', function(){ if($(this).closest('.product_card').data('product-type') == 'option'){ webshop.option.select($(this).closest('.product_card'), true); } }); //prevent menu from closing when scrolling up/down in mobile $('#select_location .dropdown').on({ "shown.bs.dropdown": function() { this.closable = true; }, "click": function(e) { var target = $(e.target); if(target.hasClass("scroll")) this.closable = false; else this.closable = true; }, "hide.bs.dropdown": function() { return this.closable; } }); $('#payment_type .payment_type[data-product-type="payment_type"] .product_select .btn').on('click', function(){ webshop.paymentType.select($(this).closest('.payment_type')); }); $('section[data-name="tc_select_options"] a.remove').on('click', function(){ webshop.option.removeAll(); }); $('body.lite_webshop .tc_btn_continue').on('click', function(){ if(site.isSmallOrMediumDevice()){ if(!$('#tc_summary_mobile').hasClass('confirm')){ //show confirm //add location hash, for browser back navigation window.location.hash = 'confirm'; webshop.showConfirm(true); } else { webshop.post('#id_frm_lite_webshop'); } } else { webshop.post('#id_frm_lite_webshop'); } }); }; this.showConfirm = function(show){ if(show){ summary.maximize(); //hide all except continue button $('#training_card_v2').addClass('no-show'); $('#tc_summary_mobile').addClass('maximized').addClass('confirm'); $('body.lite_webshop .tc_btn_continue').addClass('confirm'); $('body.lite_webshop .tc_btn_continue').find('#tc_btn_continue_navigation').html('2/4'); $('body.lite_webshop .tc_btn_back').addClass('confirm'); $('#powered_by').hide(); } else { summary.minimize(); $('#training_card_v2').removeClass('no-show'); $('#tc_summary_mobile').removeClass('maximized').removeClass('confirm'); $('body.lite_webshop .tc_btn_continue').removeClass('confirm'); $('body.lite_webshop .tc_btn_continue').find('#tc_btn_continue_navigation').html('1/4'); $('body.lite_webshop .tc_btn_back').removeClass('confirm'); } }; this.stepInto = function(step, scrollToNext){ var progressbarStep = step; if(step == 'tc_select_location'){ progressbarStep = 'tc_select_product'; } if(step == 'checkout' || step == 'tc_select_options'){ progressbarStep = 'tc_select_payment_type'; } progressbar.set(progressbarStep); webshop.showSection(step); if($('section[data-name="' + step + '"]').length) { if (scrollToNext) { $('html, body').animate({ scrollTop: $('section[data-name="' + step + '"]').offset().top - 50 }, 500); } } }; this.showSection = function(name){ $('#training_card_v2 section').each(function(){ if($(this).data('name') == name){ return false; } else { $(this).closest('li').addClass('is-done'); } }); $('section[data-name="'+name+'"]').show(); $('section[data-name="'+name+'"]').closest('li').show(); }; this.hideSection = function(name){ $('#training_card_v2 section').each(function(){ if($(this).data('name') == name){ return false; } else { $(this).closest('li').removeClass('is-done'); } }); $('section[data-name="'+name+'"]').hide(); $('section[data-name="'+name+'"]').closest('li').hide(); }; this.showNextSection = function(card, scrollToNext) { //figure out next section var currListItem = $(card).closest('li'); var nextSection = $(currListItem).next('li').find('section').data('name'); if(!nextSection){ nextSection = 'checkout'; } webshop.showSection(nextSection); webshop.stepInto(nextSection, scrollToNext); }; this.showMore = function(card){ var html = { title: $(card).find('.product_name').text(), body: $(card).find('.product_notes').html(), buttons: {accept: 'Sulje', reject: 'Takaisin'} }; showConfirmation(null, html); //piilotetaan cancel nappi $('#dialog-confirmation .user-reject').hide(); }; /*webshop.post*/ this.post = function(formId){ try { if (postMade) { return false; } postMade = true; ShowPageLoading(); hideUserNotification(); ScrollTo("#img_loading"); var url = 'index.php?func=lws_post'; if(formId == '#id_frm_tc_customer_details'){ url = 'index.php?func=lws_cd_post'; } var currentLocation = document.location; if (currentLocation.toString().indexOf('inframe=1') > -1) { url += '&inframe=1'; } if (currentLocation.toString().indexOf('iframe=0') > -1) { url += '&iframe=0'; } if (site.isSmallOrMediumDevice()) { url += '&mobile=1'; } $(formId).find('input[name="products[]"]').remove(); //remove if exists $('.tc_product_list_v2 .product_card[data-product-type="product"].selected').each(function(){ //url += '&products[]='+$(this).data('id'); var inp = $('', {name: 'products[]', type: 'hidden', value: $(this).data('id')}); $(formId).append(inp); }); $.post(url, $(formId).serialize(), function(data) { }) .done(function(redirectUrl) { window.location = redirectUrl; }) .fail(function(data) { postMade = false; //Allow to submit again var errorMsg = ''; if (data && data.responseJSON && data.responseJSON.errors) { for (errorCode in data.responseJSON.errors) { errorMsg = errorMsg + "

" + data.responseJSON.errors[errorCode] + "

"; } } else { //something went really wrong errorMsg = errorMsg + "

" + 'Toiminto epäonnistui. Ole hyvä yritä hetken kuluttua uudelleen' + "

"; } showUserNotification('danger', errorMsg); HidePageLoading(); }); } catch (e){ console.log('Error in webshop.post: '+ e.message); } }; this.reset = function(){ webshop.product.set(''); webshop.stepInto('tc_select_product', false); webshop.summary.show(); //$('.tc_btn_continue').hide(); //commented out, caused problems, button is not set visible again when selecting another center and product }; /*webshop.product*/ this.product = new function() { /*webshop.product.get*/ this.get = function () { //Get product code from cookie. return Cookie.get('lws_selected_product'); //string, values separated with | }; /*webshop.product.set*/ this.set = function (productCode) { if (!productCode) { $('.product_card').removeClass('selected'); $('.product_card').find('.btn_buy').html('Valitse'); $('.product_card').find('.btn_buy').removeClass('disabled'); //Remove saved product code from cookie return Cookie.remove('lws_selected_product'); } }; /*webshop.product.select*/ this.select = function(card, scrollToNext) { if($(card).hasClass('selected')){ //unselect option $(card).removeClass('selected'); $(card).find('.btn_buy').html('Valitse'); } else { $(card).find('.btn_buy').html(''); $(card).addClass('selected'); } if($('#id_option_select_multiple').val() == '0'){ //toggle product. unselect all others $('.tc_product_list_v2 .product_card[data-product-type="product"]').each(function(){ if($(this).data('id') !== $(card).data('id')) { $(this).removeClass('selected'); $(this).find('.btn_buy').html('Valitse'); } }); } var productIds = []; $('.product_card[data-product-type="product"].selected').each(function(){ productIds.push($(this).data('id')); }); //Save products to cookie Cookie.set('lws_selected_product', productIds.join('|')); //if product has options, show them. if not, skip to personal trainers if($(card).data('has-options')){ //product linked options if(!('.options_list[data-for-product="'+$(card).data('product')+'"]').length){ webshop.hideSection('tc_select_commitMonths'); if($('section[data-name="tc_select_personalTrainer"]').length){ webshop.showSection('tc_select_personalTrainer'); } else { webshop.showSection('checkout'); } } else { $('.options_list').hide(); $('.options_list[data-for-product="'+$(card).data('product')+'"]').show(); webshop.showNextSection(card, scrollToNext); webshop.hideSection('checkout'); } } else { webshop.hideSection('tc_select_commitMonths'); $('#id_commitMonths').val(); //set none option selected for post if($('section[data-name="tc_select_personalTrainer"]').length){ webshop.showSection('tc_select_personalTrainer'); webshop.hideSection('checkout'); } else { webshop.showSection('checkout'); } } webshop.summary.show(); }; }; /*webshop.option*/ this.option = new function () { /*webshop.option.get*/ this.get = function (type) { //Get product codes from cookie. return Cookie.get('lws_selected_'+type); //string }; /*webshop.option.select*/ this.select = function(card, scrollToNext){ if ($(card).find('button.btn_buy').length) { $(card).find('button.btn_buy').html(''); } $(card).addClass('selected'); var optionType = $(card).data('option-type'); //toggle option. unselect all others $('.tc_product_list_v2 .product_card[data-product-type="option"][data-option-type="'+ optionType +'"]').each(function(){ if($(this).data('id') !== $(card).data('id')) { $(this).removeClass('selected'); if ($(this).find('select.btn_buy').length){ //$(this).find('select.btn_buy').val($(this).find('select.btn_buy').find('option:first').val()); $(this).find('select.btn_buy').val(''); } else if($(this).find('button.btn_buy').length) { $(this).find('button.btn_buy').html('Valitse'); } } }); var selectedValue = ''; if ($(card).find('button.btn_buy').length) { //button selectedValue = $(card).data('id'); $('#id_'+optionType).val(selectedValue); } else if($(card).find('select.btn_buy').length){ //select selectedValue = $(card).find('select.btn_buy').val(); $('#id_'+optionType).val(selectedValue); } //Save option to cookie Cookie.set('lws_selected_'+optionType, selectedValue); webshop.showNextSection(card, true); webshop.summary.show(); }; /* this.remove = function(product){ $('.product_card[data-product-type="option"].selected').each(function(){ if($(this).data('id') == product){ $(this).removeClass('selected'); $(this).find('.btn_buy').removeClass('disabled'); $(this).find('.btn_buy').html('Valitse'); } }); //Read filter values if ($('.product_card[data-product-type="option"]').length) { $('.product_card[data-product-type="option"].selected').each(function(){ webshop.option.values.personalTrainers.values.push($(this).data('id')); }); } Cookie.set('tc_selected_personalTrainer', webshop.option.values.personalTrainers.values.join('|')); if($('.product_card[data-product-type="option"].selected').length) { $('section[data-name="tc_select_options"] a.remove').hide(); } webshop.summary.show(); }; this.removeAll = function(){ $('.product_card[data-product-type="option"].selected').each(function(){ webshop.option.remove($(this).data('id')); }); $('section[data-name="tc_select_options"] a.remove').hide(); webshop.stepInto('tc_select_options', true); }; */ }; this.paymentType = new function(){ /*webshop.paymentType.get*/ this.get = function () { //Get payment_type from cookie. return Cookie.get('tc_selected_payment_type'); }; /*webshop.paymentType.select*/ this.select = function(card, scrollToNext) { var type = card.data('type'); $('#payment_type .payment_type').removeClass('selected'); $(card).addClass('selected'); $('.payment_type .btn_buy').removeClass('disabled'); $('.payment_type .btn_buy').html('Valitse'); $(card).find('.btn_buy').addClass('disabled'); $(card).find('.btn_buy').html(''); $('#payment_type .product_details').hide(); $('#payment_type .product_details[data-type="'+ type +'"]').show(); Cookie.set('tc_selected_payment_type', type); $('#id_payment_type').val(type); webshop.stepInto('checkout', scrollToNext); webshop.summary.show(); }; }; /*webshop.customerDetails*/ this.customerDetails = new function(){ this.init = function() { if(site.isSmallOrMediumDevice()) { summary.show(); } else { summary.hide(); } /*Read input values*/ $("#tc_customer_details input").each(function () { try { if ($(this).attr('type') != 'radio') { $(this).val(webshop.input.get($(this).prop('name'))); } /*Validate input values*/ if ($(this).val()) { webshop.input.set($(this)); } $(this).blur(function() { webshop.input.set($(this)); }); } catch (e) { console.log('Error in customerdetails read input values: ' + e.message); } }); $('body.lws_customer_details .tc_cd_btn_continue').on('click', function(){ if (webshop.input.showErrors()) { //Errors in form return false; } webshop.post('#id_frm_tc_customer_details'); }); }; this.reset = function () { $("#tc_customer_details input, #tc_customer_details select").each(function () { try { //reset input and cookie value if ($(this).attr('type') != 'radio') { $(this).val(''); //reset cookie value Cookie.set('lws_input_'+ $(this).prop('name'), ''); } } catch (e){ console.log('Error in customerdetails reset: '+ e.message); } }); }; this.post = function() { /* if(Cookie.get('lws_selected_products')) { var products = Cookie.get('lws_selected_products').split('|'); for (var i in products) { var inp = $('', {name: 'products[]', type: 'hidden', value: products[i]}); $("#id_frm_tc_customer_details").append(inp); } } */ }; }; /*webshop.filter*/ this.filter = new function (readFilterInputs) { this.values = { /*'productTypes': {'dataName': 'product-type', 'values': []}, 'commitMonths': {'dataName': 'commit-month', 'values': []}, 'frequencies': {'dataName': 'frequency', 'values': []}, 'contracts': {'dataName': 'contract', 'values': []}, 'sc_types': {'dataName': 'sc_type', 'values': []}, 'products': {'dataName': 'product', 'values': []}, 'webGroups': {'dataName': 'web-group', 'values': []}, 'locations': {'dataName': 'location', 'values': []},*/ 'centers': {'dataName': 'center', 'values': []}, }; /*webshop.filter.hideRow*/ this.hideRow = function (value, filterValues) { if (filterValues.length > 0) { if (filterValues[0] == '') { return false; } if (typeof(value) === 'string' && value.includes(',')) { var values = value.split(','); var match = false; for (var i in values) { /* console.log('productcard has values ' + values); console.log('productcard contains ' + values[i]); console.log('searching for ' + filterValues); */ if (InArray(values[i], filterValues) || values[i] == NOT_SET) { //NOT_SET is used as wildcard match = true; } } if (!match) { return true; } } else { if (!InArray(value, filterValues) && value !== NOT_SET) { return true; } } } return false; }; /*webshop.filter.execute*/ this.execute = function (readFilterInputs) { try { //remove selected product and options when filtering webshop.reset(); if (readFilterInputs) { this.readInputs(); } //Loop products $('.product_card').each(function () { $(this).show(); if(site.isSmallOrMediumDevice()) { $(this).closest('.swiper-slide').show(); } for (var filter in webshop.filter.values) { if($('#tc_select_location.centers').length){ if(filter=='locations'){ continue; } $('#id_center').val(webshop.filter.values[filter]['values']); } var value = $(this).data(webshop.filter.values[filter]['dataName']); //Ex data-commit-month if (webshop.filter.hideRow(value, webshop.filter.values[filter]['values'])) { $(this).hide(); if(site.isSmallOrMediumDevice()) { $(this).closest('.swiper-slide').hide(); } break; } } }); if(site.isSmallOrMediumDevice()) { webshop.swiperInstances[0].update(); } } catch (e){ console.log('Error in webshop.filter.execute: '+ e.message); } }; /*webshop.filter.readInputs*/ this.readInputs = function () { try { /*webshop.filter.values.productTypes.values = []; webshop.filter.values.commitMonths.values = []; webshop.filter.values.frequencies.values = []; webshop.filter.values.contracts.values = []; webshop.filter.values.sc_types.values = []; webshop.filter.values.products.values = []; webshop.filter.values.webGroups.values = []; webshop.filter.values.locations.values = [];*/ webshop.filter.values.centers.values = []; //Read filter values $('input[name="commit_months[]"]').each(function () { if ($(this).prop('checked')) { webshop.filter.values.commitMonths.values.push($(this).val()); } }); $('input[name="frequencies[]"]').each(function () { if ($(this).prop('checked')) { webshop.filter.values.frequencies.values.push($(this).val()); } }); $('input[name="contracts[]"]').each(function () { if ($(this).prop('checked')) { webshop.filter.values.contracts.values.push($(this).val()); } }); if ($('input[name="web_groups[]"]').length) { $('input[name="web_groups[]"]').each(function () { if ($(this).prop('checked')) { webshop.filter.values.webGroups.values.push($(this).val()); } }); } if ($('select[name="web_groups[]"]').length) { if($('select[name="web_groups[]"]').val()){ webshop.filter.values.webGroups.values.push($('select[name="web_groups[]"]').val()); } } $('input[name="locations[]"]').each(function () { if ($(this).prop('checked')) { webshop.filter.values.locations.values.push($(this).val()); } }); if($('#select_location[data-role-filter="1"]').length){ //webshop.filter.values.locations.values.push($('#select_location[data-role-filter="1"] .list-group-item.active').data('value')); webshop.filter.values.centers.values.push($('#select_location[data-role-filter="1"] .list-group-item.active').data('value')); } } catch (e){ console.log('Error in webshop.filter.readInputs: '+ e.message); } }; }; /*webshop.input*/ this.input = new function () { /*webshop.input.get*/ this.get = function (name, index) { var val = Cookie.get('lws_input_'+name); if(name == 'birthday[]'){ if(index != undefined && val != '') { if(DATEFMT == 'd.m.Y') { var tmp = val.split('.'); } else { var tmp = val.split('-'); } val = tmp[index]; } } return val; }; /*webshop.input.getErrorMessage*/ this.getErrorMessage = function (jQInput) { console.log('Virhe kentässä: '); return 'Virhe kentässä: ' + jQInput.attr('placeholder') + "
"; }; /*webshop.input.integer*/ this.getInteger = function (str) { str = str.replace(/[^0-9.]/g, ''); str = str.replace(/(\..*)\./g, '$1'); return str; }; /*webshop.input.set*/ this.set = function (jQInput) { try { var str = jQInput.val(); //Set to uppercase if (jQInput.attr('type') == 'text') { str = str.substring(0, 1).toLocaleUpperCase() + str.substring(1); } //Trim str = str.trim(); /*Data fetch*/ switch (jQInput.prop('name')) { case 'zip': str = this.getInteger(str); $.getJSON("index.php?func=lws_search&case=city&zip=" + str, function (data) { if (data) { $('#id_city').val(data); } }); break; } /*Validation*/ if (!jQInput.attr('required') && str == '') { jQInput.get(0).setCustomValidity(''); } else { switch (jQInput.prop('name')) { case 'social_sec_no': if (validator.isValid.socialSecNo($("input[name=country_code]").val(), str)) { jQInput.get(0).setCustomValidity(''); } else { jQInput.get(0).setCustomValidity('Virheellinen henkilötunnus'); } break; case 'birthday[]': var obj = $('[name="birthday[]"]'); var tmp = ''; var d = DATEFMT == 'd.m.Y' ? $(obj[0]).val() : $(obj[2]).val(); var m = $(obj[1]).val(); var y = DATEFMT == 'd.m.Y' ? $(obj[2]).val() : $(obj[0]).val(); //check if all values are selected if (d != '' && $.isNumeric(d) && m != '' && $.isNumeric(m) && y != '' && $.isNumeric(y)) { if(DATEFMT == 'd.m.Y'){ var strVal = d + '.' + m + '.' + y; } else { var strVal = y + '-' + m + '-' + d; } //pad day and month if (d.length == 1) { d = '0' + d; } if (m.length == 1) { m = '0' + m; } tmp = y + '-' + m + '-' + d; } if(DEBUG) { console.log(tmp); } if (tmp != '') { if (validator.isValid.date(tmp)) { jQInput.get(0).setCustomValidity(''); } else { jQInput.get(0).setCustomValidity('Virheellinen syntymäaika'); } } else { jQInput.get(0).setCustomValidity(''); } break; case 'email_confirm': if($('input[name="email"]').length){ if($('input[name="email"]').val() != $('input[name="email_confirm"]').val()){ jQInput.get(0).setCustomValidity('Sähköpostiosoitteet eivät täsmää. Ole hyvä ja tarkasta antamasi osoitteet.'); } else { jQInput.get(0).setCustomValidity(''); } } break; } } if (jQInput[0].checkValidity()) { jQInput.removeClass('invalid'); jQInput.closest('.form-group').find('.control-label').removeClass('invalid'); if(jQInput.prop('name') == 'birthday[]'){ if(strVal){ Cookie.set('lws_input_' + jQInput.prop('name'), strVal); } } else { Cookie.set('lws_input_' + jQInput.prop('name'), jQInput.val()); } } else { jQInput.addClass('invalid'); jQInput.closest('.form-group').find('.control-label').addClass('invalid'); } jQInput.val(str); } catch (e){ console.log('Error in webshop.input.set: '+ e.message); } }; this.showErrors = function () { var errorMsg = ''; $("#tc_customer_details input").each(function (){ $(this).removeClass('invalid'); $(this).closest('.form-group').find('.control-label').removeClass('invalid'); }); $("#tc_customer_details select").each(function (){ $(this).removeClass('invalid'); $(this).closest('.form-group').find('.control-label').removeClass('invalid'); }); $("#tc_customer_details input:invalid").each(function (){ errorMsg = errorMsg + webshop.input.getErrorMessage($(this)); $(this).addClass('invalid'); $(this).closest('.form-group').find('.control-label').addClass('invalid'); }); $("#tc_customer_details select:invalid").each(function (){ errorMsg = errorMsg + webshop.input.getErrorMessage($(this)); $(this).addClass('invalid'); $(this).closest('.form-group').find('.control-label').addClass('invalid'); }); if (errorMsg) { showUserNotification ('danger', errorMsg); $('#tc_customer_details .tc_cd_required_fields').addClass('invalid'); return true; }else{ hideUserNotification(); $('#tc_customer_details .tc_cd_required_fields').removeClass('invalid'); return false; } }; }; /*webshop.summary*/ this.summary = new function () { /*webshop.summary.show*/ this.show = function() { try { var url = 'index.php?func=lws_summary'; var arrProducts = webshop.product.get().split('|'); for (var option in arrProducts) { var productCard = $('.product_card[data-id="' + arrProducts[option] + '"]'); if($(productCard).length) { url += '&products[]=' + arrProducts[option]; } } if (site.isSmallOrMediumDevice()){ if(!arrProducts.length){ summary.hide(); return false; } } $('.product_card[data-product-type="option"]:visible.selected').each(function(){ var type = $(this).data('option-type'); var val = $(this).data('id'); if($(this).find('select.btn_buy').length){ //drop down val = $(this).find('select.btn_buy').val(); } url += '&options[' + type + ']=' + val; }); if($('#id_center').length){ if($('#id_center').val()){ url += '¢er=' + $('#id_center').val(); } } //location //url += '&rr_location=' + $('#select_location .list-group-item.active').data('value'); if($('#payment_type .payment_type.selected').length){ url += '&payment_type=' + $('#payment_type .payment_type.selected').data('type'); } if(site.isSmallOrMediumDevice()){ url += '&mobile=1'; } //get product details $.getJSON(url, function (html) { //Show summary summary.show(); $("#base_summary_content").html(html); if($('#btn_tc_campaign_code').length){ $('#btn_tc_campaign_code').on('click', function(){ if($('body.lite_webshop.v2 #campaign_code').val()) { var url = 'index.php?func=lws&campaign_code=' + $('body.lite_webshop.v2 #campaign_code').val(); //location //url += '&rr_location=' + $('#select_location .list-group-item.active').data('value'); window.location = url; } }); $('body.lite_webshop.v2 #campaign_code').on('keydown', function(e){ if (e.keyCode == 13) { $('#btn_tc_campaign_code').click(); } }); if($('#campaign_code_in_use').length){ $('body.lite_webshop.v2 #campaign_code').closest('.row').hide(); } } //overridable function webshop.summary.fetchReady(); }); } catch (e){ console.log('Error in webshop.summary.show: '+ e.message); } }; this.fetchReady = function(){ //overridable function }; }; };