Clean modal forms in Identity Users

Refactoring identity users modals.
Based on merged patch: https://review.openstack.org/#/c/123472/

Change-Id: Ic3777e3b4db185eb17f988c4d9567313108b0171
Partially-Implements: blueprint form-template-to-view
This commit is contained in:
Thai Tran 2015-01-27 13:40:25 -08:00
parent 486d0071e8
commit ba97e645bc
3 changed files with 36 additions and 64 deletions

View File

@ -1,35 +1,16 @@
{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% load url from future %}
{% block form_id %}create_user_form{% endblock %}
{% block form_action %}{% url 'horizon:identity:users:create' %}{% endblock %}
{% block modal-header %}{% trans "Create User" %}{% endblock %}
{% block modal-body %}
<div class="left">
<fieldset>
{% include "horizon/common/_form_fields.html" %}
</fieldset>
</div>
<div class="right">
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Create a new user and set related properties including the Primary Project and Role." %}</p>
</div>
<script type="text/javascript">
if (typeof horizon.user !== 'undefined') {
horizon.user.init();
} else {
addHorizonLoadEvent(function() {
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Create a new user and set related properties including the Primary Project and Role." %}</p>
<script type="text/javascript">
if (typeof horizon.user !== 'undefined') {
horizon.user.init();
});
}
</script>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Create User" %}" />
<a href="{% url 'horizon:identity:users:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% endblock %}
} else {
addHorizonLoadEvent(function() {
horizon.user.init();
});
}
</script>
{% endblock %}

View File

@ -1,35 +1,16 @@
{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% load url from future %}
{% block form_id %}update_user_form{% endblock %}
{% block form_action %}{% url 'horizon:identity:users:update' user.id %}{% endblock %}
{% block modal-header %}{% trans "Edit User" %}{% endblock %}
{% block modal-body %}
<div class="left">
<fieldset>
{% include "horizon/common/_form_fields.html" %}
</fieldset>
</div>
<div class="right">
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Edit the user's details, including the Primary Project." %}</p>
</div>
<script type="text/javascript">
if (typeof horizon.user !== 'undefined') {
horizon.user.init();
} else {
addHorizonLoadEvent(function() {
{% block modal-body-right %}
<h3>{% trans "Description:" %}</h3>
<p>{% trans "Edit the user's details, including the Primary Project." %}</p>
<script type="text/javascript">
if (typeof horizon.user !== 'undefined') {
horizon.user.init();
});
}
</script>
{% endblock %}
{% block modal-footer %}
<input class="btn btn-primary pull-right" type="submit" value="{% trans "Save" %}" />
<a href="{% url 'horizon:identity:users:index' %}" class="btn btn-default secondary cancel close">{% trans "Cancel" %}</a>
{% endblock %}
} else {
addHorizonLoadEvent(function() {
horizon.user.init();
});
}
</script>
{% endblock %}

View File

@ -71,8 +71,12 @@ class IndexView(tables.DataTableView):
class UpdateView(forms.ModalFormView):
form_class = project_forms.UpdateUserForm
template_name = 'identity/users/update.html'
modal_header = _("Update User")
form_id = "update_user_form"
form_class = project_forms.UpdateUserForm
submit_label = _("Update User")
submit_url = "horizon:identity:users:update"
success_url = reverse_lazy('horizon:identity:users:index')
@method_decorator(sensitive_post_parameters('password',
@ -93,7 +97,8 @@ class UpdateView(forms.ModalFormView):
def get_context_data(self, **kwargs):
context = super(UpdateView, self).get_context_data(**kwargs)
context['user'] = self.get_object()
args = (self.kwargs['user_id'],)
context['submit_url'] = reverse(self.submit_url, args=args)
return context
def get_initial(self):
@ -118,8 +123,13 @@ class UpdateView(forms.ModalFormView):
class CreateView(forms.ModalFormView):
template_name = 'identity/users/create.html'
modal_header = _("Create User")
form_id = "create_user_form"
form_class = project_forms.CreateUserForm
template_name = 'identity/users/create.html'
submit_label = _("Create User")
submit_url = reverse_lazy("horizon:identity:users:create")
success_url = reverse_lazy('horizon:identity:users:index')
@method_decorator(sensitive_post_parameters('password',