Commit 6bf11f0f by Oláh István Gergely

dashboard: enable-disable node without javascript, css menu

parent e63bb8ce
...@@ -126,7 +126,7 @@ $(function() { ...@@ -126,7 +126,7 @@ $(function() {
// addMessage(data['message'], "success"); // addMessage(data['message'], "success");
}, },
error: function(xhr, textStatus, error) { error: function(xhr, textStatus, error) {
addMessage("uhoh", "danger"); addMessage("uhoh", "danger");
} }
}); });
return false; return false;
...@@ -168,13 +168,14 @@ $(function() { ...@@ -168,13 +168,14 @@ $(function() {
$('#table_container').on('click','.node-enable',function() { $('#table_container').on('click','.node-enable',function() {
enablenode($(this).attr('data-node-pk'), $(this).attr('data-status'),enabletableSuccess,this); 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 // on node details, change node status, with calling enable node, refresh status span, resources div
$('#node-info-pane').on('click','.node-enable',function(){ $('#node-info-pane').on('click','.node-enable',function(){
// post, change node status // post, change node status
enablenode($(this).attr('data-node-pk'),$(this).attr('data-status'),enabledetailsSuccess); enablenode($(this).attr('data-node-pk'),$(this).attr('data-status'),enabledetailsSuccess);
return false;
}); });
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<script src="{{ STATIC_URL}}dashboard/bootstrap-slider/bootstrap-slider.js"></script> <script src="{{ STATIC_URL}}dashboard/bootstrap-slider/bootstrap-slider.js"></script>
<link rel="stylesheet" href="{{ STATIC_URL }}dashboard/bootstrap-slider/slider.css"/> <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/dashboard.css" rel="stylesheet">
<link href="{{ STATIC_URL }}dashboard/node.css" rel="stylesheet">
<script src="{{ STATIC_URL }}dashboard/dashboard.js"></script> <script src="{{ STATIC_URL }}dashboard/dashboard.js"></script>
</head> </head>
......
...@@ -4,11 +4,12 @@ ...@@ -4,11 +4,12 @@
<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 style="display:none" data-status="enable" data-node-pk="{{ record.pk }}" class="real-link node-enable" href="#" ><i class="icon-remove"></i> Enable</a> <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="#" ><i class="icon-remove"></i> Disable</a></li> <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 %} {% 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> <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" >
<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> <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 %} {% 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>
......
...@@ -6,7 +6,7 @@ from .views import ( ...@@ -6,7 +6,7 @@ from .views import (
VmDelete, VmMassDelete, vm_activity, NodeList, NodeDetailView, PortDelete, VmDelete, VmMassDelete, vm_activity, NodeList, NodeDetailView, PortDelete,
TransferOwnershipView, TransferOwnershipConfirmView, NodeDelete, TransferOwnershipView, TransferOwnershipConfirmView, NodeDelete,
TemplateList, LeaseDetail, NodeCreate, LeaseCreate, TemplateCreate, TemplateList, LeaseDetail, NodeCreate, LeaseCreate, TemplateCreate,
FavouriteView, FavouriteView, NodeStatus,
) )
urlpatterns = patterns( urlpatterns = patterns(
...@@ -45,6 +45,8 @@ urlpatterns = patterns( ...@@ -45,6 +45,8 @@ urlpatterns = patterns(
name='dashboard.views.vm-transfer-ownership-confirm'), name='dashboard.views.vm-transfer-ownership-confirm'),
url(r'^node/delete/(?P<pk>\d+)/$', NodeDelete.as_view(), url(r'^node/delete/(?P<pk>\d+)/$', NodeDelete.as_view(),
name="dashboard.views.delete-node"), 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(), url(r'^node/create/$', NodeCreate.as_view(),
name='dashboard.views.node-create'), name='dashboard.views.node-create'),
url(r'^favourite/$', FavouriteView.as_view(), url(r'^favourite/$', FavouriteView.as_view(),
......
...@@ -787,6 +787,62 @@ class NodeDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView): ...@@ -787,6 +787,62 @@ class NodeDelete(LoginRequiredMixin, SuperuserRequiredMixin, DeleteView):
return reverse_lazy('dashboard.index') 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): class PortDelete(LoginRequiredMixin, DeleteView):
model = Rule model = Rule
pk_url_kwarg = '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