Added serializer to VM model, Rewrite django hosting view , Created price selection templates , Added price selector with automatic price change
This commit is contained in:
parent
5e1419cd1c
commit
9694681dd2
7 changed files with 412 additions and 5 deletions
58
hosting/static/hosting/js/pricing.js
Normal file
58
hosting/static/hosting/js/pricing.js
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
$( document ).ready(function() {
|
||||
|
||||
//we need to load first VMTypesData from base.html django template
|
||||
var pricingData = window.VMTypesData;
|
||||
|
||||
|
||||
// Function to calculate the price given a vm type
|
||||
function calculate_price(vm_type){
|
||||
|
||||
var ID_SELECTOR = "#";
|
||||
var CURRENCY = "$";
|
||||
var final_price_selector = ID_SELECTOR.concat(vm_type.concat('-final-price'));
|
||||
var core_selector = ID_SELECTOR.concat(vm_type.concat('-cores'));
|
||||
var memory_selector = ID_SELECTOR.concat(vm_type.concat('-memory'));
|
||||
var disk_size_selector = ID_SELECTOR.concat(vm_type.concat('-disk_space'));
|
||||
|
||||
//Get vm type prices
|
||||
var cores = $(core_selector).val();
|
||||
var memory = $(memory_selector).val();
|
||||
var disk_size = $(disk_size_selector).val();
|
||||
var pricingData = eval(window.VMTypesData);
|
||||
var company_prices = _.head(_.filter(pricingData, {hosting_company: vm_type}));
|
||||
|
||||
//Calculate final price
|
||||
var price = company_prices.base_price;
|
||||
price += company_prices.core_price*cores;
|
||||
price += company_prices.memory_price*memory;
|
||||
price += company_prices.disk_size_price*disk_size;
|
||||
|
||||
console.log(final_price_selector);
|
||||
$(final_price_selector).text(price.toString().concat(CURRENCY));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Listener function
|
||||
function change_attribute(e){
|
||||
|
||||
var vm_type = this.getAttribute('data-vm-type');
|
||||
calculate_price(vm_type);
|
||||
}
|
||||
|
||||
|
||||
//Listeners
|
||||
$('.cores-selector').on('change',change_attribute);
|
||||
|
||||
$('.memory-selector').on('change',change_attribute);
|
||||
|
||||
$('.disk-space-selector').on('change',change_attribute);
|
||||
|
||||
console.log("mirame",window.VMTypesData);
|
||||
|
||||
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue