PageSourceSearch

https://chateaudefesles.com/modules/prestatilldrive/views/js/carrier.js

js chateaudefesles.com collected 2026-10-10 01:36:18 UTC 42,823 bytes, 1,035 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 ADAM & DEV SAS
8*  @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
9*/
10
11var ps_url = $('#psd_base_url').val();
12var nb_colmuns;
13var current_start_column = 2;
14var current_nb_display_column = 7;
15// 3.0.0
16var firstLoading = true;
17
18$(document).ready(function() {
19    $('#active_js').addClass('disabled');
20    $('button[name=processCarrier]').css("display", "block");
21    $('#extra_carrier').css("display", "block");
22    $('#delivery_options_address').css("display", "block");
23    $('#HOOK_PAYMENT').css("display", "block");
24    $('#form > div.order_carrier_content > div.box').css("display", "block");
25    $('.delivery_options_address').css("display", "block");
26    $('button[name=confirmDeliveryOption]').hide();
27    $('#verifyCreneau').appendTo('#js-delivery');
28    $('#nav_buttons').hide();
29    $('#prev_days').addClass('selected');
30    // 1.4.0
31    $('#carrier_message').hide();
32    $('#store_list, #map').hide();
33    // 2.0.0
34    $('#store_selector_modal').appendTo('body');
35    
36    setTimeout(function(){
37        _hideOrShow();
38       	if($('#checkout-payment-step').hasClass('-current'))
39       	{
40       	    // FIX NO CARRIER : 1.3.1
41            if($('body').find('#creneau_selected #creneau_day').text().trim() == '') { 
42                $('#creneau_selected').hide(); 
43            }
44        }	
45   	
46    }, 500);
47   
48    // 1.4.0 : Ajout d'informations sur les produits du panier
49    if($('body').attr('id') == 'cart')
50    {
51        $('.carriers_list').each(function(){
52            
53            $(this).appendTo($(this).parents('li'));
54        });
55        setTimeout(function(){
56            $('.carriers_list').slideDown();
57        }, 100)
58    }
59   
60    // On recharge la page si elle reste affichée plus de 10 minutes pour éviter que le créneau ne devienne obsolète si on reste sur la page
61    refresh(600);
62    
63    $('.delivery-option input[type=radio]:checked').parents('.delivery-option').next().append($('#table_box'));
64    
65    $('#checkout-payment-step').on('click tap', function(e){
66    	if($(this).hasClass('no_slot_checked'))
67    	{
68    		$('#checkout-delivery-step span.step-edit').trigger('click');
69    	}
70    });
71    
72    // On est au niveau du checkout : click sur le bouton "choisir"
73    $('body').on('click tap', '#store_list .clickable button', function() {
74    	if(!$(this).parents('.clickable').hasClass('not_allowed'))
75    	{
76    		$('#store_list li.clickable').removeClass('active_store');
77	        $(this).parents('.clickable').addClass('active_store');
78	        var id_store = $(this).parents('.clickable').data('id_store');
79	        _selectStore(id_store);
80    	}
81    });
82
83    // On est au niveau du checkout : click sur la div du store
84    $('body').on('click tap', '#store_list .clickable', function() {
85        //console.log('on click sur la div au niveau du checkout');
86    	if($(this).hasClass('active_store') == false && !$(this).hasClass('not_allowed'))
87    	{
88    		let store_list = $(this);
89            let lat = $(this).data('lat');
90            let long = $(this).data('long');
91
92            $('#store_list li.clickable').removeClass('active_store');
93	        $(this).addClass('active_store');
94
95            if($('#map').length > 0)
96            {
97                if(firstLoading && map === undefined)
98                {
99                    _initMap();
100                    firstLoading = false;
101                }
102                _checkMap(store_list, lat, long);
103            }
104    	}
105    });
106
107    // 3.0.0 Click on MAP
108    $('body').on('click tap', '#map .selectStore', function() {
109	        var id_store = $(this).data('id_store');
110	        _selectStore(id_store);
111
112            // 3.0.0
113            map.closePopup();
114
115            $('#store_selector_modal .close').trigger('click');
116    });
117    
118    // 1.4.0 : Check si on a au moins un transporteur commun
119    if($('#checkout-delivery-step').hasClass('-current') || $('#checkout-delivery-step').hasClass('js-current-step'))
120    {
121        // Si on a aucun transporteur de disponible, on supprime tout et on affiche le message
122        if($('#common_carriers').length == 1 && $('#common_carriers').val() == 0)
123        {
124            $('.delivery-options-list').hide().remove();
125            $('#carrier_message').fadeIn();
126        }
127        // On vérifie également s'il y a un transporteur éligible
128        else {
129            $('.delivery-option input[type=radio]:checked').parents('.delivery-option').next().append($('#table_box'));
130            setTimeout(function(){
131                _filterStoresByCarrier(0);
132                _hideOrShow();
133                //console.log(_checkStoresCarrier());
134                if (_checkStoresCarrier() == 0) {
135                    _reInitStore();
136                }
137            }, 500);
138        }
139    }
140    
141    // 1.4.0 : test
142    $('#cart').on('click tap', '.cart-item .qty', function() {
143        //console.log('qty');    
144    
145    });
146    
147    $('#cart').on('click tap', '.remove-from-cart', function(){
148        //console.log('delete');
149    });
150
151    $('body').on('click tap', '.psdrive.modal-backdrop, .modal-content .close', function() {
152        $('#modal_creneau, #modal, .psdrive.modal-backdrop').removeClass('in').addClass('out').hide();
153    });    
154       
155    $('body').on('click tap', '#list_creneau.viewList td span', function(){
156    	if($(this).hasClass('disabled') == false)
157    	{
158    		$('#list_creneau.viewList td span').removeClass('active');
159	    	$(this).addClass('active');
160	    	$('#table_creneau tr td span').hide();
161	    	var the_day = $(this).data('date');
162	    	$('#table_creneau tr td span[data-date="'+the_day+'"].dispo').fadeIn(250).css('display','inline-block');
163	    	$('#table_creneau tr td span[data-date="'+the_day+'"].red').fadeIn(250).css('display','inline-block');
164            $('#table_creneau').scrollTop(0);
165    	}
166    });
167    
168    $('body').on('click tap', '#table_creneau td.dispo', function() {
169        $('#table_creneau td').removeClass('selected');
170        $('#table_dispo_overlay').fadeIn();
171        $(this).addClass('selected');
172        $('#table_box').attr('data-creneau', '1');
173        $.ajax({
174            url: $('#table_dispo').data('url'),
175            action: 'assignSlot',
176            type: 'json',
177            method: 'post',
178            data: {
179            	slot: $(this).data(),
180            	action: 'assignSlot',
181            	},
182        }).done(function(response) {
183            if (response.success == true) {
184                $('#creneau_day').html(response.msg);
185                $('#creneau_selected').removeClass('alert-warning').addClass('alert-success');
186                $('#table_legend, #nav_buttons').hide();
187                $('#table_dispo_overlay').hide();
188                // 2.0.0 : On valide la réservation côté front
189                _validateSlotReservation();
190               
191            } else {
192                //alert('error');
193            }
194            if($('#creneau_selected').length > 0)
195                {
196                // 2.1.0
197                $('body').find('#creneau_valid').slideUp();
198            }
199        }).fail(function() {
200            //alert('An error has occured, please check your HTTPS parameters on Prestashop Back-office');
201        });
202    });
203    
204    $('body').on('click tap', '#table_creneau span.dispo', function() {
205        $('#table_creneau span').removeClass('selected');
206        $(this).addClass('selected');
207        $('#table_box').attr('data-creneau', '1');
208        $.ajax({
209            url: $('#table_dispo').data('url'),
210            action: 'assignSlot',
211            type: 'json',
212            method: 'post',
213            data: {
214            	slot: $(this).data(),
215            	action: 'assignSlot',
216            	}, 
217        }).done(function(response) {
218            if (response.success == true) {
219                $('#creneau_day').html(response.msg);
220                $('#creneau_selected').removeClass('alert-warning').addClass('alert-success');
221                
222                // 2.0.0 : On valide la réservation côté front
223                _validateSlotReservation();
224                
225                if($('#creneau_selected').length > 0)
226                {
227                    // 2.1.0
228                    $('body').find('#creneau_valid').slideUp();
229                }
230               
231            } else {
232                //alert('error');
233            }
234        }).fail(function() {
235            //alert('An error has occured, please check your HTTPS parameters on Prestashop Back-office');
236        });
237    });
238    
239    // 1.2.6
240    $('body').on('click tap', '#checkout-delivery-step h1', function() {
241        $('.delivery-option input[type=radio]:checked').trigger('click');
242    });
243    
244    /*
245     * IE FIX !
246     */
247    if (!String.prototype.padStart) {
248	    String.prototype.padStart = function padStart(targetLength,padString) {
249	        targetLength = targetLength>>0; //truncate if number or convert non-number to 0;
250	        padString = String((typeof padString !== 'undefined' ? padString : ' '));
251	        if (this.length > targetLength) {
252	            return String(this);
253	        }
254	        else {
255	            targetLength = targetLength-this.length;
256	            if (targetLength > padString.length) {
257	                padString += padString.repeat(targetLength/padString.length); //append to original to ensure we are longer than needed
258	            }
259	            return padString.slice(0,targetLength) + String(this);
260	        }
261	    };
262	}
263    
264    $('#verifyCreneau').on('click tap', function(e) {
265        var creneau = $('#table_box').attr('data-creneau');
266        var msg_error = null;
267        
268        if (_checkStoresCarrier() > 0) {
269            if ($('#table_box').attr('data-creneau') == 0 && ($('#store_list li.active_store').length == 0 && $('body').find('#shop_selected').hasClass('alert-warning'))) {
270                msg_error = $('#choose_store_msg').text(); 
271                $('#modal_creneau.modal').addClass('in').show().find('.js-modal-content').html(msg_error);
272                $('body').append('<div class="psdrive modal-backdrop in fade"></div>');
273                e.preventDefault();
274            } else if ($('#store_list li.active_store').length == 0 && $('body').find('#shop_selected').hasClass('alert-warning')) {
275                msg_error = $('#choose_store_msg').text();
276                $('#modal_creneau.modal').addClass('in').show().find('.js-modal-content').html(msg_error);
277                $('body').append('<div class="psdrive modal-backdrop in fade"></div>');
278                e.preventDefault();
279            } else if ($('#table_box').attr('data-creneau') == 0) {
280                msg_error = $('#choose_slot_msg').text();
281                $('#modal_creneau.modal').addClass('in').show().find('.js-modal-content').html(msg_error);
282                $('body').append('<div class="psdrive modal-backdrop in fade"></div>');
283                e.preventDefault();
284            } else {
285                e.preventDefault();
286		    	$.ajax({
287		            url: $('#table_dispo').data('url'),
288		            action: 'processCarrier',
289		            type: 'json',
290		            method: 'post',
291		            data: {
292		                action: 'processCarrier',
293		            },
294		            success: function(data) {
295
296		                if (data.status == 'success') {
297		                    if (data.message.success == false) {
298		                       $('#modal_creneau').addClass('in').show().find('.js-modal-content').html($('#error_slot_msg').text());
299		                       $('body').append('<div class="psdrive modal-backdrop in fade"></div>');
300		                       //_createDaysTable();
301		                    } else {
302		                       $('button[name=confirmDeliveryOption]').click();
303		                    }
304		                } else {
305		                    //alert(data.message);
306		                }
307		            }
308		        });
309            }
310        }
311    });
312    
313    $('body').find('#next_days').on('click tap', function() {
314        current_start_column = Math.min(current_start_column + current_nb_display_column, nb_colmuns - current_nb_display_column + 2);
315        diplayOrHideColumns(current_start_column, current_nb_display_column, nb_colmuns);
316        if(parseInt(current_start_column+current_nb_display_column) >= nb_colmuns)
317            $('#next_days').addClass('selected');
318            
319        $('body').find('#prev_days').removeClass('selected');
320    });
321    
322    $('body').find('#prev_days').on('click tap', function() {
323        current_start_column = Math.max(2, current_start_column - current_nb_display_column);
324        diplayOrHideColumns(current_start_column, current_nb_display_column, nb_colmuns);
325        if(current_start_column <= current_nb_display_column)
326            $('#prev_days').addClass('selected');
327            
328        $('body').find('#next_days').removeClass('selected');
329    });
330    
331    /*
332     * On click on delivery option when drive carrier not checked on loading
333     */
334    $('body').on('click tap', '.delivery-option input[type=radio]', function(e) {
335            $('.delivery-option input[type=radio]:checked').parents('.delivery-option').next().append($('#table_box'));
336            //1.4.0 : check of stores <> carriers
337            //console.log('select_carrier');
338            _filterStoresByCarrier(0);
339            _hideOrShow();
340            //console.log(_checkStoresCarrier());
341            if (_checkStoresCarrier() == 0) {
342                _reInitStore();
343            }
344    });
345    
346    //2.0.0 : Change Slot pour changer de créneau
347    $('body').on('click tap', '#creneau_selected .changeSlot', function(){
348       
349       //console.log('ON SOUHAITE CHANGER DE CRENEAU');
350       var id_store = $(this).data('id_store');
351       if(id_store > 0)
352       {
353            _hideReservationSlot(true);
354            _createDaysTable(id_store);
355            $('body').find('#creneau_day').html('');
356            $('body').find('#creneau_selected').removeClass('alert-success').addClass('alert-warning');
357            $('body').find('#store_list, #map').hide();
358       }
359       
360    });
361    
362    //2.0.0 : Change Slot pour changer de magasin
363    $('body').on('click tap', '#shop_selected .changeStore', function(){
364       _changeStoreAndSlot();
365    });
366    
367    if (_checkStoresCarrier() > 0) {
368        if(($.trim($('#checkout-payment-step #creneau_day').text()) == ''))
369        {
370            if(parseInt($('#slot_disabled').val()) != 1 || (parseInt($('#slot_disabled').val()) == 1 && $('#store_selected').length == 0))
371            {
372                $('#checkout-delivery-step span.step-edit').trigger('click');
373                $('#checkout-payment-step').addClass('no_slot_checked');
374                if($('.delivery-option').length > 0) {
375                    //1.4.0 : check of stores <> carriers
376                    //_filterStoresByCarrier(0);
377                    //_reInitStore();
378                }
379            }
380        }
381    }
382});
383
384
385function diplayOrHideColumns(current_start_column, current_nb_display_column, nb_colmuns) {
386    for (var i = 2; i <= nb_colmuns + 1; i++) {
387        if (i < current_start_column || i >= current_start_column + current_nb_display_column) {
388            $('#table_creneau tr td:nth-child(' + i + ')').hide();
389        } else {
390            $('#table_creneau tr td:nth-child(' + i + ')').show();
391        }
392    }
393}
394
395function _createDaysTable(id_store) {
396    //console.log('initTable');
397    $('#table_dispo_overlay').fadeIn();
398    if (_checkStoresCarrier() > 0) {
399        $.ajax({
400            url: $('#table_dispo').data('url'),
401            action: 'initTable',
402            type: 'json',
403            method: 'post',
404            data: {
405                action: 'initTable',
406                id_store: id_store,
407                init_bo: 0,
408            },
409            success: function(data) {
410                if (data.status == 'success') {
411                    
412                    // On affiche en fonction du mode d'affichage retenu
413                    if(data.message.display_table == 1 || data.message.table_days.increment == 0)
414                    {
415                        _viewList(data.message.table_days);
416                    } 
417                    else
418                    {
419                        _viewTable(data.message.table_days);
420                        nb_colmuns = data.message.table_days.nb_days_view;
421                        diplayOrHideColumns(current_start_column, current_nb_display_column, nb_colmuns);
422                        changeclass(data.message.table_days);
423                        carrence(data.message.table_days);
424                        disabledButtonsDays();
425                        reserved(data.message.table_days);
426                        vacation(data.message.table_days);
427                        _adjustTableDisplay();
428                    }
429                    
430                    // On affiche en fonction du mode d'affichage retenu
431                    if(data.message.display_table == 1 || data.message.table_days.increment == 0)
432                    {
433                        changeclass(data.message.table_days);
434                        adjustListDisplay(data.message.table_days, data.message.hide_empty_days);
435                        
436                        // 2.0.2
437                        var size = $('body').find('#list_creneau td').length;
438                        //$('body').find('#list_creneau').width(size*220+'px');
439                        
440                        $('#table_legend, #nav_buttons').hide().remove();
441                        reserved(data.message.table_days);
442                        vacation(data.message.table_days);
443                        
444                        _adjustScrollDisplay();
445                    }
446                    else {
447                        var nbr_days = Object.keys(data.message.table_days.days).length;
448                        if(nbr_days > 7)
449                        {
450                            $('#nav_buttons').show();  
451                        }
452                        else
453                        {
454                            $('#nav_buttons').hide().remove();
455                        } 
456                    }
457                    
458                    if(data.message.creneau != null) {
459                        $('#creneau_day').html(data.message.creneau);
460                        var creneau = data.message.creneau;
461                        var infos = creneau.split(" ");
462                        $('#table_dispo td[data-date="'+infos[0]+' '+infos[1]+' '+infos[2]+'"][data-hour="'+infos[4]+'"]').addClass('selected');
463                        $('#table_box').attr('data-creneau', '1');
464                    }
465
466                    if($('body').attr('id') == 'checkout')
467                    {
468                        if(data.message.display_table == 1)
469                        {
470                            //1.2.1
471                            if($('body').find('#creneau_valid').hasClass('active'))
472                            {
473                                $([document.documentElement, document.body]).animate({
474                                    scrollTop: $('#creneau_valid').offset().top-15
475                                },1000);
476                            }
477                            else
478                            {
479                                $([document.documentElement, document.body]).animate({
480                                    scrollTop: $('#table_box').offset().top-10
481                                },1000);
482                            }
483                            
484                            
485                        }
486                        else
487                        {
488                            //1.2.2
489                            $([document.documentElement, document.body]).animate({
490                                scrollTop: $('#table_box').offset().top-10
491                            },1000);
492                        }
493                    }
494                    
495                    // 2.2.0 : Si aucun créneau disponible on affiche le message, sinon on le masque
496                    //$('#no_slot_available').appendTo('#table_dispo tbody tr td');
497                    if($('#table_dispo .dispo').length == 0)
498                    {
499                        $('#no_slot_available').slideDown();
500                    }
501                    else
502                    {
503                        $('#no_slot_available').slideUp();
504                    }
505
506                } else {
507                    //alert(data.message);
508                }
509                
510                setTimeout(function(){
511                    //console.log('trigger');
512                    $('#table_dispo_overlay').fadeOut();
513                    _adjustScrollDisplay();
514                },500);
515            }
516        });
517    }
518    _hideOrShow();
519}
520
521function _adjustTableDisplay()
522{
523    // Adjut Table Display 
524    $('body').find('#table_creneau tbody tr').each(function(){
525        if($(this).children('td.dispo').length == 0)
526        {
527            $(this).css('height','1px').css('padding','0');
528            $(this).find('td').css('height','1px').css('padding','0');
529            $(this).find('td').text('');
530        }
531    });
532}
533
534function _viewStore(message) {
535    
536    var store = message.store;
537    var id_lang = message.id_lang;
538    if(message.store != undefined) {
539        var html = '';
540        html += '<div id="store_selected">';
541        html += '<input type="hidden" name="valueIdStore" value="' + store.id + '"/>';
542        if (id_lang > 0) {
543            html += '<span>' + store.name[id_lang] + '<br/>' + store.address1[id_lang] + '<br/>';
544            if(store.address2[id_lang] != '')
545                html += store.address2[id_lang] + '<br/>';
546        }
547        else
548        {
549            html += '<span>' + store.name + '<br/>' + store.address1 + '<br/>';
550            if(store.address2 != '')
551                html += store.address2 + '<br/>';
552        }
553        html += store.postcode + ' ' + store.city + '<br/>';
554        if (message.phone) {
555            html += store.phone + '<br/>';
556        }
557        html += '</span>';
558        html += '</div>';
559        $('#shop').html(html);
560    }
561    else {
562        $('#shop').html('');
563        $('#store_list li.clickable').removeClass('active_store');
564    }
565    
566    if($('#store_selector_active').length == 0)
567    {
568        if($('body').find('#store_list .clickable').length == 1 && !$(this).hasClass('not_allowed')) {
569            setTimeout(function(){
570                //console.log('trigger');
571                //$('body').find('#store_list .clickable button').trigger('click');
572            },500);
573        }
574    }
575}
576
577function _hideOrShow() {
578    if (_checkStoresCarrier() > 0) {
579        $('#shop_selected, #creneau_selected, #store_list, #map, #table_creneau, #verifyCreneau, #table_dispo').show();
580        $('#table_box').slideDown();
581        $('button[name=confirmDeliveryOption]').hide();     
582    } else {
583       $('#shop_selected, #creneau_selected, #store_list, #map, #table_creneau, #table_box, #table_dispo, #verifyCreneau').hide();
584       
585       if(_checkStoresCarrier() > 0) {
586            $('button[name=confirmDeliveryOption]').hide();
587       }
588       else 
589       {
590            if($('body').find('#HDverifyCreneau').css('display') == 'none' || $('body').find('#HDverifyCreneau').css('display') == undefined)
591                $('button[name=confirmDeliveryOption]').show();
592       }
593   }
594   //$('#table_dispo_overlay').hide();
595}
596
597// 1.4.0 : check stores <> carrier
598function _checkStoresCarrier()
599{
600    var count_stores = 0;
601    if($('input[data-id_store]').length > 0)
602    {
603        $('input[data-id_store]').each(function(){
604            if($('.delivery-option input[type=radio]:checked').val() == $(this).val() + "," 
605            || $('.delivery-option input[type=radio]:checked').val() == $(this).val())
606            {
607                count_stores++;
608            }
609        });
610    }
611    
612    // 2.0.0
613    if($('#store_selector_modal .store_list li.active').length == 1)
614    {
615        count_stores++;
616    }
617    
618    return count_stores;
619}
620
621function _reInitStore() {
622    //$('#table_dispo_overlay').fadeIn();
623    $.ajax({
624        url: $('#table_dispo').data('url'),
625        action: 'reInitStore',
626        type: 'json',
627        method: 'post',
628        data: {
629            action: 'reInitStore',
630        },
631        success: function(data) {
632            if (data.status == 'success') {
633                //_viewStore(data.message.store);
634                $('#creneau_day').html('');
635                $('#table_box').attr('data-creneau', '0');
636                $('#store_list li.clickable').removeClass('active_store');
637                $('#table_creneau').remove();
638                $('#creneau_selected').removeClass('alert-success').addClass('alert-warning');
639                $('#shop_selected').removeClass('alert-success').addClass('alert-warning');
640                $('#table_dispo_overlay').hide();
641                $('#table_dispo_head').hide();
642                $('#table_legend, #nav_buttons').hide();
643                //_filterStoresByCarrier(0);
644
645            } else {
646                //alert(data.message);
647            }
648        }
649    });
650}
651
652function _filterStoresByCarrier(force)
653{
654    //$('#table_dispo_overlay').fadeIn();
655    $('#store_list, #map').hide();
656    $.ajax({
657        url: $('#table_dispo').data('url'),
658        action: 'filterStoresByCarrier',
659        type: 'json',
660        method: 'post',
661        data: {
662            action: 'filterStoresByCarrier',
663            id_carrier: $('.delivery-option input[type=radio]:checked').val(),
664            force: force,
665        },
666        success: function(data) {
667            if (data.status == 'success') {
668                // 2.0.0
669                //console.log('rechargement forcé ? : ' + force);
670                if(data.message.id_store != null && force == false)
671                {
672                    _selectStore(data.message.id_store);
673                    $('#store_list').html('').slideUp();
674                    $('#map').slideUp();
675                }
676                else
677                {
678                    var stores = data.message.tpl;
679                    $('#store_list').html(stores);
680                    
681                    if($('#store_selector_active').length == 0)
682                    {
683                        if($('body').find('#store_list .clickable').length == 1 && !$(this).hasClass('not_allowed') && !$('body').find('#store_list .clickable').hasClass('active_store')) {
684                            setTimeout(function(){
685                                $('body').find('#store_list .clickable button').trigger('click');
686                            },500);
687                        }
688                    }
689                    else
690                    {
691                        // 2.1.0 : si on change de carrier, on ne peut pas aller plus loin sans sélection
692                        $('#table_box').attr('data-creneau', '0');
693                    }
694                    $('body').find('#creneau_selected, #table_dispo_head, #table_dispo, #shop_selected, #hd_legend, #nav_buttons, #table_legend').hide(); 
695                    $('#choose_store_msg').show();
696                    $('#store_list, #map').slideDown();
697                    // 3.0.0
698                    if($('#map').length > 0)
699                    {
700                        if(firstLoading && map === undefined)
701                        {
702                            _initMap();
703                            firstLoading = false;
704                        }
705                        let store_list = $('#store_list .clickable');
706                        _checkMap(store_list, null, null);
707                    }
708                }
709                
710                // 2.0.2
711                //console.log(data.message.nbr_stores);
712                $('body').find('#nbr_stores').val(data.message.nbr_stores);
713            } else {
714               // alert(data.message);
715            }
716        }
717    });
718}
719
720function _selectStore(id_store) { /*$('.delivery_option_radio:checked').parents('table').parent().append($('#table_box'));*/
721    $('#table_dispo_overlay').fadeIn();
722    $.ajax({
723        url: $('#table_dispo').data('url'),
724        action: 'assignStore',
725        type: 'json',
726        method: 'post',
727        data: {
728            action: 'assignStore',
729            store: id_store,
730            id_carrier: $('#id_carrier').val(),
731        },
732        success: function(data) {
733            
734            if (data.status == 'success') {
735                _viewStore(data.message);
736                
737                if(data.message.slot_enabled == 1)
738                {
739                    if(data.message.msg != null && id_store == data.message.store.id && data.message.crenau_valid == true)
740                    {
741                        $('body').find('#creneau_day').html(data.message.msg);
742                        $('body').find('#creneau_selected').removeClass('alert-warning').addClass('alert-success');
743                        $('#table_box').attr('data-creneau', '1');
744                        _hideOrShow();
745                        $('body').find('#table_dispo_head, #table_dispo, #table_legend, #nav_buttons, #store_list, #map').hide();
746                        $('#table_dispo_overlay').hide();
747                        //$('body').find('#creneau_selected button.changeSlot').data('id_store', id_store);
748                    }
749                    else
750                    {
751                        if(data.message.crenau_valid == false)
752                        {
753                            $('body').find('#creneau_valid').addClass('active').show();
754                        }
755                        _createDaysTable(id_store);
756                        $('#creneau_selected').removeClass('alert-success').addClass('alert-warning');
757                        $('#creneau_day').html('');
758                        $('#table_box').attr('data-creneau', '0');
759                        $('#table_dispo_head').show();
760                        $('#table_legend, #nav_buttons').show();
761                    }
762                    $('body').find('#store_list, #map').hide();
763                    
764                    //2.0.1
765                    if($('body').find('#nbr_stores').val() == 1)
766                    {
767                        $('body').find('#shop_selected button').hide();
768                    }
769                    else
770                    {
771                        $('body').find('#shop_selected button').show();
772                    }
773                }
774                else
775                {
776                    $('#table_dispo_overlay').hide();
777                    $('#table_legend, #nav_buttons').hide().remove();
778                    $('#creneau_selected').remove();
779                    $('#creneau_day').html(-1);
780                    $('#table_box').attr('data-creneau', -1);
781                    $('button[name=confirmDeliveryOption]').show();
782                    $('#checkout-payment-step').removeClass('no_slot_checked');
783                }
784                if(id_store > 0) {
785                    $('#choose_store_msg').hide();
786                    $('#min_amount_to_order').hide();
787                    $('#shop_selected').removeClass('alert-warning').addClass('alert-success');
788                    $('#shop_selected').slideDown();
789                    $('body').find('#store_list, #map').hide();
790                }
791                
792            } else {
793                //alert(data.message);
794            }
795        }
796    });
797}
798
799
800function disabledButtonsDays() {
801    var date = new Date();
802    var date_today = $.format.date(date, "E d MMM");
803    $('#prev_days, #next_days').removeClass('disabled');
804    if ($('#table_creneau > thead > tr > td:nth-child(2)').html() == date_today) {
805        $('#prev_days').addClass('disabled');
806    }
807}
808
809function _viewTable(message) {
810    var html = '';
811    html += '<table id="table_creneau" class="col-sm-12"><thead>';
812    html += '<td></td>';
813    var size = Object.keys(message.days).length;
814    for (var i = 1; i <= size; i++) {
815        html += '<td>' + message.days[i].day + '</td>';
816    }
817    html += '</thead>';
818    var sizeh = Object.keys(message.creneau).length;
819    for (var h = 0; h < sizeh - 1; h++) {
820        html += '<tr><td>' + $.format.date("0000-00-00 " + message.creneau[h] + "", "H:mm") + ' - ' + $.format.date("0000-00-00 " + message.creneau[h + 1] + "", "H:mm") + '</td>';
821        for (var i = 1; i <= size; i++) {
822            var additional_class = 'indispo';
823            html += '<td class="creneau ' + additional_class + '" data-id-day="' + message.days[i].id_day + '" data-datetime="' + message.days[i].dateen + ' ' + message.creneau[h] + '" data-hour="' + message.creneau[h] + '" data-date="' + message.days[i].date + '" data-hour_end="00:00:00"></td>';
824        }
825        html += '</tr>';
826    }
827    html += '</table>';
828    html += '<div class="clear"></div>';
829        
830    $('#table_dispo').html(html);
831}
832
833function _viewList(message) {
834    
835    if($.format != undefined)
836    {
837        var html = '';
838        var size = Object.keys(message.days).length;
839
840        html += '<table id="list_creneau" data-size="'+parseInt(size)+'" class="col-sm-12 viewList"><thead>';
841        for (var i = 1; i <= size; i++) {
842            html += '<td><span data-date="' + $.format.date("" + message.days[i].dateen, "d MMM yyyy") + '">' + message.days[i].day + '</span></td>';
843        }
844        html += '</thead>';
845        html += '</table>';
846        
847        $('#table_dispo_head').html(html);
848        
849        html = '<table id="table_creneau" data-size="'+parseInt(size)+'" class="viewList">';
850        
851        var sizeh = Object.keys(message.creneau).length;
852        html +='<tr><td>';
853
854        // UPDATE 2.3.0
855        if(message.increment > 0)
856        {
857            for (var h = 0; h < sizeh - 1; h++) {
858                for (var i = 1; i <= size; i++) {
859                    var additional_class = 'indispo';
860                    html += '<span class="creneau ' + additional_class + '" data-date="'+message.days[i].dateen+'" data-id-day="' + message.days[i].id_day + '" data-datetime="' + message.days[i].dateen + ' ' + message.creneau[h] + '" data-hour="' + message.creneau[h] + '" data-date="' + message.days[i].date + '"  data-hour_end="00:00:00">';
861                    html += '' + $.format.date("0000-00-00 " + message.creneau[h] + "", "H:mm") + ' - ' + $.format.date("0000-00-00 " + message.creneau[h + 1] + "", "H:mm") + '</span>';
862                }
863            
864            }
865        }
866        else
867        {
868            for (var i = 1; i <= size; i++) {
869                    
870                // on est dans le cadre des CP
871                if(message.days[i].op.length > 0)
872                {
873                    message.days[i].op = message.days[i].op.sort();
874                    message.days[i].cl = message.days[i].cl.sort();
875                    for(var j = 0; j < message.days[i].op.length; j++)
876                    {
877                        var additional_class = 'indispo';
878                        html += '<span class="creneau ' + additional_class + '" data-date="'+message.days[i].dateen+'" data-id-day="' + message.days[i].id_day + '" data-datetime="' + message.days[i].dateen + ' ' + message.days[i].op[j] + ':00" data-hour="' + message.days[i].op[j] + ':00" data-hour_end="' + message.days[i].cl[j] + ':00" data-date="' + message.days[i].date + '" >';
879                        //html += '' + $.format.date("0000-00-00 " + message.days[i].dateen + "", "H:mm") + ' - ' + $.format.date("0000-00-00 " + message.creneau[h + 1] + "", "H:mm") + '</span>';
880                        html += '' + $.format.date("0000-00-00 " + message.days[i].op[j] + ":00", "H:mm") + ' - ' + $.format.date("0000-00-00 " + message.days[i].cl[j] + ":00", "H:mm") + '</span>';
881                    }
882                }
883            }
884
885        }
886        html += '</td></tr>';
887        html += '</tbody></table>';
888        html += '<div class="clear"></div>';
889        $('#table_dispo').html(html);
890    }
891}
892
893function changeclass(message) {
894    $('#table_creneau .indispo').each(function() {
895        for (var e = 1; e <= 7; e++) {
896            if (message.open[e] != undefined && $(this).data('idDay') == message.open[e].id_day && message.open[e].nonstop == true && $(this).data('hour') >= message.open[e].hour_open_am && $(this).data('hour') < message.open[e].hour_close_pm) {
897                $(this).removeClass('indispo');
898                $(this).addClass('dispo');
899            } else if (message.open[e] != undefined && $(this).data('idDay') == message.open[e].id_day && message.open[e].nonstop == false && (($(this).data('hour') >= message.open[e].hour_open_am && $(this).data('hour') < message.open[e].hour_close_am) || ($(this).data('hour') >= message.open[e].hour_open_pm && $(this).data('hour') < message.open[e].hour_close_pm))) {
900                $(this).removeClass('indispo');
901                $(this).addClass('dispo');
902            }
903        }
904    });
905}
906
907function adjustListDisplay(message, hide_empty_days) {
908    
909    // On gère les carrences
910    /*Date d'aujourd'hui à l'instant T*/
911    var date_today = Date.now();        
912    var carence = message.creneau_carence*60*1000;
913    var add = date_today + carence; 
914    var date_limit = new Date(add);
915    var datetime = date_limit.getFullYear()+'-'+((date_limit.getMonth()+1)+'').padStart(2,'0')+'-'+(date_limit.getDate()+'').padStart(2,'0')+' '+(date_limit.getHours()+'').padStart(2,'0')+':'+(date_limit.getMinutes()+'').padStart(2,'0')+':'+(date_limit.getSeconds()+'').padStart(2,'0');
916    
917   
918    $('#table_creneau tbody tr span').each(function(){
919        if($(this).data('datetime') <= datetime)
920        {
921            $(this).removeClass('dispo').addClass('indispo');   
922        }
923    });
924    
925    // On check les vacances 
926    vacation(message);
927    
928    // On supprime les jours où il n'y a aucune dispo dans l'entête
929    $('body').find('#list_creneau tr td span').each(function(){
930        var the_day = $(this).data('date');
931        if($('#table_creneau tr td span[data-date="'+the_day+'"].dispo').length == 0)
932        
933        // 2.0.2 : masquage des jours fermés
934        if(hide_empty_days == 1)
935        {
936            $(this).parent().remove();
937        }
938        else
939        {
940            $(this).addClass('disabled');
941        }
942    });
943    
944    $('#table_dispo_head').scrollLeft(0);
945    
946    _adjustScrollDisplay();
947    
948    $('#nav_buttons').hide().remove();
949}
950
951function _adjustScrollDisplay()
952{
953    // On affiche les premières dispos
954    $('body').find('#table_dispo_head #list_creneau tr td span').each(function()
955    {
956        if($(this).hasClass('disabled') == false)
957        {
958            var distance_left = $(this).position().left;
959            var div_width = $(this).outerWidth();
960            var div_nbr = $('body').find('#table_dispo_head #list_creneau tr td span').length;
961            $('#table_dispo_head').scrollLeft(parseInt(distance_left-div_width+(div_nbr*10)-2));
962            $(this).trigger('click');
963            return false;
964        }
965            
966    });
967}
968
969function carrence(message) { 
970    /*Date d'aujourd'hui à l'instant T*/
971    var date_today = Date.now();        
972    var carence = message.creneau_carence*60*1000;
973    var add = date_today + carence; 
974    var date_limit = new Date(add);
975    var datetime = date_limit.getFullYear()+'-'+((date_limit.getMonth()+1)+'').padStart(2,'0')+'-'+(date_limit.getDate()+'').padStart(2,'0')+' '+(date_limit.getHours()+'').padStart(2,'0')+':'+(date_limit.getMinutes()+'').padStart(2,'0')+':'+(date_limit.getSeconds()+'').padStart(2,'0');
976    
977    $('#table_creneau tbody tr td').each(function(){
978        if($(this).data('datetime') <= datetime)
979        {
980            $(this).removeClass('dispo').addClass('indispo');   
981        }
982    });
983}
984
985function vacation(message) {
986    $('#table_creneau .creneau').each(function() {
987        var sizevacation = Object.keys(message.vacations).length;
988        for (var j = 0; j < sizevacation; j++) {
989            var datetime_creneau = $(this).data('datetime');
990            var date_creneau_format = datetime_creneau.substr(0,10);
991            //console.log([datetime_creneau,date_creneau_format,message.vacations[j].vacation_start,message.vacations[j].vacation_end]);
992            if (date_creneau_format >= message.vacations[j].vacation_start && date_creneau_format <= message.vacations[j].vacation_end) {
993                $(this).addClass('red indispo');
994                $(this).removeClass('dispo');
995            }
996        }
997    });
998}
999
1000function reserved(message) {
1001    // On ajoute les reservés
1002    var sizer = message.reserved!=null?Object.keys(message.reserved).length:0;
1003    if(sizer > 0)
1004    {
1005        for (var key in message.reserved) {
1006            if(message.reserved[key] < message.creneau_limit) {
1007                if(message.creneau_limit > 0)
1008                {
1009                    if(message.reserved[key]/message.creneau_limit >= 0.50)
1010                    {
1011                        $('[data-datetime="'+key+'"]').addClass('busy');
1012                    }
1013                }
1014            } else if (message.reserved[key] >= message.creneau_limit) {
1015                $('[data-datetime="'+key+'"]').removeClass('dispo').addClass('red indispo');
1016            }
1017        }
1018    }
1019}
1020
1021function refresh(time) {
1022    setTimeout(function () {
1023    
1024        // UPDATE 1.4.0 : Si on est sur l''étape de paiement, on force le choix d'un nouveau créneau après X min
1025        if($('#checkout-payment-step').hasClass('-current') || $('#checkout-payment-step').hasClass('js-current-step'))
1026        {
1027            $('#checkout-delivery-step span.step-edit').trigger('click');
1028        }
1029        else
1030        {
1031            window.location.reload(); 
1032        }    
1033        
1034    }, time*1000);
1035}

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.