Commit 21af5532 by Oláh István Gergely

dashboard: fix node-details status changing modal

parent 8b1979aa
...@@ -135,7 +135,7 @@ $(function () { ...@@ -135,7 +135,7 @@ $(function () {
return false; return false;
}); });
/* for Node removes buttons */ /* for Group removes buttons */
$('.group-delete').click(function() { $('.group-delete').click(function() {
var group_pk = $(this).data('group-pk'); var group_pk = $(this).data('group-pk');
var dir = window.location.pathname.indexOf('list') == -1; var dir = window.location.pathname.indexOf('list') == -1;
...@@ -149,19 +149,6 @@ $(function () { ...@@ -149,19 +149,6 @@ $(function () {
return false; return false;
}); });
/* for Group removes buttons */
$('.group-delete').click(function() {
var group_pk = $(this).data('group-pk');
var dir = window.location.pathname.indexOf('list') == -1;
addModalConfirmation(deleteGroup,
{ 'url': '/dashboard/group/delete/' + group_pk + '/',
'data': [],
'group_pk': group_pk,
'redirect': dir});
return false;
});
/* search for vms */ /* search for vms */
var my_vms = [] var my_vms = []
$("#dashboard-vm-search-input").keyup(function(e) { $("#dashboard-vm-search-input").keyup(function(e) {
...@@ -311,6 +298,7 @@ function addModalConfirmation(func, data) { ...@@ -311,6 +298,7 @@ function addModalConfirmation(func, data) {
url: data['url'], url: data['url'],
data: jQuery.param(data['data']), data: jQuery.param(data['data']),
success: function(result) { success: function(result) {
console.log(result);
$('body').append(result); $('body').append(result);
$('#confirmation-modal').modal('show'); $('#confirmation-modal').modal('show');
$('#confirmation-modal').on('hidden.bs.modal', function() { $('#confirmation-modal').on('hidden.bs.modal', function() {
......
...@@ -25,3 +25,43 @@ ...@@ -25,3 +25,43 @@
}); });
return false; return false;
}); });
/* for Node removes buttons */
$('.node-enable').click(function() {
var node_pk = $(this).data('node-pk');
var node_status = $(this).data('status');
var dir = window.location.pathname.indexOf('list') == -1;
addModalConfirmation(deleteObject,
{ 'url': '/dashboard/node/status/' + node_pk + '/?status='+node_status,
'data': {'new_status':node_status},
'pk': node_pk,
'status': node_status,
'type': "node",
'redirect': dir});
return false;
});
function changeNodeStatus(data) {
$.ajax({
type: 'POST',
url: data['url'],
headers: {"X-CSRFToken": getCookie('csrftoken')},
success: function(re, textStatus, xhr) {
if(!data['redirect']) {
selected = [];
addMessage(re['message'], 'success');
$('a[data-'+data['type']+'-pk="' + data['pk'] + '"]').closest('tr').fadeOut(function() {
$(this).remove();
});
} else {
window.location.replace('/dashboard');
}
},
error: function(xhr, textStatus, error) {
addMessage('Uh oh :(', 'danger')
}
});
}
{% load i18n %}
<div class="modal fade" id="confirmation-modal" tabindex="-1" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-body">
{% if text %}
{{ text }}
{% else %}
{%blocktrans with object=object%}
Are you sure you want to change <strong>{{ object }}</strong> status?
{%endblocktrans%}
{% endif %}
<div class="pull-right">
<form action="" method="POST">
{% csrf_token %}
<a class="btn btn-default">Back</a>
<input type="hidden" name="new_status" value="{{ status }}"/>
<button class="btn btn-warning">Yes, {{ status }}</button>
</form>
</div>
<div class="clearfix"></div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
...@@ -1241,6 +1241,12 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -1241,6 +1241,12 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
template_name = "dashboard/confirm/node-status.html" template_name = "dashboard/confirm/node-status.html"
model = Node model = Node
def get_template_names(self):
if self.request.is_ajax():
return ['dashboard/confirm/ajax-node-status.html']
else:
return ['dashboard/confirm/node-status.html']
def get_success_url(self): def get_success_url(self):
next = self.request.GET.get('next') next = self.request.GET.get('next')
if next: if next:
...@@ -1256,7 +1262,6 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -1256,7 +1262,6 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
if request.POST.get('new_status'): if request.POST.get('new_status'):
print self.request.GET.get('next')
return self.__set_status(request) return self.__set_status(request)
def __set_status(self, request): def __set_status(self, request):
......
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