1/* 2* 3*/ 4; 5(function ($, undefined) { 6 var ON_BEFORE_SHOWNEAREST = "beforeShowNearest"; 7 var ON_AFTER_SHOWNEAREST = "afterShowNearest"; 8 var ON_BEFORE_UPDATELATLNG = "beforeUpdateLatLng"; 9 var ON_AFTER_UPDATELATLNG = "afterUpdateLatLng"; 10 11 var storeAvailabilityLocatorWidgetCustom = { 12 name: "storeAvailabilityLocatorCustom", 13 extend: "mvvmwidget", 14 events: [ 15 ON_BEFORE_SHOWNEAREST, 16 ON_AFTER_SHOWNEAREST, 17 ON_BEFORE_UPDATELATLNG, 18 ON_AFTER_UPDATELATLNG 19 ], 20 21 options: { 22 widgetGuid: null, 23 addressSearchId: "", 24 25 searchResultsMax: 3, 26 whenNoStoreSetText: "Please select your store", 27 setStoreButtonText: "Set Location", 28 currentStoreButtonText: "My Store", 29 userCurrentStoreName: "", 30 storeLocationDetailsFieldDataCustomFieldGroup: "store-location-availability", 31 32 errorMessageAddressNotFound: "Address not found.", 33 errorMessageAddressLookupFailed: "Address lookup failed.", 34 errorMessageUnableToShowMap: "Unable to show map.", 35 checkStoreAvailabilityClickAndCollect: true, 36 37 enforceStoreSelection: false, 38 maxDistance: 250, 39 showDistanceSlider: false, 40 widgetMode: "display", 41 popupWidgetId: "" 42 }, 43 44 initialise: function (el, o) { 45 var widget = this, 46 opts = widget.options, 47 vm = widget.viewModel; 48 //if (typeof($.cookie("UserStoreName") != "undefined")) 49 //{ 50 // $.cv.css.storeLocator.setUserCurrentStore({ storeName: $.cookie("UserStoreName")}); 51 //} 52 53 if (opts.enforceStoreSelection === "True" && opts.widgetMode != "display") { 54 // 13aug18 tf No home page exclusion needed 55 // #268649 56 if ($(".page-ProductDisplay").length == 1 && $(".role-PUBLIC").length == 1 ) { 57 58 // not the home page, check for dealer selection 59 if (opts.userCurrentStoreName == "") { 60 // No Dealer Selected, enforce 61 // vm._toggleStoreLocationDisplay(); 62 if (typeof($.cookie("UserStoreName")) == "undefined") 63 { 64 65 vm.set("storeSelectionRequired", true); 66 $(".cv-ico-general-cross").hide(); 67 } 68 else 69 { 70 $.cv.css.storeLocator.setUserCurrentStore({ storeName: $.cookie("UserStoreName")}); 71 vm.set("currentStoreName", $.cookie("UserStoreName")); 72 $(".cv-ico-general-cross").show(); 73 } 74 console.log('cookiefound'); 75 console.log($.cookie('UserStoreName')); 76 if (typeof($.cookie("UserStoreName")) == "undefined" && $(".page-ProductDisplay").length == 1 && $(".role-PUBLIC").length == 1) 77 { 78 vm._toggleStoreLocationDisplayPopup(); 79 } 80 81 } 82 } 83 } 84 vm._bindSuburbLookup(); 85 }, 86 87 // Called after the widget view is bound to the viewModel. 88 viewModelBound: function () { 89 var widget = this; 90 }, 91 92 _getViewModel: function () { 93 var widget = this; 94 95 var viewModel = kendo.observable({ 96 storeLocations: [], 97 currentStoreDetails: [], 98 currentStoreName: widget.options.userCurrentStoreName, 99 selectedAddress: "", 100 selectDone: false, 101 disableView: false, 102 noResults: false, 103 maxDistance: widget.options.maxDistance, 104 storeSelectionRequired: false, 105 106 isProcessing: false, 107 isProcessingSetStore: false, 108 109 _showError: function (messageText) { 110 viewModel.set("isProcessing", false); 111 viewModel._showMessage({ Type: "error", Message: messageText }); 112 }, 113 114 _showMessage: function (message, clearExisting) { 115 // Get CSS class for type of error. 116 var type = ""; 117 $.each($.cv.css.messageTypes, function (key, value) { 118 if (key == message.Type) { 119 type = value; 120 } 121 }); 122 123 var result = $.cv.css.trigger($.cv.css.eventnames.message, { type: type, message: message.Message, source: widget.name, clearExisting: clearExisting });
124 if (result.handlerCount == 0) { 125 // No widget handled message - display alert. 126 alert(message.Message); 127 } 128 }, 129 130 _clearMessages: function() { 131 $.cv.css.trigger($.cv.css.eventnames.message, { message: "", type: "", source: widget.name, clearExisting: true }); 132 }, 133 134 _bindSuburbLookup: function () { 135 var vm = this; 136 if (widget.options.addressSearchId != "") { 137 var inptAddessSearch = $("input#" + widget.options.addressSearchId); 138 139 var suburbList = $.cv.data.dataSource({ 140 method: 'storeLocator/getSuburbHelpers', 141 params: function () { 142 return { 143 searchFilter: inptAddessSearch.val().trim(), 144 incName: true, 145 useLikeName: true, 146 incPostcode: true, 147 useLikePostcode: true, 148 maxResults: 50 149 }; 150 } 151 }); 152 153 inptAddessSearch.kendoAutoComplete({ 154 dataSource: suburbList, 155 filter: "startswith", 156 template: '<span>#= data.Name # #= data.State # #= data.Postcode #</span>', 157 noDataTemplate: 'Please enter a suburb or postcode', 158 change: function(e) { 159 //console.log(e); 160 }, 161 select: function(e) { 162 if (e.item.length > 0) { 163 if (e.item[0].innerText == undefined) { 164 vm.set("selectedAddress", e.item[0].textContent); 165 } else { 166 vm.set("selectedAddress", e.item[0].innerText); 167 } 168 vm.set("selectDone", true); 169 } 170 }, 171 close: function (e) { 172 if (vm.get("selectDone") == true) { 173 inptAddessSearch.val(vm.get("selectedAddress")); 174 } else { 175 vm.set("selectDone", true); // use the manually entered one 176 } 177 } 178 }); 179 } 180 }, 181 182 _getDataView: function (data) { 183 var array = []; 184 $.each(data, function (idx, item) { 185 // add standard commands 186 item.index = idx; 187 var dataItem = $.cv.util.getFieldItemData(item); 188 array.push(dataItem); 189 190 }); 191 return array; 192 }, 193 194 _findStores: function() { 195 var vm = this; 196 var address = vm.get("selectedAddress"); 197 vm.set("noResults", false); 198 if (vm.get("selectDone") == false) { 199 return false; 200 } 201 vm.set("isProcessing", true); 202 $("div.k-nodata").hide(); 203 204 // 2. Get latitude/longitude of address. 205 var geocoder = new google.maps.Geocoder(); 206 geocoder.geocode({ "address": address, "region": 'Australia' }, function(results, status) { 207 if (status === google.maps.GeocoderStatus.OK) { 208 // 3. Get nearest stores. 209 var origLat = results[0].geometry.location.lat(), 210 origLng = results[0].geometry.location.lng(); 211 212 // event tracking for GA 213 if ($.cv.util.hasValue(results, "[0]")) { 214 if ($.cv.util.hasValue(results[0].address_components)) { 215 if (results[0].address_components.length == 5) { 216 var pushData = { 217 event: "dealerlocator",
218 suburb: results[0].address_components[0].long_name 219 }; 220 221 $.cv.css.tracker.push(pushData) 222 } 223 } 224 } 225 226 var p = $.cv.css.storeLocator.findNearestStore({ 227 latitude: origLat, 228 longitude: origLng, 229 maxStores: widget.options.searchResultsMax, 230 jsonFieldGroupName: widget.options.storeLocationDetailsFieldDataCustomFieldGroup, 231 checkStoreAvailabilityClickAndCollect: widget.options.checkStoreAvailabilityClickAndCollect 232 }); 233 234 235 $.when(p).done(function (data) { 236 $.cssWebServicesAjax.getCustomTableData({ 237 key: 'BranchPostCode', 238 jsonFieldGroupName: 'BranchPostCodes', 239 skip: 0, 240 take: 9999, 241 filter: '', 242 success: function (Postcodes) { 243 var availablepostcodes = Postcodes; 244 var SelectedPostcode = address.substr(-4, 4); 245 246 var localMaxDistance = 999999; 247 if ($.isNumeric(vm.get("maxDistance"))) { 248 localMaxDistance = vm.get("maxDistance"); 249 } 250 $.each(availablepostcodes.Data, function (i, Postcodes) { 251 if (Postcodes.PostCode == SelectedPostcode) { 252 return Postcodes.PostCode; 253 } 254 }); 255 $.each(availablepostcodes.Data, function (i, Postcodes) { 256 if( Postcodes.PostCode == SelectedPostcode){ 257 data.data = _.filter(data.data, _.bind(function(z) { return (z.DistanceKm < localMaxDistance ) })); 258 var filtered = _.filter(data.data, function(i, item) { 259 return i.WarehouseCode != ""; 260 }); 261 data.data = filtered; 262 var matchWarhouse = _.filter(data.data, function(i, finalData) { 263 return i.WarehouseCode == Postcodes.Warehouse; 264 }); 265 data.data = matchWarhouse; 266 } 267 if (data.data.length == 0 || Postcodes.PostCode != SelectedPostcode ) { 268 vm.set("noResults", true); 269 vm.set("isProcessing", false); 270 } else { 271 $.each(data.data, function (i, storeLocation) { 272 if (storeLocation.StoreLocationDetailsFieldData ) { 273 274 storeLocation.StoreLocationDetailsFieldData = vm._getDataView(storeLocation.StoreLocationDetailsFieldData); 275 }else{ 276 vm.set("noResults", true); 277 vm.set("isProcessing", false); 278 } 279 280 }); 281 vm.set("noResults", false); 282 return false; // breaks 283 } 284 }); 285 vm.set("storeLocations", data.data); 286 vm.set("isProcessing", false); 287 vm.set("selectDone", true); 288 $('.fancybox-inner').scrollTop($("div.store-listing").offset().top); 289 290 } 291 }); 292 }); 293 } else { 294 vm.set("noResults", true); 295 vm.set("isProcessing", false); 296 vm.set("selectDone", true); 297 } 298 }); 299 300 return false; // prevent postback 301 }, 302 303 storeSelected: function() { 304 return widget.options.userCurrentStoreName != ""; 305 }, 306 307 _closePopup: function() { 308 $("div[id='" + widget.options.popupWidgetId + "']").hide(); 309 window.location = '/home.aspx'; 310 return false; 311 $.fancybox.close(); 312 window.location = '/home.aspx'; 313 $(".fancybox-overlay").fancybox.close(); 314 }, 315 316 _setStore: function (item) { 317 var vm = this, 318 CustomerCode = item.data.ProntoAccountCode; 319 storeToSet = item.data.StoreName; 320 _postCode = item.data.Postcode.trim(); 321 // just return if click on current store. 322 323 if (storeToSet === vm.get("currentStoreName")){ 324 $.fancybox.close(); 325 326 return false; 327 } else { 328 329 var p = storeToSet; 330 vm._stopIsProcessingSetStore(true, storeToSet); 331 332 333 $.cv.css.orders.updateOrderValidationPostCode({ postCode: _postCode }).done(function (data) { 334 vm.set("currentStoreName", storeToSet); 335 // Set Cookie 336 vm._setCurrentStoreNameCookie(storeToSet); 337 338 // Go through and update each one so correct one shows as current store. 339 var searchStores = vm.get("storeLocations"); 340 341 $.each(searchStores, function(i, store) { 342 store.set("IsUsersCurrentPickupStore", store.StoreName === storeToSet); 343 });
344 345 window.location.href = '/home.aspx?role=PublicPostcode'; 346 }); 347 /* 348 $.cv.css.getCurrentUser().done(function(objKey){ 349 var list = {}; 350 list["_objectKey"] = objKey.data[0]._objectKey; 351 list["CustomerCode"] = CustomerCode; 352 list["InitialRole"] = 'CSSUser'; 353 var customer = $.cv.css.user.setCurrentUser({ data: list}); 354 355 // var p = $.cv.css.storeLocator.setUserCurrentStore({ storeName: storeToSet}); 356 $.when(customer).done(function (data) { 357 if (data.data) { 358 359 // Update vm with what current store is 360 vm.set("currentStoreName", storeToSet); 361 362 // Set Cookie 363 vm._setCurrentStoreNameCookie(storeToSet); 364 365 if (data.data) { 366 $.cv.css.getCurrentOrder({ 367 success: function (curOrderMsg) { 368 $.cv.css.orders.updateCurrentOrder({ 369 _objectKey: curOrderMsg.data[0]._objectKey, 370 SoCustCode: CustomerCode 371 }); 372 } 373 });
374 $.cv.css.removeLocalStorage($.cv.css.sessionStorageKeys.currentUser); 375 window.location.href = '/home.aspx?role=PublicPostcode'; 376 377 } 378 379 // Go through and update each one so correct one shows as current store. 380 var searchStores = vm.get("storeLocations"); 381 382 $.each(searchStores, function(i, store) { 383 store.set("IsUsersCurrentPickupStore", store.StoreName === storeToSet); 384 385 }); 386 } 387 388 vm._stopIsProcessingSetStore(false, ""); 389 }); 390 391 }); 392 */ 393 return false; // prevent postback 394 } 395 }, 396 397 _stopIsProcessingSetStore: function (checked, storeToSet) { 398 var vm = this; 399 var searchStoresCheck = vm.get("storeLocations"); 400 if (checked) { 401 _.each(searchStoresCheck, function (store) { 402 store.set("isProcessingSetStore", store.StoreName === storeToSet); 403 store.set("disableView", store.StoreName !== storeToSet); 404 }); 405 } else { 406 407 _.each(searchStoresCheck, function (store) { 408 store.set("isProcessingSetStore", false); 409 store.set("disableView", true); 410 }); 411 } 412 }, 413 414 _getCurrentStoreText: function () { 415 var vm = this, 416 currStore = vm.get("currentStoreName"); 417 var cookieStoreName = $.cookie("UserStoreName"); 418 419 if (currStore.length < 1) 420 { 421 if (typeof(cookieStoreName) != "undefined" && cookieStoreName != "") 422 { 423 currStore = $.cookie("UserStoreName"); 424 } 425 } 426 427 /* 428 var currentOrder = $.cv.css.localGetCurrentOrder(); 429 430 if(currentOrder == null) { 431 return widget.options.whenNoStoreSetText; 432 } 433 */ 434 435 return currStore.length > 0 ? currStore : widget.options.whenNoStoreSetText; 436 }, 437 438 _getSetStoreButtonText: function (item) { 439 return item.get("IsUsersCurrentPickupStore") ? widget.options.currentStoreButtonText : widget.options.setStoreButtonText; 440 }, 441 442 _setCurrentStoreNameCookie: function (storeName) { 443 $.cookie("User.StoreName", storeName, { expires: 365, path: '/' } ); 444 $.cookie("UserStoreName", storeName, { expires: 365, path: '/' } ); 445 }, 446 447 showStoreList: false, 448 449 _toggleStoreLocationDisplay: function () { 450 var vm = this; 451 vm.set("showStoreList", !vm.get("showStoreList")); 452 //var addInp = $("#" + widget.options.addressSearchId); 453 //if (addInp.length > 0) { 454 // addInp.kendoAutoComplete(); 455 // var kendAutoComp = addInp.data('kendoAutoComplete'); 456 // kendAutoComp.focus(); 457 //} 458 }, 459 460 _toggleStoreLocationDisplayPopupOption: function() { 461 var dealerLocatorPopup = $("div[data-role='storeavailabilitylocatorcustom'][data-widget-mode='popup']").data("storeAvailabilityLocatorCustom"); 462 if (dealerLocatorPopup != undefined) { 463 var popupVM = dealerLocatorPopup.viewModel; 464 popupVM.set("storeSelectionRequired", false); 465 popupVM._toggleStoreLocationDisplayPopup(); 466 } 467 }, 468 469 _toggleStoreLocationDisplayPopup: function () { 470 var vm = this; 471 472 $.fancybox.open({ 473 href: "#" + widget.options.popupWidgetId, 474 topRatio: "0.25", 475 minWidth: "320", 476 padding: "0", 477 modal: true, 478 parent: "form:first", 479 afterShow: function () { 480 //if (widget.options.addressSearchId != "") { 481 // var addInp = $("#" + widget.options.addressSearchId); 482 // var addInpPopUp = $("#" + widget.options.addressSearchId + "-list"); 483 // addInpPopUp.find("k-nodata").css('display:none !important'); 484 // if (addInp.length > 0) { 485 // // addInp.kendoAutoComplete({ noDataTemplate: 'No Data!' }); 486 // var kendAutoComp = addInp.data('kendoAutoComplete'); 487 // kendAutoComp.focus(); 488 // } 489 //} 490 if (widget.options.showDistanceSlider) { 491 $("#distance-slider").kendoSlider({ 492 orientation: "horizontal", 493 min: 0, 494 max: widget.options.maxDistance, 495 smallStep: 1, 496 largeStep: 20, 497 showButtons: true, 498 change: function(e) { 499 vm.set("maxDistance", e.value); 500 }, 501 slide: function(e) { 502 vm.set("maxDistance", e.value); 503 } 504 }); 505 } 506 }, 507 onCleanup: function() { 508 console.log("Clean Up") 509 }, 510 onClosed: function() { 511 console.log("Closed") 512 } 513 }); 514 } 515 }); 516 517 return viewModel; 518 } 519 }; 520 521 // Register the widget. 522 $.cv.ui.widget(storeAvailabilityLocatorWidgetCustom); 523})(jQuery);
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.