diff --git a/circle/dashboard/static/dashboard/dashboard.js b/circle/dashboard/static/dashboard/dashboard.js index 6bd5c09..64c7e2c 100644 --- a/circle/dashboard/static/dashboard/dashboard.js +++ b/circle/dashboard/static/dashboard/dashboard.js @@ -140,9 +140,10 @@ $(function () { /* for Node flush buttons */ $('.node-flush').click(function() { var node_pk = $(this).data('node-pk'); + var postto = $(this).attr('href'); var dir = window.location.pathname.indexOf('list') == -1; addModalConfirmation(function(){}, - { 'url': '/dashboard/node/flush/' + node_pk + '/', + { 'url': postto, 'data': [], 'pk': node_pk, 'type': "node", diff --git a/circle/dashboard/templates/dashboard/confirm/ajax-node-flush.html b/circle/dashboard/templates/dashboard/confirm/ajax-node-flush.html index 9b43c1c..7a91cfa 100644 --- a/circle/dashboard/templates/dashboard/confirm/ajax-node-flush.html +++ b/circle/dashboard/templates/dashboard/confirm/ajax-node-flush.html @@ -12,7 +12,7 @@ {%endblocktrans%} {% endif %} <div class="pull-right"> - <form action="" method="POST"> + <form action="{% url "dashboard.views.flush-node" pk=node.pk %}?next={{next}}" method="POST"> {% csrf_token %} <button type="button" class="btn btn-default" data-dismiss="modal">{% trans "Cancel" %}</button> <input type="hidden" name="flush" value=""/> diff --git a/circle/dashboard/templates/dashboard/node-detail.html b/circle/dashboard/templates/dashboard/node-detail.html index 0f382db..f38d361 100644 --- a/circle/dashboard/templates/dashboard/node-detail.html +++ b/circle/dashboard/templates/dashboard/node-detail.html @@ -29,15 +29,10 @@ <button type="button" class="btn {{ btn_size }} btn-warning nojs-dropdown-toogle dropdown-toggle" data-toggle="dropdown">Action <i class="icon-caret-down"></i></button> <ul class="dropdown-menu nojs-dropdown-toogle" role="menu"> <li><a href="#" class="node-details-rename-button"><i class="icon-pencil"></i> {% trans "Rename" %}</a></li> - <li><a data-node-pk="{{ node.pk }}" class="real-link node-flush" href="{% url "dashboard.views.flush-node" pk=node.pk %}?next={{ request.path }}"><i class="icon-cloud-upload"></i> Flush</a> - {% if node.enabled %} - <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-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-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-flush" href="{% url "dashboard.views.flush-node" pk=node.pk %}"><i class="icon-cloud-upload"></i>{% trans "Flush" %}</a> + <li> + <a style="display:{% if node.enabled %}none{% else %}block{% endif %}" 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>{% trans "Enable" %}</a> + <a style="display:{% if not node.enabled %}none{% else %}block{% endif %}" 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>{% trans "Disable" %}</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> </div> diff --git a/circle/dashboard/templates/dashboard/node-list/column-actions.html b/circle/dashboard/templates/dashboard/node-list/column-actions.html index c2f70b5..3f707d3 100644 --- a/circle/dashboard/templates/dashboard/node-list/column-actions.html +++ b/circle/dashboard/templates/dashboard/node-list/column-actions.html @@ -3,15 +3,9 @@ <button type="button" class="btn {{ btn_size }} btn-warning nojs-dropdown-toogle dropdown-toggle" data-toggle="dropdown">Action <i class="icon-caret-down"></i></button> <ul class="dropdown-menu nojs-dropdown-toogle" role="menu"> <li><a href="#" class="node-details-rename-button"><i class="icon-pencil"></i> {% trans "Rename" %}</a></li> - <li><a data-node-pk="{{ record.pk }}" class="real-link node-flush" href="{% url "dashboard.views.flush-node" pk=record.pk %}?next={{ request.path }}"><i class="icon-cloud-upload"></i> Flush</a> - {% if record.enabled %} - <li><a style="display:none" data-status="enable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=record.pk %}?next={{ request.path }}&status=enable"><i class="icon-check"></i> Enable</a> - <a style="display:block" data-status="disable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=record.pk %}?next={{ request.path }}&status=disable"><i class="icon-remove"></i> Disable</a></li> - {% else %} - <li><a style="display:block" data-status="enable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=record.pk %}?next={{ request.path }}&status=enable" > - <i class="icon-check"></i> Enable</a> - <a style="display:none" data-status="disable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=record.pk %}?next={{ request.path }}&status=disable" ><i class="icon-remove"></i> Disable</a></li> - {% endif %} - <li><a data-node-pk="{{ record.pk }}" class="real-link node-delete" href="{% url "dashboard.views.delete-node" pk=record.pk %}?next={{ request.path }}"><i class="icon-trash"></i> Delete</a></li> + <li><a data-node-pk="{{ record.pk }}" class="real-link node-flush" href="{% url "dashboard.views.flush-node" pk=record.pk %}"><i class="icon-cloud-upload"></i>{% trans "Flush" %}</a> + <li><a style={% if record.enabled %}"display:none"{% else %}"display:block"{% endif %} data-status="enable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=record.pk %}?next={{ request.path }}&status=enable"><i class="icon-check"></i>{% trans "Enable" %}</a> + <a style={% if record.enabled %}"display:block"{% else %}"display:none"{% endif %} data-status="disable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="{% url "dashboard.views.status-node" pk=record.pk %}?next={{ request.path }}&status=disable"><i class="icon-remove"></i>{% trans "Disable" %}</a></li> + <li><a data-node-pk="{{ record.pk }}" class="real-link node-delete" href="{% url "dashboard.views.delete-node" pk=record.pk %}?next={{ request.path }}"><i class="icon-trash"></i>{% trans "Delete" %}</a></li> </ul> </div> diff --git a/circle/dashboard/views.py b/circle/dashboard/views.py index 0ed926f..a4e14f1 100644 --- a/circle/dashboard/views.py +++ b/circle/dashboard/views.py @@ -503,8 +503,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): return self.__set_status(request) if request.POST.get('to_remove'): return self.__remove_trait(request) - if request.POST.get('flush') is not None: - return self.__flush(request) return redirect(reverse_lazy("dashboard.views.node-detail", kwargs={'pk': self.get_object().pk})) @@ -530,24 +528,6 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): return redirect(reverse_lazy("dashboard.views.node-detail", kwargs={'pk': self.object.pk})) - def __flush(self, request): - self.object = self.get_object() - self.object.flush_async(user=request.user) - success_message = _("Node successfully flushed!") - if request.is_ajax(): - response = { - 'message': success_message, - 'node_pk': self.object.pk - } - return HttpResponse( - json.dumps(response), - content_type="application/json" - ) - else: - messages.success(request, success_message) - return redirect(reverse_lazy("dashboard.views.node-detail", - kwargs={'pk': self.object.pk})) - def __set_status(self, request): self.object = self.get_object() if not self.object.enabled: @@ -1444,19 +1424,8 @@ class NodeFlushView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): self.object = self.get_object() self.object.flush_async(user=request.user) success_message = _("Node successfully flushed!") - - if request.is_ajax(): - response = { - 'message': success_message, - 'node_pk': self.object.pk - } - return HttpResponse( - json.dumps(response), - content_type="application/json" - ) - else: - messages.success(request, success_message) - return redirect(self.get_success_url()) + messages.success(request, success_message) + return redirect(self.get_success_url()) class PortDelete(LoginRequiredMixin, DeleteView):