Commit 2fc07a8d by Oláh István Gergely

dashboard: fix set_status in NodeStatus

parent e7672078
...@@ -298,7 +298,6 @@ function addModalConfirmation(func, data) { ...@@ -298,7 +298,6 @@ 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() {
......
...@@ -29,13 +29,11 @@ ...@@ -29,13 +29,11 @@
/* for Node removes buttons */ /* for Node removes buttons */
$('.node-enable').click(function() { $('.node-enable').click(function() {
var node_pk = $(this).data('node-pk'); var node_pk = $(this).data('node-pk');
var node_status = $(this).data('status');
var dir = window.location.pathname.indexOf('list') == -1; var dir = window.location.pathname.indexOf('list') == -1;
addModalConfirmation(deleteObject, addModalConfirmation(deleteObject,
{ 'url': '/dashboard/node/status/' + node_pk + '/?status='+node_status, { 'url': '/dashboard/node/status/' + node_pk + '/',
'data': {'new_status':node_status}, 'data': {'change_status':""},
'pk': node_pk, 'pk': node_pk,
'status': node_status,
'type': "node", 'type': "node",
'redirect': dir}); 'redirect': dir});
......
...@@ -32,12 +32,12 @@ ...@@ -32,12 +32,12 @@
<li><a href="#" class="node-details-rename-button"><i class="icon-pencil"></i> {% trans "Rename" %}</a></li> <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> <li><a href="#"><i class="icon-cloud-upload"></i> Flush</a></li>
{% if node.enabled %} {% 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> <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-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: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 %} {% 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> <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 %} {% 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> <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> </ul>
......
...@@ -1264,32 +1264,24 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -1264,32 +1264,24 @@ class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return context return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
if request.POST.get('new_status'): if request.POST.get('change_status'):
return self.__set_status(request) return self.__set_status(request)
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 new_status == "enable": if self.object.enable:
Node.objects.filter(pk=self.object.pk).update( Node.objects.filter(pk=self.object.pk).update(
**{'enabled': True}) **{'enabled': True})
elif new_status == "disable": else:
Node.objects.filter(pk=self.object.pk).update( Node.objects.filter(pk=self.object.pk).update(
**{'enabled': False}) **{'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!") 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(
......
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