Commit 82a96649 by tarokkk

webui: Added stop,restart,resume functions

parent caef159a
...@@ -37,6 +37,18 @@ $(function() { ...@@ -37,6 +37,18 @@ $(function() {
} }
} }
$('.wm .summary').unbind('click').click(toggleDetails); $('.wm .summary').unbind('click').click(toggleDetails);
$('.stop-vm-button').click(function() {
stop_vm($(this).data('id'), $(this).data('name'));
});
$('.resume-vm-button').click(function() {
manage_vm($(this).data('id'), "resume");
});
$('.delete-vm-button').click(function() {
delete_vm($(this).data('id'), $(this).data('name'));
});
$('.restart-vm-button').click(function() {
restart_vm($(this).data('id'), $(this).data('name'));
});
$('#new-wm-button').click(function() { $('#new-wm-button').click(function() {
$('#modal').show(); $('#modal').show();
$('#modal-container').html($('#new-wm').html()); $('#modal-container').html($('#new-wm').html());
...@@ -91,6 +103,58 @@ $(function() { ...@@ -91,6 +103,58 @@ $(function() {
}); });
/** /**
* Confirm pop-up window
*/
function vm_confirm_popup(confirm_message, button_text) {
return confirm(confirm_message);
}
/**
* Manage VM State (STOP)
*/
function stop_vm(id, name) {
confirm_message = interpolate(gettext("Are you sure stopping %s?"), [name])
if (vm_confirm_popup(confirm_message, gettext("Stop"))) {
manage_vm(id, "stop")
}
}
/**
* Manage VM State (DELETE)
*/
function delete_vm(id, name) {
confirm_message = interpolate(gettext("Are you sure deleting %s?"), [name])
if (vm_confirm_popup(confirm_message, gettext("Delete"))) {
manage_vm(id, "delete")
}
}
/**
* Manage VM State (RESET)
*/
function restart_vm(id, name) {
confirm_message = interpolate(gettext("Are you sure restarting %s?"), [name])
if (vm_confirm_popup(confirm_message, gettext("Restart"))) {
manage_vm(id, "restart")
}
}
/**
* Manage VM State (RESUME)
*/
function resume_vm(id, name) {
manage_vm(id, "resume")
}
/**
* Manage VM State generic
*/
function manage_vm(id, state) {
$.ajax({
type: 'POST',
data: '',
url: '/vm/'+state+'/'+id+'/',
success: function(data) {
}
})
}
/**
* Convert bytes to human readable format * Convert bytes to human readable format
*/ */
......
...@@ -16,29 +16,29 @@ ...@@ -16,29 +16,29 @@
<a href="{{i.get_connect_uri}}" title="{% trans "Connect" %}"> <a href="{{i.get_connect_uri}}" title="{% trans "Connect" %}">
<img src="/static/icons/plug.png" alt="{% trans "Connect" %}" /> <img src="/static/icons/plug.png" alt="{% trans "Connect" %}" />
</a> </a>
<a href="/vm/suspend/{{i.id}}/" onclick="alert('Hamarosan a mozikban.'); return false" title="{% trans "Suspend" %}"> <a href="#" class="stop-vm-button" data-name="{{ i.name}}" data-id="{{ i.id }}" title="{% trans "Stop" %}">
<img src="/static/icons/control-pause.png" alt="{% trans "Suspend" %}" /> <img src="/static/icons/control-pause.png" alt="{% trans "Suspend" %}" />
</a> </span>
<a href="/vm/delete/{{i.id}}/" onclick="return confirm('Biztosan törli a gépet?')" title="{% trans "Delete" %}"> <a href="#" class="delete-vm-button" data-name="{{ i.name}}" data-id="{{ i.id }}" title="{% trans "Delete" %}">
<img src="/static/icons/minus-circle.png" alt="{% trans "Delete" %}" /> <img src="/static/icons/minus-circle.png" alt="{% trans "Delete" %}" />
</a> </a>
<a href="/vm/reset/{{i.id}}/" onclick="alert('Hamarosan a mozikban.'); return false" title="{% trans "Reboot" %}"> <a href="#" class="restart-vm-button" data-name="{{ i.name}}" data-id="{{ i.id }}" title="{% trans "Restart" %}">
<img src="/static/icons/arrow-circle-double.png" alt="↺" /> <img src="/static/icons/arrow-circle-double.png" alt="↺" />
</a> </a>
{% endif %} {% endif %}
{% if i.state == 'PENDING' %} {% if i.state == 'PENDING' %}
<img src="/static/load-2.gif" /> {% trans "starting…" %} <img src="/static/load-2.gif" /> {% trans "starting…" %}
{% endif %} {% endif %}
{% if i.state == 'SUSPENDED' %} {% if i.state == 'STOPPED' %}
<a href="/vm/continue/{{i.id}}/" title="{% trans "Resume" %}"> <a href="#" class="resume-vm-button" data-name="{{ i.name}}" data-id="{{ i.id }}" title="{% trans "Resume" %}">
<img src="/static/icons/control.png" alt="{% trans "Resume" %}" /> <img src="/static/icons/control.png" alt="{% trans "Resume" %}" />
</a> </span>
<a href="/vm/delete/{{i.id}}/" onclick="return confirm('Biztosan törli a gépet?')" title="{% trans "Delete" %}"> <a href="#" class="delete-vm-button" data-name="{{ i.name}}" data-id="{{ i.id }}" title="{% trans "Delete" %}">
<img src="/static/icons/minus-circle.png" alt="{% trans "Delete" %}" /> <img src="/static/icons/minus-circle.png" alt="{% trans "Delete" %}" />
</a> </a>
{% endif %} {% endif %}
{% if i.state == 'FAILED' %} {% if i.state == 'FAILED' %}
<a href="/vm/delete/{{i.id}}/" title="{% trans "Delete" %}"> <a href="#" class="delete-vm-button" data-name="{{ i.name}}" data-id="{{ i.id }}" title="{% trans "Delete" %}">
<img src="/static/icons/minus-circle.png" alt="{% trans "Delete" %}" /> <img src="/static/icons/minus-circle.png" alt="{% trans "Delete" %}" />
</a> </a>
{% endif %} {% endif %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment