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
3015399692
commit
cb51e08cef
7 changed files with 412 additions and 5 deletions
95
hosting/static/hosting/css/pricing.css
Normal file
95
hosting/static/hosting/css/pricing.css
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
.pricing {
|
||||
text-align: center;
|
||||
border: 1px solid #f0f0f0;
|
||||
color: #777;
|
||||
font-size: 14px;
|
||||
padding-left: 0;
|
||||
margin-bottom: 30px;
|
||||
font-family: 'Lato';
|
||||
}
|
||||
.pricing img {
|
||||
display: block;
|
||||
margin: auto;
|
||||
width: 32px;
|
||||
}
|
||||
.pricing li:first-child,
|
||||
.pricing li:last-child {
|
||||
padding: 20px 13px;
|
||||
}
|
||||
.pricing li {
|
||||
list-style: none;
|
||||
padding: 13px;
|
||||
}
|
||||
.pricing li + li {
|
||||
border-top: 1px solid #f0f0f0;
|
||||
}
|
||||
.pricing big {
|
||||
font-size: 32px;
|
||||
}
|
||||
.pricing h3 {
|
||||
margin-bottom: 0;
|
||||
font-size: 36px;
|
||||
}
|
||||
.pricing span {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
font-weight: normal;
|
||||
}
|
||||
.pricing li:nth-last-child(2) {
|
||||
padding: 30px 13px;
|
||||
}
|
||||
.pricing button {
|
||||
width: auto;
|
||||
margin: auto;
|
||||
font-size: 15px;
|
||||
font-weight: bold;
|
||||
border-radius: 50px;
|
||||
color: #fff;
|
||||
padding: 9px 24px;
|
||||
background: #aaa;
|
||||
opacity: 1;
|
||||
transition: opacity .2s ease;
|
||||
border: none;
|
||||
outline: none;
|
||||
}
|
||||
.pricing button:hover {
|
||||
opacity: .9;
|
||||
}
|
||||
.pricing button:active {
|
||||
box-shadow: inset 0px 2px 2px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
/* pricing color */
|
||||
.p-green big,
|
||||
.p-green h3 {
|
||||
color: #4c7737;
|
||||
}
|
||||
.p-green button {
|
||||
background: #4c7737;
|
||||
}
|
||||
.p-yel big,
|
||||
.p-yel h3 {
|
||||
color: #ffbb42;
|
||||
}
|
||||
.p-yel button {
|
||||
background: #ffbb42;
|
||||
}
|
||||
.p-red big,
|
||||
.p-red h3 {
|
||||
color: #e13c4c;
|
||||
}
|
||||
|
||||
.pricing .short-input{
|
||||
min-width: 0;
|
||||
width: 90px;
|
||||
}
|
||||
|
||||
.p-red button {
|
||||
background: #e13c4c;
|
||||
}
|
||||
.p-blue big,
|
||||
.p-blue h3 {
|
||||
color: #3f4bb8;
|
||||
}
|
||||
.p-blue button {
|
||||
background: #3f4bb8;
|
||||
}
|
||||
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