Skip to content

Instantly share code, notes, and snippets.

@kevinchl
Created May 15, 2017 04:20
Show Gist options
  • Select an option

  • Save kevinchl/e3c5097db290781b693491e4126413f0 to your computer and use it in GitHub Desktop.

Select an option

Save kevinchl/e3c5097db290781b693491e4126413f0 to your computer and use it in GitHub Desktop.
var SymptomForm = (function() {
// code
var order;
var repair_levels;
function init( order ) {
order = order;
var repairLevelAPI = '/data/repair_levels.json';
$.getJSON(repairLevelAPI, function(data) {
repair_levels = data;
});
//
$('#repair_level').change(function(e){
reloadPrice( );
});
$('#discount').on("input", function(e){
recalculateTotal();
});
}
var repairLevelForId = function( level_id ) {
var selected_level = null;
for (var idx in repair_levels) {
var level_obj = repair_levels[idx];
if (level_obj.id == level_id ){
selected_level = level_obj;
break;
}
}
return selected_level;
};
var priceForLevel = function( level_id ){
var level = repairLevelForId(level_id);
console.log( level );
return (this.order.in_warranty) ? level.in_warranty_price : level.out_warranty_price;
};
var reloadPrice = function() {
var price = priceForLevel( $("#repair_level").val() );
$('#price').val( price );
recalculateTotal();
};
var recalculateTotal = function() {
var price = $('#price').val();
var discount = $('#discount').val();
// Calculate Total
var total = price - discount;
if (total < 0) {
total = 0;
}
$('#total_amount').text(total);
};
return {
init: init,
};
})();
var order = { in_warranty: true};
SymptomForm.init(order);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment