1//Callback-Funktion für Checker V2 (Webcomponent) 2let CheckerFillConfiguratorCallback = function( res) { 3 // res ist vom Typ CheckerCallbackModel (siehe Repository gfo_checker2) 4 let addressInstall = { 5 city: res.result.address.city, 6 street: res.result.address.street, 7 street_number: res.result.address.houseNr, 8 zip_code: res.result.address.zip 9 } 10 if (res.result.address.building){ 11 addressInstall.street = res.result.address.building; 12 addressInstall.street_number = ""; 13 } 14 15 let resultGroup = res.result.resultGroups[0]; 16 let netzSlug = resultGroup.netzSlugs[0]; 17 let profiles = resultGroup.profiles.filter(function(item){ 18 return item.netzIsMixin == false; 19 }) 20 let mixin_profiles = resultGroup.profiles.filter(function(item){ 21 return item.netzIsMixin == true; 22 }) 23 24 profiles = profiles.map(function(item){ 25 return { 26 api_version: 2, 27 customer_id: item.customerId, 28 group: "", 29 max_upstream: item.maxUpstream, 30 max_downstream: item.maxDownstream, 31 netz_id: item.netzId, 32 netz_slug: item.netzSlug, 33 product_variant_id: item.productVariantId, 34 service_provider: item.serviceProvider, 35 service_type: item.serviceType, 36 } 37 }); 38 mixin_profiles = mixin_profiles.map(function(item){ 39 return { 40 api_version: 2, 41 customer_id: item.customerId, 42 group: "", 43 max_upstream: item.maxUpstream, 44 max_downstream: item.maxDownstream, 45 netz_id: item.netzId, 46 netz_slug: item.netzSlug, 47 product_variant_id: item.productVariantId, 48 service_provider: item.serviceProvider, 49 service_type: item.serviceType, 50 } 51 }) 52 let maxSpeed = resultGroup.maxSpeed; 53 iWidgetKonguratorFillFromChecker({ 54 selector: '.iWidget_Configurator', 55 netz: netzSlug, 56 address: addressInstall, 57 max_speed: maxSpeed, 58 available_profiles: profiles, 59 mixin_profiles: mixin_profiles, 60 checker_query: "", // braucht es das wirklich? 61 checker_result_uid: res.checker_result_uid 62 }); 63} 64 65/* 66 * Author: Adrian Kuehis 67 *
68 * Dieses Script haucht dem Availability Checker Leben ein 69 * 70 * Dependencies (in theme' function.php geladen) 71 * //iway.ch/gfo/api/checker_service.js 72 * //themes/iwayone/assets/js/vue.min.js 73 */ 74document.addEventListener('DOMContentLoaded', function () { 75 // 24.4.24 - mit checker v2 nicht mehr benoetigt 76 return 77 if (typeof Vue == 'undefined') { 78 console.log('Vue ist nicht verfügbar'); 79 $('.block_availability_check').hide(); 80 return; 81 } 82 if (typeof gfo_api_url == 'undefined') { 83 console.log('gfo_api_url ist nicht verfügbar'); 84 $('.block_availability_check').hide(); 85 return; 86 } 87 if (typeof gfo_api_token == 'undefined') { 88 console.log('gfo_api_token ist nicht verfügbar'); 89 $('.block_availability_check').hide(); 90 return; 91 } 92 if (typeof GfoNg == 'undefined'){ 93 console.log('GfoNg ist nicht verfügbar'); 94 $('.block_availability_check').hide(); 95 return; 96 } 97 var checkers_on_page = document.querySelectorAll('.block_availability_check'); 98 for (var i = 0; i < checkers_on_page.length; i++) { 99 initBlockAvailabilityCheck(checkers_on_page[i]); 100 } 101}); 102 103function initBlockAvailabilityCheck(el) { 104 // 24.4.24 - mit checker v2 nicht mehr benoetigt 105 return 106 $(el).removeClass('gfo_hide'); 107 $(el).find('.gfo_hide').removeClass('gfo_hide'); 108 var checker_key = el.getAttribute('data-checker_key'); 109 var checker_keys = checker_key.split(','); 110 var check_bys = el.getAttribute('data-check_by').split(','); 111 var netz_display = el.getAttribute('data-netz_display'); 112 var box_ids_0 = el.getAttribute('data-access_product_box_1'); 113 var box_ids_1 = el.getAttribute('data-access_product_box_2'); 114 var box_ids_2 = el.getAttribute('data-access_product_box_3'); 115 var box_variant_ids = { 116 0: !box_ids_0 ? [] : box_ids_0.split(',').map(function (item) { return parseInt(item) }), 117 1: !box_ids_1 ? [] : box_ids_1.split(',').map(function (item) { return parseInt(item) }), 118 2: !box_ids_2 ? [] : box_ids_2.split(',').map(function (item) { return parseInt(item) }), 119 }; 120 var gfo_ng = new GfoNg({ 121 api_token: gfo_api_token, 122 api_url: gfo_api_url, 123 }); 124 var app = new Vue({ 125 el: el, 126 data: { 127 address_api: gfo_ng.getAddressApi(), 128 gfo_ng: gfo_ng, 129 gfo_checker: null, // checker object, set during check 130 check_bys: check_bys, 131 check_by: check_bys[0], 132 checker_key: checker_keys[0], 133 checker_keys: checker_keys, 134 found_place_id: 0, 135 found_street_id: 0, 136 street: '', 137 street_number: '', 138 zip_code: '', 139 city: '', 140 oto_id: '', 141 phone: '', 142 checked: false, 143 checking: false, 144 netze: [], 145 checker_query_uid: '', 146 error: '', 147 result_display: el.getAttribute('data-result_display'), 148 result_places: [], 149 result_streets: [], 150 result_housenr: [], 151 checker_result_uid: '', 152 }, 153 computed: { 154 address: function () { 155 return { 156 street: this.street, 157 street_number: this.street_number, 158 zip_code: this.zip_code, 159 city: this.city, 160 }; 161 }, 162 instadr: function () { 163 var that = this; 164 for (var i = 0; i < this.netze.length; i++) { 165 var profiles = that.gfo_checker.getProfiles(this.netze[i]); 166 if (0 < profiles.length) { 167 var address = that.gfo_checker.getInstadr(this.netze[i]); 168 if (null !== address) { 169 return address.street + ' ' + address.street_number + ', ' + 170 address.zip_code + ' ' + address.city; 171 } 172 } 173 } 174 return this.street + ' ' + this.street_number + ', ' + 175 this.zip_code + ' ' + this.city; 176 }, 177 address_install: function () { 178 var that = this; 179 if (!this.gfo_checker) { 180 return this.address; 181 } 182 for (var i = 0; i < this.netze.length; i++) { 183 var profiles = this.getProfiles(this.netze[i]); 184 if (0 < profiles.length) { 185 var address = that.gfo_checker.getInstadr(this.netze[i]); 186 if (null !== address) { 187 return address; 188 } 189 } 190 } 191 return this.address; 192 }, 193 show_no_fiber_info: function () { 194 if (0 == this.netze.length) { 195 return false;
196 } 197 for (var i = 0; i < this.netze.length; i++) { 198 if ('gf' == this.netze[i].anschluss) { 199 return false; 200 } 201 } 202 return true; 203 }, 204 check_button_value: function() { 205 return this.checking ? 'Prüfung läuft' : 'Jetzt prüfen'; 206 207 }, 208 checker_choices: function () { 209 var choices = []; 210 var private_key = checker_keys.filter(function(item){ 211 return -1 < item.indexOf('private') 212 })[0] 213 var business_key = checker_keys.filter(function(item){ 214 return -1 < item.indexOf('business') 215 })[0] 216 if (private_key){ 217 choices.push({ 218 value: private_key, 219 label: 'Privat', 220 }); 221 } 222 if (business_key){ 223 choices.push({ 224 value: business_key, 225 label: 'Business', 226 }); 227 } 228 229 return choices; 230 }, 231 check_by_choices: function () { 232 var choices = []; 233 if (-1 < this.check_bys.indexOf('address')) { 234 choices.push({ 235 value: 'address', 236 label: 'Adresse', 237 }); 238 } 239 if (-1 < this.check_bys.indexOf('oto_id')) { 240 choices.push({ 241 value: 'oto_id', 242 label: 'OTO-ID', 243 }); 244 } 245 if (-1 < this.check_bys.indexOf('phone')) { 246 choices.push({ 247 value: 'phone', 248 label: 'Telefon-Nummer', 249 }); 250 } 251 return choices; 252 253 }, 254 result_housenr_filtered: function () { 255 var that = this; 256 var filtered = this.result_housenr 257 .filter(function (nr) { 258 return 0 == nr.toUpperCase().indexOf(that.street_number.toUpperCase()); 259 }) 260 .slice(0, 10); 261 return filtered.map(function (nr) { 262 return { 263 id: nr, 264 name: nr 265 }; 266 }); 267 }, 268 269 }, 270 methods: { 271 getCheckerQueryParts: function(){ 272 // Checker-Query zusammen stellen (wird dann vom Konfigurator/Produkt-Box so weiter gegeben) 273 let parts = []; 274 parts.push('checker_key=' + encodeURIComponent(this.checker_key)); 275 if ('oto_id' == this.check_by) { 276 parts.push('checker_quali=' + encodeURIComponent(this.oto_id)); 277 } else if ('phone' == this.check_by) { 278 parts.push('checker_quali=' + encodeURIComponent(this.phone)); 279 } else { 280 parts.push('checker_quali=' + encodeURIComponent(this.street 281 + ' ' + this.street_number 282 + ', ' + this.zip_code 283 + ' ' + this.city)); 284 } 285 let ok_netze = this.gfo_checker.getAvailableNetze('available_with_mixins'); 286 let ok_netze_str = ok_netze.map(function(item){ 287 return item.slug; 288 }).join(','); 289 parts.push('checker_available_netze=' + encodeURIComponent(ok_netze_str)); 290 return parts; 291 }, 292 check: function (evt) { 293 evt.preventDefault(); 294 var that = this; 295 this.checker_result_uid = ''; 296 this.checked = false; 297 this.checking = true; 298 this.netze = []; 299 this.gfo_checker = gfo_ng.getAccessChecker(this.checker_key); 300 var checker_method = 'checkByAddress'; 301 var checked_value = this.address; 302 if ('oto_id' == this.check_by) { 303 checker_method = 'checkByOto'; 304 checked_value = this.oto_id; 305 } 306 if ('phone' == this.check_by) { 307 checker_method = 'checkByNumber'; 308 checked_value = this.phone.split(' ').join(''); 309 } 310 this.gfo_checker[checker_method](checked_value, function (res) { 311 let checker_query = {} 312 if ('checkByOto' == checker_method){ 313 checker_query = {oto: checked_value} 314 } else if ('checkByNumber' == checker_method){ 315 checker_query = {number: checked_value} 316 } else if ('checkByAddress' == checker_method){ 317 checker_query = { 318 street: checked_value.street, 319 houseNr: checked_value.street_number, 320 zip: checked_value.zip_code, 321 city: checked_value.city, 322 } 323 } 324 let checker_result_data = { 325 checker_key: that.checker_key, 326 query: checker_query, 327 response: res 328 } 329 that.gfo_ng.getApi().sendRequest('POST', '/checker_result', checker_result_data, function(res2){ 330 that.checker_result_uid = res2.uid; 331 that.checking = false;
332 that.checked = true; 333 that.error = ''; 334 that.netze = that.gfo_checker.getAvailableNetze(netz_display); 335 if ('configurator' == that.result_display && 0 < that.netze.length) { 336 var netz = that.gfo_checker.getAvailableNetze('first')[0]; 337 var profiles = that.gfo_checker.getProfiles(netz); 338 var profiles_width_mixins = that.gfo_checker.getProfilesWithMixins(netz); 339 340 var mixin_profiles = profiles_width_mixins.filter(function (item) { 341 return item.netz_slug != netz.slug; 342 }); 343 344 var max_speed = that.gfo_checker.getMaxSpeed(netz) 345 iWidgetKonguratorFillFromChecker({ 346 selector: '.iWidget_Configurator', 347 netz: netz.slug, 348 address: that.address_install, 349 max_speed: max_speed, 350 available_profiles: profiles, 351 mixin_profiles: mixin_profiles, 352 checker_query: that.getCheckerQueryParts().join('&'), 353 checker_result_uid: res2.uid 354 }); 355 } 356 if ('product_box' == that.result_display && 0 < that.netze.length) { 357 var netz = that.gfo_checker.getAvailableNetze('first')[0]; 358 var profiles = that.gfo_checker.getProfiles(netz); 359 var available_pvids = profiles.map(function (profile) { 360 return profile.product_variant_id; 361 }); 362 iWidgetProductBoxesFillFromChecker({ 363 selector: '.iWidget_productBoxes', 364 netz: netz.slug, 365 available_pvids: available_pvids, 366 address: that.address_install, 367 box_variant_ids: box_variant_ids, 368 checker_query: that.getCheckerQueryParts().join('&'), 369 checker_result_uid: res2.uid 370 }); 371 } 372 }); 373 }, function (err) { 374 that.error = 'Ein Fehler ist aufgetreten'; 375 that.checked = true; 376 that.checking = false; 377 }); 378 }, 379 getProfiles: function (netz) { 380 let profiles = this.gfo_checker.getProfilesWithMixins(netz); 381 return profiles; 382 }, 383 384 getMaxSpeed: function (netz) { 385 var speed = this.gfo_checker.getMaxSpeed(netz); 386 387 if (speed[0] < 1000) { 388 speed[0] = Number(((speed[0] / 10) / 100).toFixed(1)); 389 } else { 390 speed[0] = Math.floor(speed[0] / 1000); 391 } 392 393 if (speed[1] < 1000) { 394 speed[1] = Number(((speed[1] / 10) / 100).toFixed(1)); 395 } else { 396 speed[1] = Math.floor(speed[1] / 1000); 397 } 398 399 400 console.log(speed); 401 return speed; 402 }, 403 getUrlOfProfile: function (profile) { 404 var order_page = window['gfo_default_checkout_page']; 405 var url_parts = order_page.split('#'); 406 var url = url_parts[0]; 407 var parts = []; 408 var netz = null; 409 if (profile && profile.hasOwnProperty('netz_slug')) { 410 parts.push('netz=' + encodeURIComponent(profile.netz_slug)); 411 var a = profile.customer_id.split('_'); 412 parts.push('pv_ids=' + a[1]); 413 } else { 414 if (!profile) { 415 netz = this.netze[this.netze.length - 1]; 416 } else { 417 var a = profile.customer_id.split('_'); 418 parts.push('pv_ids=' + a[1]); 419 netz = this.netze.filter(function (item) { 420 return item.netz_id == parseInt(a[0]); 421 })[0]; 422 } 423 if (netz) { 424 parts.push('netz=' + encodeURIComponent(netz.slug)); 425 } 426 } 427 if (this.checker_result_uid){ 428 parts.push('checker_result_uid=' + this.checker_result_uid) 429 } else if (this.address_install) { 430 parts.push('address_install[street]=' + encodeURIComponent(this.address_install.street)); 431 parts.push('address_install[street_number]=' + encodeURIComponent(this.address_install.street_number)); 432 parts.push('address_install[zip_code]=' + encodeURIComponent(this.address_install.zip_code)); 433 parts.push('address_install[city]=' + encodeURIComponent(this.address_install.city)); 434 parts.push('checker_key=' + encodeURIComponent(this.checker_key)); 435 if ('oto_id' == this.check_by) { 436 parts.push('checker_quali=' + encodeURIComponent(this.oto_id)); 437 } else if ('phone' == this.check_by) { 438 parts.push('checker_quali=' + encodeURIComponent(this.phone)); 439 } else { 440 parts.push('checker_quali=' + encodeURIComponent(this.street 441 + ' ' + this.street_number 442 + ', ' + this.zip_code 443 + ' ' + this.city)); 444 }
445 let ok_netze = this.gfo_checker.getAvailableNetze('available_with_mixins'); 446 let ok_netze_str = ok_netze.map(function(item){ 447 return item.slug; 448 }).join(','); 449 parts.push('checker_available_netze=' + encodeURIComponent(ok_netze_str)); 450 } 451 452 url += (-1 == url.indexOf('?')) ? '?' : '&'; 453 url += parts.join('&'); 454 if (2 == url_parts.length) { 455 url += '#' + url_parts[1]; 456 } 457 return url; 458 }, 459 onBlurPlace: function () { 460 var that = this; 461 window.setTimeout(function () { 462 that.result_places = []; 463 }, 500); 464 }, 465 onBlurStreet: function () { 466 var that = this; 467 window.setTimeout(function () { 468 that.result_streets = []; 469 }, 500); 470 }, 471 onBlurHouse: function () { 472 var that = this; 473 window.setTimeout(function () { 474 that.result_housenr = []; 475 }, 500); 476 }, 477 478 searchZip: function() { 479 var that = this; 480 this.found_place_id = 0; 481 if (!that.zip_code){ 482 that.result_places = []; 483 return; 484 } 485 this.address_api.searchZip(this.zip_code, null, function(res){ 486 that.result_places = res; 487 }); 488 }, 489 searchCity: function() { 490 var that = this; 491 this.found_place_id = 0; 492 if (that.zip_code && 4 == that.zip_code.length) { 493 // User hat PLZ eingegeben, suche nach ZIP 494 that.address_api.searchZip(that.zip_code, null, function(res){ 495 that.result_places = res; 496 }); 497 } else if ("" == that.city) { 498 that.result_places = []; 499 } else { 500 that.address_api.searchCity(that.city, null, function(res){ 501 that.result_places = res; 502 }); 503 } 504 }, 505 searchStreet: function(evt) { 506 // IWEB-774: aus irgend einem Grund funktioniert das nicht auf Samsung 20 Chrome 507 // Aber nur bei street. this.street bleibt auf 1. Buchstaben stecken... 508 // Darum wird hier der Wert direkt aus dem Event-Target gelesen 509 let street = evt.target.value; 510 var that = this; 511 if (!this.found_place_id) { 512 this.result_streets = []; 513 return; 514 } 515 this.address_api.searchStreet(street, this.found_place_id, null, function(res){ 516 that.result_streets = res; 517 }); 518 }, 519 520 searchHouse: function() { 521 var that = this; 522 if (!this.found_street_id) { 523 this.result_housenr = []; 524 return; 525 } 526 this.address_api.searchHouse(this.found_street_id, null, function(res){ 527 that.result_housenr = res; 528 }); 529 }, 530 531 selectPlace: function(result) { 532 this.found_place_id = result.id; 533 this.zip_code = result.postcode; 534 this.city = result.name; 535 this.result_places = []; 536 this.$refs["input_street"].focus(); 537 }, 538 selectStreet: function(result) { 539 this.found_street_id = result.id; 540 this.street = result.name; 541 this.result_streets = []; 542 this.$refs["input_housenr"].focus(); 543 }, 544 selectHouse: function(result) { 545 this.street_number = result.name; 546 } 547 }, 548 created: function(){ 549 // Prevent autocompletion 550 var elements = document.querySelectorAll("input[autocomplete=off]"); 551 elements.forEach(function(el){ 552 el.setAttribute('autocomplete', 'new-password') 553 }) 554 } 555 }); 556 557} 558
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.