Commit 03ac86a3 by Kálmán Viktor

dashboard: vm action buttons

parent d488150d
......@@ -6,25 +6,34 @@
<div class="page-header">
<div class="pull-right" style="padding-top: 15px;">
<a title="Rename" href="#" class="btn btn-default btn-xs vm-details-rename-button"><i class="icon-pencil"></i></a>
{% if instance.state.lower == "running" %}
<a title="Pause" href="#" class="btn btn-default btn-xs"><i class="icon-pause"></i></a>
<a title="Sleep" href="#" class="btn btn-default btn-xs"><i class="icon-moon"></i></a>
{% else %}
<a title="Start" href="#" class="btn btn-default btn-xs"><i class="icon-play"></i></a>
<a title="Wake up" href="#" class="btn btn-default btn-xs"><i class="icon-sun"></i></a>
{% endif %}
<a title="Pause == sleep?" href="#" class="btn btn-default btn-xs"><i class="icon-pause"></i></a>
<form style="display: inline;" method="POST" action="{% url "dashboard.views.detail" pk=instance.pk %}">
{% csrf_token %}
<input type="hidden" name="sleep" value="dummy"/>
<button title="{% trans "Sleep" %}" class="btn btn-default btn-xs" type="submit"><i class="icon-moon"></i></button>
</form>
<form style="display: inline;" method="POST" action="{% url "dashboard.views.detail" pk=instance.pk %}">
{% csrf_token %}
<input type="hidden" name="deploy" value="dummy"/>
<button title="{% trans "Deploy" %}" class="btn btn-default btn-xs" type="submit"><i class="icon-play"></i></button>
</form>
<form style="display: inline;" method="POST" action="{% url "dashboard.views.detail" pk=instance.pk %}">
{% csrf_token %}
<input type="hidden" name="wake_up" value="dummy"/>
<button title="{% trans "Wake up" %}" class="btn btn-default btn-xs" type="submit"><i class="icon-sun"></i></button>
</form>
<form style="display: inline;" method="POST" action="{% url "dashboard.views.detail" pk=instance.pk %}">
{% csrf_token %}
<input type="hidden" name="shut_down" value="dummy"/>
<button title="Shut down" class="btn btn-default btn-xs" type="submit"><i class="icon-off"></i></button>
<button title="{% trans "Shut down" %}" class="btn btn-default btn-xs" type="submit"><i class="icon-off"></i></button>
</form>
<a title="Migrate" href="#" class="btn btn-default btn-xs"><i class="icon-truck"></i></a>
<form style="display: inline;" method="POST" action="{% url "dashboard.views.detail" pk=instance.pk %}">
{% csrf_token %}
<input type="hidden" name="save_as" value="dummy"/>
<button title="Save as template" class="btn btn-default btn-xs" type="submit"><i class="icon-save"></i></button>
<button title="{% trans "Save as template" %}" class="btn btn-default btn-xs" type="submit"><i class="icon-save"></i></button>
</form>
<a title="Destroy" href="{% url "dashboard.views.delete-vm" pk=instance.pk %}" class="btn btn-default btn-xs vm-delete" data-vm-pk="{{ instance.pk }}"><i class="icon-remove"></i></a>
<a title="{% trans "Destroy" %}" href="{% url "dashboard.views.delete-vm" pk=instance.pk %}" class="btn btn-default btn-xs vm-delete" data-vm-pk="{{ instance.pk }}"><i class="icon-remove"></i></a>
</div>
<h1>
<div id="vm-details-rename">
......
......@@ -177,8 +177,12 @@ class VmDetailView(CheckedDetailView):
'save_as': self.__save_as,
'disk-name': self.__add_disk,
'shut_down': self.__shut_down,
'sleep': self.__sleep,
'wake_up': self.__wake_up,
'deploy': self.__deploy,
'reset': self.__reset,
'reboot': self.__reboot,
}
for k, v in options.iteritems():
if request.POST.get(k) is not None:
return v(request)
......@@ -370,8 +374,47 @@ class VmDetailView(CheckedDetailView):
raise PermissionDenied()
self.object.shutdown_async(request.user)
return redirect("%s#activity" % reverse_lazy(
"dashboard.views.detail", kwargs={'pk': self.object.pk}))
return redirect("%s#activity" % self.object.get_absolute_url())
def __sleep(self, request):
self.object = self.get_object()
if not self.object.has_level(request.user, 'owner'):
raise PermissionDenied()
self.object.sleep_async(request.user)
return redirect("%s#activity" % self.object.get_absolute_url())
def __wake_up(self, request):
self.object = self.get_object()
if not self.object.has_level(request.user, 'owner'):
raise PermissionDenied()
self.object.wake_up_async(request.user)
return redirect("%s#activity" % self.object.get_absolute_url())
def __deploy(self, request):
self.object = self.get_object()
if not self.object.has_level(request.user, 'owner'):
raise PermissionDenied()
self.object.deploy_async(request.user)
return redirect("%s#activity" % self.object.get_absolute_url())
def __reset(self, request):
self.object = self.get_object()
if not self.object.has_level(request.user, 'owner'):
raise PermissionDenied()
self.object.reset_async(request.user)
return redirect("%s#activity" % self.object.get_absolute_url())
def __reboot(self, request):
self.object = self.get_object()
if not self.object.has_level(request.user, 'owner'):
raise PermissionDenied()
self.object.reboot_async(request.user)
return redirect("%s#activity" % self.object.get_absolute_url())
class NodeDetailView(LoginRequiredMixin, SuperuserRequiredMixin, DetailView):
......
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