/**
* 2007-2014 Mondial relay
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to Mondial relay so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Mondial relay to newer
* versions in the future. If you wish to customize Mondial relay for your
* needs please refer to Mondial relay for more information.
*
* @author Mondial relay
* @copyright 2007-2014 Mondial relay
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of Mondial relay
*/
var Widgets = Widgets || function () {
var private = {
ashx: 'service.ashx',
svc: 'services/parcelshop-picker.v2.0.0.svc',
w_name: 'parcelshop-picker/v2.0.0',
sw_url: '',
img_url: 'www.mondialrelay.fr',
bounds: null,
map: null,
overlays: [],
infowindows: [],
InfoWindow: null,
container: null,
callback: null,
mapLoaded: false,
containerId: null,
params: null,
protocol: '',
jsonpcall: function (fn, paramArray, callbackFn) {
// Create list of parameters in the form (http get format):
// paramName1 = paramValue1 & paramName2 = paramValue2 &
var paramList = '';
if (paramArray.length > 0) {
for (var i = 0; i < paramArray.length; i += 2) {
paramList += paramArray[i] + '=' + paramArray[i + 1] + '&';
}
}
// =======================================
// CORRECTION PROFILEO
// =======================================
$.ajax({
type: 'GET',
url: private.protocol + private.sw_url + '/' + fn + '?' + paramList + 'method=?',
dataType: 'json',
headers: {
'Accept-Language': 'fr-fr'
},
success: callbackFn
});
},
loadhtml: function (container, urlraw, callback) {
var urlselector = (urlraw).split(" ", 1);
var url = urlselector[0];
var selector = urlraw.substring(urlraw.indexOf(' ') + 1, urlraw.length);
private.container = container;
private.callback = callback;
private.jsonpcall(private.ashx, ['downloadurl', escape(url)],
function (msg) {
// gets the contents of the Html in the 'msg'
// todo: apply selector
private.container.html(msg);
if ($.isFunction(private.callback)) {
private.callback();
}
});
},
Manage_Response: function (result, container, Target, TargetDisplay, TargetDisplayInfoPR) {
if (result.Error == null) {
container.find(".MRW-Results").slideDown('slow');
container.find(".MRW-RList").html(result.Value).show();
if (private.params.ShowResultsOnMap) {
// Ajout des points sur la google map
//if (!private.mapLoaded) {
private.MR_LoadMap(private.params);
private.mapLoaded = true;
//}
// Supprime le contenu de la carte
private.MR_clearOverlays();
// Boucle sur les Points Relais
for (var i = 0; i < result.PRList.length; i++) {
// Ajout d'un marker pour chaque Point Relais
private.MR_AddGmapMarker(
private.map,
new google.maps.LatLng(result.PRList[i].Lat.replace(',', '.'), result.PRList[i].Long.replace(',', '.')),
result.PRList[i],
i,
private.sw_url,
Target,
TargetDisplay,
TargetDisplayInfoPR
);
}
// Redimentionne la carte
private.map.fitBounds(private.bounds);
// AutoSelect
if (private.params.AutoSelect) {
private.MR_FocusOnMaker(private.params.AutoSelect);
}
} else {
$('#MRW-Map', private.container).html("");
for (var i = 0; i < result.PRList.length; i++) {
$('#MRW-Map', private.container).append(private.MR_BuildparcelShopDetails(result.PRList[i]))
$.data($('#MRW-Map > div:last-child')[0], "ParcelShop", result.PRList[i])
$('#MRW-Map > div:last-child').bind("select", function () {
private.MR_SelectparcelShop($.data($(this)[0], "ParcelShop"));
});
$('#MRW-Map > div', private.container).hide()
}
}
} else {
container.find(".MRW-Results").hide();
container.find(".MRW-Errors").html(result.Error).slideDown("slow");
}
container.find('.progressBar').hide();
// Gestion du hover sur les items
container.find('.PR-List-Item').mouseover(function () {
$(this).addClass("PR-hover");
});
container.find('.PR-List-Item').mouseout(function () {
$(this).removeClass("PR-hover");
});
},
MR_Widget_Call: function (container, Target, TargetDisplay, TargetDisplayInfoPR) {
container.find(".MRW-Errors").hide();
container.find('.progressBar').show();
container.find(".MRW-Errors").html("");
var a0 = container.find('input.Arg0')[0].value;
var a1 = container.find('input.Arg1')[0].value;
var a2 = container.find('input.Arg2')[0].value;
var a3 = container.find('input.Arg3')[0].value;
var a4 = container.find('input.Arg4')[0].value;
var a5 = container.find('input.Arg5')[0].value;
var a6 = container.find('input.Arg6')[0].value;
var a7 = container.find('input.Arg7')[0].value;
var a8 = private.params.VacationBefore || '';
var a9 = private.params.VacationAfter || '';
private.jsonpcall(private.w_name + "/" + private.svc + "/SearchPR",
["Brand", a0, "Country", a1, "PostCode", a2, "ColLivMod", a3, "Weight", a4, "NbResults", a5, "SearchDelay", a6, "SearchFar", a7, "ClientContainerId", private.containerId, "VacationBefore", a8, "VacationAfter", a9],
function (result) {
private.Manage_Response(result, container, Target, TargetDisplay, TargetDisplayInfoPR);
});
},
MR_LoadMap: function (prms) {
var myOptions = {
zoom: 5,
center: new google.maps.LatLng(46.80000, 1.69000),
mapTypeId: google.maps.MapTypeId.ROADMAP,
panControl: false, // Flèches de direction
rotateControl: true,
scaleControl: true, // Mesure de distance
scrollwheel: prms.MapScrollWheel ? prms.MapScrollWheel : false, // Zoom avec la molette de la souris
streetViewControl: prms.MapStreetView ? prms.MapStreetView : false, // Autorisation de StreetView
zoomControl: true // Zoom
};
private.map = new google.maps.Map(document.getElementById('MRW-Map'), myOptions);
private.bounds = new google.maps.LatLngBounds();
private.overlays = [];
private.infowindows = [];
},
MR_clearOverlays: function () {
for (var n = 0, overlay; overlay = private.overlays[n]; n++) {
overlay.setMap(null);
}
// Clear overlays from collection
private.overlays = [];
private.infowindows = [];
private.bounds = new google.maps.LatLngBounds();
},
MR_FocusOnMaker: function (id) {
// Boucle sur les Markers
for (var i = 0; i < private.overlays.length; i++) {
// Test de validité
if (id == private.overlays[i].get("id")) {
private.MR_FocusOnMap(i);
}
}
},
MR_AddGmapMarker: function (map, latLng, PRI, Id, sw_url, Target, TargetDisplay, TargetDisplayInfoPR) {
// Get the letter for the marker
var letter = String.fromCharCode("A".charCodeAt(0) + (private.overlays.length));
// Create the marker
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: new google.maps.MarkerImage(private.protocol + private.sw_url + "/" + private.w_name + "/css/imgs/gmaps_pr02" + letter + ".png")
});
// Add clickListener
google.maps.event.addListener(marker, 'click', function () {
// Fermeture de la fenêtre précédente
for(i in private.infowindows)
if(private.infowindows[i] != null)
private.infowindows[i].close();
private.InfoWindow = new google.maps.InfoWindow({
content: private.MR_BuildparcelShopDetails(PRI)
});
private.InfoWindow.open(private.map, marker);
private.infowindows.push(private.InfoWindow);
private.map.setCenter(marker.getPosition());
});
// Add clickListener
google.maps.event.addListener(marker, 'click', function () {
private.MR_SelectparcelShop(PRI);
});
// Add Marker to Overlays collection
private.overlays.push(marker);
// Redimentionne la carte
private.bounds.extend(latLng);
//map.fitBounds(bounds);
return marker;
},
MR_SelectparcelShop: function (PRI) {
$(private.params.Target).val(PRI.Pays + '-' + PRI.ID).trigger('change');
$(private.params.TargetDisplay).html(PRI.Pays + '-' + PRI.ID);
if (private.params.TargetDisplayInfoPR) {
$(private.params.TargetDisplayInfoPR).html(PRI.Nom + '
' + PRI.Adresse1 + '
' + PRI.Adresse2 + '
' + PRI.Pays + '-' + PRI.CP + ' ' + PRI.Ville + ' ');
}
$(".PR-Selected").removeClass("PR-Selected");
$('.PR-Id[Value="' + PRI.Pays + '-' + PRI.ID + '"]').parent().addClass("PR-Selected");
if (private.params.OnParcelShopSelected) {
private.params.OnParcelShopSelected(PRI)
}
},
MR_BuildparcelShopDetails: function (PRI) {
var content = '