{% extends "base.html" %}

{% block head %}
{{ super() }}
<script type="text/javascript">
function getPeriod()
{
    var period = 0;
    var periodselect = document.getElementById('period');
    period = periodselect.value;
    return period;
}

function calculateTotal()
{
    var period = getPeriod();
    var ppm = {{ ppm }};
    var discount = {{ discount }};
    
    var pricetotal = 0;
    pricetotal = period * ppm;
    var priceselect = document.getElementById('totalPrice');
    priceselect.innerHTML = "Total Price: "+pricetotal+" {{ currency }}";

    var discounttotal = 0;
    discounttotal = period * discount;

    var discountselect = document.getElementById('totalDiscount');
    discountselect.innerHTML = "Discount <font color=#ff0000>-{{ deploy.discount }}%</font>: "+discounttotal+" {{ currency }}";

}
</script>
{% endblock %}

{% block title %}Activate deployment{% endblock %}

{% block page_content %}

<div class="row">

<div class="col-md-12">
<div class="panel panel-info">
<div class="panel-heading">Activate deployment {{ deploy.machine_alias }}</div>
<div class="panel-body">

<form method="POST" action="{{ url_for('vmanager.activate', itemid=deploy.machine_id) }}">
<h3>
CPU: {{ deploy.machine_cpu }} cores<br />
Memory: {{ deploy.machine_mem }} MB<br />
Storage: {{ deploy.machine_hdd }} GB<br />
{{ form.period.label }} {{ form.period(**{"onchange":"calculateTotal()"}) }}<br />
   {% for error in form.period.errors %}
       {{ error }}<br />
   {% endfor %}
---<br />
{% if deploy.discount != 0 %}
<div id="totalDiscount">Discount <font color=#ff0000>-{{ deploy.discount }}%</font>: {{ discount }} {{ currency }}</div>
{% endif %}
<div id="totalPrice">{% if deploy.protected == False %}Total:{% else %}Previous Period:{% endif %} {{ total }} {{ currency }}</div>
</h3>

<p>
    {{ form.csrf_token() }}
    {{ form.submit }}
</p>

</div>
</div>
</div>

</div>

{% endblock %}

