534 lines
23 KiB
JavaScript
534 lines
23 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 () {
|
|
|
|
/*
|
|
* CHANGE PHONE
|
|
*/
|
|
$('#sf_modify_phone').click(function () {
|
|
var change_phone = prompt('Nouveau numéro de téléphone :');
|
|
change_phone = change_phone.split(' ').join('').replace(/\D/g, '');
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: $('#soflexibilite_save_info_commande_url').val(),
|
|
dataType: 'json',
|
|
data: {
|
|
email: null,
|
|
phone: change_phone,
|
|
infoDelivery: null,
|
|
cart: $('#soflexibilite_id_cart').val()
|
|
},
|
|
success: function (data) {
|
|
//window.console && console.log(data);
|
|
if (data.status === true) {
|
|
$('#sf_phone').text(betterPhoneNumber(change_phone));
|
|
typeof showSuccessMessage === 'function' && showSuccessMessage('Le numéro de téléphone a été changé avec succès !')
|
|
} else {
|
|
//window.console && console.log('Error', data);
|
|
}
|
|
},
|
|
error: function (er) {
|
|
//window.console && console.log(er);
|
|
|
|
var error_msg = 'Une erreur est survenue lors du changement de téléphone...';
|
|
typeof showErrorMessage === 'function' ?
|
|
showErrorMessage(error_msg) :
|
|
alert(error_msg);
|
|
}
|
|
});
|
|
});
|
|
|
|
function betterPhoneNumber(nb) {
|
|
var prefix = '';
|
|
var prefix_length = 0;
|
|
var ret_nb = '';
|
|
|
|
if (nb.match(/^((\+)33)/i)) {
|
|
prefix = '+33 (0)';
|
|
prefix_length = 3;
|
|
} else if (nb.match(/^((00)33)/i)) {
|
|
prefix = '0033 (0)';
|
|
prefix_length = 4;
|
|
} else if (nb.match(/^((\+)32)/i)) {
|
|
prefix = '+32 (0)';
|
|
prefix_length = 3;
|
|
} else if (nb.match(/^((00)32)/i)) {
|
|
prefix = '0032 (0)';
|
|
prefix_length = 4;
|
|
}
|
|
|
|
if (prefix.length) {
|
|
nb = nb.substr(prefix_length);
|
|
}
|
|
|
|
nb = nb.split('').reverse().join('');
|
|
var length = nb.length;
|
|
|
|
for (i = 0; i < length; i += 1) {
|
|
if (i % 2 === 0) {
|
|
ret_nb += ' ';
|
|
}
|
|
ret_nb += nb[i];
|
|
}
|
|
|
|
ret_nb = ret_nb.split('').reverse().join('');
|
|
|
|
return (prefix + ret_nb);
|
|
}
|
|
|
|
|
|
/*
|
|
* CHANGE DELIVERY POINT
|
|
*/
|
|
|
|
$('.soflexibilite_overlay').click(function () {
|
|
$('.soflexibilite_overlay').fadeOut('fast', function () {
|
|
$('#so_box').fadeOut('slow');
|
|
setTimeout(resetOverlay, 300);
|
|
});
|
|
});
|
|
|
|
$('#sf_address').keypress(function (e) {
|
|
if (e.keyCode === 13) {
|
|
e.preventDefault();
|
|
$('#sf_lookup_address').click();
|
|
}
|
|
});
|
|
|
|
$('#sf_modify_relay').click(function () {
|
|
$('.soflexibilite_overlay').fadeIn('fast', function () {
|
|
$('#so_box').fadeIn(1000);
|
|
if (typeof (sf_map) !== 'undefined' && sf_map !== null) {
|
|
google.maps.event.trigger(sf_map, 'resize');
|
|
sf_map.fitBounds(sf_bounds);
|
|
}
|
|
});
|
|
});
|
|
|
|
var sf_customer_address = $('#sf_address').val();
|
|
var soflex_image_url = $('#sf_panel').find('img[alt="Colissimo"]').attr('src').split('img/')[0] + 'img/';
|
|
var sf_customer_lat = null;
|
|
var sf_customer_lng = null;
|
|
var sf_map = null;
|
|
var sf_map_zoom = 14;
|
|
var sf_map_options = null;
|
|
var sf_customer_house = null;
|
|
var sf_markers = [];
|
|
var sf_info_windows = [];
|
|
var sf_bounds = null;
|
|
var search_address_parameters = [];
|
|
var sf_mapping_relay_marker = [];
|
|
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)
|
|
);
|
|
|
|
if (typeof google.maps === 'object') {
|
|
try {
|
|
var geocoder = new google.maps.Geocoder();
|
|
}
|
|
catch (e) {
|
|
window.console && console.log('Erreur GeoCODER', e);
|
|
alert($('#geocoder_failed').val());
|
|
}
|
|
|
|
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);*/
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: $('#soflexibilite_point_list_url').val(),
|
|
dataType: 'json',
|
|
data: {
|
|
adresseRecherche: $('#sf_address1').text(),
|
|
address: $('#sf_address1').text(),
|
|
postcode: $('#sf_postcode').text(),
|
|
city: $('#sf_city').text(),
|
|
country: $('#sf_iso_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('sf_map'), sf_map_options);
|
|
|
|
sf_relay_control_div = document.createElement('div');
|
|
setControlRelay(sf_relay_control_div);
|
|
sf_relay_control_div.index = 1;
|
|
sf_map.controls[google.maps.ControlPosition.LEFT_TOP].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);*/
|
|
}
|
|
});
|
|
});
|
|
|
|
function setControlRelay(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 = 'left';
|
|
//controlCenterMap.title = 'Recentrer la carte et les points de retrait';
|
|
controlDiv.appendChild(controlCenterMap);
|
|
|
|
// Set CSS for the control BPR interior.
|
|
var controlBPRText = document.createElement('div');
|
|
controlBPRText.style.color = 'rgb(0, 0, 0)';
|
|
controlBPRText.style.fontFamily = 'Roboto, Arial, sans-serif';
|
|
controlBPRText.style.fontSize = '11px';
|
|
controlBPRText.style.padding = '8px';
|
|
controlBPRText.innerHTML = 'Bureau de poste';
|
|
controlBPRText.id = 'sf_filter_bpr';
|
|
controlCenterMap.appendChild(controlBPRText);
|
|
|
|
// Set CSS for the control A2P interior.
|
|
var controlA2PText = document.createElement('div');
|
|
controlA2PText.style.color = 'rgb(0, 0, 0)';
|
|
controlA2PText.style.fontFamily = 'Roboto, Arial, sans-serif';
|
|
controlA2PText.style.fontSize = '11px';
|
|
controlA2PText.style.padding = '8px';
|
|
controlA2PText.innerHTML = 'PickUp Station';
|
|
controlA2PText.id = 'sf_filter_a2p';
|
|
controlCenterMap.appendChild(controlA2PText);
|
|
|
|
// Setup the click event listeners
|
|
$('#so_box').delegate('#sf_filter_bpr, #sf_filter_a2p', 'click', function () {
|
|
var mode = $(this).attr('id').split('_')[2].toUpperCase();
|
|
|
|
if ($(this).hasClass('sf_active')) {
|
|
$('#sf_filter_bpr, #sf_filter_a2p').removeClass('sf_active');
|
|
for (var x in sf_markers) {
|
|
sf_markers[x].setMap(sf_map);
|
|
}
|
|
} else {
|
|
$('#sf_filter_bpr, #sf_filter_a2p').removeClass('sf_active');
|
|
$(this).addClass('sf_active');
|
|
for (var x in sf_markers) {
|
|
if (sf_mapping_relay_marker[x] == mode) {
|
|
sf_markers[x].setMap(sf_map);
|
|
} else {
|
|
sf_markers[x].setMap(null);
|
|
}
|
|
}
|
|
}
|
|
|
|
closeSFInfoWindows();
|
|
});
|
|
}
|
|
|
|
function fillPR(points, horaires, fermetures) {
|
|
deleteMarkers();
|
|
|
|
$.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);
|
|
|
|
sf_mapping_relay_marker[p] = in_array(point.typeDePoint, ['BPR', 'BDP', 'CDI']) ? 'BPR' : 'A2P';
|
|
|
|
if (point.distanceEnMetre < 1000)
|
|
distance = '(env ' + point.distanceEnMetre + 'm)';
|
|
else
|
|
distance = '(env ' + (point.distanceEnMetre / 1000).toFixed(2) + 'Km)';
|
|
|
|
// 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();
|
|
}
|
|
});
|
|
|
|
// Info windows
|
|
var content_string = '<div class="so-infoWindow" rel="' + point.identifiant + '" style="min-width: 300px;">' +
|
|
'<strong>' + point.nom + '</strong><span class="float-right">' + distance + '</span><br><br>' +
|
|
point.adresse1 + '<br>' +
|
|
point.codePostal + ', ' + point.localite + '<br>' +
|
|
point.libellePays +
|
|
'</div><br>' +
|
|
'<u>Horaires :</u><br><br>';
|
|
|
|
content_string += '<table>';
|
|
var horaires_ws = {
|
|
lundi: point.horairesOuvertureLundi,
|
|
mardi: point.horairesOuvertureMardi,
|
|
mercredi: point.horairesOuvertureMercredi,
|
|
jeudi: point.horairesOuvertureJeudi,
|
|
vendredi: point.horairesOuvertureVendredi,
|
|
samedi: point.horairesOuvertureSamedi,
|
|
dimance: point.horairesOuvertureDimanche
|
|
};
|
|
|
|
for (var day in horaires_ws) {
|
|
horaires_ws[day] = horaires_ws[day].split(' ');
|
|
|
|
if (horaires_ws[day][0] === '00:00-00:00' && horaires_ws[day][1] === '00:00-00:00') {
|
|
horaires_ws[day][0] = 'Fermé';
|
|
horaires_ws[day][1] = '';
|
|
} else {
|
|
if (horaires_ws[day][0] === '00:00-00:00') {
|
|
horaires_ws[day][0] = '';
|
|
}
|
|
if (horaires_ws[day][1] === '00:00-00:00') {
|
|
horaires_ws[day][1] = '';
|
|
}
|
|
}
|
|
|
|
content_string += '<tr><td><strong>' + day.charAt(0).toUpperCase() + day.slice(1) + ' :</strong> </td><td style="padding-right: 10px;">' + horaires_ws[day][0] + '</td><td>' + horaires_ws[day][1] + '</td>';
|
|
}
|
|
|
|
content_string += '</table><br><br><button type="button" class="button btn btn-default float-right">Choisir</button><img src="' + soflex_image_url + 'import-loader.gif" class="float-right" width="26" style="display: none; margin-right: 10px;">';
|
|
|
|
if (fermetures[p] === 'disabled') {
|
|
content_string += '<strong>Fermé</strong>';
|
|
} else {
|
|
content_string += '';
|
|
}
|
|
sf_info_windows[p] = new google.maps.InfoWindow({
|
|
content: content_string,
|
|
maxWidth: 500
|
|
});
|
|
|
|
// Close when clic on map
|
|
google.maps.event.addListener(sf_map, 'click', function () {
|
|
sf_info_windows[p].close();
|
|
});
|
|
});
|
|
}
|
|
|
|
$('#sf_lookup_address').click(function () {
|
|
$('#sf_address').addClass('sf_loading');
|
|
|
|
var adresse_de_recherche = $('#sf_address').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) {
|
|
$('#sf_address').removeClass('sf_loading');
|
|
//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.');
|
|
|
|
$('#sf_map *').length <= 1 && (sf_map = new google.maps.Map(document.getElementById('sf_map'), 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);
|
|
}
|
|
},
|
|
error: function (e) {
|
|
$('#sf_address').removeClass('sf_loading');
|
|
//window.console && console.log('error recherche adresse', e);
|
|
}
|
|
});
|
|
}, 800);
|
|
}
|
|
else {
|
|
$('#sf_address').removeClass('sf_loading');
|
|
$('#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);
|
|
}
|
|
});
|
|
});
|
|
|
|
function selectPoint(id) {
|
|
//window.console && console.log('selectPoint : ' + id);
|
|
$('.so-infoWindow').parent().find('img.float-right').show();
|
|
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: $('#soflexibilite_change_pickup_url').val(),
|
|
dataType: 'json',
|
|
data: {
|
|
id_pickup: id,
|
|
id_customer: id_customer,
|
|
id_order: id_order,
|
|
id_cart: $('#soflexibilite_id_cart').val()
|
|
},
|
|
success: function (data) {
|
|
$('.so-infoWindow').parent().find('img.float-right').hide();
|
|
//window.console && console.log(data, 'SelectPoint Succeed');
|
|
|
|
if (data.status) {
|
|
window.location.reload();
|
|
} else {
|
|
alert('Une erreur est survenue lors de l\'enregistrement du point de retrait, contactez le webmaster de la boutique.\n\n' + data.responseText);
|
|
}
|
|
},
|
|
error: function (er) {
|
|
$('.so-infoWindow').parent().find('img.float-right').hide();
|
|
alert('Une erreur est survenue lors de l\'enregistrement du point de retrait, contacter le webmaster de la boutique.');
|
|
//window.console && console.log('une erreur sur selectpoint ! ' + er.debug, er);
|
|
}
|
|
});
|
|
}
|
|
|
|
$('#sf_map').delegate('button.float-right', 'click', function () {
|
|
var id_point = $(this).parent().find('.so-infoWindow').attr('rel');
|
|
selectPoint(id_point);
|
|
});
|
|
|
|
function setLocationGeoCode(lat, lng) {
|
|
google.maps.event.trigger(sf_map, 'resize');
|
|
sf_map.fitBounds(sf_bounds);
|
|
}
|
|
|
|
function closeSFInfoWindows() {
|
|
for (var x in sf_info_windows)
|
|
if (typeof (sf_info_windows[x]) === 'object')
|
|
sf_info_windows[x].close();
|
|
}
|
|
|
|
function resetOverlay() {
|
|
if (typeof (infoWindow) !== 'undefined' && infoWindow !== null)
|
|
for (var x in infoWindow)
|
|
if (typeof (infoWindow[x]) === 'object')
|
|
infoWindow[x].close();
|
|
}
|
|
|
|
function deleteMarkers() {
|
|
for (var x in sf_markers)
|
|
if (typeof (sf_markers[x]) === 'object')
|
|
sf_markers[x].setMap(null);
|
|
sf_markers = [];
|
|
}
|
|
|
|
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);*/
|
|
}
|
|
});
|
|
}
|
|
} else {
|
|
$('#sf_modify_relay').hide();
|
|
}
|
|
|
|
}); |