Commit 9eb35a7a by Oláh István Gergely

dashboard: add node enable-disable function

parent 76b8e42a
...@@ -59,14 +59,29 @@ $(function() { ...@@ -59,14 +59,29 @@ $(function() {
return retval; return retval;
}); });
/*
$('.popover-link').popover();
$(':not(#anything)').on('click', function (e) {
$('.popover-link').each(function () {
//the 'is' for buttons that trigger popups
//the 'has' for icons and other elements within a button that triggers a popup
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide');
return;
}
});
});
*/
$(':not(#anything)').on('click', function (e) { $(':not(#anything)').on('click', function (e) {
$('.node-list-details').each(function () { $('.node-list-details').each(function () {
//the 'is' for buttons that trigger popups //the 'is' for buttons that trigger popups
// //the 'has' for icons and other elements within a button that triggers a popup // //the 'has' for icons and other elements within a button that triggers a popup
if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) { if (!$(this).is(e.target) && $(this).has(e.target).length === 0 && $('.popover').has(e.target).length === 0) {
$(this).popover('hide'); $(this).popover('hide');
return; return;
} }
}); });
}); });
...@@ -80,6 +95,7 @@ $(':not(#anything)').on('click', function (e) { ...@@ -80,6 +95,7 @@ $(':not(#anything)').on('click', function (e) {
'trigger': 'click' 'trigger': 'click'
}); });
$('tbody a').mousedown(function(e) { $('tbody a').mousedown(function(e) {
// parent tr doesn't get selected when clicked // parent tr doesn't get selected when clicked
e.stopPropagation(); e.stopPropagation();
...@@ -127,8 +143,33 @@ $(':not(#anything)').on('click', function (e) { ...@@ -127,8 +143,33 @@ $(':not(#anything)').on('click', function (e) {
}); });
return false; return false;
}); });
$('#table_container').on('click','#node-list-enable-button',function(){
enablenode($(this).attr('data-node-pk'),$(this).attr('data-status'));
});
// enabling / disabling node
function enablenode(pk,new_status) {
var url = '/dashboard/node/' + pk + '/';
console.log('success');
$.ajax({
method: 'POST',
url: url,
data: {'new_status':new_status},
headers: {"X-CSRFToken": getCookie('csrftoken')},
success: function(data, textStatus, xhr) {
$('#table_container').load(location.href+" "+'#rendered_table');
},
error: function(xhr, textStatus, error) {
addMessage("uhoh", "danger");
}
});
return false;
}
/* group actions */ /* group actions */
/* select all */ /* select all */
......
...@@ -54,3 +54,7 @@ ...@@ -54,3 +54,7 @@
</div> </div>
{% endblock %} {% endblock %}
{% block extra_js %}
<script src="{{ STATIC_URL}}dashboard/node-list.js"></script>
{% endblock %}
...@@ -26,9 +26,11 @@ ...@@ -26,9 +26,11 @@
<a disabled href="#" class="btn btn-default btn-xs"><i class="icon-off"></i> Shutdown</a> <a disabled href="#" class="btn btn-default btn-xs"><i class="icon-off"></i> Shutdown</a>
<a id="node-list-group-delete" disabled href="#" class="btn btn-danger btn-xs"><i class="icon-remove"></i> Discard</a> <a id="node-list-group-delete" disabled href="#" class="btn btn-danger btn-xs"><i class="icon-remove"></i> Discard</a>
</p> </p>
</div> </div>
<div class="panel-body"> <div id="table_container">
<div id="rendered_table" class="panel-body">
{% render_table table %} {% render_table table %}
</div>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
<ul class="dropdown-menu" role="menu"> <ul class="dropdown-menu" role="menu">
<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 record.enabled %} {% if record.enabled %}
<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-remove"></i> Disable</a></li> <li><a data-status="disable" data-node-pk="{{ record.pk }}" class="real-link node-enable" id="node-list-enable-button" href="#" ><i class="icon-remove"></i> Disable</a></li>
{% else %} {% else %}
<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-check"></i> Enable</a></li> <li><a data-status="enable" data-node-pk="{{ record.pk }}" class="real-link node-enable" id="node-list-enable-button" href="#" ><i class="icon-check"></i> Enable</a></li>
{% endif%} {% 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-delete" href="{% url "dashboard.views.delete-node" pk=record.pk %}?next={{ request.path }}"><i class="icon-trash"></i> Delete</a></li>
</ul> </ul>
......
...@@ -286,6 +286,8 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -286,6 +286,8 @@ 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'):
return self.__set_status(request)
def __set_name(self, request): def __set_name(self, request):
self.object = self.get_object() self.object = self.get_object()
...@@ -309,6 +311,34 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView): ...@@ -309,6 +311,34 @@ class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
return redirect(reverse_lazy("dashboard.views.node-detail", return redirect(reverse_lazy("dashboard.views.node-detail",
kwargs={'pk': self.object.pk})) kwargs={'pk': self.object.pk}))
def __set_status(self, request):
self.object = self.get_object()
new_status = request.POST.get("new_status")
if new_status == "enable":
Node.objects.filter(pk=self.object.pk).update(
**{'enabled': True})
elif new_status == "disable":
Node.objects.filter(pk=self.object.pk).update(
**{'enabled': False})
else:
return
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(
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}))
class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin): class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin):
......
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