PageSourceSearch

https://www.velozen.com/modules/geodisofficiel/views/js/GeodisCarrierSelector.js

js velozen.com collected 2026-10-07 22:37:43 UTC 55,794 bytes, 1,690 lines download raw bytes

1/**
2 * 2018 GEODIS.
3 *
4 * NOTICE OF LICENSE
5 *
6 * This source file is subject to the Academic Free License (AFL 3.0)
7 * that is bundled with this package in the file LICENSE.txt.
8 * It is also available through the world-wide-web at this URL:
9 * http://opensource.org/licenses/afl-3.0.php
10 * If you did not receive a copy of the license and are unable to
11 * obtain it through the world-wide-web, please send an email
12 * to [email protected] so we can send you a copy immediately.
13 *
14 * DISCLAIMER
15 *
16 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17 * versions in the future. If you wish to customize PrestaShop for your
18 * needs please refer to http://www.prestashop.com for more information.
19 *
20 *  @author    GEODIS <[email protected]>
21 *  @copyright 2018 GEODIS
22 *  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
23 */
24
25"use strict";
26
27var GeodisCarrierSelector = function(idPrestaShopCarrier, jsonConfig, jsonValues, getTemplateUrl, submitUrl, pointListUrl, formatPriceUrl, quoteAddressUrl, intlUtilsUrl, markerShopUrl, markerSelectedShopUrl, markerHomeUrl, sentenceDistanceKilometers, sentenceDistanceMeters, mapEnabled, checkboxIdentifier, quote, module, GeodisJQuery) {
28    this.idPrestaShopCarrier = idPrestaShopCarrier;
29    this.jsonConfig = jsonConfig;
30    this.jsonValues = jsonValues;
31    this.submitUrl = submitUrl;
32    this.pointListUrl = pointListUrl;
33    this.optionsSelectedByCarrier = [];
34    this.intlTelephone = [];
35    this.intlMobilephone = [];
36    this.intlUtilsUrl = intlUtilsUrl;
37    this.formatPriceUrl = formatPriceUrl;
38    this.quoteAddressUrl = quoteAddressUrl;
39    this.markerShopUrl = markerShopUrl;
40    this.markerSelectedShopUrl = markerSelectedShopUrl;
41    this.markerHomeUrl = markerHomeUrl;
42    this.sentenceDistanceKilometers = sentenceDistanceKilometers;
43    this.sentenceDistanceMeters = sentenceDistanceMeters;
44    this.mapEnabled = mapEnabled;
45    this.useGlobalMap = true;
46    this.checkboxIdentifier = checkboxIdentifier;
47    this.module = module;
48    this.GeodisJQuery = GeodisJQuery;
49    this.quote = quote;
50
51    this.relayMap = [];
52    this.timeoutMapMove = [];
53
54    if (this.jsonValues.idCarrier) {
55        this.optionsSelectedByCarrier[this.jsonValues.idCarrier] = this.jsonValues.idOptionList;
56    }
57
58    this.template = new GeodisTemplate(getTemplateUrl, this, this.jsonValues.token, this.GeodisJQuery)
59
60    this.isOpen = false;
61    this.pickupPointList = [];
62    this.mapInitialized = [];
63    this.mapDefaultCenter = [];
64    this.wasOpened = false;
65
66    this.errors = [];
67
68    this.$popin = this.GeodisJQuery('<div></div>');
69
70    if (this.jsonConfig.carrierList.length === 1) {
71        this.jsonValues.idCarrier = this.jsonConfig.carrierList[0].id_carrier;
72    }
73
74    // Remove empty idOption from idOptionList
75    for (var i in this.jsonValues.idOptionList) {
76        if (i != parseInt(i)) {
77            continue;
78        }
79
80        if (!this.jsonValues.idOptionList[i]) {
81            this.jsonValues.idOptionList.splice(i, 1);
82        }
83    }
84
85    if (!this.jsonValues.info) {
86        this.jsonValues.info = [];
87    }
88
89    // Classical case (click on the checkbox)
90    this.GeodisJQuery(document).on(
91        'click',
92        this.checkboxIdentifier,
93        (function(e) { this.open(); return false; }).bind(this)
94    );
95
96    if (this.GeodisJQuery(this.checkboxIdentifier).is(':visible') && this.GeodisJQuery(this.checkboxIdentifier).is(':checked')) {
97        this.open();
98    }
99        // Case of classic theme of PrestaShop (ckeckbox not visible)
100/*    this.GeodisJQuery(this.checkboxIdentifier).closest('.delivery-option').click(
101        (function(e) { this.open(); return false; }).bind(this)
102    );
103
104//    window.setInterval((function() {
105        if (this.GeodisJQuery(this.checkboxIdentifier).is(':visible')) {
106//            this.GeodisJQuery(this.checkboxIdentifier).closest('.row').click((function() {
107            this.GeodisJQuery(this.checkboxIdentifier).closest('.delivery-option').click((function() {
108                this.open();
109            }).bind(this));
110
111            if (this.wasOpened) {
112                return;
113            }
114
115            if (this.GeodisJQuery(this.checkboxIdentifier).is(':checked')) {
116                this.open();
117            }
118        }
119//    }).bind(this), 250);
120*/
121    // Reset idOptionList is current carrier do not exist in list of carrier
122    this.resetCarrierList();
123
124    this.listenContinueButton();
125};
126
127GeodisCarrierSelector.prototype.listenContinueButton = function() {
128    this.GeodisJQuery('body').on('click', '[name=confirmDeliveryOption]', (function () {
129        if (!this.GeodisJQuery('#delivery_option_'+this.idPrestaShopCarrier).is(':checked')) {
130            return true;
131        }
132
133        if (!this.validate()) {
134            this.open((function() {
135                this.validate();
136            }).bind(this));
137            return false;
138        }
139
140        return true;
141    }).bind(this));
142};
143
144GeodisCarrierSelector.prototype.resetCarrierList = function() {
145    for (var i in this.jsonConfig.carrierList) {
146        if (i != parseInt(i)) {
147            continue;
148        }
149
150        var carrier = this.jsonConfig.carrierList[i];
151        if (this.jsonValues.idCarrier == carrier.id_carrier) {
152            return;
153        }
154    }
155    this.jsonValues.idOptionList = [];
156};
157
158GeodisCarrierSelector.prototype.initListener = function() {
159    this.GeodisJQuery(this.$popin).on('click', '[data-action]', (function(e) {
160        var $elm = this.GeodisJQuery(e.target).closest('[data-action]');
161
162        this[$elm.data('action')]($elm.data('values'), $elm, $elm.data('parent'));
163
164        return false;
165    }).bind(this));
166
167    this.GeodisJQuery(this.$popin).on('change', '[data-change]', (function(e) {
168        var $elm = this.GeodisJQuery(e.target);
169
170        this[$elm.data('change')]($elm.data('values'), $elm, $elm.data('parent'));
171
172        return false;
173    }).bind(this));
174};
175
176GeodisCarrierSelector.prototype.switchRequiredEntry = function() {
177    // Email not required if mobilephone is set
178    if (this.$popin.find('.js-mobilephone').val().length) {
179        this.$popin.find('.geodisInfo__inputContainer--email').removeClass('geodisInfo__inputContainer--required');
180    } else {
181        this.$popin.find('.geodisInfo__inputContainer--email').addClass('geodisInfo__inputContainer--required');
182    }
183
184    // Mobilephone not required if phone is set
185    if (this.$popin.find('.js-telephone').val().length) {
186        this.$popin.find('.geodisInfo__inputContainer--mobilephone').removeClass('geodisInfo__inputContainer--required');
187    } else {
188        this.$popin.find('.geodisInfo__inputContainer--mobilephone').addClass('geodisInfo__inputContainer--required');
189    }
190
191    // Telephone is not required if mobilephone is set
192    if (this.$popin.find('.js-mobilephone').val().length) {
193        this.$popin.find('.geodisInfo__inputContainer--telephone').removeClass('geodisInfo__inputContainer--required');
194    } else {
195        this.$popin.find('.geodisInfo__inputContainer--telephone').addClass('geodisInfo__inputContainer--required');
196    }
197};
198
199GeodisCarrierSelector.prototype.submit = function() {
200    if (!this.validate()) {
201        this.showErrors();
202        return;
203    }
204
205    this.processForm();
206
207    this.GeodisJQuery('#delivery_option_'+this.idPrestaShopCarrier).prop('checked', true).change();
208
209    // Add the idPrestaShopCarrier to datas to transfert
210    var fullJsonValues = JSON.parse(JSON.stringify(this.jsonValues));
211    fullJsonValues['idPrestaShopCarrier'] = this.idPrestaShopCarrier;
212
213    this.GeodisJQuery.ajax({
214        url: this.submitUrl,
215        data: fullJsonValues,
216        dataType: 'json'
217    }).done((function(data) {
218        // Magento
219        this.GeodisJQuery(this.checkboxIdentifier).parent().find('.price').html(data.price);
220        this.GeodisJQuery(this.checkboxIdentifier).prop('checked', true);
221
222        // PrestaShop
223        this.GeodisJQuery('[for="delivery_option_'+this.idPrestaShopCarrier+'"] .carrier-price').html(data.price);
224
225        // Magento
226        if (typeof shippingMethod != 'undefined') {
227            shippingMethod.save()
228        }
229
230        this.close();
231    }).bind(this));
232};
233
234GeodisCarrierSelector.prototype.processForm = function() {
235    this.$popin.find('[data-process]').each((function(key, elm) {
236        var $elm = this.GeodisJQuery(elm);
237        if (!$elm.closest('.js-prestation').hasClass('geodisPrestation--selected')) {
238            return;
239        }
240
241        var callback = $elm.data('process');
242
243        this[callback]($elm.val(), this.GeodisJQuery(elm).data('values'));
244
245    }).bind(this));
246};
247
248GeodisCarrierSelector.prototype.processFloor = function(value, values) {
249    var carrier = this.getSelectedCarrier();
250    for (var i in this.jsonValues.idOptionList) {
251        if (i != parseInt(i)) {
252            continue;
253        }
254
255        var idOption = this.jsonValues.idOptionList[i];
256        var option = this.getCarrierOption(carrier.id_carrier, idOption);
257
258        if (option.id_option == values) {
259            this.setInfo('floor', value);
260        }
261    }
262};
263
264GeodisCarrierSelector.prototype.processTelephone = function(value, values) {
265    var idCarrier = this.getIdCarrier(this.jsonConfig.carrierType, this.jsonValues.idCarrier);
266
267    this.setInfo('telephone', this.intlTelephone[idCarrier].getNumber());
268    this.setInfo('dialCodeTelephone', this.intlTelephone[idCarrier].getSelectedCountryData().dialCode);
269    this.setInfo('nationalTelephone', this.intlTelephone[idCarrier].getNumber(intlTelInputUtils.numberFormat.NATIONAL));
270};
271
272GeodisCarrierSelector.prototype.processMobilephone = function(value, values) {
273    var idCarrier = this.getIdCarrier(this.jsonConfig.carrierType, this.jsonValues.idCarrier);
274
275    this.setInfo('mobilephone', this.intlMobilephone[idCarrier].getNumber());
276    this.setInfo('dialCodeMobilephone', this.intlMobilephone[idCarrier].getSelectedCountryData().dialCode);
277    this.setInfo('nationalMobilephone', this.intlMobilephone[idCarrier].getNumber(intlTelInputUtils.numberFormat.NATIONAL));
278};
279
280GeodisCarrierSelector.prototype.processEmail = function(value, values) {
281    this.setInfo('email', value);
282};
283
284GeodisCarrierSelector.prototype.processDigicode = function(value, values) {
285    this.setInfo('digicode', value);
286};
287
288GeodisCarrierSelector.prototype.processInstruction = function(value, values) {
289    this.setInfo('instruction', value);
290};
291
292GeodisCarrierSelector.prototype.setInfo = function(attribute, value) {
293    if (typeof this.jsonValues['info'] == 'undefined') {
294        this.jsonValues['info'] = [];
295    }
296
297    for (var i in this.jsonValues.info) {
298        if (i != parseInt(i)) {
299            continue;
300        }
301
302        var info = this.jsonValues.info[i];
303
304        if (info.name == attribute) {
305            info.value = value;
306            return;
307        }
308    }
309
310    this.jsonValues.info.push({
311        name: attribute,
312        value: value
313    });
314};
315
316GeodisCarrierSelector.prototype.validate = function() {
317    this.errors = [];
318    this.$popin.find('.geodisError').removeClass('geodisError');
319    this.$popin.find('.js-error').html('');
320
321    this.$popin.find('[data-validate]').each((function(key, elm) {
322        var $elm = this.GeodisJQuery(elm);
323
324        if (!$elm.closest('.js-prestation').hasClass('geodisPrestation--selected')) {
325            return;
326        }
327
328        var callback = $elm.data('validate');
329
330        if (!this[callback]($elm.val(), $elm.data('values'))) {
331            $elm.addClass('geodisError');
332            $elm.closest('.js-input-container').addClass('geodisError');
333            this.errors.push(this.GeodisJQuery(elm).closest('.js-input-container').data('error'));
334        };
335
336    }).bind(this));
337
338    if (this.errors.length) {
339        return false;
340    }
341
342    return true;
343};
344
345GeodisCarrierSelector.prototype.showErrors = function() {
346    this.errors.forEach((function(message) {
347        this.$popin.find('.js-error').append(
348            this.GeodisJQuery('<li></li>').text(message)
349        );
350    }).bind(this));
351};
352
353GeodisCarrierSelector.prototype.canSubmit = function(value, values) {
354    for (var i in this.jsonConfig.carrierList) {
355        if (i != parseInt(i)) {
356            continue;
357        }
358
359        var carrier = this.jsonConfig.carrierList[i];
360        if (carrier.id_carrier == this.jsonValues.idCarrier) {
361            if (this.jsonConfig.carrierType == 'classic' || this.jsonValues.codeWithdrawalAgency || this.jsonValues.codeWithdrawalPoint) {
362                return true;
363            }
364        }
365    }
366
367    return false;
368};
369
370GeodisCarrierSelector.prototype.validateHasPoint = function(value, values) {
371    if (this.jsonValues.codeWithdrawalPoint || this.jsonValues.codeWithdrawalAgency) {
372        return true;
373    }
374
375    return false;
376};
377
378GeodisCarrierSelector.prototype.validateFloor = function(value, values) {
379    var carrier = this.getSelectedCarrier();
380    for (var i in this.jsonValues.idOptionList) {
381        if (i != parseInt(i)) {
382            continue;
383        }
384
385        var idOption = this.jsonValues.idOptionList[i];
386        var option = this.getCarrierOption(carrier.id_carrier, idOption);
387
388        if (option.id_option == values) {
389            if (!value.length && option.code == 'livEtage') {
390                return false;
391            }
392            if (null == value.match(/^\d+$/) && value.length) {
393                return false;
394            }
395        }
396    }
397
398    return true;
399};
400
401GeodisCarrierSelector.prototype.validateTelephone = function(value, values) {
402    // Not required if mobilephone is set
403    if (!value.length && this.$popin.find('.js-mobilephone').val().length) {
404        return true;
405    }
406
407    var idCarrier = this.getIdCarrier(this.jsonConfig.carrierType, this.jsonValues.idCarrier);
408
409    if (!this.intlTelephone[idCarrier]) {
410        return true;
411    }
412
413    if (!this.intlTelephone[idCarrier].isValidNumber()) {
414        return false;
415    }
416
417    if (this.intlTelephone[idCarrier].getNumberType() == 1) {
418        // If it's a mobile copy on mobile phone
419        if (!this.$popin.find('.js-mobilephone').val().length) {
420            this.$popin.find('.js-mobilephone').val(this.$popin.find('.js-telephone').val());
421            this.$popin.find('.js-telephone').val('');
422            return true;
423        }
424        return false;
425    }
426
427    return true;
428};
429
430GeodisCarrierSelector.prototype.validateMobilephone = function(value, values) {
431    // Not required if telephone is set
432    if (!value.length && this.$popin.find('.js-telephone').val().length) {
433        return true;
434    }
435
436    var idCarrier = this.getIdCarrier(this.jsonConfig.carrierType, this.jsonValues.idCarrier);
437    if (!this.intlMobilephone[idCarrier]) {
438        return true;
439    }
440
441    if (!this.intlMobilephone[idCarrier].isValidNumber()) {
442        return false;
443    }
444
445    if (this.intlMobilephone[idCarrier].getNumberType() != 1 && this.intlMobilephone[idCarrier].getNumberType() != 2 && this.intlMobilephone[idCarrier].getNumberType() != -1) {
446        return false;
447    }
448
449    return true;
450}
451
452GeodisCarrierSelector.prototype.validateEmail = function(value, values) {
453    // Not required if mobilephone is set
454    if (!value.length && this.$popin.find('.js-mobilephone').val().length) {
455        return true;
456    }
457
458    if (null == value.match(/^[^@]+@[^@]+\.[A-Za-z]+$/)) {
459        return false;
460    }
461
462    return true;
463};
464
465GeodisCarrierSelector.prototype.selectCarrier = function(idCarrier, $elm) {
466    if (idCarrier == this.jsonValues.idCarrier) {
467        return;
468    }
469
470    this.$popin.find('.geodisPrestation--selected').removeClass('geodisPrestation--selected');
471
472    for (var i in this.jsonConfig.carrierList) {
473        if (i != parseInt(i)) {
474            continue;
475        }
476
477        var carrier = this.jsonConfig.carrierList[i];
478        if (carrier.id_carrier == idCarrier) {
479            this.jsonValues.idCarrier = carrier.id_carrier;
480            $elm.addClass('geodisPrestation--selected');
481
482            this.jsonValues.idOptionList = [];
483            if (typeof this.optionsSelectedByCarrier[idCarrier] != 'undefined') {
484                this.jsonValues.idOptionList = this.optionsSelectedByCarrier[idCarrier];
485            }
486        }
487    }
488
489    if (this.canSubmit()) {
490        this.$popin.find('.js-submit').removeClass('geodisPopinFooter__submit--inactive');
491    } else {
492        this.$popin.find('.js-submit').addClass('geodisPopinFooter__submit--inactive');
493    }
494
495
496    // Move phone to mobile phone if it's a mobile phone
497    var idCarrier = this.getIdCarrier(this.jsonConfig.carrierType, this.jsonValues.idCarrier);
498    if (this.intlTelephone[idCarrier] && this.intlTelephone[idCarrier].isValidNumber() && this.intlTelephone[idCarrier].getNumberType() == 1) {
499        if (!this.$popin.find('.js-mobilephone').val().length) {
500            this.$popin.find('.js-mobilephone').val(this.$popin.find('.js-telephone').val());
501            this.$popin.find('.js-telephone').val('');
502        }
503    }
504
505    this.updateCarrierPrice();
506    this.updateOptionPrice();
507};
508
509GeodisCarrierSelector.prototype.updateCarrierPrice = function(carrier) {
510    for (var i in this.jsonConfig.carrierList) {
511        if (i != parseInt(i)) {
512            continue;
513        }
514
515        var carrier = this.jsonConfig.carrierList[i];
516        var price = carrier.price;
517
518        for (var j in this.optionsSelectedByCarrier[carrier.id_carrier]) {
519            if (j != parseInt(j)) {
520                continue;
521            }
522
523            var idOption = this.optionsSelectedByCarrier[carrier.id_carrier][j];
524            var option = this.getCarrierOption(carrier.id_carrier, idOption);
525
526            if (!option) {
527                continue;
528            }
529
530            price += option.price_impact;
531        }
532
533        this.formatPrice(price, (function(carrier, price) {
534            if (carrier.id_carrier == this.getSelectedCarrier().id_carrier) {
535                this.$popin.find('.js-popin-price').html(price);
536            }
537        }).bind(this, carrier));
538
539        this.formatPrice(carrier.price, (function(carrier, price) {
540            this.$popin.find('.js-price[data-values='+carrier.id_carrier+']').html(price);
541        }).bind(this, carrier));
542    }
543};
544
545GeodisCarrierSelector.prototype.updateOptionPrice = function() {
546    for (var i in this.jsonConfig.carrierList) {
547        if (i != parseInt(i)) {
548            continue;
549        }
550
551        var carrier = this.jsonConfig.carrierList[i];
552
553        for (var j in carrier.optionList) {
554            if (j != parseInt(j)) {
555                continue;
556            }
557            var option = carrier.optionList[j];
558            var price = option.price_impact;
559            this.formatPrice(price, (function(carrier, option, price) {
560                this.$popin.find('.js-prestation[data-values='+carrier.id_carrier+'] .js-option-price[data-values='+option.id_option+']').html(price);
561            }).bind(this, carrier, option));
562        }
563    }
564};
565
566
567GeodisCarrierSelector.prototype.selectOption = function(idOption, $elm) {
568
569    this.$popin.find('.geodisOptionRow--selected').removeClass('geodisOptionRow--selected');
570    $elm.addClass('geodisOptionRow--selected');
571
572    this.jsonValues.idOptionList = [];
573    this.optionsSelectedByCarrier[this.getSelectedCarrier().id_carrier] = [];
574
575    var carrier = this.getSelectedCarrier();
576
577    if (idOption) {
578        this.jsonValues.idOptionList.push(idOption);
579        this.optionsSelectedByCarrier[carrier.id_carrier].push(idOption);
580    }
581
582    this.updateCarrierPrice();
583    this.addClassToOptions();
584
585    /*
586    var index = this.jsonValues.idOptionList.indexOf(idOption);
587    if (index !== -1) {
588        // Remove option
589        $elm.removeClass('option--selected');
590        this.jsonValues.idOptionList.splice(index, 1);
591    } else {
592        // Add option
593        $elm.addClass('option--selected');
594        this.jsonValues.idOptionList.push(idOption);
595    }
596    */
597};
598
599GeodisCarrierSelector.prototype.addClassToOptions = function() {
600    for (var i in this.optionsSelectedByCarrier) {
601        if (i != parseInt(i)) {
602            continue;
603        }
604
605        this.$popin.find('.js-options[data-values='+i+'] .js-option').removeClass('geodisOptionRow--selected');
606        if (!this.optionsSelectedByCarrier[i].length) {
607                this.$popin.find('.js-options[data-values='+i+'] .js-option[data-values=\'\']').addClass('geodisOptionRow--selected');
608        } else {
609            for (var j in this.optionsSelectedByCarrier[i]) {
610                if (j != parseInt(j)) {
611                    continue;
612                }
613
614                var idOption = this.optionsSelectedByCarrier[i][j];
615                this.$popin.find('.js-options[data-values='+i+'] .js-option[data-values='+idOption+']').addClass('geodisOptionRow--selected');
616            }
617        }
618    }
619}
620
621GeodisCarrierSelector.prototype.open = function(callback) {
622    if (this.isOpen) {
623        return;
624    }
625
626    if(callback === undefined) {
627       var callback = null;
628    }
629
630    this.wasOpened = true;
631    this.isOpen = true;
632
633    if (this.quoteAddressUrl) {
634        // Update json values address
635        this.GeodisJQuery.ajax({
636            url: this.quoteAddressUrl,
637            dataType: 'json',
638            data: {
639                token: this.jsonValues.token
640            },
641            method: 'GET'
642        }).done((function(data) {
643            if (data.hasResults) {
644                this.jsonValues.address = data.address;
645                this.jsonValues.countryCode = data.countryCode;
646                this.jsonValues.telephone1 = data.telephone1;
647                this.jsonValues.email = data.email;
648            }
649            this.openPopin(callback);
650        }).bind(this));
651    } else if (null != this.quote) {
652        if (this.quote.shippingAddress().street[0]) {
653            this.jsonValues.address = {
654                'address1': this.quote.shippingAddress().street[0],
655                'address2': '',
656                'city': this.quote.shippingAddress().city,
657                'zipCode': this.quote.shippingAddress().postcode,
658                'countryCode': this.quote.shippingAddress().countryId,
659            };
660        }
661
662        if (this.quote.shippingAddress().countryId) {
663            this.jsonValues.countryCode = this.quote.shippingAddress().countryId;
664        }
665
666        if (this.quote.shippingAddress().telephone) {
667            this.jsonValues.telephone1 = this.quote.shippingAddress().telephone;
668        }
669
670        if (this.quote.shippingAddress().email) {
671            this.jsonValues.email = this.quote.shippingAddress().email;
672        }
673        this.openPopin(callback);
674    } else {
675        this.openPopin(callback);
676    }
677}
678
679GeodisCarrierSelector.prototype.openPopin  = function(callback) {
680    if(callback === undefined) {
681       var callback = null;
682    }
683
684    this.$overlay = this.GeodisJQuery('<div class="geodisPopinOverlay"></div>');
685    this.$popin = this.GeodisJQuery('<div class="geodisPopin geodisPopin--' + this.module + '"></div>');
686
687    this.GeodisJQuery('body').css({'overflow':'hidden'});
688    this.GeodisJQuery('body').append(this.$overlay);
689    this.GeodisJQuery('body').append(this.$popin);
690
691    var template = this.loadMainTemplate();
692
693    // Check white label
694    if (this.jsonConfig.whiteLabel != 0) {
695        var carrierId = this.jsonConfig.idCarrier
696        this.GeodisJQuery('.geodisPopin--' + this.module + ' .geodisPopinHeader').css('background', "url('"+this.jsonConfig.whiteLabelImageUrl+"') no-repeat 25px center white");
697    }
698    this.switchRequiredEntry();
699
700    if (!this.mapEnabled) {
701        this.renderPointList();
702    }
703
704
705    if (callback != null) {
706        callback();
707    }
708};
709
710GeodisCarrierSelector.prototype.close = function() {
711    this.$popin.remove();
712    this.$overlay.remove();
713    this.GeodisJQuery('body').css({'overflow':'visible'});
714    this.isOpen = false;
715};
716
717GeodisCarrierSelector.prototype.loadMainTemplate = function() {
718    if (this.jsonConfig.carrierType == 'relay') {
719        if (this.useGlobalMap) {
720            if (this.mapEnabled) {
721                var template = 'relay';
722            } else {
723                var template = 'relayWithoutMap';
724            }
725        } else {
726            var template = 'carriersRelay';
727        }
728    } else {
729        var template = 'carriers';
730    }
731
732    this.template.replace(
733        template,
734        this.$popin,
735        [
736            {
737                name: 'popinTitle',
738                value: this.jsonConfig.popinTitle
739            },
740            {
741                name: 'popinSubtitle',
742                value: this.jsonConfig.popinSubtitle
743            },
744            {
745                name: 'description',
746                value: this.jsonConfig.description
747            }
748        ]
749    );
750
751    this.addClassToOptions();
752    this.updateCarrierPrice();
753    this.updateOptionPrice();
754
755    this.initInfo();
756    this.initMaps();
757    this.initListener();
758    this.hideShowAppointmentMessage(this.jsonConfig.carrierType2);
759}
760
761GeodisCarrierSelector.prototype.initInfo = function()
762{
763    this.$popin.find('.js-telephone').each((function(key, item) {
764        var idCarrier = this.getIdCarrier(this.jsonConfig.carrierType , this.GeodisJQuery(item).data('values'));
765        this.intlTelephone[idCarrier] = window.intlTelInput(item, {
766            initialCountry: this.jsonValues.countryCode,
767            placeholderNumberType: 'FIXED_LINE',
768            utilsScript: this.intlUtilsUr,
769            dropdownContainer: document.body
770        });
771    }).bind(this));
772
773    this.$popin.find('.js-mobilephone').each((function(key, item) {
774        var idCarrier = this.getIdCarrier(this.jsonConfig.carrierType , this.GeodisJQuery(item).data('values'));
775        this.intlMobilephone[idCarrier] = window.intlTelInput(item, {
776            initialCountry: this.jsonValues.countryCode,
777            placeholderNumberType: 'MOBILE',
778            utilsScript: this.intlUtilsUrl,
779            dropdownContainer: document.body
780        });
781    }).bind(this));
782
783    this.GeodisJQuery('.geodisPopinContent').get(0).addEventListener('scroll', function() {
784        var e = document.createEvent('Event');
785        e.initEvent('scroll', true, true);
786        window.dispatchEvent(e);
787    });
788
789    var listenTelephone = true;
790    this.$popin.find('.js-telephone').on('countrychange', (function(e) {
791        if (!listenTelephone) {
792            return;
793        }
794
795        listenTelephone = false;
796        var idCarrier = this.getIdCarrier(this.jsonConfig.carrierType , this.GeodisJQuery(e.target).data('values'));
797        var number = this.intlTelephone[idCarrier].getNumber();
798
799        for (var i in this.intlTelephone) {
800            this.intlTelephone[i].setNumber(number);
801        }
802
803        listenTelephone = true;
804    }).bind(this));
805
806    var listenMobile = true;
807    this.$popin.find('.js-mobilephone').on('countrychange', (function(e) {
808        if (!listenMobile) {
809            return;
810        }
811
812        listenMobile = false;
813        var idCarrier = this.getIdCarrier(this.jsonConfig.carrierType , this.GeodisJQuery(e.target).data('values'));
814        var number = this.intlMobilephone[idCarrier].getNumber();
815
816        for (var i in this.intlMobilephone) {
817            this.intlMobilephone[i].setNumber(number);
818        }
819        listenMobile = true;
820    }).bind(this));
821    this.$popin.find('.js-telephone').change((function(e) { this.$popin.find('.js-telephone').val(this.GeodisJQuery(e.target).val()); }).bind(this));
822    this.$popin.find('.js-mobilephone').change((function(e) { this.$popin.find('.js-mobilephone').val(this.GeodisJQuery(e.target).val()); }).bind(this));
823    this.$popin.find('.js-instruction').change((function(e) { this.$popin.find('.js-instruction').val(this.GeodisJQuery(e.target).val()); }).bind(this));
824    this.$popin.find('.js-digicode').change((function(e) { this.$popin.find('.js-digicode').val(this.GeodisJQuery(e.target).val()); }).bind(this));
825    this.$popin.find('.js-email').change((function(e) { this.$popin.find('.js-email').val(this.GeodisJQuery(e.target).val()); }).bind(this));
826}
827
828GeodisCarrierSelector.prototype.renderCarriers = function($elm) {
829    // Be sure no relay are set
830
831    this.jsonValues.codeWithdrawalAgency = null;
832    this.jsonValues.codeWithdrawalPoint = null;
833
834    for (var i in this.jsonConfig.carrierList) {
835        if (i != parseInt(i)) {
836            continue;
837        }
838
839        var carrier = this.jsonConfig.carrierList[i];
840        this.template.append(
841            'carrier',
842            $elm,
843            [
844                {
845                    name: 'id',
846                    value: carrier.id_carrier
847                },
848                {
849                    name: 'name',
850                    value: carrier.name
851                },
852                {
853                    name: 'desc',
854                    value: carrier.desc
855                },
856                {
857                    name: 'longdesc',
858                    value: carrier.longdesc
859                },
860                {
861                    name: 'price',
862                    value: carrier.price
863                },
864                {
865                    name: 'appointmentTypeDesc',
866                    value: carrier.appointmentType
867                }
868            ]
869        );
870    }
871};
872
873GeodisCarrierSelector.prototype.renderCarriersRelay = function($elm) {
874    for (var i in this.jsonConfig.carrierList) {
875        if (i != parseInt(i)) {
876            continue;
877        }
878
879        var carrier = this.jsonConfig.carrierList[i];
880        this.template.append(
881            'carrierRelay',
882            $elm,
883            [
884                {
885                    name: 'id',
886                    value: carrier.id_carrier
887                },
888                {
889                    name: 'name',
890                    value: carrier.name
891                },
892                {
893                    name: 'desc',
894                    value: carrier.desc
895                },
896                {
897                    name: 'longdesc',
898                    value: carrier.longdesc
899                },
900                {
901                    name: 'price',
902                    value: carrier.price
903                }
904            ]
905        );
906    }
907};
908
909
910GeodisCarrierSelector.prototype.renderAdditionalOption = function($elm) {
911    var option = this.getOption($elm.data('values'));
912    if (option.code == 'livEtage'
913        || option.code == 'miseLieuUtil'
914    ) {
915        this.template.append(
916            'floor',
917            $elm,
918            [
919                {
920                    name: 'id',
921                    value: $elm.data('values')
922                },
923                {
924                    name: 'code',
925                    value: option.code
926                }
927            ]
928        );
929    }
930};
931
932GeodisCarrierSelector.prototype.getSelectedCarrier = function() {
933    for (var i in this.jsonConfig.carrierList) {
934        if (i != parseInt(i)) {
935            continue;
936        }
937
938        var carrier = this.jsonConfig.carrierList[i];
939
940        if (carrier.id_carrier == this.jsonValues.idCarrier) {
941            return carrier;
942        }
943    }
944
945    return false;
946}
947
948GeodisCarrierSelector.prototype.getCarrier = function(idCarrier) {
949    for (var i in this.jsonConfig.carrierList) {
950        if (i != parseInt(i)) {
951            continue;
952        }
953
954        var carrier = this.jsonConfig.carrierList[i];
955
956        if (carrier.id_carrier == idCarrier) {
957            return carrier;
958        }
959    }
960
961    return false;
962}
963
964GeodisCarrierSelector.prototype.getOption = function(idOption) {
965    for (var i in this.jsonConfig.carrierList) {
966        if (i != parseInt(i)) {
967            continue;
968        }
969
970        var carrier = this.jsonConfig.carrierList[i];
971        for (var j in carrier.optionList) {
972            if (j != parseInt(j)) {
973                continue;
974            }
975
976            var option = carrier.optionList[j];
977
978            if (option.id_option == idOption) {
979                return option;
980            }
981        }
982    }
983
984    return false;
985}
986
987GeodisCarrierSelector.prototype.getCarrierOption = function(idCarrier, idOption) {
988    var carrier = this.getCarrier(idCarrier);
989    for (var i in carrier.optionList) {
990        if (i != parseInt(i)) {
991            continue;
992        }
993
994        var option = carrier.optionList[i];
995
996        if (option.id_option == idOption) {
997            return option;
998        }
999    }
1000
1001    return false;
1002}
1003
1004GeodisCarrierSelector.prototype.renderOptions = function($elm) {
1005    var carrier = this.getCarrier($elm.data('values'));
1006
1007    if (!carrier.optionList.length) {
1008        $elm.remove();
1009        return;
1010    }
1011
1012    var optionList = carrier.optionList.slice(0);
1013    optionList.reverse();
1014    for (var i in optionList) {
1015        if (i != parseInt(i)) {
1016            continue;
1017        }
1018
1019        var option = optionList[i];
1020        this.template.prepend(
1021            'option',
1022            $elm,
1023            [
1024                {
1025                    name: 'id',
1026                    value: option.id_option
1027                },
1028                {
1029                    name: 'name',
1030                    value: option.name
1031                },
1032                {
1033                    name: 'desc',
1034                    value: option.desc
1035                },
1036                {
1037                    name: 'price_impact',
1038                    value: option.price_impact
1039                }
1040            ]
1041        );
1042    }
1043};
1044
1045GeodisCarrierSelector.prototype.renderOptionsTitle = function($elm) {
1046    var carrier = this.getCarrier($elm.data('values'));
1047    if ('nb options', !carrier.optionList.length) {
1048        $elm.remove();
1049        return;
1050    }
1051};
1052
1053GeodisCarrierSelector.prototype.setCarrierClass = function(idCarrier) {
1054    if (idCarrier == this.jsonValues.idCarrier) {
1055        return 'geodisPrestation--selected';
1056    }
1057};
1058
1059GeodisCarrierSelector.prototype.setSubmitClass = function() {
1060    if (this.canSubmit()) {
1061        return '';
1062    } else {
1063        return 'geodisPopinFooter__submit--inactive';
1064    }
1065};
1066
1067GeodisCarrierSelector.prototype.getInfo = function(attribute) {
1068    for (var i in this.jsonValues.info) {
1069        if (i != parseInt(i)) {
1070            continue;
1071        }
1072
1073        var info = this.jsonValues.info[i];
1074
1075        if (info.name == attribute) {
1076            return info.value;
1077        }
1078    }
1079
1080    return '';
1081};
1082
1083GeodisCarrierSelector.prototype.getFloor = function(values) {
1084    return this.getInfo('floor');
1085};
1086
1087GeodisCarrierSelector.prototype.getTelephone = function(values) {
1088    var telephone = this.getInfo('telephone');
1089
1090    if (!telephone && this.jsonValues.telephone1.length && !this.getMobilephone()) {
1091        return this.jsonValues.telephone1;
1092    }
1093
1094    return telephone;
1095};
1096
1097GeodisCarrierSelector.prototype.getAddress = function(values) {
1098    var address = this.getInfo('defaultAddress');
1099
1100    if (!address) {
1101        if (typeof this.jsonValues.address != 'undefined') {
1102            address = this.jsonValues.address;
1103        } else {
1104            return '';
1105        }
1106    }
1107
1108    return this.formatInlineAddress(address);
1109};
1110
1111GeodisCarrierSelector.prototype.getZipCode = function(values) {
1112    var zipCode = this.getInfo('defaultZipCode');
1113
1114    if (!zipCode) {
1115        if (typeof this.jsonValues.address != 'undefined') {
1116            return this.jsonValues.address.zipCode;
1117        } else {
1118            return '';
1119        }
1120    }
1121
1122    return zipCode;
1123};
1124
1125GeodisCarrierSelector.prototype.getCountryCode = function(values) {
1126    var countryCode = this.getInfo('defaultCountryCode');
1127
1128    if (!countryCode) {
1129        if (typeof this.jsonValues.address != 'undefined') {
1130            return this.jsonValues.address.countryCode;
1131        } else {
1132            return '';
1133        }
1134    }
1135
1136    return countryCode;
1137};
1138
1139GeodisCarrierSelector.prototype.formatInlineAddress = function(address) {
1140    if (typeof address == 'string') {
1141        return address;
1142    }
1143
1144    return address.address1 + (address.address2.length ? ' ' : '') + address.address2 + ', ' + address.zipCode + ' ' + address.city;
1145};
1146
1147
1148GeodisCarrierSelector.prototype.getMobilephone = function(values) {
1149    var mobilephone = this.getInfo('mobilephone');
1150
1151    if (!mobilephone && this.jsonValues.telephone2.length) {
1152        return this.jsonValues.telephone2;
1153    }
1154
1155    return mobilephone;
1156};
1157
1158GeodisCarrierSelector.prototype.getEmail = function(values) {
1159    var email = this.getInfo('email');
1160
1161    if (!email.length) {
1162        email = this.jsonValues.email;
1163    }
1164
1165    return email;
1166};
1167
1168GeodisCarrierSelector.prototype.getDigicode = function(values) {
1169    var digicode = this.getInfo('digicode');
1170
1171    if (!digicode.length) {
1172        digicode = this.jsonValues.digicode;
1173    }
1174    return digicode;
1175};
1176
1177GeodisCarrierSelector.prototype.getInstruction = function(values) {
1178    var instruction = this.getInfo('instruction');
1179
1180    if (!instruction.length) {
1181        instruction = this.jsonValues.instruction;
1182    }
1183    return instruction;
1184};
1185
1186
1187GeodisCarrierSelector.prototype.initMaps = function() {
1188    this.$popin.find('.js-geodis-relay-map').each((function(key, item) {
1189        var $item = this.GeodisJQuery(item);
1190
1191        var idCarrier = 0;
1192        if (!this.useGlobalMap) {
1193            idCarrier = $item.data('values');
1194        }
1195
1196        this.relayMap[(this.useGlobalMap ? 0 : idCarrier)] = new GeodisMap($item, {countryCode: this.jsonValues.countryCode}, this.GeodisJQuery);
1197        this.relayMap[(this.useGlobalMap ? 0 : idCarrier)].autoCenter();
1198        this.relayMap[(this.useGlobalMap ? 0 : idCarrier)].onChange((function(idCarrier, e) { this.renderPointList(idCarrier, e) }).bind(this, idCarrier));
1199
1200        this.relayMap[(this.useGlobalMap ? 0 : idCarrier)].getPositionFromAddress(this.getAddress(), (function(idCarrier, position) {
1201            this.mapDefaultCenter[(this.useGlobalMap ? 0 : idCarrier)] = position;
1202            this.relayMap[(this.useGlobalMap ? 0 : idCarrier)].setCenter(position.latitude, position.longitude);
1203        }).bind(this, idCarrier));
1204
1205        this.mapInitialized[(this.useGlobalMap ? 0 : idCarrier)] = false;
1206    }).bind(this));
1207
1208    return;
1209};
1210
1211GeodisCarrierSelector.prototype.showMap = function(idCarrier, $elm) {
1212    this.$popin.find('.js-switch-list').removeClass('geodisSwitch--active');
1213    this.$popin.find('.js-point-list').removeClass('geodisRelayPicker__list--active');
1214    this.$popin.find('.js-geodis-relay-map').addClass('geodisRelayPicker__map--active');
1215    $elm.addClass('geodisSwitch--active');
1216
1217    if (this.jsonValues.codeWithdrawalPoint) {
1218        this.selectPoint(this.jsonValues.codeWithdrawalPoint, undefined, this.get
1218SelectedCarrier().id_carrier, true);
1219    }
1220
1221    if (this.jsonValues.codeWithdrawalAgency) {
1222        this.selectPoint(this.jsonValues.codeWithdrawalAgency, undefined, this.getSelectedCarrier().id_carrier, true);
1223    }
1224
1225    this.mapAutoFit();
1226};
1227
1228GeodisCarrierSelector.prototype.showList = function(idCarrier, $elm) {
1229    this.$popin.find('.js-switch-map').removeClass('geodisSwitch--active');
1230    this.$popin.find('.js-point-list').addClass('geodisRelayPicker__list--active');
1231    this.$popin.find('.js-geodis-relay-map').removeClass('geodisRelayPicker__map--active');
1232    $elm.addClass('geodisSwitch--active');
1233};
1234
1235GeodisCarrierSelector.prototype.renderPointList = function(idCarrier, e) {
1236    // Set timeout
1237    if (typeof this.timeoutMapMove[(this.useGlobalMap ? 0 : idCarrier)] != 'undefined') {
1238        window.clearTimeout(this.timeoutMapMove[(this.useGlobalMap ? 0 : idCarrier)]);
1239    }
1240
1241    if (this.useGlobalMap) {
1242        idCarrier = [];
1243
1244        this.jsonConfig.carrierList.forEach((function(idCarrier, item) {
1245            idCarrier.push(item.id_carrier);
1246        }).bind(this, idCarrier));
1247    }
1248
1249    if (this.mapEnabled) {
1250        var data = {
1251            idCarrier: idCarrier,
1252            latitude: e.latitude,
1253            longitude: e.longitude,
1254            token: this.jsonValues.token,
1255            defaultLatitude: (!this.mapDefaultCenter[(this.useGlobalMap ? 0 : idCarrier)]) ? '' : this.mapDefaultCenter[(this.useGlobalMap ? 0 : idCarrier)].latitude,
1256            defaultLongitude: (!this.mapDefaultCenter[(this.useGlobalMap ? 0 : idCarrier)]) ? '' : this.mapDefaultCenter[(this.useGlobalMap ? 0 : idCarrier)].longitude
1257        };
1258    } else {
1259        var data = {
1260            idCarrier: idCarrier,
1261            zipCode: this.getZipCode(),
1262            token: this.jsonValues.token,
1263            countryCode: this.getCountryCode()
1264        };
1265    }
1266
1267    this.timeoutMapMove[(this.useGlobalMap ? 0 : idCarrier)] = window.setTimeout((function() {
1268        this.GeodisJQuery.ajax({
1269            'url': this.pointListUrl,
1270            data: data,
1271            dataType: 'json',
1272            method: 'GET'
1273        }).done((function(idCarrier, data) {
1274            var $elm = this.$popin.find('.js-point-list[data-values='+idCarrier+']');
1275
1276            if (data.status == 'error') {
1277                return;
1278            }
1279
1280            $elm.html('');
1281            this.pickupPointList = data.pickupPointList;
1282
1283            if (this.mapEnabled) {
1284                this.relayMap[idCarrier].flushMarkers();
1285
1286                // Home
1287                this.relayMap[idCarrier].addMarker({
1288                    position: this.mapDefaultCenter[idCarrier],
1289                    size: {
1290                        width: 26,
1291                        height: 43
1292                    },
1293                    url: this.markerHomeUrl
1294                });
1295            }
1296
1297
1298            // Shops
1299            for (var i in data.pickupPointList) {
1300                if (i != parseInt(i)) {
1301                    continue;
1302                }
1303
1304                var point = data.pickupPointList[i];
1305                var point2 = data.pickupPointList[i];
1306
1307                if (this.mapEnabled) {
1308                    this.relayMap[idCarrier].addMarker({
1309                        id: point.code,
1310                        position: {
1311                            latitude: point.latitude,
1312                            longitude: point.longitude,
1313                        },
1314                        size: {
1315                            width: 20,
1316                            height: 33
1317                        },
1318                        url: ((this.jsonValues.codeWithdrawalPoint == point.code || this.jsonValues.codeWithdrawalAgency == point.code) ? this.markerSelectedShopUrl : this.markerShopUrl),
1319                        onClick: (function(idCarrier, codePoint) {
1320                            this.selectPoint(codePoint, undefined, idCarrier, true);
1321                        }).bind(this, idCarrier)
1322                    });
1323                }
1324
1325                this.template.append(
1326                    'point',
1327                    $elm,
1328                    [
1329                        {
1330                            name: 'idCarrier',
1331                            value: idCarrier
1332                        },
1333                        {
1334                            name: 'code',
1335                            value: point.code
1336                        },
1337                        {
1338                            name: 'name',
1339                            value: point.name
1340                        },
1341                        {
1342                            name: 'address1',
1343                            value: point.address1
1344                        },
1345                        {
1346                            name: 'address2',
1347                            value: point.address2
1348                        },
1349                        {
1350                            name: 'zipCode',
1351                            value: point.zipCode
1352                        },
1353                        {
1354                            name: 'city',
1355                            value: point.city
1356                        },
1357                        {
1358                            name: 'monday',
1359                            value: JSON.stringify(point.openingTime[0])
1360                        },
1361                        {
1362                            name: 'tuesday',
1363                            value: JSON.stringify(point.openingTime[1])
1364                        },
1365                        {
1366                            name: 'wednesday',
1367                            value: JSON.stringify(point.openingTime[2])
1368                        },
1369                        {
1370                            name: 'thursday',
1371                            value: JSON.stringify(point.openingTime[3])
1372                        },
1373                        {
1374                            name: 'friday',
1375                            value: JSON.stringify(point.openingTime[4])
1376                        },
1377                        {
1378                            name: 'saturday',
1379                            value: JSON.stringify(point.openingTime[5])
1380                        },
1381                        {
1382                            name: 'sunday',
1383                            value: JSON.stringify(point.openingTime[6])
1384                        },
1385                        {
1386                            name: 'distance',
1387                            value: this.formatDistance(point.distance)
1388                        }
1389                    ]
1390                );
1391            }
1392
1393            if (this.mapEnabled) {
1394                if (!this.mapInitialized[idCarrier]) {
1395                    this.mapInitialized[idCarrier] = true;
1396                    this.mapAutoFit();
1397                }
1398            }
1399        }).bind(this, (this.useGlobalMap ? 0 : idCarrier)));
1400    }).bind(this), 1000);
1401};
1402
1403GeodisCarrierSelector.prototype.mapAutoFit = function() {
1404    var idCarrier = this.jsonValues.idCarrier;
1405    var defaultPosition = this.mapDefaultCenter[(this.useGlobalMap ? 0 : idCarrier)];
1406
1407    var positions = [
1408    ];
1409
1410    for (var i in this.pickupPointList) {
1411        if (i != parseInt(i)) {
1412            continue;
1413        }
1414
1415        var point = this.pickupPointList[i];
1416        if (this.jsonValues.codeWithdrawalPoint || this.jsonValues.codeWithdrawalAgency) {
1417            if (point.type != 'agency' && this.jsonValues.codeWithdrawalPoint == point.code
1418                || point.type == 'agency' && this.jsonValues.codeWithdrawalAgency == point.code
1419            ) {
1420                positions.push({
1421                    latitude: point.latitude,
1422                    longitude: point.longitude
1423                });
1424            }
1425        } else {
1426            positions.push({
1427                latitude: point.latitude,
1428                longitude: point.longitude
1429            });
1430        }
1431    }
1432    positions.push(this.mapDefaultCenter[(this.useGlobalMap ? 0 : idCarrier)]);
1433
1434    if (this.mapEnabled) {
1435        this.relayMap[(this.useGlobalMap ? 0 : idCarrier)].fitPositions(positions);
1436    }
1437};
1438
1439GeodisCarrierSelector.prototype.displayTimetable = function(values, $elm) {
1440    if ($elm.is('.geodisRelay__actionSeeTimetable--active')) {
1441        $elm.removeClass('geodisRelay__actionSeeTimetable--active');
1442    } else {
1443        $elm.addClass('geodisRelay__actionSeeTimetable--active');
1444    }
1445};
1446
1447GeodisCarrierSelector.prototype.renderTimeline = function($elm, values) {
1448    if (typeof values == 'undefined') {
1449        values = {
1450            morningStart: false,
1451            morningStop: false,
1452            eveningStart: false,
1453            eveningStop: false
1454        }
1455    }
1456
1457    if (!values.morningStart || values.morningStart == values.morningStop) {
1458        if (!values.eveningStop) {
1459            // Closed
1460            this.template.append(
1461                'point-timeline-closed',
1462                $elm
1463            );
1464            return;
1465        }
1466
1467        // Opened the afternoon only
1468        this.template.append(
1469            'point-timeline-one',
1470            $elm,
1471            [
1472                {
1473                    name: 'start',
1474                    value: values.eveningStart
1475                },
1476                {
1477                    name: 'end',
1478                    value: values.eveningStop
1479                }
1480            ]
1481        );
1482        return;
1483    }
1484
1485    // Opened the morning only
1486    if (!values.eveningStop) {
1487        this.template.append(
1488            'point-timeline-one',
1489            $elm,
1490            [
1491                {
1492                    name: 'start',
1493                    value: values.morningStart
1494                },
1495                {
1496                    name: 'end',
1497                    value: values.morningStop
1498                }
1499            ]
1500        );
1501        return;
1502    }
1503
1504    // Opened the morning and afternoon, no cut for lunch
1505    if (!values.eveningStart) {
1506        if (values.morningStart == values.eveningStop) {
1507            // Closed
1508            this.template.append(
1509                'point-timeline-closed',
1510                $elm
1511            );
1512        } else {
1513            this.template.append(
1514                'point-timeline-one',
1515                $elm,
1516                [
1517                    {
1518                        name: 'start',
1519                        value: values.morningStart
1520                    },
1521                    {
1522                        name: 'end',
1523                        value: values.eveningStop
1524                    }
1525                ]
1526            );
1527        }
1528        return;
1529    }
1530
1531    // Opened the morning and afternoon, cut for lunch
1532    this.template.append(
1533        'point-timeline-two',
1534        $elm,
1535        [
1536            {
1537                name: 'start1',
1538                value: values.morningStart
1539            },
1540            {
1541                name: 'end1',
1542                value: values.morningStop
1543            },
1544            {
1545                name: 'start2',
1546                value: values.eveningStart
1547            },
1548            {
1549                name: 'end2',
1550                value: values.eveningStop
1551            }
1552        ]
1553    );
1554    return;
1555};
1556
1557GeodisCarrierSelector.prototype.formatDistance = function(distance) {
1558    if (distance === '') {
1559        return;
1560    }
1561
1562    if (distance > 1000) {
1563        var distanceKm = parseFloat(distance) / 1000;
1564        if (distanceKm == parseInt(distanceKm)) {
1565            return this.sentenceDistanceKilometers.replace('@', parseInt(distanceKm));
1566        } else {
1567            return this.sentenceDistanceKilometers.replace('@', parseFloat(distance / 1000).toFixed(1));
1568        }
1569    }
1570
1571    return this.sentenceDistanceMeters.replace('@', distance);
1572}
1573
1574GeodisCarrierSelector.prototype.selectPoint = function(codePoint, $elm, idCarrier, autoFit) {
1575    this.$popin.find('.geodisRelay--selected').removeClass('geodisRelay--selected');
1576
1577    if (typeof $elm != 'undefined') {
1578        var idCarrier = $elm.data('parent');
1579    }
1580
1581    if (!this.useGlobalMap) {
1582        this.jsonValues.idCarrier = idCarrier;
1583    }
1584
1585    for (var i in this.pickupPointList) {
1586        if (i != parseInt(i)) {
1587            continue;
1588        }
1589
1590        var point = this.pickupPointList[i];
1591        if (point.code == codePoint) {
1592            if (point.type == 'agency') {
1593                this.jsonValues.codeWithdrawalPoint = null;
1594                this.jsonValues.codeWithdrawalAgency = codePoint;
1595            } else {
1596                this.jsonValues.codeWithdrawalPoint = codePoint;
1597                this.jsonValues.codeWithdrawalAgency = null;
1598            }
1599
1600            if (this.useGlobalMap) {
1601                this.jsonValues.idCarrier = point.idCarrier;
1602            }
1603
1604            this.setInfo('instructionsEnlevement', point.instructionsEnlevement);
1605            this.setInfo('instructionsLivraison', point.instructionsLivraison);
1606            this.setInfo('address', {
1607                name: point.name,
1608                address1: point.address1,
1609                address2: point.address2,
1610                zipCode: point.zipCode,
1611                city: point.city,
1612                countryCode: point.countryCode
1613            });
1614
1615            this.$popin.find('.js-geodis-relay-address[data-values='+(this.useGlobalMap ? 0 : idCarrier)+']').val(this.getAddress());
1616            if (typeof $elm != 'undefined') {
1617                $elm.closest('.geodisRelay').addClass('geodisRelay--selected');
1618            }
1619
1620            if (typeof autoFit == 'undefined' || autoFit === true) {
1621                this.mapAutoFit();
1622            }
1623        }
1624    }
1625
1626    if (this.canSubmit()) {
1627        this.$popin.find('.js-submit').removeClass('geodisPopinFooter__submit--inactive');
1628    } else {
1629        this.$popin.find('.js-submit').addClass('geodisPopinFooter__submit--inactive');
1630    }
1631
1632    this.updateCarrierPrice();
1633};
1634
1635GeodisCarrierSelector.prototype.setPointClass = function(codePoint, idCarrier) {
1636    if (this.jsonValues.codeWithdrawalPoint == codePoint || this.jsonValues.codeWithdrawalAgency == codePoint) {
1637        if (!this.mapInitialized[(this.useGlobalMap ? 0 : idCarrier)]) {
1638            this.selectPoint(codePoint, undefined, idCarrier, false);
1639        }
1640        return 'geodisRelay--selected';
1641    }
1642}
1643
1644GeodisCarrierSelector.prototype.updateRelayAddress = function(idCarrier) {
1645    var address = this.GeodisJQuery('.js-geodis-relay-address[data-values='+(this.useGlobalMap ? 0 : idCarrier)+']').val();
1646
1647    this.setInfo('defaultAddress', address);
1648    this.relayMap[(this.useGlobalMap ? 0 : idCarrier)].setAddress(address, (function(idCarrier, position) {
1649        this.mapDefaultCenter[(this.useGlobalMap ? 0 : idCarrier)] = position;
1650    }).bind(this, idCarrier));
1651};
1652
1653GeodisCarrierSelector.prototype.updateRelayShortAddress = function(idCarrier) {
1654    var zipCode = this.GeodisJQuery('.js-geodis-relay-zipcode').val();
1655    var countryCode = this.GeodisJQuery('.js-geodis-relay-country').val();
1656
1657    this.setInfo('defaultZipCode', zipCode);
1658    this.setInfo('defaultCountryCode', countryCode);
1659
1660    this.renderPointList();
1661};
1662
1663GeodisCarrierSelector.prototype.formatPrice = function(price, callback) {
1664    this.GeodisJQuery.ajax({
1665        url: this.formatPriceUrl,
1666        data: {
1667            token: this.jsonValues.token,
1668            price: price
1669        },
1670        dataType: 'json'
1671    }).done((function(data) {
1672        callback(data.price);
1673    }).bind(this));
1674};
1675
1676GeodisCarrierSelector.prototype.hideShowAppointmentMessage = function(carrierType) {
1677    if (carrierType == 'rdv') {
1678        this.GeodisJQuery('.js-description').show();
1679    } else {
1680        this.GeodisJQuery('.js-description').hide();
1681    }
1682};
1683
1684GeodisCarrierSelector.prototype.getIdCarrier = function (carrierType, carrierId) {
1685    if (carrierType == 'relay') {
1686        return 0;
1687    }
1688
1689    return carrierId;
1690}

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.