Commit 2fc07a8d by Oláh István Gergely

dashboard: fix set_status in NodeStatus

parent e7672078
......@@ -298,7 +298,6 @@ function addModalConfirmation(func, data) {
url: data['url'],
data: jQuery.param(data['data']),
success: function(result) {
console.log(result);
$('body').append(result);
$('#confirmation-modal').modal('show');
$('#confirmation-modal').on('hidden.bs.modal', function() {
......
......@@ -29,13 +29,11 @@
/* 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},
{ 'url': '/dashboard/node/status/' + node_pk + '/',
'data': {'change_status':""},
'pk': node_pk,
'status': node_status,
'type': "node",
'redirect': dir});
......
......@@ -32,12 +32,12 @@
<li><a href="#" class="node-details-rename-button"><i class="icon-pencil"></i> {% trans "Rename" %}</a></li>
<li><a href="#"><i class="icon-cloud-upload"></i> Flush</a></li>
{% if node.enabled %}
<li><a style="display:none" data-status="enable" data-node-pk="{{ node.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=node.pk %}?next={{ request.path }}&status=enable"><i class="icon-check"></i> Enable</a>
<a style="display:block" data-status="disable" data-node-pk="{{ node.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=node.pk %}?next={{ request.path }}&status=disable"><i class="icon-remove"></i> Disable</a></li>
<li><a style="display:none" data-node-pk="{{ node.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=node.pk %}?next={{ request.path }}"><i class="icon-check"></i> Enable</a>
<a style="display:block" data-node-pk="{{ node.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=node.pk %}?next={{ request.path }}"><i class="icon-remove"></i> Disable</a></li>
{% else %}
<li><a style="display:block" data-status="enable" data-node-pk="{{ node.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=node.pk %}?next={{ request.path }}&status=enable" >
<li><a style="display:block" data-node-pk="{{ node.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=node.pk %}?next={{ request.path }}" >
<i class="icon-check"></i> Enable</a>
<a style="display:none" data-status="disable" data-node-pk="{{ node.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=node.pk %}?next={{ request.path }}&status=disable" ><i class="icon-remove"></i> Disable</a></li>
<a style="display:none" data-node-pk="{{ node.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=node.pk %}?next={{ request.path }}" ><i class="icon-remove"></i> Disable</a></li>
{% endif %}
<li><a data-node-pk="{{ node.pk }}" class="real-link node-delete" href="{% url "dashboard.views.delete-node" pk=node.pk %}?next={{ request.path }}"><i class="icon-trash"></i> Delete</a></li>
</ul>
......
......@@ -1264,32 +1264,24 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return context
def post(self, request, *args, **kwargs):
if request.POST.get('new_status'):
if request.POST.get('change_status'):
return self.__set_status(request)
def __set_status(self, request):
self.object = self.get_object()
new_status = request.POST.get("new_status")
if new_status == "enable":
if self.object.enable:
Node.objects.filter(pk=self.object.pk).update(
**{'enabled': True})
elif new_status == "disable":
else:
Node.objects.filter(pk=self.object.pk).update(
**{'enabled': False})
else:
if request.is_ajax():
return HttpResponse(content_type="application/json")
else:
return redirect(self.get_success_url())
success_message = _("Node successfully changed status!")
if request.is_ajax():
response = {
'message': success_message,
'new_status': new_status,
'node_pk': self.object.pk
}
return HttpResponse(
......
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