PageSourceSearch

https://www.iway.ch/wp-content/themes/iwaytwo/assets/js/block_intro_availability_check.js?ver=1790855779

js iway.ch collected 2026-10-01 11:58:09 UTC 5,302 bytes, 142 lines download raw bytes

1/*
2 * Author: Adrian Kuehis
3 *
4 * Dieses Script braucht der Lazy-Block 'intro'
5 *
6 * Dependencies (in theme' function.php geladen) 
7 * //iway.ch/gfo/api/checker_service.js
8 * //themes/iwayone/assets/js/vue.min.js
9 * //themes/iwayone/assets/js/vuex.js
10 *
11 * Note: IE does not support:
12 * forEach on node list (querySelectorAll)
13 * direct object binding (must do {el: el, one: one}
14 * let or const
15 */
16document.addEventListener('DOMContentLoaded', function(){
17    if (typeof GfoNg == 'undefined') {
18        console.log('GfoNg ist nicht verfügbar');
19        $('.block_availability_check').hide();
20        return;
21    }
22    if (typeof Vue == 'undefined') {
23        console.log('Vue ist nicht verfügbar');
24        $('.block_availability_check').hide();
25        return;
26    }
27    if (typeof gfo_api_url == 'undefined') {
28        console.log('gfo_api_url ist nicht verfügbar');
29        $('.block_availability_check').hide();
30        return;
31    }
32    if (typeof gfo_api_token == 'undefined') {
33        console.log('gfo_api_token ist nicht verfügbar');
34        $('.block_availability_check').hide();
35        return;
36    }
37    var el = document.querySelector('.intro_availability_check');
38    if (el) {
39        initIntroAvailabilityCheck(el);
40    }
41});
42
43function initIntroAvailabilityCheck(el) {
44    var checker_key = el.getAttribute('data-checker_key');
45    var order_page  = el.getAttribute('data-order_page');
46    var gfo_ng = new GfoNg({
47        api_token: window.gfo_api_token,
48        api_url:   window.gfo_api_url,
49        debug: true,
50    });
51    var access_checker = gfo_ng.getAccessChecker(checker_key);
52    var product_boxes_element = document.querySelector('.iWidget_productBoxes');
53    var box_ids_0 = el.getAttribute('data-access_product_box_1');
54    var box_ids_1 = el.getAttribute('data-access_product_box_2');
55    var box_ids_2 = el.getAttribute('data-access_product_box_3');
56    var box_variant_ids = {
57        0: !box_ids_0 ? [] : box_ids_0.split(',').map(function(item){return parseInt(item)}), 
58        1: !box_ids_1 ? [] : box_ids_1.split(',').map(function(item){return parseInt(item)}), 
59        2: !box_ids_2 ? [] : box_ids_2.split(',').map(function(item){return parseInt(item)}), 
60    };
61
62    // Remove all gfo_hide classes in these elements. Vuejs takes control
63    $(el).find('.gfo_hide').removeClass('gfo_hide');
64
65    // This is the application for the intro block
66    var app = new Vue({
67        el: el,
68        data: function(){
69            return {
70                is_checking:   false,
71                is_checked:    false,
72                is_found:      true,
73                has_profiles:  true,
74                show_checker_form: false,
75                error:         '',
76                street: '',
77                street_number: '',
78                zip_code: '',
79                city: '',
80            }
81        },
82        methods: {
83            showCheckerForm: function(evt) {
84                evt.preventDefault();
85                this.street = '';
86                this.street_number = '';
87                this.zip_code = evt.target.zip.value;
88                this.city = '';
89                this.show_checker_form = true;
90            },
91            check: function(evt) {
92                evt.preventDefault();
93                var that = this;
94                var search_address = {
95                    street: this.street,
96                    street_number: this.street_number,
97                    zip_code: this.zip_code,
98                    city: this.city,
99                };
100
101                this.error = '';
102                this.is_checked = false;
103                this.is_checking = true;
104                access_checker.checkByAddress(search_address, function(res){
105                    that.is_checking = false;
106                    that.is_checked  = true;
107                    
108                    that.has_profiles     = access_checker.hasProfiles();
109                    that.is_found         = access_checker.isFound();
110                    var netz              = access_checker.getAvailableNetze('first')[0];
111                    var profiles          = access_checker.getProfiles(netz);
112                    var address           = access_checker.getInstadr(netz);
113                    if (!address) {
114                        address = search_address;
115                    }
116                    var available_pvids = profiles.map(function(profile){
117                            return profile.product_variant_id;
118                        });
119                    if (that.is_found && that.has_profiles) {
120                        that.show_checker_form = false;
121                        iWidgetProductBoxesFillFromChecker({
122                                selector: '.iWidget_productBoxes', 
123                                netz: netz.slug,
124                                available_pvids: available_pvids,
125                                address: address,
126                                box_variant_ids: box_variant_ids,
127                            });
128                    }
129                }, function(err){
130                    that.is_checked = true;
131                    that.is_checking = false;
132                    that.error = 'Bei der Prüfung ist ein Fehler aufgetreten.';
133                });
134            },
135            
136            
137        },
138    });
139
140}
141
142

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.