Commit 6bf11f0f by Oláh István Gergely

dashboard: enable-disable node without javascript, css menu

parent e63bb8ce
......@@ -168,13 +168,14 @@ $(function() {
$('#table_container').on('click','.node-enable',function() {
enablenode($(this).attr('data-node-pk'), $(this).attr('data-status'),enabletableSuccess,this);
return false;
});
// on node details, change node status, with calling enable node, refresh status span, resources div
$('#node-info-pane').on('click','.node-enable',function(){
// post, change node status
enablenode($(this).attr('data-node-pk'),$(this).attr('data-status'),enabledetailsSuccess);
return false;
});
......
......@@ -18,6 +18,7 @@
<script src="{{ STATIC_URL}}dashboard/bootstrap-slider/bootstrap-slider.js"></script>
<link rel="stylesheet" href="{{ STATIC_URL }}dashboard/bootstrap-slider/slider.css"/>
<link href="{{ STATIC_URL }}dashboard/dashboard.css" rel="stylesheet">
<link href="{{ STATIC_URL }}dashboard/node.css" rel="stylesheet">
<script src="{{ STATIC_URL }}dashboard/dashboard.js"></script>
</head>
......
......@@ -4,11 +4,12 @@
<ul class="dropdown-menu" role="menu">
<li><a href="#"><i class="icon-cloud-upload"></i> Flush</a></li>
{% if record.enabled %}
<li><a style="display:none" data-status="enable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="#" ><i class="icon-remove"></i> Enable</a>
<a style="display:block" data-status="disable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="#" ><i class="icon-remove"></i> Disable</a></li>
<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="#" ><i class="icon-remove"></i> Enable</a>
<a style="display:none" data-status="disable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="#" ><i class="icon-remove"></i> Disable</a></li>
<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>
</ul>
......
......@@ -6,7 +6,7 @@ from .views import (
VmDelete, VmMassDelete, vm_activity, NodeList, NodeDetailView, PortDelete,
TransferOwnershipView, TransferOwnershipConfirmView, NodeDelete,
TemplateList, LeaseDetail, NodeCreate, LeaseCreate, TemplateCreate,
FavouriteView,
FavouriteView, NodeStatus,
)
urlpatterns = patterns(
......@@ -45,6 +45,8 @@ urlpatterns = patterns(
name='dashboard.views.vm-transfer-ownership-confirm'),
url(r'^node/delete/(?P<pk>\d+)/$', NodeDelete.as_view(),
name="dashboard.views.delete-node"),
url(r'^node/status/(?P<pk>\d+)/$', NodeStatus.as_view(),
name="dashboard.views.status-node"),
url(r'^node/create/$', NodeCreate.as_view(),
name='dashboard.views.node-create'),
url(r'^favourite/$', FavouriteView.as_view(),
......
......@@ -787,6 +787,62 @@ class NodeDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
return reverse_lazy('dashboard.index')
class NodeStatus(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
template_name = "dashboard/confirm/node-status.html"
model = Node
def get_success_url(self):
next = self.request.GET.get('next')
if next:
return next
else:
return reverse_lazy("dashboard.views.node-detail",
kwargs={'pk': self.object.pk})
def get_context_data(self, **kwargs):
context = super(NodeStatus, self).get_context_data(**kwargs)
context['status'] = self.request.GET.get('status')
return context
def post(self, request, *args, **kwargs):
if request.POST.get('new_status'):
print self.request.GET.get('next')
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":
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:
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(
json.dumps(response),
content_type="application/json"
)
else:
messages.success(request, success_message)
return redirect(self.get_success_url())
class PortDelete(LoginRequiredMixin, DeleteView):
model = Rule
pk_url_kwarg = 'rule'
......
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