Commit 04305fa9 by Bach Dániel

dashboard: improve transfer ownership view

parent ab87f4fc
...@@ -1062,6 +1062,14 @@ class AclUserOrGroupAddForm(forms.Form): ...@@ -1062,6 +1062,14 @@ class AclUserOrGroupAddForm(forms.Form):
attrs={'class': 'form-control'})) attrs={'class': 'form-control'}))
class TransferOwnershipForm(forms.Form):
name = forms.CharField(
widget=autocomplete_light.TextWidget(
'AclUserAutocomplete',
autocomplete_js_attributes={"placeholder": _("Name of user")},
attrs={'class': 'form-control'}),
label=_("E-mail address or identifier of user"))
class AddGroupMemberForm(forms.Form): class AddGroupMemberForm(forms.Form):
new_member = forms.CharField( new_member = forms.CharField(
......
...@@ -2,6 +2,12 @@ ...@@ -2,6 +2,12 @@
<div class="modal fade" id="confirmation-modal" tabindex="-1" role="dialog"> <div class="modal fade" id="confirmation-modal" tabindex="-1" role="dialog">
<div class="modal-dialog"> <div class="modal-dialog">
<div class="modal-content"> <div class="modal-content">
{% if box_title and ajax_title %}
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title">{{ box_title }}</h4>
</div>
{% endif %}
<div class="modal-body"> <div class="modal-body">
{% if template %} {% if template %}
{% include template %} {% include template %}
......
...@@ -9,8 +9,10 @@ ...@@ -9,8 +9,10 @@
{% endblocktrans %} {% endblocktrans %}
{% endif %} {% endif %}
{% if user == instance.owner or user.is_superuser %} {% if user == instance.owner or user.is_superuser %}
<span class="operation-wrapper">
<a href="{% url "dashboard.views.vm-transfer-ownership" instance.pk %}" <a href="{% url "dashboard.views.vm-transfer-ownership" instance.pk %}"
class="btn btn-link">{% trans "Transfer ownership..." %}</a> class="btn btn-link operation">{% trans "Transfer ownership..." %}</a>
</span>
{% endif %} {% endif %}
</p> </p>
<h3>{% trans "Permissions"|capfirst %}</h3> <h3>{% trans "Permissions"|capfirst %}</h3>
......
{% extends "dashboard/base.html" %}
{% load i18n %} {% load i18n %}
{% block content %} <div class="pull-right">
<div class="body-content"> <form action="{% url "dashboard.views.vm-transfer-ownership" pk=instance.pk %}" method="POST" style="max-width: 400px;">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="no-margin">
{% trans "Transfer ownership" %}
</h3>
</div>
<div class="panel-body">
<div class="pull-right">
<form action="" method="POST">
{% csrf_token %} {% csrf_token %}
<label> <label>
{% trans "E-mail address or identifier of user" %}: {{ form.name.label }}
<input name="name">
</label> </label>
<input type="submit"> <div class="input-group">
</form> {{form.name}}
<div class="input-group-btn">
<input type="submit" value="{% trans "Save" %}" class="btn btn-primary">
</div> </div>
</div> </div>
</div> </form>
{% endblock %} </div>
...@@ -2766,11 +2766,30 @@ class FavouriteView(TemplateView): ...@@ -2766,11 +2766,30 @@ class FavouriteView(TemplateView):
return HttpResponse("Added.") return HttpResponse("Added.")
class TransferOwnershipView(LoginRequiredMixin, DetailView): class TransferOwnershipView(CheckedDetailView, DetailView):
model = Instance model = Instance
template_name = 'dashboard/vm-detail/tx-owner.html'
def get_template_names(self):
if self.request.is_ajax():
return ['dashboard/_modal.html']
else:
return ['dashboard/nojs-wrapper.html']
def get_context_data(self, *args, **kwargs):
context = super(TransferOwnershipView, self).get_context_data(
*args, **kwargs)
context['form'] = TransferOwnershipForm()
context.update({
'box_title': _("Transfer ownership"),
'ajax_title': True,
'template': "dashboard/vm-detail/tx-owner.html",
})
return context
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = TransferOwnershipForm(request.POST)
if not form.is_valid():
return self.get(request)
try: try:
new_owner = search_user(request.POST['name']) new_owner = search_user(request.POST['name'])
except User.DoesNotExist: except User.DoesNotExist:
......
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