/*
* Modifiche fatte
* 20120113 - controllo banner per cooperativa - se ci sono piccolo cooperative non vengono conteggaiate
* - CR 20120113
*
*
*
*/
var contextPath = "/StoreLocator";
var isGeolocationEnabled = true;
var isCooperativaFromUrlActivateSearch = true;
var ajaxLoading =
'
Prossima '+ (apertura.orario.aperto ? 'apertura' : 'chiusura') +' straordinaria: ' +
'
'+ formatFullDate(apertura.giorno) +
(apertura.orario.aperto ? '' : ' (CHIUSO)') +
'
';
}
//promozioni
serviziSpeciali += getPromoInfo(store);
var strView = '');
return $('
'+
'
' +
'
'+ store.ragioneSociale +'
'+
'
'+ store.indirizzo +'
'+ store.citta +'
'+
'
' +
'
' +
getPromoInfo(store, true) +
'
' +
'
' +
'
')
// var divStreet = $("");
.qtip({
content: {
text: '
' + ( createInfoWindowHtml(store) + createDetailPromo(store)) + '
', // text to show,
title: {
text: ' ', //'Punto vendita : ' + store.ragioneSociale,
button: true
}
},
show: {
event: 'click',
solo: false, // Only show one tooltip at a time
effect: function() {
//alert($(this).html());
$(this).show();
$('.scroll-pane', this).jScrollPane();
//alert($(this).attr("class"));
//alert($(this).find('div.strViewLink').html());
storeApplication.strView($(this).find('div.strViewLink'), true);
}
},
events: {
show: function(event, api) {
//manage favourite link
var tipId = "#ui-tooltip-" + api.id;
var addFavSelectorName = 'storeLocator-add-favourite_';
var removeFavSelectorName = 'storeLocator-remove-favourite_';
var promoSelectorName = 'store-promo-info_';
//alert("idStore " + $(tipId).find('div.'+ addFavSelectorName).attr("id").substring(addFavSelectorName.length));
var storeId = $(tipId).find('div.'+ addFavSelectorName).attr("id").substring(addFavSelectorName.length);
var ids = new Array();
ids.push(storeId);
//RESTYLE
//caricamento promo dinamico
$(tipId).find('div.'+ promoSelectorName).html(ajaxLoading);
RemoteCoopStoreLocator.getStoresByIdsAndVolantino(ids, {
callback:function(stores) {
if (stores == undefined) {
alert("KO");
$(tipId).find('div.'+ promoSelectorName).html("");
return;
}
//non viene aggiunto perchè esiste già senza volantini
//storeApplication.resultManager.addStoreResults(stores, true);
$(tipId).find('div.'+ promoSelectorName).html(createDetailPromo(stores[0]));
//alert(createDetailPromo(stores[0]));
//alert(stores[0].cooperativa);
},
errorHandler:function(message) {openDialogErrore(message);}
});
$(tipId).find('div.'+ addFavSelectorName).click(function(){
var idStore = $(this).attr('id').substring(addFavSelectorName.length);
favManager.addFavourite(idStore);
$(this).hide().siblings('.'+ removeFavSelectorName).show();
});
$(tipId).find('div.'+ removeFavSelectorName).click(function(){
var idStore = $(this).attr('id').substring(removeFavSelectorName.length);
favManager.removeFavourite(idStore);
$(this).hide().siblings('.'+ addFavSelectorName).show();
});
}
},
hide: {
event: 'unfocus'
},
position: {
my: 'left center', // Use the corner...
at: 'right center', // ...and opposite corner
viewport: $(window),
adjust: {
method: "flip",
x: parseInt(20, 10) || 0,
y: parseInt(20, 10) || 0
}
},
style: {
classes: 'ui-tooltip-rounded ui-tooltip-' + 'light ui-qtip-province ui-tooltip-jtools-coop', // ui-tooltip-shadow
width: true // Set the tooltip width
}
})
.click(function() {
//alert("ko");
//RESTYLE
//alert("click");
//$('#store-dettaglio').html(createInfoWindowHtml(store) + createDetailPromo(store));
//vista stradle
//storeApplication.strView($('#store-dettaglio' + store.id).find('div.strViewLink'), true);
//$('#banner-navi-intro').addClass("outofpage");
//$('#store-dettaglio').removeClass('outofpage');
//GEvent.trigger(store._web.marker,'click');
});
}
function setQtipDetail(obj, store) {
alert(store.id);
obj.qtip({
content: {
text: '
' + ( createInfoWindowHtml(store) + createDetailPromo(store)) + '
', // text to show,
title: {
text: ' ', //'Punto vendita : ' + store.ragioneSociale,
button: true
}
},
show: {
//event: 'click',
solo: true, // Only show one tooltip at a time
effect: function() {
//alert($(this).html());
$(this).show();
$('.scroll-pane', this).jScrollPane();
//alert($(this).attr("class"));
//alert($(this).find('div.strViewLink').html());
storeApplication.strView($(this).find('div.strViewLink'), true);
}
},
events: {
show: function(event, api) {
//manage favourite link
var tipId = "#ui-tooltip-" + api.id;
var addFavSelectorName = 'storeLocator-add-favourite_';
var removeFavSelectorName = 'storeLocator-remove-favourite_';
$(tipId).find('div.'+ addFavSelectorName).click(function(){
var idStore = $(this).attr('id').substring(addFavSelectorName.length);
favManager.addFavourite(idStore);
$(this).hide().siblings('.'+ removeFavSelectorName).show();
});
$(tipId).find('div.'+ removeFavSelectorName).click(function(){
var idStore = $(this).attr('id').substring(removeFavSelectorName.length);
favManager.removeFavourite(idStore);
$(this).hide().siblings('.'+ addFavSelectorName).show();
});
}
},
hide: {
event: 'unfocus'
},
position: {
my: 'left center', // Use the corner...
at: 'right center', // ...and opposite corner
viewport: $(window),
adjust: {
method: "flip",
x: parseInt(20, 10) || 0,
y: parseInt(20, 10) || 0
}
},
style: {
classes: 'ui-tooltip-rounded ui-tooltip-' + 'light ui-qtip-province ui-tooltip-jtools-coop', // ui-tooltip-shadow
width: true // Set the tooltip width
}
})
}
function createDetailPromo(store) {
var serviziSpeciali = "";
if ((store.volantini && store.volantini.length > 0) || store.cooperativa.id == 8) {
serviziSpeciali += '
';
if (store.cooperativa.id != 8)
serviziSpeciali += '';
var x, volantino;
//var counter = 0;
var volantino_folder , volantino_id, volantino_campagna_id, volantino_img_url;
for (counter = 0; counter < store.volantini.length ; counter ++) {
volantino = store.volantini[counter];
volantino_id = volantino.id;
volantino_campagna_id = volantino.idCampagna;
volantino_folder = "img/volantini/campagna_"+ volantino_campagna_id +"/volantino_"+ volantino_id;
volantino_img_url = volantino_folder + "/small/page-0.jpg"
if (counter == 0) {
serviziSpeciali += '
'
}
if (counter == 1) {
serviziSpeciali += '';
serviziSpeciali += '
'
}
//alert("counter " + counter);
}
}
return serviziSpeciali;
}
function createFavDetail(store,favManager) {
var box = $('
');
// dettaglio
$('
'+
'
'+ store.ragioneSociale +'
'+
'
'+ store.indirizzo +'
'+ store.citta +'
'+
'
').click(function() {
GEvent.trigger(store._web.marker,'click');
openDettaglioDialog(store.id, store.ragioneSociale);
}).appendTo(box);
// rimuovi dai preferiti
$('
')
.click(function(){
store._web.marker.closeInfoWindow();
favManager.removeFavourite(store.id);
}).mouseover(function(){
$(this).addClass('bg-cross-red');
}).mouseout(function(){
$(this).removeClass('bg-cross-red');
}).appendTo(box);
return box;
}
//RESTYLE verifica se la ricerca è per cooperativa
function isCooperativaSearch()
{
var isCooperativa = false;
if ($("#ricerca-cooperativa").is(":visible"))
isCooperativa = true;
return isCooperativa;
}
function isStoreInBounds(store) {
//RESTYLE se in visualizzazione elenco ritorna true
if ($("#content-elenco").is(":visible"))
return true;
else
return store._web.map.getBounds().containsLatLng(store._web.marker.getLatLng());
}
function isStoreVisibile(store, isElenco) {
//RESTYLE
if (isElenco == "undefinded")
isElenco = false;
//per la cooperativa non considera i range della mappa
//alert("store._web.soddisfa_filtri " + store._web.soddisfa_filtri);
//alert("isCooperativaSearch() " + isCooperativaSearch());
//alert("isStoreInBounds(store)() " + isStoreInBounds(store));
return (store._web.map.getZoom() >= getMinStoreZoomLevel() || isCooperativaSearch())
&& store._web.soddisfa_filtri
&& (store._web.is_preferito
|| (store._web.categoria.visible
&& (isStoreInBounds(store) || isElenco))
);
}
function updateStoreVisibility(store) {
//logger.log('updateStoreVisibility : '+ store.ragioneSociale + " isStoreVisibile : " + isStoreVisibile(store));
if (isStoreVisibile(store)) {
$(store._web.dettaglio).show();
store._web.marker.show();
} else {
$(store._web.dettaglio).hide();
store._web.marker.hide();
store._web.marker.closeInfoWindow();
}
}
function updateAllStoresVisibility(stores) {
for (var x in stores)
updateStoreVisibility(stores[x]);
}
function getMinZoomLevel () {return 5;}
function getMinStoreZoomLevel () {return 9;}
function getMinGroupZoomLevel (groupType) {
if (groupType == group_PROVINCE)
return 7;
return getMinZoomLevel();
}
function isGroupedZoomLevel (zoom, groupType) {
if (zoom && groupType) {
if (groupType == group_REGIONI
&& zoom < getMinGroupZoomLevel(group_PROVINCE))
return true;
if (groupType == group_PROVINCE
&& zoom >= getMinGroupZoomLevel(groupType)
&& zoom < getMinStoreZoomLevel())
return true;
}
return false;
}
function removeStore(storeArray, arrayPosition) {
var store = storeArray[arrayPosition];
logger.log('rimuovo store: '+ store.ragioneSociale);
store._web.map.removeOverlay(store._web.marker);
$(store._web.dettaglio).remove();
delete store._web; // distruggo l'oggetto web
storeArray.splice(arrayPosition,1); // rimuovo dall'array l'elemento
// TODO verificare se cancellare anche l'oggetto store
}
function FavouriteManager (stores, favBox, favContainer) {
this.stores = stores;
this.favBox = favBox;
this.favContainer = favContainer;
this.cookieName = 'preferiti';
this.refreshVisibility = function() {
var visible = false;
for (var x in this.stores) {
if (this.stores[x]._web.is_preferito) {
visible = true;
break;
}
}
if (visible) {
$(this.favBox).show();
// modifico altezza sidebar
$('#sidebar').addClass('reduced');
$('#introFlash').hide();
//RESTYLE
$("#filtri").css('height', '345px');
$("#accordion-filtri").css('height', '325px');
$("#accordion-filtri").accordion( "resize" );
}else {
$(this.favBox).hide();
// modifico altezza sidebar
$('#sidebar').removeClass('reduced');
$('#introFlash').show();
//RESTYLE
$("#filtri").css('height', '455px');
$("#accordion-filtri").css('height', '435px');
$("#accordion-filtri").accordion( "resize" )
}
}
this.addFavourite = function(idStore) {
logger.info('addFavourite '+ idStore);
var store = null;
for (var x in this.stores) {
if (this.stores[x].id == idStore) {
store = this.stores[x];
store._web.is_preferito = true;
store._web.dettaglio_preferito = createFavDetail(store, this);
$(store._web.dettaglio_preferito).appendTo(this.favContainer);
this.cookieAdd(idStore);
updateStoreVisibility(store);
this.refreshVisibility();
break;
}
}
}
this.removeFavourite = function(idStore) {
var store = null;
for (var x in this.stores) {
if (this.stores[x].id == idStore) {
store = this.stores[x];
store._web.is_preferito = false;
$(store._web.dettaglio_preferito).remove();
this.cookieRemove(idStore);
var categoria = store._web.categoria;
updateStoreVisibility(store);
if (! isStoreVisibile(store)) {
removeStore(this.stores, x);
}
this.refreshVisibility();
categoria.refresh();
break;
}
}
}
this.cookieAdd = function(idStore) {
logger.log('aggiungiPreferito - id: '+ idStore);
var preferiti = $.cookie(this.cookieName);
if(!preferiti) {
preferiti = idStore;
}else {
var tokens = preferiti.split(',');
for(var i in tokens) {
if(!isNaN(i) && tokens[i] == idStore) {
return;
}
}
preferiti = preferiti + ',' + idStore;
}
$.cookie(this.cookieName, preferiti);
logger.log('aggiungiPreferito - scritto: ' + preferiti);
}
this.cookieRemove = function(idStore) {
logger.log('rimuoviPreferito - id: '+ idStore);
var preferiti = $.cookie(this.cookieName);
if(!preferiti) {
return;
}
var tokens = preferiti.split(',');
preferiti = '';
for(var i in tokens) {
if(!isNaN(i)) {
var token = tokens[i];
if(token != idStore) {
preferiti += token + ',';
}
}
}
if(preferiti.length == 0) {
preferiti = null;
} else {
preferiti = preferiti.substring(0, preferiti.length-1);
}
$.cookie(this.cookieName, preferiti);
logger.log('rimuoviPreferito - scritto: ' + preferiti);
}
}
function BannerManager(stores, areasData, isDetailPage, map) {
this.stores = stores;
this.areas = [];
this.isDetailPage = isDetailPage; // variabile per la pagina di dettaglio
this.map = map;
this.initialize(areasData);
this.lastUniqueCoopId = null;
}
BannerManager.prototype.initialize = function(areasData) {
var area, x, data;
for (x in areasData) {
data = areasData[x];
if (data.id && data.alignment && data.height && data.width && data.container) {
area = new BannerArea(data, this);
this.areas.push(area);
}
}
}
BannerManager.prototype.notifyNewCoopId = function (coopId) {
if (coopId != this.lastUniqueCoopId) {
for (var x = 0; x < this.areas.length; x++) {
var area = this.areas[x];
var timeoutId = area.timeoutId;
if (timeoutId != 0) {
clearTimeout(timeoutId);
timeoutId = 0;
}
area.refresh();
}
this.lastUniqueCoopId = coopId;
}
}
BannerManager.prototype.getBannerParams = function(areaId, maxHeight, maxWidth, displayedBannerIds) {
var store; // variabile di appoggio
var storeIds = []; // ID pdv in pagina
var categoriaIds = []; // ID categorie di pdv in pagina
var cooperativaIds = []; // ID cooperative dei pdv in pagina
if (this.isDetailPage) {
store = this.stores[0];
storeIds.push(store.id);
categoriaIds.push(store.categoria.id);
cooperativaIds.push(store.cooperativa.id);
} else if (this.map.getZoom() >= getMinStoreZoomLevel()) {
var x;
for (x in this.stores) {
store = this.stores[x];
if (isStoreInBounds(store)) {
storeIds.push(store.id);
categoriaIds[store.categoria.id] = store.categoria.id; // evito duplicati ma creo "buchi" nell'array
//RESTYLE
//CR 20120113
//considero solo sovrapposizioni tra le grandi 9 cooperative
if (store.cooperativa.id < 10) {
cooperativaIds[store.cooperativa.id] = store.cooperativa.id; // evito duplicati ma creo "buchi" nell'array
}
}
}
// ripulisco i "buchi" nell'array delle categorie
for (x = categoriaIds.length -1; x >= 0; x--) {
if (! categoriaIds[x])
categoriaIds.splice(x, 1);
}
// ripulisco i "buchi" nell'array delle cooperative
for (x = cooperativaIds.length -1; x >= 0; x--) {
if (! cooperativaIds[x])
cooperativaIds.splice(x, 1);
}
}
var params = {
areaId: areaId,
maxHeight: maxHeight,
maxWidth: maxWidth,
storeIds: storeIds,
categoriaIds: categoriaIds,
cooperativaIds: cooperativaIds,
displayedBannerIds: displayedBannerIds
}
return params;
}
function BannerArea(areaData, bannerMgr) {
this.id = areaData.id;
this.alignment = areaData.alignment;
this.bannerBorder = 1;
this.bannerMargin = 3;
this.maxManagedGap = (this.bannerMargin + (2*this.bannerBorder)) * 3;
this.container = areaData.container;
this.height = areaData.height;
this.width = areaData.width;
this.manager = bannerMgr;
this.bannerBox = [];
this.bannerNum = 0;
this.timeoutId = 0;
this.displayedBannerIds = [];
this.initialize();
}
BannerArea.prototype.initialize = function() {
/*var sel = $(this.container).find('div.banner-box');
var count = 0;
for (var x in sel) {
if (!isNaN(x)) {
this.bannerBox.push(sel[x]);
count++;
}
}
this.bannerNum = count;*/
this.refresh();
}
BannerArea.prototype.setRefreshTimeout = function() {
var _this = this;
this.timeoutId = setTimeout(function(){_this.refresh();}, 30000 + Math.floor(Math.random() * 4000));
}
BannerArea.prototype.refresh = function() {
var maxHeight = this.height - (this.bannerBorder *2); //per il bordo
var maxWidth = this.width - (this.bannerBorder *2); //per il bordo
var params = this.manager.getBannerParams(this.id, maxHeight, maxWidth, this.displayedBannerIds);
var _this = this;
RemoteCoopStoreLocator.loadBanners(params, {
callback:function(banners) {
_this.manageBanners(banners);
_this.setRefreshTimeout();
},
errorHandler:function(message) {
//openDialogErrore(message);
logger.error(message);
_this.setRefreshTimeout();
}
});
}
BannerArea.prototype.manageBanners = function(banners) {
logger.dir(banners);
var x,b,bPixel,pixelLeft;
this.displayedBannerIds = [];
var bannerSelected = [];
if (banners && banners.length > 0) {
if (this.alignment == 'vertical')
pixelLeft = this.height;
else
pixelLeft = this.width;
//** while commentato per evitare la ripetizione dei banner **//
//var prevLoopLength = -1;
//while (pixelLeft > 0 && bannerSelected.length != prevLoopLength) {
// prevLoopLength = bannerSelected.length;
for (x in banners) {
b = banners[x];
if (this.alignment == 'vertical')
bPixel = b.altezza + (this.bannerBorder *2);
else
bPixel = b.larghezza + (this.bannerBorder *2);
if (bPixel <= pixelLeft) {
bannerSelected.push({banner: b, margin: this.bannerMargin});
this.displayedBannerIds.push(b.id);
pixelLeft = pixelLeft - bPixel;
}
}
//}
// resetto il margine dell'utlimo banner
if (bannerSelected.length > 0) {
bannerSelected[bannerSelected.length -1].margin = 0;
}
// calcolo il margine tra i banner
if (pixelLeft > 0 && pixelLeft <= this.maxManagedGap && this.bannerMargin > 0 && bannerSelected.length > 1) {
var numGaps = bannerSelected.length -1;
var gap = Math.floor(pixelLeft / numGaps);
for(x = 0; x < numGaps -1; x++)
bannerSelected[x].margin = gap;
bannerSelected[numGaps -1].margin = pixelLeft - (gap * (numGaps -1));
}
}
this.drawBanners(bannerSelected);
}
BannerArea.prototype.drawBanners = function(banners) {
$(this.container).empty();
var x,banner,height,width,div_style;
for (x in banners) {
banner = banners[x].banner;
height = banner.altezza;
width = banner.larghezza;
div_style = 'float:left;height:'+height+'px;width:'+width+'px;';
if (this.alignment == 'vertical')
div_style += 'margin-bottom:'+banners[x].margin+'px;';
else
div_style += 'margin-right:'+banners[x].margin+'px;';
if (this.bannerBorder > 0) {
div_style += 'border:'+this.bannerBorder+'px solid #999';
}
if (banner.tipo == 'IMMAGINE') {
var pre_img = '', post_img = '', html_img = '';
if (banner.url && banner.url != '') {
pre_img = '
';
post_img = '';
}
var img_src = banner.webFilename ? contextPath + '/img/banner/'+banner.webFilename : contextPath + '/banner?id='+banner.id;
html_img = '

';
$('
'+ pre_img + html_img + post_img +'
')
.appendTo(this.container);
} else if (banner.tipo == 'FLASH') {
var flashvars = {};
if (banner.url && banner.url != '') {
flashvars = {javascript: "javascript:manageLink('"+ banner.urlFlash +"','"+ banner.tipoUrl +"');"};
}
/*var html_swf = '
';*/
var flash_id = "flashbanner_"+ this.id +"_"+ x;
var flash_src = banner.webFilename ? contextPath + '/img/banner/'+banner.webFilename : contextPath + '/banner?id='+banner.id;
$('
')
.appendTo(this.container);
swfobject.embedSWF(flash_src, flash_id, width, height, "8.0.0", contextPath + "/swf/expressInstall.swf", flashvars, {wmode:"transparent"});
}
}
}
function FilterManager(stores, categories) {
this.stores = stores;
this.categories = categories;
this.initialize();
}
FilterManager.prototype.initialize = function () {
var _this = this;
$('#filtri #accordion-filtri input[type="checkbox"]').click(function () {
if (($(this).attr('checked'))){
_this.filtraServizi();
}else{
_this.applyAllFilter(true);
}
});
$('#filtri #ckbox-cooperativa').click(function () {
if (($(this).attr('checked'))){
_this.filtraCooperativa('check');
}else{
_this.applyAllFilter(true);
}
})
$('#filtri #select-cooperativa').change(function () {
_this.filtraCooperativa('switch');
})
$('#filtri #ckbox-settimana').click(function () {
if (($(this).attr('checked'))){
_this.filtraGiornoAperturaStandard();
}else{
_this.applyAllFilter(true);
}
})
$('#filtri #filtri-settimana input[name="gruppo-giorni-settimana"]').click(function () {
_this.filtraGiornoAperturaStandard();
})
$('#filtri #ckbox-data').click(function () {
if (($(this).attr('checked'))){
_this.filtraGiornoAperturaStraordinaria('check');
}else{
_this.applyAllFilter(true);
}
})
$('#filtri #data-apertura').change(function () {
_this.filtraGiornoAperturaStraordinaria('switch');
})
$('#filtri #ckbox-orario').click(function () {
if (($(this).attr('checked'))){
_this.filtraOrario('check');
}else{
_this.applyAllFilter(true);
}
})
$('#filtri #slider').bind('slidechange', function(event, ui) {
_this.filtraOrario('switch');
});
}
FilterManager.prototype.getGiornoSettimanaSelezionato = function() {
var giorno_settimana = '#filtri #filtri-settimana input[name="gruppo-giorni-settimana"]:checked:enabled';
var giorno_selezionato = $(giorno_settimana);
var giorno_sett_sel;
for (x in giorno_selezionato) {
if (!isNaN(x)) {
giorno_sett_sel = giorno_selezionato[x].value;
break;
}
}
return giorno_sett_sel;
}
FilterManager.prototype.getGiornoApertStraordSelezionato = function() {
var apertura_straordinaria = '#filtri #data-apertura:enabled';
var selected_apertura_straordinaria = $(apertura_straordinaria);
return selected_apertura_straordinaria;
}
FilterManager.prototype.getCooperativaSelezionata = function() {
var cooperative = '#filtri #select-cooperativa:enabled';
var selected_cooperative = $(cooperative);
return selected_cooperative;
}
FilterManager.prototype.getOrarioSelezionato = function() {
var orario = '#filtri #orario';
var selected_orario = $(orario);
return selected_orario;
}
FilterManager.prototype.getServiziSelezionati = function() {
var services = '#filtri #accordion-filtri input[type="checkbox"]:checked';
var selected_services = $(services);
return selected_services;
}
FilterManager.prototype.getGiornoSettimanaStore = function(giorno_sel,store) {
var giorno_sett_store;
if (store.aperturaSettimanale == undefined)
return null;
if (giorno_sel == 'lun'){
giorno_sett_store = store.aperturaSettimanale.lunedi;
}
else if(giorno_sel == 'mar'){
giorno_sett_store = store.aperturaSettimanale.martedi;
}
else if(giorno_sel == 'mer'){
giorno_sett_store = store.aperturaSettimanale.mercoledi;
}
else if(giorno_sel == 'gio'){
giorno_sett_store = store.aperturaSettimanale.giovedi;
}
else if(giorno_sel == 'ven'){
giorno_sett_store = store.aperturaSettimanale.venerdi;
}
else if(giorno_sel == 'sab'){
giorno_sett_store = store.aperturaSettimanale.sabato;
}
else if(giorno_sel == 'dom'){
giorno_sett_store = store.aperturaSettimanale.domenica;
}
return giorno_sett_store;
}
FilterManager.prototype.isAperturaStandardChecked = function() {
var ckbox_apert_stand = '#filtri #ckbox-settimana';
if ($(ckbox_apert_stand).attr('checked')){
return true;
}
return false;
}
FilterManager.prototype.isOrarioChecked = function() {
var ckbox_orario = '#filtri #ckbox-orario';
if ($(ckbox_orario).attr('checked')){
return true;
}
return false;
}
FilterManager.prototype.filtraServizi = function() {
//RESTYLE
this.applyActiveState();
for (var x in this.stores){
var _store = this.stores[x];
if(_store._web.soddisfa_filtri){
if(this.checkServizi(_store)){
_store._web.soddisfa_filtri = true;
}
else{
_store._web.soddisfa_filtri = false;
}
}
}
updateAllStoresVisibility(this.stores);
for (x in this.categories){
this.categories[x].refresh();
}
}
FilterManager.prototype.filtraOrario = function(azione) {
//RESTYLE
this.applyActiveState();
if(azione == 'check'){
for (var x in this.stores){
if(this.stores[x]._web.soddisfa_filtri) {
if (this.checkOrarioApertura(this.stores[z])) {
this.stores[x]._web.soddisfa_filtri = true;
} else {
this.stores[x]._web.soddisfa_filtri = false;
}
}
}
} else if(azione == 'switch'){
for (var z in this.stores){
if(this.stores[z]._web.soddisfa_filtri){
if (this.checkOrarioApertura(this.stores[z])) {
this.stores[z]._web.soddisfa_filtri = true;
} else {
this.stores[z]._web.soddisfa_filtri = false;
}
} else{
this.stores[z]._web.soddisfa_filtri = this.checkAll(this.stores[z]);
}
}
}
updateAllStoresVisibility(this.stores);
for (x in this.categories){
}
}
FilterManager.prototype.filtraCooperativa = function(azione) {
//RESTYLE
this.applyActiveState();
if(azione == 'check'){
for (var x in this.stores){
if(this.stores[x]._web.soddisfa_filtri){
if (this.checkCooperative(this.stores[x],this.getCooperativaSelezionata())){
this.stores[x]._web.soddisfa_filtri = true;
}
else {
this.stores[x]._web.soddisfa_filtri = false;
}
}
}
}else if(azione == 'switch'){
for (var z in this.stores){
if(this.stores[z]._web.soddisfa_filtri){
if (this.checkCooperative(this.stores[z],this.getCooperativaSelezionata())){
this.stores[z]._web.soddisfa_filtri = true;
}
else {
this.stores[z]._web.soddisfa_filtri = false;
}
}else{
this.stores[z]._web.soddisfa_filtri = this.checkAll(this.stores[z]);
}
}
}
updateAllStoresVisibility(this.stores);
for (x in this.categories){
this.categories[x].refresh();
}
}
FilterManager.prototype.filtraGiornoAperturaStraordinaria = function(azione) {
//RESTYLE
this.applyActiveState();
if(azione == 'check'){
for (var x in this.stores){
if (this.checkGiornoAperturaStraordinaria(this.stores[x])){ //,this.getGiornoApertStraordSelezionato())){
this.stores[x]._web.soddisfa_filtri = true;
}
else {
this.stores[x]._web.soddisfa_filtri = false;
}
}
}else if(azione == 'switch'){
for (var z in this.stores){
if(this.stores[z]._web.soddisfa_filtri){
if (this.checkGiornoAperturaStraordinaria(this.stores[z])){ //,this.getGiornoApertStraordSelezionato())){
this.stores[z]._web.soddisfa_filtri = true;
}
else {
this.stores[z]._web.soddisfa_filtri = false;
}
}else{
this.stores[z]._web.soddisfa_filtri = this.checkAll(this.stores[z]);
}
}
}
updateAllStoresVisibility(this.stores);
for (x in this.categories){
this.categories[x].refresh();
}
}
FilterManager.prototype.filtraGiornoAperturaStandard = function() {
//RESTYLE
this.applyActiveState();
for (var z in this.stores){
if(this.stores[z]._web.soddisfa_filtri){
if (this.checkGiornoAperturaStandard(this.stores[z])){
this.stores[z]._web.soddisfa_filtri = true;
}
else {
this.stores[z]._web.soddisfa_filtri = false;
}
}else{
this.stores[z]._web.soddisfa_filtri = this.checkAll(this.stores[z]);
}
}
updateAllStoresVisibility(this.stores);
for (var x in this.categories){
this.categories[x].refresh();
}
}
FilterManager.prototype.checkOrario = function(orario_da_controllare,orario_store) {
if (orario_da_controllare != undefined || orario_store != undefined){
var selected_orario = $(orario_da_controllare);
var orario_splitted = selected_orario.text().split(".");
var orario_da_verif = new Date(1970,0,1); // 01-01-1970
orario_da_verif.setHours(orario_splitted[0],orario_splitted[1],0);
if (orario_store.continuato){
if (orario_da_verif >= orario_store.a_am && orario_da_verif <= orario_store.c_pm) {
return true;
}else{
return false;
}
}else{
if ((orario_da_verif >= orario_store.a_am && orario_da_verif <= orario_store.c_am) ||
(orario_da_verif >= orario_store.a_pm && orario_da_verif <= orario_store.c_pm)) {
return true;
}else{
return false;
}
}
}else{
return true;
}
}
FilterManager.prototype.checkOrarioApertura = function(store) {
logger.log('FilterManager.checkOrarioApertura');
if (this.isAperturaStandardChecked()){
return this.checkGiornoAperturaStandard(store);
} else {
return this.checkGiornoAperturaStraordinaria(store);
}
}
FilterManager.prototype.checkGiornoAperturaStraordinaria = function(store) {
logger.log('FilterManager.checkGiornoAperturaStraordinaria');
var apertura_straordinaria = this.getGiornoApertStraordSelezionato();
if (apertura_straordinaria.length == 0){
return true;
}else {
for (var x in apertura_straordinaria) {
if (! isNaN(x)){
var split = ($(apertura_straordinaria[x]).val()).split("/");
var date_to_check = new Date(split[2], split[1]-1, split[0]);
var aperture_straordinarie_store = store.apertureStraordinarie;
for (var z in aperture_straordinarie_store) {
var store_date = aperture_straordinarie_store[z].giorno;
if (aperture_straordinarie_store[z].orario.aperto
&& store_date.getFullYear() == date_to_check.getFullYear()
&& store_date.getMonth() == date_to_check.getMonth()
&& store_date.getDate() == date_to_check.getDate() ) {
if (this.isOrarioChecked()){
return this.checkOrario(this.getOrarioSelezionato(),aperture_straordinarie_store[z].orario);
}
return true;
}
}
return false;
}
}
return true;
}
}
FilterManager.prototype.checkGiornoAperturaStandard = function(store) {
logger.log('FilterManager.checkGiornoAperturaStandard');
var giorno_sett_sel = this.getGiornoSettimanaSelezionato();
if(giorno_sett_sel == undefined) {
return true;
} else if (store.aperturaSettimanale == null) {
return false;
} else {
var giorno_sett_store = this.getGiornoSettimanaStore(giorno_sett_sel,store);
if (giorno_sett_store == undefined || giorno_sett_store.aperto){
if (this.isOrarioChecked()){
return this.checkOrario(this.getOrarioSelezionato(),giorno_sett_store);
}
return true;
}
return false;
}
}
FilterManager.prototype.refresh = function() {
logger.log('FilterManager.refresh - isActive: ' + this.isActive());
//alert("applyAllFilter")
this.applyAllFilter();
}
FilterManager.prototype.checkCooperative = function(store) {
logger.log('FilterManager.checkCooperative');
var selected_cooperative = this.getCooperativaSelezionata();
if (selected_cooperative.length == 0 || store.cooperativa.id == selected_cooperative.val()){
return true;
}
return false;
}
FilterManager.prototype.checkAll = function(store) {
var checkAllStatus = this.checkServizi(store) && this.checkCooperative(store) && this.checkGiornoAperturaStandard(store) && this.checkGiornoAperturaStraordinaria(store)
return (checkAllStatus);
}
FilterManager.prototype.applyAllFilter = function(solo_non_visibili) {
logger.log('FilterManager.applyAllFilter - solo_non_visibili : ' + solo_non_visibili);
//RESTYLE
this.applyActiveState();
if(solo_non_visibili != undefined){
for (var x in this.stores){
var _store = this.stores[x];
if(!_store._web.soddisfa_filtri){
if (this.checkAll(_store)){
_store._web.soddisfa_filtri = true;
}
else {
_store._web.soddisfa_filtri = false;
}
}
}
}else{
for (var z in this.stores){
var __store = this.stores[z];
if (this.checkAll(__store)){
__store._web.soddisfa_filtri = true;
}
else {
__store._web.soddisfa_filtri = false;
}
}
}
//alert("updateAllStoresVisibility");
updateAllStoresVisibility(this.stores);
//alert("updateAllStoresVisibility - after");
for (x in this.categories){
//alert("this.categories " + this.categories[x])
this.categories[x].refresh();
}
}
FilterManager.prototype.checkServizi = function(store){
logger.log('FilterManager.checkServizi');
var selected_services = this.getServiziSelezionati();
if(selected_services.length == 0){
return true;
}else{
for (x in selected_services){
if (! isNaN(x) ){
if (!(this.checkServiceInStore(selected_services[x].value, store.servizi))){
return false;
}
}
}
return true;
}
}
FilterManager.prototype.checkServiceInStore = function(selected_service,store_services) {
var found = false;
for(y in store_services){
if (selected_service == store_services[y].id ){
found = true;
break;
}
}
return found;
}
//RESTYLE
FilterManager.prototype.isActive = function(){
logger.log('FilterManager.isActive');
var selected_services = this.getServiziSelezionati();
logger.log('FilterManager.isActive selected_services.length ' + selected_services.length);
if(selected_services.length != 0){
return true;
}
var selected_cooperative = this.getCooperativaSelezionata();
logger.log('FilterManager.isActive selected_cooperative.length ' + selected_cooperative.length);
if (selected_cooperative.length != 0){
return true;
}
var giorno_sett_sel = this.getGiornoSettimanaSelezionato();
logger.log('FilterManager.isActive giorno_sett_sel ' + giorno_sett_sel);
if(giorno_sett_sel != undefined) {
return true;
}
var apertura_straordinaria = this.getGiornoApertStraordSelezionato();
logger.log('FilterManager.isActive apertura_straordinaria ' + apertura_straordinaria.length);
if (apertura_straordinaria.length != 0){
return true;
}
return false;
}
//RESTYLE applica stato filtri
FilterManager.prototype.applyActiveState = function(){
if (this.isActive()) {
$("#controller-filtri").removeClass("filtri-off");
$("#controller-filtri").addClass("filtri-on");
$("#controller-filtri").attr("rel" , "Filtri attivi");
} else {
$("#controller-filtri").removeClass("filtri-on");
$("#controller-filtri").addClass("filtri-off");
$("#controller-filtri").attr("rel" , "Filtri non attivi");
}
$('.qtip-storelocator').removeData("qtip");
$('.qtip-storelocator').each(function()
{
$(this).qtip({
content: {
text: $(this).attr("rel"), // text to show,
title: {
//text: 'Punti vendita per la provincia : ' + $(this).attr("alt"),
button: true
}
},
show: {
//event: 'click',
solo: true // Only show one tooltip at a time
},
position: {
my: 'left center', // Use the corner...
at: 'right center', // ...and opposite corner
viewport: $(window),
adjust: {
method: "flip",
x: parseInt(20, 10) || 0,
y: parseInt(20, 10) || 0
}
},
style: {
classes: 'ui-tooltip-rounded ui-tooltip-' + 'light ui-qtip-province ui-tooltip-jtools-coop' // ui-tooltip-shadow
//width: true // Set the tooltip width
}
});
});
//END RESTYLE
}
function MarkerCategory(stores, catName, color, hasDetails, catContainer, provinceContainer, provinceHash) {
this.name = catName;
this.hasDetails = hasDetails;
this.container = catContainer;
this.detailContainer = null;
//RESTYLE
this.detailContainerProvince = provinceContainer;
this.province = provinceHash;
this.name = catName;
//RESTYLE
this.detailHeader = null;
this.noResultsMsg = null;
this.noResultsVisibleMsg = null;
this.disabledMsg = null;
this.visible = true;
this.stores = stores;
this.color = color;
this.icon = tinyIcon(color);
this.initialize();
}
MarkerCategory.prototype.initialize = function() {
logger.log('MarkerCategory['+ this.name +'].initialize');
if (this.hasDetails) {
var _this = this;
// init container and messages
this.detailContainer = $('
').appendTo(this.container);
this.detailHeader = $(this.container).children('.bg-marker');
this.noResultsMsg = $(this.container).children('.cat_noResultsMsg');
this.noResultsVisibleMsg = $(this.container).children('.cat_noResultsVisibleMsg').hide();
this.disabledMsg = $(this.container).children('.cat_disabledMsg').hide();
// init toggle-marker
var selector = ('#controller-markers li.bg-marker-'+this.color);
$(selector).css('cursor', 'pointer')
.click(function() {
$(this).toggleClass('bg-marker-disabled');
_this.toggleVisibility();
});
}
}
MarkerCategory.prototype.addResult = function (store) {
$(store._web.dettaglio).appendTo(this.detailContainer);
}
MarkerCategory.prototype.toggleVisibility = function () {
logger.log('MarkerCategory['+ this.name +'].toggleVisibility');
this.visible = !this.visible;
updateAllStoresVisibility(this.stores);
this.refresh();
/*var x, count=0;
for (x in this.stores) {
if (isNaN(x) || this != this.stores[x]._web.categoria) // variabili "agganciate" all'array, da ignorare
continue;
count++;
if (this.visible)
this.stores[x]._web.marker.show();
else {
this.stores[x]._web.marker.closeInfoWindow();
this.stores[x]._web.marker.hide();
}
}
if (count == 0) {
this.show(this.noResultsMsg);
} else {
if (this.visible)
this.show(this.detailContainer);
else
this.show(this.disabledMsg);
}*/
}
MarkerCategory.prototype.show = function (catProperty) {
if (catProperty == undefined || catProperty == null)
return;
if (catProperty == this.detailContainer) {
logger.log('MarkerCategory['+ this.name +'].show: detailContainer');
$(this.container).removeClass('bg-dark');
$(this.detailHeader).removeClass('bg-marker-disabled').find('.bgGrad-red-h24').removeClass('bgGrad-gray-h24');
$(this.detailContainer).show();
$(this.noResultsMsg).hide();
$(this.disabledMsg).hide();
$(this.noResultsVisibleMsg).hide();
} else if (catProperty == this.noResultsMsg) {
logger.log('MarkerCategory['+ this.name +'].show: noResultsMsg');
$(this.container).addClass('bg-dark');
$(this.detailHeader).removeClass('bg-marker-disabled').find('.bgGrad-red-h24').removeClass('bgGrad-gray-h24');
$(this.detailContainer).hide();
$(this.noResultsMsg).show();
$(this.disabledMsg).hide();
$(this.noResultsVisibleMsg).hide();
} else if (catProperty == this.disabledMsg) {
logger.log('MarkerCategory['+ this.name +'].show: disabledMsg');
$(this.container).addClass('bg-dark');
$(this.detailHeader).addClass('bg-marker-disabled').find('.bgGrad-red-h24').addClass('bgGrad-gray-h24');
$(this.detailContainer).hide();
$(this.noResultsMsg).hide();
$(this.disabledMsg).show();
$(this.noResultsVisibleMsg).hide();
} else if (catProperty == this.noResultsVisibleMsg) {
logger.log('MarkerCategory['+ this.name +'].show: noResultsVisibleMsg');
$(this.container).addClass('bg-dark');
$(this.detailHeader).removeClass('bg-marker-disabled').find('.bgGrad-red-h24').removeClass('bgGrad-gray-h24');
$(this.detailContainer).hide();
$(this.noResultsMsg).hide();
$(this.disabledMsg).hide();
$(this.noResultsVisibleMsg).show();
}
}
MarkerCategory.prototype.refresh = function () {
logger.log('MarkerCategory['+ this.name +'].refresh');
var x, store, count=0, count_visibili=0;
//RESTYLE
//aggiorna anche elenco province in base agli store visibili
this.province[this.name] = new Hashtable();
for (x in this.stores) {
store = this.stores[x];
if (this.name == store.categoria.descrizioneWeb) {
count++;
if (isStoreVisibile(store, true)) {
count_visibili++;
//RESTYLE
this.province[this.name].put(store.provinciaDesc, store.provincia);
}
}
}
//alert('MarkerCategory['+ this.name +'].refresh count' + count + " visible " + this.visible + " count_visibili " + count_visibili);
if (this.visible) {
if (count == 0)
this.show(this.noResultsMsg);
else if (count_visibili > 0)
this.show(this.detailContainer);
else
this.show(this.noResultsVisibleMsg);
}else {
this.show(this.disabledMsg);
}
//province
var _this = this;
var i = 0;
var className = "evenRow";
//sort
if (this.province[this.name] != null) {
var provinceSorted = new Array();
var provinceSortedHash = new Hashtable();
this.province[this.name].each(function(key, value){
provinceSorted.push(key);
});
provinceSorted.sort();
for (i=0; i
';
//$("');
var scrollContainer = $('
');
for (var x in stores) {
if (key == stores[x].provincia && cat == stores[x].categoria.descrizioneWeb) {
if (i % 2 == 0)
className = "evenRow"
else
className = "oddRow";
//html += this.stores[x].det;
$(createDetail(stores[x], className, true)).appendTo(divContainer);
i++ ;
}
}
$(divContainer).appendTo(scrollContainer);
return scrollContainer;
//alert($(divContainer).appendTo().html())
//return $(divContainer).appendTo($('
'));
//return '
' + $(divContainer).html() + '
';
//return "getStoreByProvincia : " + key + " store: " + this.stores.lenght;
//html
//var
//$("
" + + "
").appendTo(content);
}
function ResultManager(map, resultContainer) {
this.map = map;
this.container = $(resultContainer);
this.groupedStores = new Array();
this.stores = new Array();
this.categories = new Array();
this.favManager = null;
this.bannerManager = null;
this.showFiltersOnResult = false;
//RESTYLE
this.province = new Array();
this.bounds = new GLatLngBounds();
this.initialize();
}
ResultManager.prototype.initialize = function() {
logger.log('ResultManager.initialize');
// aggregazioni
this.groupedStores[group_PROVINCE] = new Array();
this.groupedStores[group_REGIONI] = new Array();
// categorie
var _this = this;
$('#controller-markers li.bg-marker').each(function(index) {
//var color = icon_colors[index];
//RESTYLE
var color = icon_colors_cat.get($(this).attr("id"));
$(this).addClass('bg-marker-'+color);
var catName = this.id;
var catDescr = $(this).html();
var catContainer = createCategoryBox(catDescr, color, catName);
$(catContainer).appendTo(_this.container);
//RESTYLE passa il riferimetno al solo box di dettaglio
catContainer = $('#cat_' + catName + '_category_box_details');
var provinceContainer = $('#cat_' + catName + '_details_province');
_this.categories[catName] = new MarkerCategory(_this.stores, catName, color, true, catContainer, provinceContainer, _this.province);
});
// favouriteManager
this.favManager = new FavouriteManager(this.stores, $('#preferiti'), $('#preferiti-content'));
var addFavSelectorName = 'storeLocator-add-favourite_';
var removeFavSelectorName = 'storeLocator-remove-favourite_';
/* jQuery live sostituito da listener sull'apertura del tooltip
*$('div.'+ addFavSelectorName).live('click', function(){
var idStore = $(this).attr('id').substring(addFavSelectorName.length);
_this.favManager.addFavourite(idStore);
$(this).hide().siblings('.'+ removeFavSelectorName).show();
});
$('div.'+ removeFavSelectorName).live('click', function(){
var idStore = $(this).attr('id').substring(removeFavSelectorName.length);
_this.favManager.removeFavourite(idStore);
$(this).hide().siblings('.'+ addFavSelectorName).show();
});*/
GEvent.addListener(this.map, 'infowindowopen', function(){
var tooltipContent = _this.map.getInfoWindow().getContentContainers();
$(tooltipContent).find('div.'+ addFavSelectorName).click(function(){
var idStore = $(this).attr('id').substring(addFavSelectorName.length);
_this.favManager.addFavourite(idStore);
$(this).hide().siblings('.'+ removeFavSelectorName).show();
});
$(tooltipContent).find('div.'+ removeFavSelectorName).click(function(){
var idStore = $(this).attr('id').substring(removeFavSelectorName.length);
_this.favManager.removeFavourite(idStore);
$(this).hide().siblings('.'+ addFavSelectorName).show();
});
});
// filterManager
this.filterManager = new FilterManager(this.stores,this.categories);
this.filterManager.applyActiveState();
}
ResultManager.prototype.addGroupResults = function (groups, groupType) {
logger.group('ResultManager.addGroupResults');
logger.dir(groups);
logger.groupEnd();
if (groups == undefined || groupType == undefined)
return;
this.showGroupResults(groupType);
// ciclo sull'aggregazione da presentare in mappa
var _this = this;
var x, group;
this.clearMap();
for (x in groups) {
group = groups[x];
var latlng = new GLatLng(group.latLng.lat, group.latLng.lng);
var icon = labelledIcon(group.numStore, groupType);
var opts = {
"icon": icon,
"clickable": true,
"labelText": group.numStore,
"labelOffset": new GSize(-13, -6)
};
var marker = new LabeledMarker(latlng, opts);
marker._web = new Object();
marker._web.group = group;
GEvent.addListener(marker, "click", function() {
this.openInfoWindowHtml(createGroupInfoWindowHtml(this._web.group, _this.map));
});
_this.map.addOverlay(marker);
group._web = new Object();
group._web.marker = marker;
this.groupedStores[groupType].push(group);
}
}
ResultManager.prototype.showGroupResults = function (groupType) {
this.showFiltersOnResult = false;
this.disableStoreDetail();
for (var x in this.groupedStores) {
for (var x2 in this.groupedStores[x]) {
if (x == groupType)
this.groupedStores[x][x2]._web.marker.show();
else {
this.groupedStores[x][x2]._web.marker.hide();
this.groupedStores[x][x2]._web.marker.closeInfoWindow();
}
}
}
}
ResultManager.prototype.addStoreResults = function (results, fl_preferiti, fl_Cooperativa) {
logger.group('ResultManager.addResults');
logger.dir(results);
logger.groupEnd();
if (results == undefined)
return;
var fl_pref = fl_preferiti || false;
// ripulisco la mappa dagli store fuori dal viewport
this.clearMap();
// abilito i pannelli di dettaglio tranne al primo caricamento degli store preferiti
if (! fl_pref)
this.enableStoreDetail();
// ciclo sugli stores da presentare in mappa
var _this = this;
var x, store, catName;
var uniqueCoopId = null;
var odd = 0;
var className = "oddRow";
var counterCatName = new Array();
var isCooperativa = false;
//RESTYLE
if (fl_Cooperativa != undefined)
isCooperativa = true;
//svuota le precedenti ricerche
//this.province["cat_minimercato"] = new Hashtable();
//this.province["cat_supermercato"] = new Hashtable();
//this.province["cat_ipermercato"] = new Hashtable();
//alert(results.length);
for (x in results) {
store = results[x];
catName = store.categoria.descrizioneWeb;
//restyle
/*gestione class alternate */
if (counterCatName[catName] == undefined)
counterCatName[catName] = 0;
odd = counterCatName[catName];
if (odd % 2 == 0)
className = "evenRow"
else
className = "oddRow";
counterCatName[catName] = counterCatName[catName] + 1 ;
var storeCoopId = store.cooperativa.id
if(x == 0) {
uniqueCoopId = storeCoopId;
} else if(uniqueCoopId != null && uniqueCoopId != storeCoopId) {
uniqueCoopId = null;
}
// verifico che lo store non sia già visualizzato in mappa
if (this.containsStoreId(store.id)) {
logger.log('store già presente: '+ store.ragioneSociale);
continue;
}
// controllo che la categoria sia conosciuta
if (this.categories[catName] == undefined) {
log.error('Categoria '+ catName +' non prevista');
return;
}
store.ragioneSociale = replaceSpecialChars(store.ragioneSociale);
logger.log('aggiungo store: '+ store.ragioneSociale +' ['+ catName +']');
if (store.latLng == null) {
logger.log('attenzione store.latLng = null ');
continue;
}
//RESTYLE
this.bounds.extend(new GLatLng(store.latLng.lat, store.latLng.lng));
var marker = new GMarker(new GLatLng(store.latLng.lat, store.latLng.lng),
{'icon':_this.categories[catName].icon});
marker._web = new Object();
marker._web.store = store;
GEvent.addListener(marker, 'click', function(){
if (isStoreVisibile(this._web.store)) {
this.openInfoWindowHtml(createInfoWindowHtml(this._web.store));
} else
_this.map.setCenter(this.getLatLng());
});
store._web = new Object();
store._web.map = this.map;
store._web.marker = marker;
store._web.categoria = this.categories[catName];
//RESTYLE
//store._web.dettaglio = createDetail(store, this.favManger);
store._web.dettaglio = createDetail(store,className, false, this.favManager, this);
store._web.is_preferito = false;
store._web.dettaglio_preferito = null;
store._web.soddisfa_filtri = false;
//marker.bindInfoWindowHtml(createInfoWindowHtml(store));
this.stores.push(store);
this.categories[catName].addResult(store);
//RESTYLE crea la lista delle province per ogni tipologia
var provincia = new Object();
provincia.sigla = store.provincia;
provincia.descrizione = store.provinciaDesc;
logger.log("provincia.sigla :" + provincia.sigla);
if (this.province[catName] == undefined) {
logger.log("this.province[catName] = new Hashtable(); " + catName);
this.province[catName] = new Hashtable();
}
this.province[catName].put(provincia.descrizione, provincia.sigla)
logger.log("this.province[catName] " + catName + " size : " + this.province[catName].size());
if (fl_pref)
this.favManager.addFavourite(store.id);
this.map.addOverlay(marker);
}
//alert("addStoreResults end");
//print province
//this.province["cat_supermercato"].each(function(key, value){
// logger.log("cat_supermercato key " + key + " value : " + value);
//});
//RESTYLE
//centra su italia di default
if(isCooperativa) {
//alert("addStoreResults setCenter");
//this.map.setCenter(new GLatLng(41.8954, 12.4823), getMinZoomLevel());
//alert("addStoreResults after this.minZoomLevel " + this.minZoomLevel);
// ===== determine the zoom level from the bounds =====
this.map.setZoom(this.map.getBoundsZoomLevel(this.bounds));
// ===== determine the centre from the bounds ======
this.map.setCenter(this.bounds.getCenter());
}
this.bannerManager.notifyNewCoopId(uniqueCoopId);
this.filterManager.refresh();
}
ResultManager.prototype.containsStoreId = function(storeId) {
var x;
for (x in this.stores) {
if (this.stores[x].id == storeId)
return true;
}
return false;
}
ResultManager.prototype.clearMap = function () {
logger.log('ResultManager.clearMap');
if (isCooperativaSearch())
return false;
// ciclo dall'ultimo al primo per evitare che lo splice dell'array mi faccia saltare elementi
for (var x = this.stores.length -1; x >= 0; x--) {
if (! this.stores[x]._web.is_preferito
&& ( this.map.getZoom() < getMinStoreZoomLevel()
|| ! isStoreInBounds(this.stores[x])) ) {
removeStore(this.stores, x);
}
}
}
/*RESTYLE*/
ResultManager.prototype.clearAll = function () {
logger.log('ResultManager.clearAll');
// ciclo dall'ultimo al primo per evitare che lo splice dell'array mi faccia saltare elementi
for (var x = this.stores.length -1; x >= 0; x--) {
removeStore(this.stores, x);
}
}
ResultManager.prototype.enableStoreDetail = function() {
for (var x in this.groupedStores) {
for (var x2 in this.groupedStores[x]) {
this.groupedStores[x][x2]._web.marker.hide();
this.groupedStores[x][x2]._web.marker.closeInfoWindow();
}
}
$('.showOnStoreDetail').show();
$('.hideOnStoreDetail').hide();
if (this.showFiltersOnResult) {
$('#banners-right').addClass('outofpage');
$('#filtri').removeClass('outofpage');
this.showFiltersOnResult = false;
}
}
ResultManager.prototype.disableStoreDetail = function() {
// ripulisco la mappa dai marker degli store
this.clearMap();
// aggiorno la visibilità degli eventuali store preferiti
updateAllStoresVisibility(this.stores);
$('.showOnStoreDetail').hide();
$('.hideOnStoreDetail').show();
//RESTYLE
//$('#filtri').addClass('outofpage');
$('#banners-right').removeClass('outofpage');
this.bannerManager.notifyNewCoopId(null);
}
function StoreLocatorApplication(mapContainer, initCenter, minZoom, isCooperativaFromUrl) {
this.minZoomLevel = getMinZoomLevel();
this.lastLatLng = initCenter;
this.map = null;
this.resultManager = null;
this.bannerManager = null;
this.geocoder = null;
this.streetview = null;
this.directions = null;
this.initialize(mapContainer, isCooperativaFromUrl );
}
StoreLocatorApplication.prototype.initialize = function(mapContainer, isCooperativaFromUrl) {
logger.log('StoreLocatorApplication.initialize');
if (this.map != null)
return;
var _this = this;
this.map = new GMap2(document.getElementById(mapContainer));
// Get the default GMapUIOptions.
var uiOptions = this.map.getDefaultUI();
uiOptions.controls.maptypecontrol = false;
uiOptions.controls.menumaptypecontrol = true;
// Now set the map's UI with the tweaked options.
this.map.setUI(uiOptions);
// Get the list of map types
var mt = this.map.getMapTypes();
// Overwrite the getMinimumResolution() and getMaximumResolution() methods
for (var i=0; i
= getMinStoreZoomLevel()) {
timeoutId = setTimeout(function(){
timeoutId = 0;
_this.loadStores();
}, millisec);
} else {
var groupType;
if (isGroupedZoomLevel(zoom, group_REGIONI))
groupType = group_REGIONI;
else
groupType = group_PROVINCE;
if (_this.resultManager.groupedStores[groupType].length > 0) {
_this.resultManager.showGroupResults(groupType);
} else {
_this.loadGroupedStores(groupType);
}
}
});
GEvent.addListener(this.map, 'movestart', function() {
if (timeoutId != 0) {
clearTimeout(timeoutId);
timeoutId = 0;
}
});
GEvent.addListener(this.map, 'infowindowopen', function() {
var infoWin = _this.map.getInfoWindow();
var strViewLink = $(_this.map.getInfoWindow().getContentContainers()).find('div.strViewLink');
if(strViewLink[0]) {
_this.strView(strViewLink);
}
});
}
StoreLocatorApplication.prototype.strView = function(strViewLink, isStoreDetail) {
var _this = this;
var lat = $(strViewLink).find('div.strview_lat').text();
var lng = $(strViewLink).find('div.strview_lng').text();
//alert("vista : " + $(strViewLink).html());
//RESTYLE
//controllo per tooltip: se è già chiamato in precedenza esce dalla funzione
if ( $(strViewLink).html().toUpperCase() == 'VISTA STRADALE')
return true;
var point = new GLatLng(lat,lng);
if (_this.streetviewPanorama != null) {
_this.streetviewPanorama.remove();
_this.streetviewPanorama = null;
$('#stvPano').empty();
}
_this.streetview.getNearestPanoramaLatLng(point,function(latLng){
if(latLng && (!_this.map.getInfoWindow().isHidden() || isStoreDetail)) {
/*var vista2 = $('Vista 2').click(function(){
var idPanoContainer = "stv_" + new Date().getTime();
var panoContainer = $('');
_this.map.openInfoWindowHtml(point,panoContainer[0], {
onOpenFn: function() {var panorama = new GStreetviewPanorama(panoContainer[0],{latlng:point});}
});
});*/
var vista1 = $('Vista stradale').click(function(){
//var idPanoContainer = "stv_" + new Date().getTime();
//var panoContainer = $('');
//RESTYLE
$('.qtip-dettaglio').qtip('toggle', false);
openStreetviewDialog();
if (_this.streetviewPanorama == null) {
_this.streetviewPanorama = new GStreetviewPanorama($('#stvPano')[0],{latlng:latLng});
GEvent.addListener(_this.streetviewPanorama, "error", function(errorCode){
var error = "Si è verificato un errore.";
if (errorCode == 600) {
error = "Vista stradale non disponibile.";
} else if (errorCode == 603) {
error = "Plugin Flash non disponibile.";
}
//openDialogErrore(error);
$('#stvPano').html(error);
});
}
});
$(strViewLink).empty().append(vista1);
}
if(! latLng) {
$(strViewLink).html('Vista stradale non disponibile');
}
});
}
StoreLocatorApplication.prototype.searchPath = function(fromAddress,toAddress) {
logger.log('StoreLocatorApplication.searchPath from:'+ fromAddress +' to:'+ toAddress);
if (this.directions != null) {
this.map.closeInfoWindow();
this.directions.load(fromAddress, toAddress);
}
}
StoreLocatorApplication.prototype.clearPath = function() {
if (this.directions != null) {
this.directions.clear();
}
}
StoreLocatorApplication.prototype.addressLookUp = function(address, showFilters) {
logger.log('StoreLocatorApplication.addressLookUp:'+ address);
var _this = this;
if (this.geocoder != null) {
if (this.directions != null) {
this.directions.clear();
}
this.geocoder.getLatLng(address, function(point) {
if (!point) {
openDialogErrore("Indirizzo non trovato!");
logger.info('Indirizzo non trovato: '+ address);
} else {
_this.map.setCenter(point, 11);
if (showFilters == true) {
_this.resultManager.showFiltersOnResult = true;
}
}
});
}
}
StoreLocatorApplication.prototype.positionLookUp = function(position) {
logger.log('StoreLoicatorApplication.positionLookUp:'+ position);
var _this = this;
if (this.geocoder != null) {
if (this.directions != null) {
this.directions.clear();
}
_this.map.setCenter(position, 11);
if (showFilters!= "undefined") {
if (showFilters == true)
_this.resultManager.showFiltersOnResult = true;
}
}
}
StoreLocatorApplication.prototype.loadFavouriteStores = function() {
//carica store preferiti dal database se presente cookie
var _this = this;
var preferiti = $.cookie('preferiti');
if(preferiti) {
logger.log('valore del cookie preferiti: '+preferiti);
var tokens = preferiti.split(',');
var ids = new Array();
for(var i in tokens) {
if(!isNaN(i)) {
ids.push(tokens[i]);
}
}
RemoteCoopStoreLocator.getStoresByIds(ids, {
callback:function(stores) {
if (stores == undefined)
return;
_this.resultManager.addStoreResults(stores, true);
},
errorHandler:function(message) {openDialogErrore(message);}
});
} else {
logger.log('cookie preferiti non trovato');
}
}
StoreLocatorApplication.prototype.loadGroupedStores = function(groupType) {
logger.log('StoreLocatorApplication.loadStores');
var _this = this;
if (groupType == group_PROVINCE) {
$('.ajax-loading').show();
RemoteCoopStoreLocator.getProvince({
callback:function(province){
if (province && _this.map.getZoom() < getMinStoreZoomLevel()) {
_this.resultManager.addGroupResults(province, groupType);
}
$('.ajax-loading').hide();
},
errorHandler:function(message) {
$('.ajax-loading').hide();
openDialogErrore(message);
}
});
} else if (groupType == group_REGIONI) {
$('.ajax-loading').show();
RemoteCoopStoreLocator.getRegioni({
callback:function(regioni){
if (regioni && isGroupedZoomLevel(_this.map.getZoom(), groupType)) {
_this.resultManager.addGroupResults(regioni, groupType);
}
$('.ajax-loading').hide();
},
errorHandler:function(message) {
$('.ajax-loading').hide();
openDialogErrore(message);
}
});
}
}
StoreLocatorApplication.prototype.loadStores = function() {
logger.log('StoreLocatorApplication.loadStores');
//RESTYLE
$("#no-result-found").hide();
$('.ajax-loading').show();
this.lastLatLng = this.map.getCenter();
var _this = this;
var params = {
sudOvest: {
lat: this.map.getBounds().getSouthWest().lat(),
lng: this.map.getBounds().getSouthWest().lng()
},
nordEst: {
lat: this.map.getBounds().getNorthEast().lat(),
lng: this.map.getBounds().getNorthEast().lng()
}
}
RemoteCoopStoreLocator.getStores (params,{
callback:function(stores) {
if (stores && _this.map.getZoom() >= getMinStoreZoomLevel()) {
_this.resultManager.addStoreResults(stores);
if (stores.length > 0) {
$(".content-elenco").show();
unBlockEl("#filtri");
$('#intro-image').addClass("outofpage");
} else {
$("#no-result-found").show();
}
}
$('.ajax-loading').hide();
},
errorHandler:function(message) {
$('.ajax-loading').hide();
openDialogErrore(message);
}
});
}
//RESTYLE
StoreLocatorApplication.prototype.loadStoresByCooperativa = function(cooperativa) {
logger.log('StoreLocatorApplication.loadStoresByCooperativa');
$('.ajax-loading').show();
//this.lastLatLng = this.map.getCenter();
var _this = this;
//alert('StoreLocatorApplication.loadStoresByCooperativa ' + _this.resultManager.stores.length);
//svuota le precedenti ricerche
_this.resultManager.province["cat_minimercato"] = new Hashtable();
_this.resultManager.province["cat_supermercato"] = new Hashtable();
_this.resultManager.province["cat_ipermercato"] = new Hashtable();
$("#cat_cat_supermercato_details_province_ajax").html(ajaxLoading);
$("#cat_cat_minimercato_details_province_ajax").html(ajaxLoading);
//province supermercati test
/*
RemoteCoopStoreLocator.getProvinceByCooperativaAndCategoria (cooperativa, 1,{
callback:function(provinciaCooperativa) {
alert(provinciaCooperativa.length)
$('.ajax-loading').hide();
},
errorHandler:function(message) {
$('.ajax-loading').hide();
openDialogErrore(message);
}
});
*/
//DIVISO IN 3 per problemi di performance in produzione
//iper
RemoteCoopStoreLocator.getStoresByCooperativaAndCategoria (cooperativa,3,{
callback:function(stores) {
logger.log("StoreLocatorApplication.loadStoresByCooperativa : " + stores.length);
//alert("StoreLocatorApplication.loadStoresByCooperativa : " + stores.length);
//_this.stores.length = 0;
$('.qtip-province').removeData('qtip');
//_this.resultManager.province = new Array();
//_this.resultManager.stores = new Array();
_this.resultManager.clearAll();
_this.resultManager.bounds = new GLatLngBounds();
//_this.resultManager.;
_this.resultManager.addStoreResults(stores, false, true);
//RESTYLE
if (stores.length > 0) {
$(".content-elenco").show();
if (isCooperativaSearch()) {
$('.content-map').removeClass("on");
$('.content-elenco').addClass("on");
$("#content-map").hide();
$("#content-elenco").show();
$("#controller-markers").hide();
} else {
$("#controller-markers").show();
}
unBlockEl("#filtri");
$('#intro-image').addClass("outofpage");
}
//$('.ajax-loading').hide(); hide in last
},
errorHandler:function(message) {
$('.ajax-loading').hide();
openDialogErrore(message);
}
});
$('.ajax-loading').show();
//super
RemoteCoopStoreLocator.getStoresByCooperativaAndCategoria (cooperativa, 2, {
callback:function(stores) {
logger.log("StoreLocatorApplication.loadStoresByCooperativa super : " + stores.length);
//alert("StoreLocatorApplication.loadStoresByCooperativa super : " + stores.length);
//_this.stores.length = 0;
$('.qtip-province').removeData('qtip');
//_this.resultManager.province = new Array();
//_this.resultManager.stores = new Array();
//_this.resultManager.clearAll(); aggiunge ai precedenti
//_this.resultManager.;
_this.resultManager.addStoreResults(stores, false, true);
//alert( " _this.resultManager.addStoreResults " + _this.resultManager.stores.length);
//RESTYLE
if (stores.length > 0) {
$(".content-elenco").show();
if (isCooperativaSearch()) {
$('.content-map').removeClass("on");
$('.content-elenco').addClass("on");
$("#content-map").hide();
$("#content-elenco").show();
$("#controller-markers").hide();
} else {
$("#controller-markers").show();
}
unBlockEl("#filtri");
$('#intro-image').addClass("outofpage");
}
//$('.ajax-loading').hide(); hide in last
$("#cat_cat_supermercato_details_province_ajax").html("");
},
errorHandler:function(message) {
$('.ajax-loading').hide();
$("#cat_cat_supermercato_details_province_ajax").html("");
openDialogErrore(message);
}
});
//mini
$('.ajax-loading').show();
RemoteCoopStoreLocator.getStoresByCooperativaAndCategoria (cooperativa, 1, {
callback:function(stores) {
logger.log("StoreLocatorApplication.loadStoresByCooperativa mini : " + stores.length);
//_this.stores.length = 0;
$('.qtip-province').removeData('qtip');
//_this.resultManager.province = new Array();
//_this.resultManager.stores = new Array();
//_this.resultManager.clearAll();
//_this.resultManager.;
_this.resultManager.addStoreResults(stores, false, true);
//RESTYLE
if (stores.length > 0) {
$(".content-elenco").show();
if (isCooperativaSearch()) {
$('.content-map').removeClass("on");
$('.content-elenco').addClass("on");
$("#content-map").hide();
$("#content-elenco").show();
$("#controller-markers").hide();
} else {
$("#controller-markers").show();
}
unBlockEl("#filtri");
$('#intro-image').addClass("outofpage");
}
$('.ajax-loading').hide();
$("#cat_cat_minimercato_details_province_ajax").html("");
},
errorHandler:function(message) {
$('.ajax-loading').hide();
$("#cat_cat_minimercato_details_province_ajax").html("");
openDialogErrore(message);
}
});
}
function DirectionsManager(map,opts) {
this.map = map;
this.routeContainer = null;
this.routeContainerToHide = null;
this.gdir = null;
this.initialize(opts);
}
DirectionsManager.prototype.initialize = function(opts) {
var options = opts || {};
if (options.routeContainer)
this.routeContainer = options.routeContainer;
if (options.routeContainerToHide)
this.routeContainerToHide = options.routeContainerToHide;
this.gdir = new GDirections(this.map, this.routeContainer);
this.initListeners();
}
DirectionsManager.prototype.initListeners = function() {
this.initErrorListener();
this.initAddoverlayListener();
}
DirectionsManager.prototype.initErrorListener = function() {
var _this = this;
// === Array for decoding the failure codes ===
/*var reasons = [];
reasons[G_GEO_SUCCESS] = "Success";
reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value.";
reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address.";
reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons.";
reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed.";
reasons[G_GEO_BAD_REQUEST] = "A directions request could not be successfully parsed.";
reasons[G_GEO_MISSING_QUERY] = "No query was specified in the input.";
reasons[G_GEO_UNKNOWN_DIRECTIONS] = "The GDirections object could not compute directions between the points.";
// === catch Directions errors ===
var _this = this;
GEvent.addListener(this.gdir, "error", function() {
var code = _this.gdir.getStatus().code;
if (code == G_GEO_SUCCESS) {
} else {
var reason = "Code "+ code;
if (reasons[code]) {
reason = reasons[code]
}
if (_this.routeContainer)
$(_this.routeContainer).hide();
if (_this.routeContainerToHide)
$(_this.routeContainerToHide).show();
//alert("Failed to obtain directions, "+ reason);
}
});*/
GEvent.addListener(this.gdir, "error", function() {
if (_this.routeContainer)
$(_this.routeContainer).hide();
if (_this.routeContainerToHide)
$(_this.routeContainerToHide).show();
var code = _this.gdir.getStatus().code;
if (code == G_GEO_UNKNOWN_ADDRESS)
openDialogErrore("Uno degli indirizzi specificati non può essere individuato sulla mappa. Ciò potrebbe essere dovuto al fatto che l'indirizzo è relativamente nuovo oppure non è corretto. \nCodice errore: "+ code);
else if (code == G_GEO_SERVER_ERROR)
openDialogErrore("Il percorso richiesto non può momentaneamente essere calcolato.Riprovare più tardi. \n Codice errore: "+ code);
else if (code == G_GEO_BAD_KEY)
openDialogErrore("La Google API key non è valida oppure non coincide con il dominio per il quale è stata rilasciata. \n Codice errore: "+ code);
else if (code == G_GEO_BAD_REQUEST)
openDialogErrore("Il percorso richiesto non può essere calcolato.\n Codice errore: "+ code);
else openDialogErrore("Si è verificato un errore sconosciuto.");
});
}
DirectionsManager.prototype.initAddoverlayListener = function() {
var _this = this;
GEvent.addListener(this.gdir, "addoverlay", function() {
$('#button-clear-path').show();
if (_this.routeContainer)
$(_this.routeContainer).show();
if (_this.routeContainerToHide)
$(_this.routeContainerToHide).hide();
});
}
DirectionsManager.prototype.load = function(fromAddress,toAddress) {
logger.log('DirectionsManager.load from:'+ fromAddress +' to:'+ toAddress);
this.gdir.load("from: " + fromAddress + " to: " + toAddress,{"locale": "it"});
}
DirectionsManager.prototype.gLatLngToAddress = function(gLatLng, locationName) {
var locName = locationName || '';
return locName +'@'+ gLatLng.lat() +','+ gLatLng.lng();
}
DirectionsManager.prototype.clear = function() {
this.gdir.clear();
$('#button-clear-path').hide();
}