PageSourceSearch

https://montagut.com/modules/prestatilldrive/views/js/storelocator.js

js montagut.com collected 2026-10-08 01:33:33 UTC 14,072 bytes, 407 lines download raw bytes

1/*
2 * Prestatill Drive - Click & Collect
3 *
4 * Drive Module & Click & Collect for Prestashop
5 *
6 *  @author    Laurent Baumgartner [email protected]
7 *  @copyright 2017-2020 Prestatill SAS
8 *  @license   Prestatill SAS
9 */
10
11var pdc_address = null;
12
13$(document).ready(function() {
14    
15    // Click sur la géolocalisation
16    $('body').on('click tap', '#store_selector_modal i', function(){
17        _processGeolocation();        
18    });   
19    
20    // Click sur CHANGE SLOT pour changer de créneau
21    $('body').on('click tap', '#store_selector_modal .reserved_slot .changeSlot', function(){
22       
23       //console.log('ON SOUHAITE CHANGER DE CRENEAU');
24       $('body').find('.psd_store_selector').removeClass('active_slot').addClass('active');
25       $('body').find('#store_selector_modal .reservation_ok').removeClass('active');
26       var id_store = $(this).data('id_store');
27       if(id_store > 0)
28       {
29            _createDaysTable(id_store);
30            _hideReservationSlot(true);
31       }
32       
33    });
34    
35    // Click sur SELECT a store 
36    $('body').on('click tap', '#store_selector_modal .store_list button', function(){
37        
38        pdc_address = '';
39        if($(this).hasClass('selectStore'))
40        {
41            var psd_id_store = $(this).data('id_store');
42            
43            
44            $('#store_selector_modal .store_list li').removeClass('active');
45            
46            $(this).parents('li').addClass('active');
47            $(this).removeClass('selectStore');
48        
49            $.ajax({
50                url: $('#ajax_url').val(),
51                action: 'selectStoreFroModal',
52                type: 'json',
53                method: 'post',
54                data: {
55                    action: 'selectStoreFroModal',
56                    id_store: psd_id_store,
57                    },
58            }).done(function(response) {
59                if (response.status == 'success') {
60                    $('body').find('.psd_store_selector').removeClass('active_slot').addClass('active');
61                    $('#store_selector_modal .store_list').html(response.message.tpl);
62                    //$(this).html(response.message.button);
63                    
64                    $('body').find('.psd_store_selector span').html(response.message.infos.substring(0,38)+'...');
65                    $('#store_selector_modal .store_list').slideDown();
66                    $('#store_selector_modal .search_cp').slideUp();
67                    
68                    // On est sur une fiche produit, on inject l'informatino sur la page pour avoir la mise à jour de l'information
69                    if($('body').attr('id') == 'product')
70                    {
71                        _createDaysTable(psd_id_store);
72                        setTimeout(function(){
73                            window.location.reload();
74                        },500);
75                        
76                    }
77                    else if($('#slot_enabled').val() == 1)
78                    {
79                        _createDaysTable(psd_id_store);
80                        // On vide les zones de réservation de créneau
81                        _hideReservationSlot(true);
82                    }
83                    else
84                    {
85                        $('#store_selector_modal .modal-footer .closing').trigger('click');
86                    }
87                } 
88            }).fail(function() {
89                
90            });
91        }
92        else
93        {
94            _changeStoreAndSlot();
95        }
96    });
97    
98    $('body').on('click tap', '#shop_selected .changeStore', function(){
99        _changeStoreOnCarrier();
100    });
101    
102    // Click manuel sur l'icon de localisation
103    $('body').on('click tap', '#localisation-icon', function(){
104        _processGeolocation();
105    });
106    
107    // Click sur le bouton chooseStore d'une fiche produit
108    $('body').on('click tap', '.chooseStore', function(){
109        $('body').find('.psd_store_selector').trigger('click');
110    });
111    
112    // Click sur le bouton de la modal
113    $('body').on('click tap', '.psd_store_selector', function(){
114        
115        _manageModal();
116        
117        if($('#store_selector_modal .store_list li.active').length > 0)
118        {
119            $('#store_selector_modal .search_cp').hide();
120            $('#store_selector_modal .store_list').show();
121        }
122        else if($('#store_selector_modal #localisation-icon').length > 0)
123        {
124            _processGeolocation();
125        }
126        
127        // On vide les zones de réservation de créneau
128        _hideReservationSlot(false);
129        
130        if($('.reserved_slot').length > 0)
131        {
132            if(!$('#store_selector_modal .reservation_ok').hasClass('active'))
133            {
134                // Si on a pas sélectionné de créneau
135                var id_store = $('#store_selector_modal .store_list button').data('id_store');
136                if(id_store > 0)
137                {
138                    _createDaysTable(id_store);
139                    _hideReservationSlot(true);
140                }
141            }
142        }
143        
144        $('#store_selector_modal .search_cp input').focus();
145        
146    });
147    
148    // Click sur recherche de CP
149    $('body').on('click tap', '#store_selector_modal #search_cp_button', function(){
150        
151        // Check si mêmes informations pour éviter de renvoyer pour rien 
152        if(pdc_address == $('#store_selector_modal .search_cp input').val())
153            return;
154
155        pdc_address = $('#store_selector_modal .search_cp input').val();
156        
157        $('#store_selector_modal .store_list li').removeClass('active');
158        
159        if(pdc_address != '' && pdc_address.length >= 3)
160        {
161            $('body').find('#modal_loader').fadeIn();
162            $.ajax({
163                url: $('#ajax_url').val(),
164                action: 'searchCP',
165                type: 'json',
166                method: 'post',
167                data: {
168                    action: 'searchCP',
169                    address: pdc_address,
170                    },
171            }).done(function(response) {
172                if (response.status == 'success') {
173                    $('#store_selector_modal .store_list').html('').html(response.message.tpl);
174                    $('#store_selector_modal .search_cp input').val('');
175                } else {
176                    $('#store_selector_modal .store_list li:first-child').html('').html(response.message.tpl);
177                    $('#store_selector_modal .store_list li:first-child').siblings().slideUp().remove();
178                }
179                
180                // On vide les zones de réservation de créneau
181                _hideReservationSlot(false);
182            
183                $('body').find('#modal_loader').fadeOut();
184                $('#store_selector_modal .store_list').show();
185                $([document.documentElement, document.body]).animate({
186                        
187                    },1000
188                );
189            }).fail(function() {
190                
191            });
192        }
193    });
194    
195    // On gère l'appuie sur ENTER pour lancer la recherche de CP
196    $('body').on('keydown', '#store_selector_modal .search_cp input', function(e){
197        
198        if (e.keyCode == 13) // touche entrée
199        {
200            $('body').find('#store_selector_modal #search_cp_button').trigger('click');
201        }
202    });
203    
204    manageStoreSelectorMenu();
205    
206    $( window ).resize(function() {
207        manageStoreSelectorMenu();
208    });
209    
210    $('body').find('.psd_store_selector').hover(
211        function() {
212            $(this).removeClass('closed');
213        }, function() {
214            $(this).addClass('closed');
215        }
216    );
217    
218    $(window).resize(function() {
219        _manageModal();
220    });
221    
222});
223
224
225// 2.0.0 : Change Store
226function _changeStoreAndSlot()
227{
228    //console.log('on passe ici ?');
229    $('#store_selector_modal .search_cp').slideDown();
230    $('#store_selector_modal .store_list').slideUp();
231    $('#store_selector_modal .search_cp input').focus();
232    $('#store_selector_modal .reservation_ok').hide().removeClass('active');
233    _hideReservationSlot(false);
234    
235    if($('#store_selector_modal #localisation-icon').length > 0)
236    {
237        _processGeolocation();
238    }
239}
240
241function _changeStoreOnCarrier()
242{
243    _filterStoresByCarrier(1);
244    _hideReservationSlot(false);
245    $('body').find('#creneau_day').html('');
246    $('body').find('#creneau_selected').removeClass('alert-success').addClass('alert-warning');
247    $('body').find('#store_selected').html('');
248    $('body').find('#shop_selected').removeClass('alert-success').addClass('alert-warning');
249}
250
251// 2.0.0
252function _hideReservationSlot(show)
253{
254    if(show == false)
255    {
256        $('#table_dispo_head').hide().html('');
257        $('#table_dispo').hide().html('');
258        $('#store_selector_modal .bookInfos').hide();
259        //TEST
260        $('#store_list').hide();
261    }
262    else
263    {
264        $('#table_dispo_head').slideDown();
265        $('#table_dispo').slideDown();
266        $('#store_selector_modal .reservation_ok').slideUp();
267        $('#store_selector_modal .bookInfos').show();
268    }
269    _manageModal();
270}
271
272function _processGeolocation()
273{
274    var options = {
275      enableHighAccuracy: true,
276      timeout: 5000,
277      maximumAge: 0
278    };
279    
280    navigator.geolocation.getCurrentPosition(success, error, options);
281}
282
283// 2.0.0 : manage modal height
284function _manageModal() {
285    
286    //console.log('modal ouverte... on resize');
287    if($('#store_selector_modal').length > 0)
288    {
289        // modal-header + modal-footer + margin-top + margin-bottom = 184
290        var modal_height = parseInt($(window).height()-184);
291        
292        // Responsive 
293        if($(window).width() < 576)
294        {
295            modal_height -= 40;
296        }
297        
298        $('#store_selector_modal .modal-body').css('max-height',modal_height);
299        
300    }    
301}
302
303function success(pos) {
304    
305    $('body').find('#modal_loader').fadeIn();
306    
307    var crd = pos.coords;
308    var lat = crd.latitude;
309    var long = crd.longitude;
310  
311    $.ajax({
312        url: $('#ajax_url').val(),
313        action: 'geolocCustomer',
314        type: 'json',
315        method: 'post',
316        data: {
317            action: 'geolocCustomer',
318            lat: lat,
319            long: long,
320            },
321    }).done(function(response) {
322        if (response.status == 'success') {
323            $('#store_selector_modal .store_list').html('').html(response.message.tpl);
324            $('#store_selector_modal .bookInfos').hide();
325        } else {
326            $('#store_selector_modal .store_list li:first-child').html('').html(response.message.tpl);
327            $('#store_selector_modal .store_list li:first-child').siblings().slideUp().remove();
328            
329            // On vide les zones de réservation de créneau
330            _hideReservationSlot(false);
331        }
332        $('body').find('#modal_loader').fadeOut();
333        $('#store_selector_modal .store_list').slideDown();
334        $([document.documentElement, document.body]).animate({
335                
336            },1000
337        );
338    }).fail(function() {
339        
340    });
341
342  //console.log(`Latitude : ${crd.latitude}`);
343  //console.log(`Longitude : ${crd.longitude}`);
344}
345
346// 2.0.0 : Gestion du menu storeSelector
347function manageStoreSelectorMenu()
348{
349    if($('body').find('.psd_store_selector').hasClass('fixed'))
350        $('body').find('.psd_store_selector').appendTo('body');
351        
352    setTimeout(function(){
353        $('body').find('.psd_store_selector').addClass('closed');
354    },2000);
355    
356}
357
358function _validateSlotReservation()
359{
360    //console.log('ON A CHOISIT UN CRENEAU');
361    
362    var url =  $('#table_dispo').data('url');
363    if($('#ajax_url').val() != undefined)
364    {
365        var url = $('#ajax_url').val();
366    }
367        
368        $('body').find('#modal_loader').fadeIn();
369        $.ajax({
370            url: url,
371            action: 'validateSlotReservation',
372            type: 'json',
373            method: 'post',
374            data: {
375                action: 'validateSlotReservation',
376                },
377        }).done(function(response) {
378            if (response.status == 'success') {
379                $('#store_selector_modal .reserved_slot .reservation_ok').addClass('active').slideDown();
380                $('#store_selector_modal .reserved_slot .reservation_ok span').html(response.message.message_creneau);
381                $('#store_selector_modal .reserved_slot .reservation_ok h4 b').html(response.message.duration);
382                // On ajoute l'information du store sur le bouton de modification de créneau
383                $('body').find('#store_selector_modal .reserved_slot .reservation_ok .changeSlot').data('id_store', response.message.id_store);
384                
385                // On modifie l'affichage de l'information dans le header
386                $('body').find('.psd_store_selector').addClass('active_slot');
387                $('body').find('.psd_store_selector span').html(response.message.message_creneau);
388                
389                // 2.0.2
390                $('body').find('#creneau_selected .changeSlot').data('id_store', response.message.id_store);
391                
392                // On vide les zones de réservation de créneau
393                _hideReservationSlot(false);
394            } else {
395                //$('#store_selector_modal .reserved_slot .reservation_ok').html(response.message.tpl);
396            }
397            $('body').find('#modal_loader').fadeOut();
398        }).fail(function() {
399            
400        });
401}
402
403function error(err) {
404    
405  console.warn('ERREUR (${err.code}): ${err.message}');
406  
407}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.