Commit 61883c5b by Kálmán Viktor

dashboard: js confirmation for mass delete vm

parent c5b3cd6a
...@@ -83,6 +83,7 @@ function deleteVm(pk, dir) { ...@@ -83,6 +83,7 @@ function deleteVm(pk, dir) {
headers: {"X-CSRFToken": getCookie('csrftoken')}, headers: {"X-CSRFToken": getCookie('csrftoken')},
success: function(data, textStatus, xhr) { success: function(data, textStatus, xhr) {
if(!dir) { if(!dir) {
selected = [];
addMessage(data['message'], 'success'); addMessage(data['message'], 'success');
$('a[data-vm-pk="' + pk + '"]').closest('tr').fadeOut(function() { $('a[data-vm-pk="' + pk + '"]').closest('tr').fadeOut(function() {
$(this).remove(); $(this).remove();
...@@ -97,6 +98,29 @@ function deleteVm(pk, dir) { ...@@ -97,6 +98,29 @@ function deleteVm(pk, dir) {
}); });
} }
function massDeleteVm() {
$.ajax({
traditional: true,
url: '/dashboard/vm/mass-delete/',
headers: {"X-CSRFToken": getCookie('csrftoken')},
type: 'POST',
data: {'vms': collectIds(selected)},
success: function(data, textStatus, xhr) {
for(var i=0; i< selected.length; i++)
$('.vm-list-table tbody tr').eq(selected[i]).fadeOut(500, function() {
// reset group buttons
selected = []
$('.vm-list-group-control a').attr('disabled', true);
$(this).remove();
addMessage(data['message'], 'success');
});
},
error: function(xhr, textStatus, error) {
// TODO this
}
});
}
function addMessage(text, type) { function addMessage(text, type) {
div = '<div style="display: none;" class="alert alert-' + type + '">' + text + '</div>'; div = '<div style="display: none;" class="alert alert-' + type + '">' + text + '</div>';
......
$(function() { var ctrlDown, shiftDown = false;
var ctrlDown, shiftDown = false; var ctrlKey = 17;
var ctrlKey = 17; var shiftKey = 16;
var shiftKey = 16; var selected = [];
var selected = [];
$(function() {
$(document).keydown(function(e) { $(document).keydown(function(e) {
if (e.keyCode == ctrlKey) ctrlDown = true; if (e.keyCode == ctrlKey) ctrlDown = true;
if (e.keyCode == shiftKey) shiftDown = true; if (e.keyCode == shiftKey) shiftDown = true;
...@@ -96,32 +96,16 @@ $(function() { ...@@ -96,32 +96,16 @@ $(function() {
$(this).addClass('vm-list-selected'); $(this).addClass('vm-list-selected');
} }
}); });
console.log(selected); if(selected.length > 0)
$('.vm-list-group-control a').attr('disabled', false);
return false; return false;
}); });
/* mass vm delete */ /* mass vm delete */
$('#vm-list-group-delete').click(function() { $('#vm-list-group-delete').click(function() {
$.ajax({ text = "Are you sure you want to delete the selected VMs?";
traditional: true, random_vm_pk = $('.vm-delete').eq(0).data('vm-pk');
url: '/dashboard/vm/mass-delete/', addModalConfirmation(text, random_vm_pk, massDeleteVm, false);
headers: {"X-CSRFToken": getCookie('csrftoken')},
type: 'POST',
data: {'vms': collectIds(selected)},
success: function(data, textStatus, xhr) {
for(var i=0; i< selected.length; i++)
$('.vm-list-table tbody tr').eq(selected[i]).fadeOut(500, function() {
// reset group buttons
selected = []
$('.vm-list-group-control a').attr('disabled', true);
$(this).remove();
addMessage(data['message'], 'success');
});
},
error: function(xhr, textStatus, error) {
// TODO this
}
});
return false; return false;
}); });
}); });
......
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