$(document).ready(function () { // framework initMijnSBBFramework(); // dashboard initHomepage(); // bestel formulier initBestellenPagina(); // bevestiging initBevestigingPagina(); }); function initMijnSBBFramework() { // initialisatie MijnSBB framework // zet module & labels initModule({ module: "Webshop", labels: [] }); // event handling voor taal switch $(document).on("LanguageChange", function (e) { var url = '/UI/ChangeLanguage'; $.ajax({ url: url, cache: false, cancelExisting: true, success: function (data) { location.reload(); }, error: function (data, error) { console.log(error); } }); }); // event handling voor organisatie switch $(document).on("OrganisatieChange", function (e) { location.reload(); }); } function initHomepage() { // initialiseren als homepage if ($('#homepage').length) { $(document).on('click', '.selecteerProduct', function () { window.location.href = '/Bestellen/Index?product=' + $(this).data('product') + '&returnUrl=' + window.location; }); if ($('.categoriefilter').length) { $(document).on('change', '.categoriefilter', function (e) { var filter = []; $(this).parent().parent().parent().find('.categoriefilter:checked').each(function () { filter.push($(this).val()); }); window.location.href = '/Home/Index?categorie=' + filter; }); } } } function initBestellenPagina() { var id_nederland; // initialiseren als bestellen if ($('#bestellen').length) { id_nederland = $('#NL').val(); $(window).resize(function () { ResizePanels(); }); bindAdresEvents(); if ($('#totaalPrijs').length) { $(document).on('change', '#BestellingProduct_Aantal', function () { ZetTotaalPrijs(); }); ZetTotaalPrijs(); } function ZetTotaalPrijs() { var aantal = parseInt($('#BestellingProduct_Aantal').val()); var prijs = parseFloat($('#BestellingProduct_Product_Prijs').val()); if (isNaN(aantal) || isNaN(prijs)) { $('#totaalPrijs').html(''); } else { var totaalPrijs = Number(Math.round(aantal * prijs + 'e2') + 'e-2').toLocaleString($('#totaalPrijs').data('locale'), { minimumFractionDigits: 2 }); $('#totaalPrijs').html('€ ' + totaalPrijs); } } ResizePanels(true); } function ResizePanels(mayextrarun) { // Extra run var extrarun = false; var panel1 = $("#panelbody-1"); var panel2 = $("#panelbody-2"); // Links en rechts even hoog houden panel1.removeAttr("style"); panel2.removeAttr("style"); if ($(window).width() > 992) { if (panel1.outerHeight() > panel2.outerHeight()) { panel2.css("height", panel1.outerHeight()); extrarun = true; } if (panel2.outerHeight() > panel1.outerHeight()) { panel1.css("height", panel2.outerHeight()); extrarun = true; } } // Als extra run if (extrarun && mayextrarun) { setTimeout(function () { ResizePanels(false); }, 100); } } function bindAdresEvents() { // Vestigingsadres: straat en plaats velden openzetten als land == Nederland anders sluiten $(document).on('change', '#Bestelling_Land', function () { var isNederland = $(this).val() == id_nederland; $('.straat-plaats').prop('readonly', isNederland); if (isNederland) { $('#formGroupStaat').hide(); $('#Bestelling_Staat').val(''); $('#postcode-huisnummer').addClass('required'); } else { $('#formGroupStaat').show(); $('#postcode-huisnummer').removeClass('required'); } ResizePanels(); $('#Bestelling_Postcode').val(''); $('#Bestelling_Huisnummer').val(''); $('#Bestelling_HuisnummerToevoeging').val(''); $('#Bestelling_Straat').val(''); $('#Bestelling_Plaats').val(''); $('#Bestelling_Staat').val(''); }); // adres aanvullen vestigingsadres $(document).on('change', '#Bestelling_Postcode, #Bestelling_Huisnummer', function () { ZoekAdres('#Bestelling_Postcode', '#Bestelling_Huisnummer', '#Bestelling_HuisnummerToevoeging', '#Bestelling_Straat', '#Bestelling_Plaats', '#Bestelling_Land' ); }); } function ZoekAdres(postcode, huisnummer, toevoeging, straat, plaats, land, onsucces) { var url = '/Bestellen/ZoekenAdresGegevens?postcode=' + $(postcode).val() + '&huisnummer=' + $(huisnummer).val() + '&toevoeging=' + $(toevoeging).val() + '&land=' + $(land).val(); $.getJSON(url, function (data) { $(postcode).val(data.Postcode); var nummer = parseInt(data.Huisnummer); if (!isNaN(nummer) && nummer > 0) { $(huisnummer).val(nummer); } $(toevoeging).val(data.Toevoeging); if ($(land).val() == id_nederland) { $(straat).val(data.Straat); $(plaats).val(data.Plaats); } if (onsucces !== undefined) { onsucces(); } }); } } function initBevestigingPagina() { if ($('#bevestiging').length) { var container = $("#download-message-container"); $(".message-success, .message-fail", container).fadeOut(5000); $(document).on('click', '.download a', function (e) { e.preventDefault(); $('.download').hide(); var action = $(this).prop('href'); $.get(action) .done(function (result) { if (result.IsToegevoegd) { openDocumentGereedModal(result.Bestandsnaam); } $('.download-afgerond').show(); }); }); } }