1268 lines
59 KiB
JavaScript
1268 lines
59 KiB
JavaScript
/**
|
|
* NOTICE OF LICENSE
|
|
*
|
|
* This source file is subject to a commercial license from Common-Services Co., Ltd.
|
|
* Use, copy, modification or distribution of this source file without written
|
|
* license agreement from the SARL SMC is strictly forbidden.
|
|
* In order to obtain a license, please contact us: contact@common-services.com
|
|
* ...........................................................................
|
|
* INFORMATION SUR LA LICENCE D'UTILISATION
|
|
*
|
|
* L'utilisation de ce fichier source est soumise a une licence commerciale
|
|
* concedee par la societe Common-Services Co., Ltd.
|
|
* Toute utilisation, reproduction, modification ou distribution du present
|
|
* fichier source sans contrat de licence ecrit de la part de la Common-Services Co. Ltd. est
|
|
* expressement interdite.
|
|
* Pour obtenir une licence, veuillez contacter Common-Services Co., Ltd. a l'adresse: contact@common-services.com
|
|
* ...........................................................................
|
|
*
|
|
* @package So Colissimo Flexibilite
|
|
* @author Alexandre D.
|
|
* @copyright Copyright (c) 2011-2015 Common Services Co Ltd - 90/25 Sukhumvit 81 - 10260 Bangkok - Thailand
|
|
* @license Commercial license
|
|
* Support by mail : support.soflexibilite@common-services.com
|
|
*/
|
|
|
|
$(document).ready(function () {
|
|
|
|
//window.console && console.log('Colissimo Flexibilite');
|
|
|
|
if ($('#SubmitLogin, #submitAccount, #submitGuestAccount').length)
|
|
$('#SubmitLogin, #submitAccount, #submitGuestAccount').click(function () {
|
|
|
|
$(document).ajaxStop(function () {
|
|
$(document).unbind('ajaxStop');
|
|
setTimeout(function () {
|
|
if ($('.address_firstname:first').text()) {
|
|
$('#sl-0-firstname').val($('.address_firstname:first').text().split(' ')[0]);
|
|
$('#sl-0-lastname').val($('.address_firstname:first').text().split(' ')[1]);
|
|
$('#sl-0-address1').val($('li.address_address1:first').text());
|
|
$('#sl-0-address2').val($('li.address_address2:first').text());
|
|
$('#sl-0-postcode').val($('li.address_postcode:first').text().substring(0, 5));
|
|
$('#sl-0-city').val($('li.address_postcode:first').text().substring(6));
|
|
$('#sl-0-company').val($('li.address_company:first').text());
|
|
$('#sl-0-country').val($('li[class="address_country_name"]:first').text());
|
|
$('#sl-0-phone').val($('li[class="address_phone_mobile"]:first').text());
|
|
}
|
|
else {
|
|
$('#sl-0-firstname').val($('#firstname').val());
|
|
$('#sl-0-lastname').val($('#lastname').val());
|
|
$('#sl-0-address1').val($('#address1').val());
|
|
$('#sl-0-address2').val('');
|
|
$('#sl-0-postcode').val($('#postcode').val());
|
|
$('#sl-0-city').val($('#city').val());
|
|
$('#sl-0-company').val($('#company').val());
|
|
$('#sl-0-country').val($('#id_country option:selected').text());
|
|
$('#sl-0-phone').val($('#phone_mobile').val());
|
|
}
|
|
setTimeout(function () {
|
|
startSoFlexibiliteEngine();
|
|
}, 800);
|
|
}, 800);
|
|
});
|
|
|
|
});
|
|
else
|
|
startSoFlexibiliteEngine();
|
|
|
|
function startSoFlexibiliteEngine() {
|
|
/* if ENTER is pressed in input address search => click on search button. */
|
|
$('.lookup').keypress(function (e) {
|
|
if (e.keyCode === 13) {
|
|
e.preventDefault();
|
|
$('#soflex-search').click();
|
|
}
|
|
});
|
|
|
|
/* If click outside of #so_box_hors, quit the overlay or click on boxlcose (x) */
|
|
$('#soflexibilite_overlay, a#boxclose').click(function () {
|
|
$('#soflexibilite_overlay').fadeOut('fast', function () {
|
|
$('#so_box_hors').fadeOut('slow');
|
|
setTimeout(resetOverlay, 300);
|
|
});
|
|
});
|
|
|
|
/* Hooking to a target div in the theme. Center Column is present in the PS default theme. */
|
|
var target_action_div = null;
|
|
if ($('#center_column').length)
|
|
target_action_div = $('#center_column');
|
|
else if ($('div.column.full:first').length)
|
|
target_action_div = $('div.column.full:first');
|
|
else if ($('#carrier_area').length)
|
|
target_action_div = $('#carrier_area');
|
|
else if ($('#content').length)
|
|
target_action_div = $('#content');
|
|
else
|
|
return (false);
|
|
|
|
/* Carrier selector */
|
|
var carrier_selector = parseInt($.fn.jquery.split('.').join('')) < 172 ? 'input:radio[name="id_carrier"]' : 'input.delivery_option_radio';
|
|
|
|
/* PS16 - Select carrier when click on carrier image */
|
|
if (parseInt($.fn.jquery.split('.').join('')) > 172)
|
|
target_action_div.delegate('.delivery_option_logo', 'click', function () {
|
|
$(this).parent().find(carrier_selector).attr('checked', true).click().parent().addClass('checked');
|
|
//SoFlexibilite.updateCarrierSelectionAndGift();
|
|
});
|
|
|
|
var dom_id = $('input#soflexibilite_dom_id').val();
|
|
var dos_id = $('input#soflexibilite_dos_id').val();
|
|
var rdv_id = $('input#soflexibilite_rdv_id').val();
|
|
var bpr_id = $('input#soflexibilite_bpr_id').val();
|
|
var a2p_id = $('input#soflexibilite_a2p_id').val();
|
|
var cit_id = $('input#soflexibilite_cit_id').val();
|
|
|
|
/* Check if at least one So Colissimo Liberte carrier is available */
|
|
var pass = false;
|
|
$(carrier_selector).each(function () {
|
|
switch ($(this).val().split(',').join('')) {
|
|
// Case : standard
|
|
case dom_id :
|
|
case dos_id :
|
|
case rdv_id :
|
|
case bpr_id :
|
|
case a2p_id :
|
|
case cit_id :
|
|
// Case : envoi differe
|
|
case dom_id + dom_id:
|
|
case dos_id + dos_id:
|
|
case rdv_id + rdv_id:
|
|
case bpr_id + bpr_id:
|
|
case a2p_id + a2p_id:
|
|
case cit_id + cit_id:
|
|
pass = true;
|
|
break;
|
|
}
|
|
// Case : 2 products with 2 different carriers
|
|
if ($(this).val().search(dom_id) > -1 || $(this).val().search(dos_id) > -1 || $(this).val().search(rdv_id) > -1 ||
|
|
$(this).val().search(bpr_id) > -1 || $(this).val().search(a2p_id) > -1 || $(this).val().search(cit_id) > -1)
|
|
pass = true;
|
|
});
|
|
if (!pass) {
|
|
//window.console && console.log('No So Colissimo Flexibilite carriers, script stop.');
|
|
return false;
|
|
}
|
|
|
|
/* Retrieving carriers ID */
|
|
var sf_carriers_id = [];
|
|
$('[id^="soflexibilite_"][id$="_id"]').not('#soflexibilite_address_id, #soflexibilite_cart_id').each(function () {
|
|
sf_carriers_id.push($(this).val());
|
|
});
|
|
|
|
// If no SF Carrier => STOP
|
|
if (!sf_carriers_id.length)
|
|
return false;
|
|
|
|
/* Check if processCarrier or opc_payment_methods is present in theme in order to check parameters before payment. */
|
|
if (!$('#opc_payment_methods, input[name="processCarrier"], button[name="processCarrier"]').length) {
|
|
alert($('#error-target-payment').val());
|
|
return;
|
|
}
|
|
|
|
/* Variables */
|
|
var sf_customer_address = $('#sl-0-address1').val() + ', ' + $('#sl-0-postcode').val() + ' ' + $('#sl-0-city').val() + ', ' + $('#sl-0-country').val();
|
|
sf_customer_address = sf_customer_address.split(/France|FRANCE|france/).length > 1 ? sf_customer_address.split(/France|FRANCE|france/)[0] + 'France' : sf_customer_address;
|
|
|
|
$('.lookup').val(sf_customer_address);
|
|
var soflex_image_url = $('#soflex_image_url').val();
|
|
var sf_delivery_mode_is_selected = false;
|
|
var sf_customer_lat = null;
|
|
var sf_customer_lng = null;
|
|
var sf_customer_mail = $('#sl-0-mail').val();
|
|
var sf_customer_phone = $('#sl-0-phone').val();
|
|
var sf_latlng = null;
|
|
var sf_map_zoom = 14;
|
|
var sf_map_options = null;
|
|
var sf_map = null;
|
|
var sf_customer_house = null;
|
|
var sf_markers = [];
|
|
var sf_info_windows = [];
|
|
var sf_bounds = null;
|
|
var sf_direction_service = new google.maps.DirectionsService();
|
|
var sf_directions_display = new google.maps.DirectionsRenderer({suppressMarkers: true});
|
|
var sf_panorama = null;
|
|
var search_address_parameters = [];
|
|
var sf_icon_home = new google.maps.MarkerImage(
|
|
soflex_image_url + 'home.png',
|
|
null,
|
|
null,
|
|
null,
|
|
new google.maps.Size(32, 32)
|
|
);
|
|
var sf_icon_relay = new google.maps.MarkerImage(
|
|
soflex_image_url + 'picto.png',
|
|
null,
|
|
null,
|
|
null,
|
|
new google.maps.Size(32, 32)
|
|
);
|
|
var sf_center_control_div = null;
|
|
var sf_center_control = null;
|
|
var sf_relay_control_div = null;
|
|
var sf_relay_control = null;
|
|
|
|
$('#so_box_hors a.boxclose').css('backgroundImage', 'url(' + soflex_image_url + 'close.png)');
|
|
$('#super-selector').css('backgroundImage', 'url(' + soflex_image_url + 'picto.png)');
|
|
$('#super-selector').css('background-repeat', 'no-repeat');
|
|
$('#super-selector').css('background-position', '2% center');
|
|
$(carrier_selector).attr('checked', false);
|
|
|
|
/* Overlay */
|
|
target_action_div.delegate(carrier_selector, 'click', function () {
|
|
sf_delivery_mode_is_selected = false;
|
|
var selected_carrier = $(this).val().split(',')[0];
|
|
|
|
if (!in_array(selected_carrier, sf_carriers_id)) {
|
|
$('#soflexibilite_description_address').remove();
|
|
return (true);
|
|
}
|
|
|
|
if (in_array(selected_carrier, [bpr_id, a2p_id])) {
|
|
$('[id^="PR"]').hide();
|
|
if (selected_carrier == bpr_id) {
|
|
$('[id^="PR"].BPR, [id^="PR"].BDP, [id^="PR"].CDI, [id^="PR"].ACP').show();
|
|
$('#super-selector option[value="choixPoste"]').attr('selected', true);
|
|
}
|
|
else if (selected_carrier == a2p_id) {
|
|
$('[id^="PR"].A2P, [id^="PR"].CMT, [id^="PR"].PCS').show();
|
|
$('#super-selector option[value="choixCom"]').attr('selected', true);
|
|
}
|
|
|
|
$('#soflexibilite_overlay').fadeIn('fast', function () {
|
|
$('#so_box_hors').fadeIn(1000);
|
|
if (typeof (sf_map) !== 'undefined' && sf_map !== null) {
|
|
google.maps.event.trigger(sf_map, 'resize');
|
|
sf_map.fitBounds(sf_bounds);
|
|
}
|
|
});
|
|
}
|
|
else
|
|
showDeliverySumUpHome();
|
|
});
|
|
|
|
if ($('#order-opc').length) {
|
|
// Address change
|
|
target_action_div.delegate('#id_address_delivery', 'change', function () {
|
|
//resetDeliveryInfoFromAddressBloc();
|
|
$('.delivery_option').remove();
|
|
$('#opc-refresh-carrier').clone().attr('id', 'opc-refresh-carrier-copy').insertAfter('.delivery_options').show();
|
|
$('#soflex-search').click();
|
|
|
|
target_action_div.ajaxComplete(function () {
|
|
$(carrier_selector).attr('checked', false).parent().removeClass('checked');
|
|
$('#soflexibilite_description_address').remove();
|
|
});
|
|
|
|
target_action_div.ajaxStop(function () {
|
|
target_action_div.unbind('ajaxComplete');
|
|
target_action_div.unbind('ajaxStop');
|
|
$(carrier_selector).attr('checked', false).parent().removeClass('checked');
|
|
setTimeout(function () {
|
|
resetDeliveryInfoFromAddressBloc();
|
|
setTooltips();
|
|
}, 500);
|
|
});
|
|
});
|
|
}
|
|
|
|
/* Google Map */
|
|
try {
|
|
var geocoder = new google.maps.Geocoder();
|
|
}
|
|
catch (e) {
|
|
/*window.console && console.log('Erreur GeoCODER', e);
|
|
alert($('#geocoder_failed').val());*/
|
|
}
|
|
|
|
function geocodeLocation() {
|
|
geocoder.geocode({'address': sf_customer_address, 'region': 'FR'}, function (results, status) {
|
|
/*if (window.console) {
|
|
console.log('Address : ' + sf_customer_address || 'N/A');
|
|
if (results[0])
|
|
console.log('Google Map Api value : ' + results[0].geometry.location_type);
|
|
}*/
|
|
|
|
if (status === google.maps.GeocoderStatus.OK) {
|
|
sf_customer_lat = parseFloat(results[0].geometry.location.lat());
|
|
sf_customer_lng = parseFloat(results[0].geometry.location.lng());
|
|
}
|
|
/*else if (window.console)
|
|
window.console && console.log('google.maps.GeocoderStatus != OK', status, results);*/
|
|
|
|
/*console.log(
|
|
$('#sl-0-address1').val(),
|
|
$('#sl-0-postcode').val(),
|
|
$('#sl-0-city').val()
|
|
);*/
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: $('#soflexibilite_point_list_url').val(),
|
|
dataType: 'json',
|
|
data: {
|
|
adresseRecherche: $('#sl-0-address1').val(),
|
|
address: $('#sl-0-address1').val(),
|
|
postcode: $('#sl-0-postcode').val(),
|
|
city: $('#sl-0-city').val(),
|
|
country: $('#sl-0-country').val()
|
|
},
|
|
success: function (data) {
|
|
//window.console && console.log(data);
|
|
|
|
if (data.status === true) {
|
|
sf_bounds = new google.maps.LatLngBounds();
|
|
sf_latlng = new google.maps.LatLng(sf_customer_lat, sf_customer_lng);
|
|
sf_map_options = {
|
|
zoom: sf_map_zoom,
|
|
center: sf_latlng,
|
|
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
|
styles: (typeof(sf_map_style) === 'object') ? sf_map_style : null
|
|
};
|
|
sf_map = new google.maps.Map(document.getElementById('gmap'), sf_map_options);
|
|
|
|
sf_center_control_div = document.createElement('div');
|
|
sf_center_control = new setControlCenter(sf_center_control_div);
|
|
sf_center_control_div.index = 1;
|
|
sf_map.controls[google.maps.ControlPosition.TOP_RIGHT].push(sf_center_control_div);
|
|
|
|
if ($('#soflexibilite_only_map').val() == '0') {
|
|
sf_relay_control_div = document.createElement('div');
|
|
sf_relay_control = new setControlRelay(sf_relay_control_div);
|
|
sf_relay_control_div.index = 1;
|
|
sf_map.controls[google.maps.ControlPosition.LEFT_BOTTOM].push(sf_relay_control_div);
|
|
}
|
|
|
|
sf_customer_house = new google.maps.Marker({
|
|
map: sf_map,
|
|
position: new google.maps.LatLng(sf_customer_lat, sf_customer_lng),
|
|
icon: sf_icon_home
|
|
});
|
|
sf_bounds.extend(sf_customer_house.position);
|
|
|
|
fillPR(data.points, data.horaires, data.fermetures);
|
|
}
|
|
},
|
|
error: function (er) {
|
|
/*if (window.console)
|
|
console.log('Erreur geocoder.geocode()', er);*/
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
geocodeLocation();
|
|
|
|
$('#super-selector').change(function () {
|
|
var type_de_point = $('#super-selector option:selected').val();
|
|
|
|
$('#information-pr').hide();
|
|
$('#points').show();
|
|
sf_directions_display.setMap(null);
|
|
|
|
$('div[id^="PR"]').hide();
|
|
if (type_de_point == 'choixPoste')
|
|
$('div[id^="PR"].BPR, div[id^="PR"].CDI, div[id^="PR"].ACP, div[id^="PR"].BDP').show();
|
|
else
|
|
$('div[id^="PR"].A2P, div[id^="PR"].CMT, div[id^="PR"].PCS').show();
|
|
|
|
$('#so_constraint').is(':checked') && setConstraint();
|
|
});
|
|
|
|
$('#gmap').delegate('.infoButton', 'click', function () {
|
|
var rel_point = $(this).parent().find('.so-infoWindow').attr('rel');
|
|
var prez = '<span class="so-info-libelle">' + $('[id="PR' + rel_point + '"]').find('.libelle').html() + '</span><br>' +
|
|
$('[id="PR' + rel_point + '"]').find('.address1').html() + '<br>' + $('[id="PR' + rel_point + '"]').find('.code_postal').html() +
|
|
' ' + $('[id="PR' + rel_point + '"]').find('.commune').html();
|
|
|
|
$('#information-pr').attr('rel', rel_point);
|
|
$('#points').hide();
|
|
$('#information-pr').find('.prez').html(prez);
|
|
$('#horaire').html('').append($('[id="PR' + rel_point + '"]').find('.horairesPR').html());
|
|
$('#fermeture').html('').append($('[id="PR' + rel_point + '"]').find('.fermeturesPR').html());
|
|
$('#information-pr').show();
|
|
checkStreetViewAvailability(
|
|
parseFloat($('[id="PR' + rel_point + '"] .pr-lat').val().split(',').join('.')),
|
|
parseFloat($('[id="PR' + rel_point + '"] .pr-lng').val().split(',').join('.'))
|
|
);
|
|
});
|
|
|
|
$('#gmap').delegate('.sf_select', 'click', function () {
|
|
var id_point = $(this).parent().find('.so-infoWindow').attr('rel');
|
|
id_point = $('[id="PR' + id_point + '"] .pr-id').val();
|
|
|
|
selectPoint(id_point);
|
|
showDeliverySumUpRelay(id_point);
|
|
});
|
|
|
|
function resetDeliveryInfoFromAddressBloc() {
|
|
$(carrier_selector).attr('checked', false).parent().removeClass('checked');
|
|
|
|
if ($('.address_firstname:first').text()) {
|
|
$('#sl-0-firstname').val($('.address_firstname:first').text().split(' ')[0]);
|
|
$('#sl-0-lastname').val($('.address_firstname:first').text().split(' ')[1]);
|
|
$('#sl-0-address1').val($('li.address_address1:first').text());
|
|
$('#sl-0-address2').val($('li.address_address2:first').text());
|
|
$('#sl-0-postcode').val($('li.address_postcode:first').text().substring(0, 5));
|
|
$('#sl-0-city').val($('li.address_postcode:first').text().substring(6));
|
|
$('#sl-0-company').val($('li.address_company:first').text());
|
|
$('#sl-0-country').val($('li[class="address_country_name"]:first').text());
|
|
$('#sl-0-phone').val($('li[class="address_phone_mobile"]:first').text());
|
|
sf_customer_phone = $('li[class="address_phone_mobile"]:first').text();
|
|
sf_customer_address = $('li.address_address1:first').text() + ' ' + $('li.address_postcode:first').text();
|
|
}
|
|
else {
|
|
$('#sl-0-firstname').val($('#firstname').val());
|
|
$('#sl-0-lastname').val($('#lastname').val());
|
|
$('#sl-0-address1').val($('#address1').val());
|
|
$('#sl-0-address2').val('');
|
|
$('#sl-0-postcode').val($('#postcode').val());
|
|
$('#sl-0-city').val($('#city').val());
|
|
$('#sl-0-company').val($('#company').val());
|
|
$('#sl-0-country').val($('#id_country option:selected').text());
|
|
$('#sl-0-phone').val($('#phone_mobile').val());
|
|
sf_customer_phone = $('#phone_mobile').val();
|
|
sf_customer_address = $('#address1').val() + ', ' + $('#postcode').val() + ' ' + $('#city').val();
|
|
}
|
|
|
|
$('input.lookup').val(sf_customer_address);
|
|
}
|
|
|
|
function setTooltips() {
|
|
$('a[id^="tooltip"]').remove();
|
|
|
|
if (parseInt($.fn.jquery.split('.').join('')) < 172)
|
|
return false;
|
|
|
|
$(carrier_selector).each(function () {
|
|
var id_carrier = $(this).val().split(',')[0];
|
|
var delivery_mode = null;
|
|
|
|
if (!in_array(id_carrier, sf_carriers_id))
|
|
return true;
|
|
|
|
switch (id_carrier) {
|
|
case dom_id:
|
|
delivery_mode = 'Dom';
|
|
break;
|
|
case dos_id:
|
|
delivery_mode = 'Dos';
|
|
break;
|
|
case bpr_id:
|
|
delivery_mode = 'Bpr';
|
|
break;
|
|
case a2p_id:
|
|
delivery_mode = 'A2p';
|
|
break;
|
|
}
|
|
|
|
$('.for' + delivery_mode).clone().appendTo($(this).closest('tr').find('.delivery_option_logo').next()).attr('id', 'tooltip' + delivery_mode).show().qtip({
|
|
content: {
|
|
text: $('.for' + delivery_mode + ' span').html().trim()
|
|
},
|
|
position: {
|
|
my: 'bottom center',
|
|
at: 'top center'
|
|
},
|
|
style: {
|
|
classes: 'qtip-light qtip-shadow',
|
|
width: 500
|
|
},
|
|
hide: {
|
|
fixed: true,
|
|
delay: 300
|
|
}
|
|
}).parent().find('strong').html(
|
|
$('#tooltip' + delivery_mode).parent().find('strong').text().split(' - ').join(' - <i style="font-style: italic;">') + '</i>'
|
|
).css('color', '#FB4F14');
|
|
|
|
// Instead of .parent().find('strong')...
|
|
//
|
|
// var txt1 = $('#tooltip' + delivery_mode).parent().html().trim().split('Faites')[0];
|
|
// var txt2 = $('#tooltip' + delivery_mode).parent().html().trim().split('Faites')[1];
|
|
//
|
|
// $('#tooltip' + delivery_mode).parent().html('<span style="color: #FB4F14;">' + txt1 + '</span>' + ' Faites' + txt2);
|
|
|
|
if ($('#tooltip' + delivery_mode).prev().text() === '')
|
|
$('#tooltip' + delivery_mode).prev().remove();
|
|
});
|
|
}
|
|
|
|
function setControlCenter(controlDiv) {
|
|
// Set CSS for the control center border.
|
|
var controlCenterMap = document.createElement('div');
|
|
controlCenterMap.style.backgroundColor = '#fff';
|
|
controlCenterMap.style.border = '2px solid #fff';
|
|
controlCenterMap.style.borderRadius = '3px';
|
|
controlCenterMap.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)';
|
|
controlCenterMap.style.cursor = 'pointer';
|
|
controlCenterMap.style.margin = '10px';
|
|
controlCenterMap.style.textAlign = 'center';
|
|
controlCenterMap.title = 'Recentrer la carte et les points de retrait';
|
|
controlDiv.appendChild(controlCenterMap);
|
|
|
|
// Set CSS for the control center interior.
|
|
var controlCenterText = document.createElement('div');
|
|
controlCenterText.style.color = 'rgb(0, 0, 0)';
|
|
controlCenterText.style.fontFamily = 'Roboto, Arial, sans-serif';
|
|
controlCenterText.style.fontSize = '11px';
|
|
controlCenterText.style.padding = '8px';
|
|
controlCenterText.innerHTML = 'Centrer la carte';
|
|
controlCenterMap.appendChild(controlCenterText);
|
|
|
|
// Setup the click event listeners
|
|
controlCenterMap.addEventListener('click', function () {
|
|
sf_map.fitBounds(sf_bounds);
|
|
});
|
|
}
|
|
|
|
function setControlRelay(controlDiv) {
|
|
// Set CSS for the control relay border.
|
|
var controlRelay = document.createElement('div');
|
|
controlRelay.style.backgroundColor = '#fff';
|
|
controlRelay.style.border = '2px solid #fff';
|
|
controlRelay.style.borderRadius = '3px';
|
|
controlRelay.style.boxShadow = '0 2px 6px rgba(0,0,0,.3)';
|
|
controlRelay.style.margin = '10px';
|
|
controlRelay.style.textAlign = 'center';
|
|
controlRelay.title = 'Cacher les points de retrait qui ne font pas partie du mode de livraison sélectionné';
|
|
controlRelay.id = 'so_control_relay';
|
|
controlDiv.appendChild(controlRelay);
|
|
|
|
// Set CSS for the control relay interior.
|
|
var controlRelayText = document.createElement('div');
|
|
controlRelayText.style.color = 'rgb(0, 0, 0)';
|
|
controlRelayText.style.fontFamily = 'Roboto, Arial, sans-serif';
|
|
controlRelayText.style.fontSize = '11px';
|
|
controlRelayText.style.padding = '8px';
|
|
controlRelayText.innerHTML = '<input type="checkbox" id="so_constraint"> Filtrer les points de retrait';
|
|
controlRelay.appendChild(controlRelayText);
|
|
|
|
// Setup the click event listeners
|
|
controlRelay.addEventListener('click', function () {
|
|
setConstraint();
|
|
});
|
|
}
|
|
|
|
function fillPR(points, horaires, fermetures) {
|
|
deleteMarkers();
|
|
$('div[id^=PR]').remove();
|
|
$('#so-no-points').hide();
|
|
|
|
var type_de_point = $('#super-selector option:selected').val();
|
|
|
|
$.each(points, function (p, point) {
|
|
var point_div = $('#model-points').clone().appendTo('div#points').attr('id', 'PR' + p).attr('class', point.typeDePoint);
|
|
var distance = null;
|
|
var position = new google.maps.LatLng(point.coordGeolocalisationLatitude, point.coordGeolocalisationLongitude);
|
|
|
|
if (point.distanceEnMetre < 1000)
|
|
distance = '(env ' + point.distanceEnMetre + 'm)';
|
|
else
|
|
distance = '(env ' + (point.distanceEnMetre / 1000).toFixed(2) + 'Km)';
|
|
// Fill divs
|
|
point_div.children('span.libelle').html(point.nom);
|
|
point_div.children('span.so_distance').html(distance);
|
|
point_div.children('span.address1').html(point.adresse1);
|
|
point_div.children('span.code_postal').html(point.codePostal);
|
|
point_div.children('span.commune').html(point.localite);
|
|
point_div.children('span.point-choose').find('img').attr('class', 'choosethePR PR' + p).click(function () {
|
|
selectPoint(point.identifiant);
|
|
showDeliverySumUpRelay(point.identifiant);
|
|
});
|
|
if (point.accesPersonneMobiliteReduite)
|
|
point_div.find('img.handicap').attr('src', soflex_image_url + 'picto-handicap.png');
|
|
var so_info = '<div class="so-info-libelle">' + point.nom + '</div>' + '<div class="so-info-adresse">' + point.adresse1 + '</div>';
|
|
if (fermetures[p] === 'disabled')
|
|
so_info += '<div class="so-info-cpt">' + point.codePostal + ' ' + point.localite + '<br><span class="enConges">En Congés</span></div>';
|
|
else
|
|
so_info += '<div class="so-info-cpt">' + point.codePostal + ' ' + point.localite + '</div>';
|
|
point_div.find('div.prez').html(so_info);
|
|
point_div.find('div.horairesPR').html(horaires[p]);
|
|
if (fermetures[p] === 'disabled') {
|
|
point_div.children('span.picto').html('<img src="' + soflex_image_url + 'picto_grey.png">');
|
|
point_div.css('opacity', '0.5').css('background', 'gainsboro').find('div.fermeturesPR').html(fermetures[p]);
|
|
point_div.find('.point-choose').hide();
|
|
}
|
|
else {
|
|
point_div.children('span.picto').html('<img src="' + soflex_image_url + 'picto.png">');
|
|
point_div.find('div.fermeturesPR').html(fermetures[p]);
|
|
}
|
|
$('#PR' + p).children('input.pr-lat').attr('value', point.coordGeolocalisationLatitude);
|
|
$('#PR' + p).children('input.pr-lng').attr('value', point.coordGeolocalisationLongitude);
|
|
$('#PR' + p).children('input.pr-id').attr('value', point.identifiant);
|
|
$('#PR' + p).children('input.pr-indice').attr('value', point.indiceDeLocalisation);
|
|
|
|
point_div.hide();
|
|
|
|
// Markers
|
|
sf_markers[p] = new google.maps.Marker({
|
|
map: sf_map,
|
|
position: position,
|
|
icon: sf_icon_relay
|
|
});
|
|
|
|
sf_bounds.extend(sf_markers[p].position);
|
|
google.maps.event.addListener(sf_markers[p], 'click', function () {
|
|
closeSFInfoWindows();
|
|
sf_info_windows[p].open(sf_map, sf_markers[p]);
|
|
if ($('#information-pr').is(':visible')) {
|
|
$('.infoButton').click();
|
|
sf_directions_display.setMap(null);
|
|
}
|
|
});
|
|
|
|
// Info windows
|
|
kind = $('div[id^="PR' + p + '"]').attr('class');
|
|
item = 'wc-' + kind + '-' + p;
|
|
var content_string = '<div class="so-infoWindow" rel="' + p + '">' + $('div[id="PR' + p + '"]').find('div.prez').html() + '</div>';
|
|
if ($('div[id="PR' + p + '"]').find('.fermeturesPR').text() !== 'disabled')
|
|
content_string += ($('#soflexibilite_only_map').val() !== '0' ?
|
|
$('div[id="PR' + p + '"]').find('div.horairesPR').html().replace('<div class="hoClean"></div>', '') + '<strong>Fermeture :</strong> ' + $('div[id="PR' + p + '"]').find('div.fermeturesPR').text() + '<br>'
|
|
:
|
|
'<input type="button" class="exclusive infoButton" style="top: 0px; float: left;" value=" Information ">') + '<input type="button" class="exclusive ' + item + ' sf_select" style="top: 0px; float: right;" value=" Choisir " >';
|
|
sf_info_windows[p] = new google.maps.InfoWindow({
|
|
content: content_string,
|
|
maxWidth: 430
|
|
});
|
|
|
|
// Close when clic on map
|
|
google.maps.event.addListener(sf_map, 'click', function () {
|
|
sf_info_windows[p].close();
|
|
});
|
|
|
|
// Clic on the list then point on map
|
|
$('div[id^="PR' + p + '"]').click(function () {
|
|
closeSFInfoWindows();
|
|
sf_info_windows[p].open(sf_map, sf_markers[p]);
|
|
|
|
// If clic on PR and screen mobile
|
|
if (window.innerWidth <= 700) {
|
|
selectPoint(point.identifiant);
|
|
showDeliverySumUpRelay(point.identifiant);
|
|
}
|
|
});
|
|
});
|
|
|
|
if (type_de_point == 'choixPoste')
|
|
$('div[id^="PR"].BPR, div[id^="PR"].CDI, div[id^="PR"].ACP, div[id^="PR"].BDP').show();
|
|
else
|
|
$('div[id^="PR"].A2P, div[id^="PR"].CMT, div[id^="PR"].PCS').show();
|
|
|
|
if ($('#points div[id^="PR"]').length === 0)
|
|
$('#so-no-points').show();
|
|
else
|
|
$('#so-no-points').hide();
|
|
}
|
|
|
|
function closeSFInfoWindows() {
|
|
for (var x in sf_info_windows)
|
|
if (typeof (sf_info_windows[x]) === 'object')
|
|
sf_info_windows[x].close();
|
|
}
|
|
|
|
function deleteMarkers() {
|
|
for (var x in sf_markers)
|
|
if (typeof (sf_markers[x]) === 'object')
|
|
sf_markers[x].setMap(null);
|
|
sf_markers = [];
|
|
}
|
|
|
|
function selectPoint(id) {
|
|
/*if (window.console)
|
|
console.log('selectPoint : ' + id);*/
|
|
|
|
var idPoint = $('.pr-id[value="' + id + '"]').parent().attr('id');
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: $('#saveDelivery_url').val(),
|
|
dataType: 'json',
|
|
data: {
|
|
id: id,
|
|
phone: $('#custPhone').val(),
|
|
type: $('#' + idPoint).attr('class'),
|
|
libelle: $('#' + idPoint).find('.libelle').text(),
|
|
indice: $('#' + idPoint).find('.pr-indice').text(),
|
|
adresse1: $('#' + idPoint).find('.address1').text(),
|
|
code_postal: $('#' + idPoint).find('.code_postal').text(),
|
|
commune: $('#' + idPoint).find('.commune').text(),
|
|
id_cart: $('#soflexibilite_cart_id').val()
|
|
},
|
|
success: function (data) {
|
|
/* if (window.console) {
|
|
console.log(data, 'SelectPoint Succeed');
|
|
}*/
|
|
if (data.status)
|
|
$('#soflexibilite_carrier_hors_dom_chose').val('1');
|
|
else
|
|
alert('Une erreur est survenue lors de l\'enregistrement du point de retrait, contactez le webmaster de la boutique.');
|
|
},
|
|
error: function (er) {
|
|
alert('Une erreur est survenue lors de l\'enregistrement du point de retrait, contacter le webmaster de la boutique.');
|
|
/*if (window.console) {
|
|
console.log('une erreur sur selectpoint ! ' + er.debug, er);
|
|
}*/
|
|
}
|
|
});
|
|
}
|
|
|
|
function showDeliverySumUpRelay(id_point) {
|
|
/*if (window.console)
|
|
console.log('ShowDetails()');*/
|
|
|
|
sf_delivery_mode_is_selected = true;
|
|
|
|
$('#soflexibilite_description_address').remove();
|
|
SoFlexibilite.hideAllForOverlay();
|
|
|
|
var fullid = '#' + $('.pr-id[value="' + id_point + '"]').parent().attr('id');
|
|
|
|
$('#soflexibilite_overlay').fadeOut('slow').hide();
|
|
$('#so_box_hors').fadeOut('slow');
|
|
$('#adresseFinal').html(SoFlexibilite.buildFinalAddress({
|
|
company: $('#sl-0-company').val(),
|
|
libelle: $(fullid).find('.libelle').html(),
|
|
firstname: $('#sl-0-firstname').val(),
|
|
lastname: $('#sl-0-lastname').val(),
|
|
address1: $(fullid).find('.address1').html(),
|
|
address2: $(fullid).find('.pr-indice').val(),
|
|
postcode: $(fullid).find('.code_postal').html(),
|
|
city: $(fullid).find('.commune').html(),
|
|
country: $(fullid).is('.BPR, .A2P, .CIT, .CDI') ? 'France' : 'Belgique'
|
|
}));
|
|
$('#custMail').val(sf_customer_mail);
|
|
$('#custPhone').val(sf_customer_phone);
|
|
|
|
SoFlexibilite.selectRightCarrier($(fullid).attr('class'));
|
|
|
|
var insert_after = parseInt($.fn.jquery.split('.').join('')) < 172 ? '#extra_carrier' : '.hook_extracarrier';
|
|
var saved_sumup = $('#soflexibilite_carrierList_template').clone().insertAfter($(insert_after)).attr('id', 'soflexibilite_description_address').show();
|
|
$(saved_sumup).find('#custPhone').attr('id', 'sf_phone');
|
|
$('#soflexibilite_speech').show();
|
|
$('#so-h3-recap-horsdom').show();
|
|
$('#so-h3-recap-dom').hide();
|
|
|
|
$('html, body').animate({
|
|
scrollTop: $('#so-h3-recap-horsdom').offset().top - 200
|
|
});
|
|
|
|
if ($('#order-opc').length) {
|
|
target_action_div.ajaxComplete(function () {
|
|
$('#soflexibilite_description_address').remove();
|
|
$(saved_sumup).insertAfter($(insert_after));
|
|
});
|
|
target_action_div.ajaxStop(function () {
|
|
target_action_div.unbind('ajaxStop');
|
|
target_action_div.unbind('ajaxComplete');
|
|
});
|
|
}
|
|
|
|
resetOverlay();
|
|
}
|
|
|
|
function showDeliverySumUpHome() {
|
|
sf_delivery_mode_is_selected = true;
|
|
$('#soflexibilite_description_address').remove();
|
|
|
|
$('#adresseFinal').html(SoFlexibilite.buildFinalAddress({
|
|
company: $('#sl-0-company').val(),
|
|
libelle: null,
|
|
firstname: $('#sl-0-firstname').val(),
|
|
lastname: $('#sl-0-lastname').val(),
|
|
address1: $('#sl-0-address1').val(),
|
|
address2: $('#sl-0-address2').val(),
|
|
postcode: $('#sl-0-postcode').val(),
|
|
city: $('#sl-0-city').val(),
|
|
country: $('#sl-0-country').val()
|
|
}));
|
|
$('#custMail').val(sf_customer_mail);
|
|
$('#custPhone').val(sf_customer_phone);
|
|
|
|
var insert_after = parseInt($.fn.jquery.split('.').join('')) < 172 ? '#extra_carrier' : '.hook_extracarrier';
|
|
var saved_sumup = $('#soflexibilite_carrierList_template').clone().insertAfter($(insert_after)).attr('id', 'soflexibilite_description_address').show();
|
|
$(saved_sumup).find('#custPhone').attr('id', 'sf_phone');
|
|
$('#soflexibilite_speech').show();
|
|
$('#so-h3-recap-horsdom').hide();
|
|
$('#so-h3-recap-dom').show();
|
|
|
|
$('html, body').animate({
|
|
scrollTop: $('#so-h3-recap-dom').offset().top - 200
|
|
});
|
|
|
|
if ($('#order-opc').length) {
|
|
target_action_div.ajaxComplete(function () {
|
|
$('#soflexibilite_description_address').remove();
|
|
$(saved_sumup).insertAfter($(insert_after));
|
|
});
|
|
target_action_div.ajaxStop(function () {
|
|
target_action_div.unbind('ajaxStop');
|
|
target_action_div.unbind('ajaxComplete');
|
|
});
|
|
}
|
|
}
|
|
|
|
function resetOverlay() {
|
|
var pos = $('#PR0').position();
|
|
|
|
if (typeof (pos) !== 'undefined' && typeof (pos) !== null && typeof (pos.top) !== 'undefined' && pos.top !== null)
|
|
$('#points').animate({scrollTop: pos.top}, 0);
|
|
$('div#header').css('z-index', 10);
|
|
$('#points').show();
|
|
$('#information-pr').hide();
|
|
$('#picStreetView').hide();
|
|
$('#header').css('z-index', 10);
|
|
if (typeof (panorama) !== 'undefined' && panorama !== null)
|
|
panorama.setVisible(null);
|
|
first_visible_relay = '';
|
|
|
|
if (typeof (infoWindow) !== 'undefined' && infoWindow !== null)
|
|
for (var x in infoWindow)
|
|
if (typeof (infoWindow[x]) === 'object')
|
|
infoWindow[x].close();
|
|
}
|
|
|
|
function codeLatLng(lat, lng) {
|
|
var latlng = new google.maps.LatLng(lat, lng);
|
|
|
|
geocoder.geocode({'latLng': latlng, 'region': 'fr'}, function (res, stat) {
|
|
if (stat === google.maps.GeocoderStatus.OK) {
|
|
if (res[0]) {
|
|
var elt = res[0].address_components;
|
|
var i = null;
|
|
|
|
for (i in elt) {
|
|
if (elt[i].types[0] === 'postal_code' || elt[i].types[0] === 'postal_code_prefix')
|
|
search_address_parameters['postcode'] = elt[i].long_name;
|
|
else if (elt[i].types[0] === 'locality')
|
|
search_address_parameters['city'] = elt[i].long_name;
|
|
else if (elt[i].types[0] === 'route')
|
|
search_address_parameters['address'] = elt[i].long_name;
|
|
else if (elt[i].types[0] === 'country')
|
|
search_address_parameters['country'] = elt[i].short_name;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
/*window.console && console.log(res, stat);*/
|
|
alert("Erreur de geolocalisation: " + stat);
|
|
}
|
|
});
|
|
}
|
|
|
|
function fillMRPickupPoints(pickup_points) {
|
|
var week_days = [
|
|
'Lundi',
|
|
'Mardi',
|
|
'Mercredi',
|
|
'Jeudi',
|
|
'Vendredi',
|
|
'Samedi',
|
|
'Dimanche'
|
|
];
|
|
|
|
$('div.sf_pickup').remove();
|
|
|
|
$.each(pickup_points, function (id_p, point) {
|
|
var model_div = $('.sf_pickup_model').clone().appendTo('#sf_delivery_point').attr('class', 'sf_pickup').attr('rel', point.Num).show();
|
|
|
|
model_div.find('.lgadr1').text(point.LgAdr1);
|
|
model_div.find('.distance').text(point.Distance >= 1000 ? (point.Distance / 1000) + 'Km' : point.Distance + 'm');
|
|
model_div.find('.lgadr3').text(point.LgAdr3);
|
|
model_div.find('.lgadr4').text(point.LgAdr4);
|
|
model_div.find('.CP').text(point.CP);
|
|
model_div.find('.ville').text(point.Ville);
|
|
model_div.find('.pays').text(point.Pays);
|
|
model_div.find('.latitude').val(point.Latitude);
|
|
model_div.find('.longitude').val(point.Longitude);
|
|
// hours
|
|
$.each(week_days, function (id_d, day) {
|
|
model_div.find('table tbody').html(
|
|
model_div.find('table tbody').html() +
|
|
'<tr>' +
|
|
'<td>' + day + '</td>' +
|
|
'<td>' + (point.Horaires[day][0] || '') + '</td>' +
|
|
'<td>' + (point.Horaires[day][1] || '') + '</td>' +
|
|
'</tr>'
|
|
);
|
|
});
|
|
|
|
sf_bounds.extend(new google.maps.LatLng(point.Latitude.split(',').join('.'), point.Longitude.split(',').join('.')));
|
|
});
|
|
}
|
|
|
|
function setLocationGeoCode(lat, lng) {
|
|
google.maps.event.trigger(sf_map, 'resize');
|
|
sf_map.fitBounds(sf_bounds);
|
|
}
|
|
|
|
function setConstraint() {
|
|
var selected_mode = $('#super-selector option:selected').val();
|
|
|
|
if ($('#so_constraint').is(':checked')) {
|
|
for (var x in sf_markers)
|
|
if (typeof (sf_markers[x]) === 'object')
|
|
sf_markers[x].setMap(sf_map);
|
|
|
|
if (selected_mode == 'choixPoste') {
|
|
for (var x in sf_markers)
|
|
if (typeof (sf_markers[x]) === 'object' && $('[id="PR' + x + '"]').is('.A2P, .CMT, .PCS'))
|
|
sf_markers[x].setMap(null);
|
|
}
|
|
else {
|
|
for (var x in sf_markers)
|
|
if (typeof (sf_markers[x]) === 'object' && $('[id="PR' + x + '"]').is('.BPR, .BDP, .ACP, .CDI'))
|
|
sf_markers[x].setMap(null);
|
|
}
|
|
}
|
|
else {
|
|
for (var x in sf_markers)
|
|
if (typeof (sf_markers[x]) === 'object')
|
|
sf_markers[x].setMap(sf_map);
|
|
}
|
|
|
|
closeSFInfoWindows();
|
|
}
|
|
|
|
$('#so_constraint').change(function () {
|
|
setConstraint();
|
|
});
|
|
|
|
/* Check everything is well done before submitting everything. */
|
|
$(target_action_div).delegate('#opc_payment_methods, [name="processCarrier"]', 'mousedown click submit', function (ev) {
|
|
var pass = false;
|
|
|
|
if (!$(carrier_selector + ':checked').length && !$('.delivery_option span.checked').length) {
|
|
ev.preventDefault();
|
|
alert($('.carrier_title:first').text().trim() + ' !');
|
|
return (false);
|
|
}
|
|
|
|
// On verifie quel transporteur est selectionne
|
|
var result = $('input[id^="delivery_option_"]:checked, input[id^="id_carrier"]:checked').val().match('^([0-9]*)')[1];
|
|
|
|
// Ce n'est pas So Colissimo qui est selectionne on intervient pas
|
|
if (!in_array(result, sf_carriers_id))
|
|
return (true);
|
|
|
|
// So Colissimo est selectionne, on verifie si un point de retrait ou domicile/rdv est selectionne
|
|
if (!sf_delivery_mode_is_selected) {
|
|
ev.preventDefault();
|
|
alert($('#must-select').val());
|
|
return (false);
|
|
}
|
|
|
|
// Check contact infos
|
|
var phone_mobile = /^((\+|00)33\s?|0)[67](\s?\d{2}){4}$/i;
|
|
var phone_mobile_es = /^((\+|00)34\s?|0)[67](\s?\d{2}){4}$/i;
|
|
var phone_mobile_without_zero = /^[6](\s?\d{2}){4}$/i;
|
|
var phone_mobile_be = /^((\+|00)32\s?|0)4(60|[789]\d)(\s?\d{2}){3}$/i;
|
|
var email = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/i;
|
|
|
|
if (!email.test($('#custMail').val())) {
|
|
ev.preventDefault();
|
|
alert('Renseignez votre email !');
|
|
return (false);
|
|
}
|
|
|
|
if (!$('#custPhone').val().length) {
|
|
ev.preventDefault();
|
|
alert($('#error-mobile-mandatory').val() + '\n\nFormat : 0661010203');
|
|
return (false);
|
|
}
|
|
|
|
if (!(phone_mobile.test($('#custPhone').val())
|
|
|| phone_mobile_be.test($('#custPhone').val())
|
|
|| phone_mobile_es.test($('#custPhone').val())
|
|
|| phone_mobile_without_zero.test($('#custPhone').val())
|
|
)
|
|
) {
|
|
ev.preventDefault();
|
|
alert($('#error-mobile-invalid').val() + '\n\nFormat : 0661010203');
|
|
return (false);
|
|
}
|
|
|
|
return (true);
|
|
});
|
|
|
|
$('#soflex-search').click(function () {
|
|
$('#search-btn, #search-btn-pending, #soflex-search img').toggle();
|
|
|
|
var adresse_de_recherche = $('input.lookup').val().toUpperCase();
|
|
adresse_de_recherche = adresse_de_recherche.split('FRANCE').length > 1 ?
|
|
adresse_de_recherche.split('FRANCE')[0] + 'FRANCE' : adresse_de_recherche;
|
|
|
|
//window.console && window.console.log('Adresse de recherche : ' + adresse_de_recherche);
|
|
|
|
geocoder.geocode({'address': adresse_de_recherche, 'region': 'fr'}, function (results, status) {
|
|
if (status === google.maps.GeocoderStatus.OK) {
|
|
sf_customer_lat = parseFloat(results[0].geometry.location.lat());
|
|
sf_customer_lng = parseFloat(results[0].geometry.location.lng());
|
|
|
|
codeLatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
|
|
|
|
setTimeout(function () {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: $('#soflexibilite_point_list_url').val(),
|
|
dataType: 'json',
|
|
data: {
|
|
adresseRecherche: adresse_de_recherche,
|
|
address: search_address_parameters['address'],
|
|
postcode: search_address_parameters['postcode'],
|
|
city: search_address_parameters['city'],
|
|
country: search_address_parameters['country']
|
|
},
|
|
success: function (data) {
|
|
//window.console && console.log(data);
|
|
|
|
if (typeof (data) === 'undefined' || data === null || typeof (data.points) === 'undefined' || data.points === null || data.points.length === 0)
|
|
$('#gmap').text('Une erreur est survenue.');
|
|
|
|
$('#search-btn, #search-btn-pending, #soflex-search img').toggle();
|
|
$('#points').scrollTop(0);
|
|
$('#picStreetView').hide();
|
|
$('#information-pr').hide();
|
|
$('#points').show();
|
|
|
|
$('#gmap *').length <= 5 && (sf_map = new google.maps.Map(document.getElementById('gmap'), sf_map_options));
|
|
|
|
if (data.status === true) {
|
|
sf_bounds = new google.maps.LatLngBounds();
|
|
sf_bounds.extend(new google.maps.LatLng(sf_customer_lat, sf_customer_lng));
|
|
sf_customer_house && sf_customer_house.setMap(null);
|
|
sf_customer_house = new google.maps.Marker({
|
|
map: sf_map,
|
|
position: new google.maps.LatLng(sf_customer_lat, sf_customer_lng),
|
|
icon: sf_icon_home
|
|
});
|
|
fillPR(data.points, data.horaires, data.fermetures);
|
|
setLocationGeoCode(sf_customer_lat, sf_customer_lng);
|
|
setConstraint();
|
|
}
|
|
},
|
|
error: function (e) {
|
|
//window.console && console.log('error recherche adresse', e);
|
|
$('#search-btn, #search-btn-pending, #soflex-search img').toggle();
|
|
}
|
|
});
|
|
}, 800);
|
|
}
|
|
else {
|
|
$('#search-btn, #search-btn-pending, #soflex-search img').toggle();
|
|
$('#gmap').html('<p style="width: 210px;height: 20px;margin: 200px auto;">L\'adresse recherchée est incorrecte.</p>');
|
|
|
|
//window.console && console.log('google.maps.GeocoderStatus != OK', results, status);
|
|
}
|
|
});
|
|
});
|
|
|
|
target_action_div.delegate('#sf_phone, #custMail, #infoCommande', 'change', function () {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: $('#saveInfoCommande_url').val(),
|
|
dataType: 'json',
|
|
data: {
|
|
email: $('#custMail').val(),
|
|
phone: $('#sf_phone').val(),
|
|
infoDelivery: $('#infoCommande').val(),
|
|
cart: $('#soflexibilite_cart_id').val()
|
|
},
|
|
success: function (data) {
|
|
if (data.status === true) {
|
|
//window.console && console.log('Informations saved !');
|
|
sf_customer_mail = $('#custMail').val();
|
|
sf_customer_phone = $('#sf_phone').val();
|
|
$('#custPhone').val($('#sf_phone').val());
|
|
}
|
|
/*else
|
|
window.console && console.log('Error', data);*/
|
|
},
|
|
error: function (er) {
|
|
/*window.console && console.log('Une erreur sur save information !', er);*/
|
|
}
|
|
});
|
|
});
|
|
|
|
$('#otherPR, #so-info-close').click(function () {
|
|
$('#picStreetView').hide();
|
|
$('#points').show();
|
|
$('#information-pr').hide();
|
|
$('#driving').attr('checked', true);
|
|
sf_directions_display.setMap(null);
|
|
if (sf_panorama)
|
|
sf_panorama.setVisible(false);
|
|
});
|
|
|
|
$('#infoChoosePR').click(function () {
|
|
var id_point = $('#information-pr').attr('rel');
|
|
id_point = $('[id="PR' + id_point + '"] .pr-id').val();
|
|
|
|
selectPoint(id_point);
|
|
showDeliverySumUpRelay(id_point);
|
|
});
|
|
|
|
$('#picDriving').click(function () {
|
|
var id_point = $('#information-pr').attr('rel');
|
|
var request = {
|
|
origin: sf_customer_house.position,
|
|
destination: new google.maps.LatLng(
|
|
$('#PR' + id_point + ' .pr-lat').val(),
|
|
$('#PR' + id_point + ' .pr-lng').val()
|
|
),
|
|
travelMode: google.maps.TravelMode.DRIVING
|
|
};
|
|
|
|
closeSFInfoWindows();
|
|
|
|
sf_directions_display.setMap(null);
|
|
sf_direction_service.route(request, function (res, stat) {
|
|
if (stat === google.maps.DirectionsStatus.OK)
|
|
sf_directions_display.setDirections(res);
|
|
});
|
|
sf_directions_display.setMap(sf_map);
|
|
});
|
|
|
|
$('#picWalking').click(function () {
|
|
var id_point = $('#information-pr').attr('rel');
|
|
var request = {
|
|
origin: sf_customer_house.position,
|
|
destination: new google.maps.LatLng(
|
|
$('#PR' + id_point + ' .pr-lat').val(),
|
|
$('#PR' + id_point + ' .pr-lng').val()
|
|
),
|
|
travelMode: google.maps.TravelMode.WALKING
|
|
};
|
|
|
|
closeSFInfoWindows();
|
|
|
|
sf_directions_display.setMap(null);
|
|
sf_direction_service.route(request, function (res, stat) {
|
|
if (stat === google.maps.DirectionsStatus.OK)
|
|
sf_directions_display.setDirections(res);
|
|
});
|
|
sf_directions_display.setMap(sf_map);
|
|
});
|
|
|
|
$('#picStreetView').click(function () {
|
|
var id_point = $('#information-pr').attr('rel');
|
|
|
|
sf_panorama = sf_map.getStreetView();
|
|
sf_panorama.setPosition(new google.maps.LatLng(
|
|
$('#PR' + id_point + ' .pr-lat').val(),
|
|
$('#PR' + id_point + ' .pr-lng').val()
|
|
));
|
|
sf_panorama.setVisible(true);
|
|
});
|
|
|
|
// New address search
|
|
$('#sf_search_button').click(function () {
|
|
var address = $('#sf_search_input').val();
|
|
$('#sf_search_button > span').toggle();
|
|
|
|
geocoder.geocode({'address': address, 'region': 'fr'}, function (results, status) {
|
|
if (status === google.maps.GeocoderStatus.OK) {
|
|
var address_lat = parseFloat(results[0].geometry.location.lat());
|
|
var address_lng = parseFloat(results[0].geometry.location.lng());
|
|
|
|
codeLatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng());
|
|
|
|
setTimeout(function () {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: $('#sf_get_delivery_point_url').val(),
|
|
dataType: 'jsonp',
|
|
data: {
|
|
postcode: search_address_parameters['postcode'],
|
|
city: search_address_parameters['city'],
|
|
country: search_address_parameters['country']
|
|
},
|
|
success: function (data) {
|
|
$('#sf_search_button > span').toggle();
|
|
$('#sf_delivery_point_info').hide();
|
|
$('#sf_delivery_point').scrollTop(0).show();
|
|
|
|
/*if (window.console)
|
|
console.log(data);*/
|
|
|
|
if (typeof(data.pickup_points) !== 'undefined' && data.pickup_points) {
|
|
sf_bounds = new google.maps.LatLngBounds();
|
|
sf_bounds.extend(new google.maps.LatLng(address_lat, address_lng));
|
|
sf_customer_house.setMap(null);
|
|
sf_customer_house = new google.maps.Marker({
|
|
map: sf_map,
|
|
position: new google.maps.LatLng(address_lat, address_lng),
|
|
icon: sf_icon_home
|
|
});
|
|
fillMRPickupPoints(data.pickup_points);
|
|
setupSFPointList();
|
|
setLocationGeoCode(address_lat, address_lng);
|
|
}
|
|
else {
|
|
var error_message = 'Aucun point de retrait n\'a été retourné.';
|
|
|
|
if (data.output) {
|
|
error_message += '\n' + data.output;
|
|
}
|
|
|
|
alert(error_message);
|
|
}
|
|
|
|
},
|
|
error: function (e) {
|
|
$('#sf_search_button > span').toggle();
|
|
alert('erreur recherche adresse');
|
|
/*if (window.console)
|
|
console.log(e);*/
|
|
}
|
|
});
|
|
}, 800);
|
|
}
|
|
else {
|
|
$('#search-btn, #search-btn-pending, #soflex-search img').toggle();
|
|
$('#gmap').html('<p style="width: 210px;height: 20px;margin: 200px auto;">L\'adresse de recherche est incorrecte.</p>');
|
|
|
|
/*if (window.console)
|
|
console.log('google.maps.GeocoderStatus != OK');*/
|
|
}
|
|
});
|
|
});
|
|
|
|
function checkStreetViewAvailability(lat, lng) {
|
|
$('#picStreetView').hide();
|
|
var streetViewLatLng = new google.maps.LatLng(lat, lng);
|
|
|
|
geocoder.geocode({'latLng': streetViewLatLng, 'region': 'fr'}, function (results, status) {
|
|
if (status === google.maps.GeocoderStatus.OK) {
|
|
if (results[0].geometry.location_type === 'ROOFTOP')
|
|
$('#picStreetView').show();
|
|
else
|
|
$('#picStreetView').hide();
|
|
}
|
|
else
|
|
$('#picStreetView').hide();
|
|
});
|
|
}
|
|
|
|
/* Set tooltips */
|
|
setTooltips();
|
|
|
|
/* PrestaShop functions compatibility */
|
|
if (typeof('in_array') === 'undefined')
|
|
in_array = function (b, a) {
|
|
for (var c in a)
|
|
if (a[c] + "" === b + "")
|
|
return !0;
|
|
return !1;
|
|
};
|
|
|
|
if (in_array($(carrier_selector).val().split(',')[0], sf_carriers_id))
|
|
$(carrier_selector).attr('checked', false).parent().removeClass('checked');
|
|
|
|
// Theme setting
|
|
if ($('#soflexibilite_only_map').val() !== '0') {
|
|
$('#so_box_hors > p, #super-selector, #so_box_hors > div.float-left.keep-left, .infoButton').hide();
|
|
$('#gmap').css('width', '100%').css('height', '86%');
|
|
}
|
|
}
|
|
|
|
}); |