File: D:/HostingSpaces/SBogers10/topswtwmobile.komma.pro/wwwroot/js/app/checkout/checkout.js
define(['app/checkout/hiddenBox', 'app/checkout/parcelshoplocator'], function ($hiddenBox, DPD) {
// Handle
var $radioAddShipping = $('#add-shipping-address');
var $radioEqualToAddress = $('#equal-to-invoice-address');
var $shippingBox = $('#shipping-box');
var $dpdBox = $('#dpd-parcel-shop-box');
var dpdLocator
var dpdActive = false;
var dpdCityHistory = '';
/*
*
function dpdChosenShop(shopID) {
var query = $.ajax({
type: 'POST'
,cache: false
,url: 'index.php?fc=module&module=dpdcarrier&controller=parcelshopselected'
,data: {
parcelshopId : shopID
}
,dataType: 'json'
,success: function(json) {
if(json.hasErrors){
alert(json.errors);
} else {
dpdLocator.hideLocator();
$('#chosenShop').html(json.result);
if($('#opc_payment_methods')){
enableOpcPayment();
}
}
}
});
}
*/
$('input[name="shipping-type"]').bind('change', function () {
switch ($(this).val()) {
case 'add-shipping-address':
$hiddenBox.close($dpdBox)
$hiddenBox.open($shippingBox)
$('#shipping-box *[tabindex="-1"]').attr('tabindex', 0);
dpdActive = false;
break
case'equal-to-invoice-address':
$hiddenBox.close($dpdBox)
$hiddenBox.close($shippingBox)
$('#shipping-box *[tabindex="0"]').attr('tabindex', '-1');
dpdActive = false;
break;
case'dpd-parcel-shop':
$hiddenBox.open($dpdBox)
$hiddenBox.close($shippingBox)
$('#shipping-box *[tabindex="0"]').attr('tabindex', '-1');
dpdActive = true;
setTimeout(function () {
renderDPDbyInvoiceCity();
}, 600);
break;
}
});
//Check if there is an dpdLocatorContainer present
if (document.getElementById('dpdLocatorContainer')) {
//window.addEventListener('load', function () {
dpdLocator = new DPD.locator({
rootpath: '',
ajaxpath: '/api/dpd-parcelshops-search',
containerId: 'dpdLocatorContainer',
fullscreen: false,
width: '100%',
height: '600px',
filter: 'pick-up',
country: 'NL',
callback: 'dpdChosenShop',
dictionaryXML: '',
language: 'NL'
});
dpdLocator.initialize();
$(document).ready(function () {
//Check if there is an chosen dpd shop
if ($('#dpd_carrier_shop_details').val().length != 0) {
disableLocator();
return;
}
enableLocator();
})
}
$('input[name="DPDsubmit"]').click(function(){
dpdLocator.renderPlace($('#pac-input').val());
});
$('#chose_another_parcel_shop').bind('click', function () {
enableLocator();
});
function enableLocator() {
dpdLocator.showLocator();
$("#chosenShop").hide()
}
function disableLocator() {
dpdLocator.hideLocator();
renderChosenShop();
$("#chosenShop").show()
}
var invoiceCity = $('input[name="invoice-city"]');
//Update on change of input field
invoiceCity.bind('change', function () {
//Get filled city location
var place = $(this).val();
//Add city location to searchbar and render DPD map
$('#pac-input').val(place);
//Only Render if dpd is active
if(dpdActive) {
dpdCityHistory = place;
//Render DPD map
dpdLocator.renderPlace(place);
}
});
function renderDPDbyInvoiceCity() {
//check if invoice input field exist
if(invoiceCity.length){
//Check if invoice has already a value (when account isset) and if invoice has and other value
if( invoiceCity.val() && invoiceCity.val() != '' && invoiceCity.val() != dpdCityHistory){
//Get filled city location
var place = invoiceCity.val();
dpdCityHistory = place;
//Add city location to searchbar and render DPD map
$('#pac-input').val(place);
dpdLocator.renderPlace(place);
}
}
}
//});
/**
* This method is called in with an onclick function on the parcelShop choose button
*
* @param parcelShopId
*/
this.dpdChosenShop = function (parcelShopId) {
//Set the id for the Carrier shop
$('#dpd_carrier_shop_id').val(parcelShopId)
//Load the parcelShop
getParcelShop(parcelShopId, true);
//Hide the current locator, and show the chosen shop
disableLocator();
}
/**
* This function loads the parcelShop with the Api
*
* @param parcelShopId
* @param force | load the parcelShop again
* @return Json
*/
function getParcelShop(parcelShopId, force) {
//Check if force is is not true, use the json from the form field
if (force != true) {
//return the dpd_carrier_shop_details, parsed ad Json
return JSON.parse($('#dpd_carrier_shop_details').val());
}
//Collect the info of a new parcelShop
var parcelShop = dpdLocator.getShopInfo(parcelShopId);
//Set it as an json string in the form field
$('#dpd_carrier_shop_details').val(JSON.stringify(parcelShop));
//return the json
return parcelShop;
}
function renderChosenShop() {
data = getParcelShop();
//Set the fields
$('#shopName').html(data.company);
$('#shop_addres').html(data.street + ' ' + data.houseNo + ' ' + data.zipCode + ' ' + data.city+ ' ('+data.isoAlpha2+')' );
$('#monday-morning').html(data.openingHours[0].openMorning + ' - ' + data.openingHours[0].closeMorning);
$('#monday-afternoon').html(data.openingHours[0].openAfternoon + ' - ' + data.openingHours[0].closeAfternoon);
$('#tuesday-morning').html(data.openingHours[1].openMorning + ' - ' + data.openingHours[1].closeMorning);
$('#tuesday-afternoon').html(data.openingHours[1].openAfternoon + ' - ' + data.openingHours[1].closeAfternoon);
$('#wednesday-morning').html(data.openingHours[2].openMorning + ' - ' + data.openingHours[2].closeMorning);
$('#wednesday-afternoon').html(data.openingHours[2].openAfternoon + ' - ' + data.openingHours[2].closeAfternoon);
$('#thursday-morning').html(data.openingHours[3].openMorning + ' - ' + data.openingHours[3].closeMorning);
$('#thursday-afternoon').html(data.openingHours[3].openAfternoon + ' - ' + data.openingHours[3].closeAfternoon);
$('#friday-morning').html(data.openingHours[4].openMorning + ' - ' + data.openingHours[4].closeMorning);
$('#friday-afternoon').html(data.openingHours[4].openAfternoon + ' - ' + data.openingHours[4].closeAfternoon);
$('#saturday-morning').html(data.openingHours[5].openMorning + ' - ' + data.openingHours[5].closeMorning);
$('#saturday-afternoon').html(data.openingHours[5].openAfternoon + ' - ' + data.openingHours[5].closeAfternoon);
$('#sunday-morning').html(data.openingHours[6].openMorning + ' - ' + data.openingHours[6].closeMorning);
$('#sunday-afternoon').html(data.openingHours[6].openAfternoon + ' - ' + data.openingHours[6].closeAfternoon);
}
var $issuerHolder = $('#iDealBankIssuerHolder');
var $radioIdeal = $('#pm-iDeal');
var $radioPaymentMethod = $('input[name="pm"]');
$radioPaymentMethod.bind('change', function () {
if ($(this).attr('id') == 'pm-iDeal') {
$hiddenBox.open($issuerHolder)
}
else {
$hiddenBox.close($issuerHolder)
}
});
if ($radioIdeal.is(':checked')) {
$hiddenBox.open($issuerHolder)
}
// Prevent entering in couponCode from submitting Cart
var $couponCodeInputField = $('#couponCode');
if ($couponCodeInputField.size()) {
$couponCodeInputField.keydown(function (event) {
if (event.keyCode == 13) {
event.preventDefault();
$('#couponCodeSubmit').click();
}
});
}
});