1function PostalCodeLookupClass(clientID) { 2 var countryCode = "uk"; 3 this.ImisWebServerURL; 4 this.jsClientId = clientID; 5 this.SubmitPostalCode = function (event) { 6 event.stopImmediatePropagation(); 7 event.preventDefault(); 8 var postalCode = document.getElementById(clientID + "_PostalCodeLookup_PostalCode").value; 9 var options = document.getElementById(clientID + "_PostalCodeLookup_AddressOptions-Group"); 10 if (!options.classList.contains("hidden")); 11 options.classList.add("hidden"); 12 var thisInstance = this; 13 showHideNoResults(false); 14 var theSearchButton = jQuery(event.target); 15 var searchBtnOrigTxt = theSearchButton.text(); 16 var searchBtnDisabledTxt = jQuery("#"+clientID+"_SearchInProgressText").text(); 17 //Do the AJAX call 18 //disable search while AJAX call running 19 theSearchButton.attr("disabled", "disabled"); 20 theSearchButton.text(searchBtnDisabledTxt); 21 jQuery.ajax(this.ImisWebServerURL + "/api/addressverification?countrycode=" + countryCode + "&postalcode=" + postalCode + "", 22 { 23 type: "get", 24 contentType: "application/json", 25 headers: { "RequestVerificationToken": document.getElementById("__RequestVerificationToken").value }, 26 success: function (data) { 27 if (thisInstance.CheckData(data)) { 28 thisInstance.PopulateChoices(data); 29 } else { 30 showHideNoResults(true); 31 } 32 }, 33 error: function (err) { 34 console.log(err); 35 showHideNoResults(true); 36 }, 37 //runs after other handlers on success or fail, like finally 38 complete: function() { 39 theSearchButton.removeAttr("disabled");//re-enable search button 40 theSearchButton.text(searchBtnOrigTxt); 41 } 42 }); 43 } 44 this.PopulateChoices = function (response) { 45 var values = response.Items.$values; 46 var selectBox = document.getElementById(clientID + "_PostalCodeLookup_AddressOptions"); 47 while (selectBox.hasChildNodes()) { 48 selectBox.removeChild(selectBox.lastChild); 49 } 50 var firstOption = document.createElement("option"); 51 firstOption.appendChild(document.createTextNode("Select address")); 52 selectBox.appendChild(firstOption); 53 for (var i = 0; i < values.length; i++) { 54 var option = document.createElement("option"); 55 option.setAttribute("data-addresstokenid", values[i].AddressTokenId); 56 option.appendChild(document.createTextNode(values[i].FullAddress)); 57 selectBox.appendChild(option); 58 } 59 document.getElementById(clientID + "_PostalCodeLookup_AddressOptions-Group").classList.remove("hidden"); 60 } 61 this.SelectAddressTokenId = function (event, jsCallback) { 62 event.stopImmediatePropagation(); 63 event.preventDefault(); 64 var list = document.getElementById(clientID + "_PostalCodeLookup_AddressOptions"); 65 var AddressTokenId = list.options[list.selectedIndex].dataset.addresstokenid; 66 var thisInstance = this; 67 jQuery.ajax(this.ImisWebServerURL + "/api/addressverification?countrycode=" + countryCode + "&tokenid=" + AddressTokenId + "", 68 { 69 type: "get", 70 contentType: "application/json", 71 headers: { "RequestVerificationToken": document.getElementById("__RequestVerificationToken").value }, 72 success: function (data) { 73 var resolvedCallbackRef = thisInstance.ResolveCallbackRef(jsCallback, thisInstance); 74 if (resolvedCallbackRef) { 75 resolvedCallbackRef(data.Items.$values[0]); 76 } 77 }, 78 error: function (err) { 79 console.log(err); 80 } 81 }); 82 } 83 this.ResolveCallbackRef = function (jsCallback, thisInstance) 84 { 85 var typeCheck = eval("typeof " + jsCallback); 86 if (typeCheck === "function") { 87 var checkFunctionRef = eval(jsCallback); 88 if (checkFunctionRef !== null && checkFunctionRef !== undefined && checkFunctionRef.length > 0) { 89 return checkFunctionRef; 90 } 91 } 92 if (thisInstance.jsClientId && 93 thisInstance.jsClientId.length > 0) { 94 var newjsCallback = thisInstance.jsClientId + "_" + jsCallback; 95 if (window[newjsCallback] && 96 window[newjsCallback].length > 0) { 97 return window[newjsCallback]; 98 } 99 } 100 if (window[jsCallback]&& 101 window[jsCallback].length > 0) { 102 return window[jsCallback]; 103 } 104 return undefined; 105 } 106 this.CheckData = function (data) { 107 if (data.Items.$values.length === 1) { 108 if (data.Items.$values[0].AddressTokenId.length <= 0) { 109 return false; 110 } else { 111 return true; 112 } 113 } 114 return true; 115 } 116 117 function showHideNoResults(show) { 118 var control = document.getElementById(clientID + "_PostalCodeLookup_NoResults"); 119 if (show) { 120 control.classList.remove('hidden'); 121 } else { 122 if (!control.classList.contains('hidden')) 123 control.classList.add('hidden'); 124 } 125 } 126} 127
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.