add calculator placeholder to cms_integration

This commit is contained in:
Arvind Tiwari 2018-04-25 14:52:25 +05:30
commit 3bf064a017
13 changed files with 195 additions and 74 deletions

View file

@ -1,7 +1,7 @@
/* Create VM calculator */
.price-calc-section {
padding: 80px 40px !important;
padding: 20px 0 !important;
}
@media (max-width: 768px) {
@ -40,7 +40,7 @@
}
.price-calc-section .card {
width: 50%;
/* width: 50%; */
margin: 0 auto;
background: #fff;
box-shadow: 1px 3px 6px 2px rgba(0, 0, 0, 0.2);
@ -52,7 +52,7 @@
@media (min-width: 768px) {
.price-calc-section .card {
margin-left: 0;
/* margin-left: 0; */
}
}

View file

@ -153,4 +153,84 @@ $( document ).ready(function() {
$('.navbar-fixed-top.topnav').css('padding-right', topnavPadding-scrollbarWidth);
}
});
/* ---------------------------------------------
Scripts initialization
--------------------------------------------- */
var cardPricing = {
'cpu': {
'id': 'coreValue',
'value': 1,
'min': 1,
'max': 48,
'interval': 1
},
'ram': {
'id': 'ramValue',
'value': 2,
'min': 1,
'max': 200,
'interval': 1
},
'storage': {
'id': 'storageValue',
'value': 10,
'min': 10,
'max': 2000,
'interval': 10
}
};
function _initPricing() {
_fetchPricing();
$('.fa-minus-circle.left').click(function(event) {
var data = $(this).data('minus');
if (cardPricing[data].value > cardPricing[data].min) {
cardPricing[data].value = Number(cardPricing[data].value) - cardPricing[data].interval;
}
_fetchPricing();
});
$('.fa-plus-circle.right').click(function(event) {
var data = $(this).data('plus');
if (cardPricing[data].value < cardPricing[data].max) {
cardPricing[data].value = Number(cardPricing[data].value) + cardPricing[data].interval;
}
_fetchPricing();
});
$('.input-price').change(function() {
var data = $(this).attr("name");
cardPricing[data].value = $('input[name=' + data + ']').val();
_fetchPricing();
});
}
function _fetchPricing() {
Object.keys(cardPricing).map(function(element) {
$('input[name=' + element + ']').val(cardPricing[element].value);
});
_calcPricing();
}
function _calcPricing() {
if(typeof window.coresUnitPrice === 'undefined'){
window.coresUnitPrice = 5;
}
if(typeof window.ramUnitPrice === 'undefined'){
window.coresUnitPrice = 2;
}
if(typeof window.ssdUnitPrice === 'undefined'){
window.ssdUnitPrice = 0.6;
}
console.log(coresUnitPrice, ramUnitPrice, ssdUnitPrice, cardPricing)
var total = (cardPricing['cpu'].value * window.coresUnitPrice) +
(cardPricing['ram'].value * window.ramUnitPrice) +
(cardPricing['storage'].value * window.ssdUnitPrice);
total = parseFloat(total.toFixed(2));
$("#total").text(total);
}
_initPricing();
});

View file

@ -1,5 +1,5 @@
{% load staticfiles bootstrap3%}
{% load i18n %}
{% load staticfiles i18n cms_tags sekizai_tags %}
<!DOCTYPE html>
<html lang="en">
@ -29,6 +29,9 @@
{% block css_extra %}
{% endblock css_extra %}
{% render_block "css" postprocessor "compressor.contrib.sekizai.compress" %}
{% render_block "js" postprocessor "compressor.contrib.sekizai.compress" %}
<!-- Custom Fonts -->
<link href='//fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>
<link href="{% static 'datacenterlight/font-awesome/css/font-awesome.min.css' %}" rel="stylesheet" type="text/css">
@ -48,7 +51,7 @@
</head>
<body>
{% cms_toolbar %}
{% block navbar %}
{% include "hosting/includes/_navbar_user.html" %}

View file

@ -1,7 +1,9 @@
{% extends "hosting/base_short.html" %}
{% load staticfiles bootstrap3 i18n %}
{% load staticfiles bootstrap3 i18n cms_tags %}
{% block content %}
<div class="dashboard-container create-vm-container">
<div class="row">
<div class="col-sm-5">
@ -17,14 +19,8 @@
{% endif %}
</div>
</div>
<div class="col-sm-6">
<div class="price-calc-section no-padding">
<div class="landing card">
<div class="caption">
{% include "hosting/calculator_form.html" %}
</div>
</div>
</div>
<div class="col-sm-6 hosting-calculator">
{% render_placeholder cms_integration.calculator_placeholder %}
</div>
</div>
</div>

View file

@ -32,6 +32,7 @@ from stored_messages.settings import stored_messages_settings
from datacenterlight.models import VMTemplate
from datacenterlight.tasks import create_vm_task
from datacenterlight.utils import get_cms_integration
from membership.models import CustomUser, StripeCustomer
from opennebula_api.models import OpenNebulaManager
from opennebula_api.serializers import (
@ -1003,7 +1004,11 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
@method_decorator(decorators)
def get(self, request, *args, **kwargs):
context = {'templates': VMTemplate.objects.all()}
print(get_cms_integration('default'))
context = {
'templates': VMTemplate.objects.all(),
'cms_integration': get_cms_integration('default'),
}
return render(request, self.template_name, context)
@method_decorator(decorators)