87 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
		
		
			
		
	
	
			87 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
|  | /* | ||
|  |  * This Source Code Form is subject to the terms of the Mozilla Public | ||
|  |  * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
|  |  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 | ||
|  |  */ | ||
|  | 
 | ||
|  | function updateRateForm() { | ||
|  |     $("#itemweight").css("display", "none"); | ||
|  |     $("#itemsize").css("display", "none"); | ||
|  |     $("#itemweightlbs").css("display", ""); | ||
|  |     switch ($(this).val()) { | ||
|  |         case "Card": | ||
|  |             $("#itemweight").css("display", "none"); | ||
|  |             $("#weightLbs").val("0"); | ||
|  |             $("#weightOz").val("0"); | ||
|  |             break; | ||
|  |         case "Letter": | ||
|  |             $("#itemweight").css("display", ""); | ||
|  |             $("#itemweightlbs").css("display", "none"); | ||
|  |             $("#weightLbs").val("0"); | ||
|  |             break; | ||
|  |         case "Flat": | ||
|  |             $("#itemweight").css("display", ""); | ||
|  |             break; | ||
|  |         case "Parcel": | ||
|  |             $("#itemweight").css("display", ""); | ||
|  |             $("#itemsize").css("display", ""); | ||
|  |             break; | ||
|  |         case "RegionalRateBoxA": | ||
|  |         case "RegionalRateBoxB": | ||
|  |             $("#itemweight").css("display", ""); | ||
|  |             break; | ||
|  |         default: | ||
|  |             break; | ||
|  |     } | ||
|  | } | ||
|  | 
 | ||
|  | $("#app").on("click change", "#itemType", updateRateForm); | ||
|  | 
 | ||
|  | function initRateForm() { | ||
|  |     $("#itemType").val(""); | ||
|  |     updateRateForm(); | ||
|  | } | ||
|  | 
 | ||
|  | function getRates() { | ||
|  |     app.dialog.preloader("Loading..."); | ||
|  | 
 | ||
|  |     apirequest( | ||
|  |             SETTINGS.apis.rates, | ||
|  |             { | ||
|  |                 from_street1: $("#from_street1").val(), | ||
|  |                 from_zip: $("#from_zip").val(), | ||
|  |                 to_street1: $("#to_street1").val(), | ||
|  |                 to_zip: $("#to_zip").val(), | ||
|  |                 itemType: $("#itemType").val(), | ||
|  |                 length: $("input[name=length]").val(), | ||
|  |                 width: $("input[name=width]").val(), | ||
|  |                 height: $("input[name=height]").val(), | ||
|  |                 weightLbs: $("#weightLbs").val(), | ||
|  |                 weightOz: $("#weightOz").val() | ||
|  |             }, | ||
|  |             function (resp) { | ||
|  |                 app.dialog.close(); | ||
|  |                 if (resp.status == "OK") { | ||
|  |                     if (resp.rates.length == 0) { | ||
|  |                         resp.rates = false; | ||
|  |                     } | ||
|  |                     if (resp.hints.length == 0) { | ||
|  |                         resp.hints = false; | ||
|  |                     } | ||
|  |                     router.navigate("/rateresult", { | ||
|  |                         context: resp | ||
|  |                     }); | ||
|  |                 } else { | ||
|  |                     app.dialog.alert(resp.message, "Error"); | ||
|  |                 } | ||
|  |             }, | ||
|  |             function (xhr) { | ||
|  |                 app.dialog.close(); | ||
|  |                 var error = $.parseJSON(xhr.responseText); | ||
|  |                 if (error && typeof error.msg != 'undefined') { | ||
|  |                     app.dialog.alert(error.msg, "Error"); | ||
|  |                 } else { | ||
|  |                     app.dialog.alert("A server or network error occurred.", "Error"); | ||
|  |                 } | ||
|  |             }, "GET"); | ||
|  | } |