Commit dff04fba by Czémán Arnold

dashboard, vm: add boot menu toggle button for vm-detail view and add toggle_boot_menu permission

Issue: #439
parent cbcbb8e6
......@@ -20,6 +20,7 @@
"bootbox": "~4.3.0",
"intro.js": "0.9.0",
"favico.js": "~0.3.5",
"datatables": "~1.10.4"
"datatables": "~1.10.4",
"bootstrap-toggle": "~2.2.1"
}
}
......@@ -178,6 +178,7 @@ PIPELINE_CSS = {
"all": {"source_filenames": (
"compile_bootstrap.less",
"bootstrap/dist/css/bootstrap-theme.css",
"bootstrap-toggle/css/bootstrap-toggle.min.css",
"fontawesome/css/font-awesome.css",
"jquery-simple-slider/css/simple-slider.css",
"intro.js/introjs.css",
......@@ -227,6 +228,7 @@ PIPELINE_JS = {
"output_filename": "all.js",
},
"vm-detail": {"source_filenames": (
"bootstrap-toggle/js/bootstrap-toggle.min.js",
"dashboard/vm-details.js",
"no-vnc/include/util.js",
"no-vnc/include/webutil.js",
......
......@@ -1429,6 +1429,27 @@ class RawDataForm(forms.ModelForm):
return helper
class ToggleBootMenuForm(forms.ModelForm):
class Meta:
model = Instance
fields = ('boot_menu', )
widgets = {
'boot_menu': forms.CheckboxInput(attrs={'data-toggle': 'toggle',
'data-on': _('On'),
'data-off': _('Off')})
}
@property
def helper(self):
helper = FormHelper()
helper.form_show_labels = True
helper.form_action =\
reverse_lazy("dashboard.views.vm-toggle-boot-menu",
kwargs={'pk': self.instance.pk})
return helper
class GroupPermissionForm(forms.ModelForm):
permissions = forms.ModelMultipleChoiceField(
queryset=None,
......
......@@ -252,4 +252,8 @@ $(function() {
return e.preventDefault();
});
$("#id_boot_menu").change(function(){
$("#id_boot_menu").parents("form").submit();
});
});
......@@ -2,7 +2,6 @@
{% load sizefieldtags %}
{% load crispy_forms_tags %}
<div class="label label-info label-100" id="modify-the-resources">
{% trans "Modify the resources" %}
</div>
......@@ -104,6 +103,15 @@
{% endif %}
{% if toggle_boot_menu_form %}
<hr />
<div class="row">
<div class="col-sm-12">
{% crispy toggle_boot_menu_form %}
</div>
</div>
{% endif %}
{% block extra_js %}
<style>
label {padding-top: 6px;}
......
......@@ -42,7 +42,7 @@ from .views import (
ConnectCommandDelete, ConnectCommandDetail, ConnectCommandCreate,
StoreList, store_download, store_upload, store_get_upload_url, StoreRemove,
store_new_directory, store_refresh_toplist,
VmTraitsUpdate, VmRawDataUpdate,
VmTraitsUpdate, VmRawDataUpdate, VmToggleBootMenuUpdate,
GroupPermissionsView,
LeaseAclUpdateView,
toggle_template_tutorial,
......@@ -113,6 +113,9 @@ urlpatterns = patterns(
name='dashboard.views.vm-traits'),
url(r'^vm/(?P<pk>\d+)/raw_data/$', VmRawDataUpdate.as_view(),
name='dashboard.views.vm-raw-data'),
url(r'^vm/(?P<pk>\d+)/toggle_boot_menu/$',
VmToggleBootMenuUpdate.as_view(),
name='dashboard.views.vm-toggle-boot-menu'),
url(r'^vm/(?P<pk>\d+)/toggle_tutorial/$', toggle_template_tutorial,
name='dashboard.views.vm-toggle-tutorial'),
......
......@@ -61,6 +61,7 @@ from .util import (
)
from ..forms import (
AclUserOrGroupAddForm, VmResourcesForm, TraitsForm, RawDataForm,
ToggleBootMenuForm,
VmAddInterfaceForm, VmCreateDiskForm, VmDownloadDiskForm, VmSaveForm,
VmRenewForm, VmStateChangeForm, VmListSearchForm, VmCustomizeForm,
VmDiskResizeForm, RedeployForm, VmDiskRemoveForm,
......@@ -161,6 +162,10 @@ class VmDetailView(GraphMixin, CheckedDetailView):
context['traits_form'] = TraitsForm(instance=instance)
context['raw_data_form'] = RawDataForm(instance=instance)
if is_owner and user.has_perm("vm.toggle_boot_menu"):
context['toggle_boot_menu_form'] =\
ToggleBootMenuForm(instance=instance)
# resources change perm
context['can_change_resources'] = self.request.user.has_perm(
"vm.change_resources")
......@@ -310,6 +315,26 @@ class VmRawDataUpdate(SuperuserRequiredMixin, UpdateView):
return self.get_object().get_absolute_url() + "#resources"
class VmToggleBootMenuUpdate(LoginRequiredMixin, UpdateView):
form_class = ToggleBootMenuForm
model = Instance
def get(self, *args, **kwargs):
raise Http404()
def form_valid(self, form):
user = self.request.user
is_owner = form.instance.has_level(user, "owner")
if not (is_owner and user.has_perm("vm.toggle_boot_menu")):
raise PermissionDenied()
return super(VmToggleBootMenuUpdate, self).form_valid(form)
def get_success_url(self):
return self.get_object().get_absolute_url() + "#resources"
class VmOperationView(AjaxOperationMixin, OperationView):
model = Instance
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('vm', '0002_interface_model'),
]
operations = [
migrations.AlterModelOptions(
name='instance',
options={'ordering': ('pk',), 'verbose_name': 'instance', 'verbose_name_plural': 'instances', 'permissions': (('access_console', 'Can access the graphical console of a VM.'), ('change_resources', 'Can change resources of a running VM.'), ('set_resources', 'Can change resources of a new VM.'), ('create_vm', 'Can create a new VM.'), ('redeploy', 'Can redeploy a VM.'), ('config_ports', 'Can configure port forwards.'), ('recover', 'Can recover a destroyed VM.'), ('emergency_change_state', 'Can change VM state to NOSTATE.'), ('toggle_boot_menu', 'Can turn on/off boot menu.'))},
),
]
......@@ -272,6 +272,7 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
('config_ports', _('Can configure port forwards.')),
('recover', _('Can recover a destroyed VM.')),
('emergency_change_state', _('Can change VM state to NOSTATE.')),
('toggle_boot_menu', _('Can turn on/off boot menu.')),
)
verbose_name = _('instance')
verbose_name_plural = _('instances')
......
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