Commit 824068e0 by Oláh István Gergely

dashboard: fix node status changer

parent 2fc07a8d
...@@ -30,9 +30,9 @@ ...@@ -30,9 +30,9 @@
$('.node-enable').click(function() { $('.node-enable').click(function() {
var node_pk = $(this).data('node-pk'); var node_pk = $(this).data('node-pk');
var dir = window.location.pathname.indexOf('list') == -1; var dir = window.location.pathname.indexOf('list') == -1;
addModalConfirmation(deleteObject, addModalConfirmation(changeNodeStatus,
{ 'url': '/dashboard/node/status/' + node_pk + '/', { 'url': '/dashboard/node/status/' + node_pk + '/',
'data': {'change_status':""}, 'data': [],
'pk': node_pk, 'pk': node_pk,
'type': "node", 'type': "node",
'redirect': dir}); 'redirect': dir});
......
...@@ -14,8 +14,8 @@ ...@@ -14,8 +14,8 @@
<div class="pull-right"> <div class="pull-right">
<form action="" method="POST"> <form action="" method="POST">
{% csrf_token %} {% csrf_token %}
<a class="btn btn-default">Back</a> <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<input type="hidden" name="new_status" value="{{ status }}"/> <input type="hidden" name="change_status" value="_"/>
<button class="btn btn-warning">Yes, {{ status }}</button> <button class="btn btn-warning">Yes, {{ status }}</button>
</form> </form>
</div> </div>
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<form action="" method="POST"> <form action="" method="POST">
{% csrf_token %} {% csrf_token %}
<a class="btn btn-default">Back</a> <a class="btn btn-default">Back</a>
<input type="hidden" name="new_status" value="{{ status }}"/> <input type="hidden" name="change_status" value="_"/>
<button class="btn btn-warning">Yes, {{ status }}</button> <button class="btn btn-warning">Yes, {{ status }}</button>
</form> </form>
</div> </div>
......
...@@ -456,8 +456,10 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -456,8 +456,10 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
if request.POST.get('new_name'): if request.POST.get('new_name'):
return self.__set_name(request) return self.__set_name(request)
if request.POST.get('new_status'): if request.POST.get('change_status'):
return self.__set_status(request) return self.__set_status(request)
return redirect(reverse_lazy("dashboard.views.node-detail",
kwargs={'pk': self.get_object().pk}))
def __set_name(self, request): def __set_name(self, request):
self.object = self.get_object() self.object = self.get_object()
...@@ -469,7 +471,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -469,7 +471,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
if request.is_ajax(): if request.is_ajax():
response = { response = {
'message': success_message, 'message': success_message,
'new_name': new_name,
'node_pk': self.object.pk 'node_pk': self.object.pk
} }
return HttpResponse( return HttpResponse(
...@@ -483,19 +484,14 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -483,19 +484,14 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
def __set_status(self, request): def __set_status(self, request):
self.object = self.get_object() self.object = self.get_object()
new_status = request.POST.get("new_status") if not self.object.enabled:
if new_status == "enable":
self.object.enable(user=request.user) self.object.enable(user=request.user)
elif new_status == "disable":
self.object.disable(user=request.user)
else: else:
return self.object.disable(user=request.user)
success_message = _("Node successfully changed status!") success_message = _("Node successfully changed status!")
if request.is_ajax(): if request.is_ajax():
response = { response = {
'message': success_message, 'message': success_message,
'new_status': new_status,
'node_pk': self.object.pk 'node_pk': self.object.pk
} }
return HttpResponse( return HttpResponse(
...@@ -1266,11 +1262,12 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -1266,11 +1262,12 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
if request.POST.get('change_status'): if request.POST.get('change_status'):
return self.__set_status(request) return self.__set_status(request)
return redirect(reverse_lazy("dashboard.views.node-detail",
kwargs={'pk': self.get_object().pk}))
def __set_status(self, request): def __set_status(self, request):
self.object = self.get_object() self.object = self.get_object()
if not self.object.enabled:
if self.object.enable:
Node.objects.filter(pk=self.object.pk).update( Node.objects.filter(pk=self.object.pk).update(
**{'enabled': True}) **{'enabled': True})
else: else:
......
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