Bug 1126674

Summary: [RFE][horizon]: Move form templating logic to the ModalFormView
Product: Red Hat OpenStack Reporter: RHOS Integration <rhos-integ>
Component: RFEsAssignee: RHOS Maint <rhos-maint>
Status: CLOSED UPSTREAM QA Contact:
Severity: medium Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: markmc, yeylon
Target Milestone: ---Keywords: FutureFeature
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
URL: https://blueprints.launchpad.net/horizon/+spec/form-template-to-view
Whiteboard: upstream_milestone_none upstream_definition_approved upstream_status_implemented
Fixed In Version: Doc Type: Enhancement
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-03-19 16:57:24 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description RHOS Integration 2014-08-05 04:04:33 UTC
Cloned from launchpad blueprint https://blueprints.launchpad.net/horizon/+spec/form-template-to-view.

Description:

Below is a typical form:

{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% load url from future %}
{% block form_id %}update_role_form{% endblock %}
{% block form_action %}{% url 'horizon:admin:roles:update' role.id %}{% endblock %}
{% block modal-header %}{% trans "Update Role" %}{% 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 "From here you can edit the role's details." %}</p>
</div>
{% endblock %}
{% block modal-footer %}
  <a href="{% url 'horizon:admin:roles:index' %}" class="btn btn-default cancel">{% trans "Cancel" %}</a>
  <input class="btn btn-primary" type="submit" value="{% trans "Update Role" %}"/>
{% endblock %}

----------------------------------------------------------------------------------------------------------------------------------------------------
In a typical form, many variables such as id, action_url, success_url, cancel button, submit button are repeated. Currently, we are redefining these variables by overriding them using blocks. It is much cleaner to define these variables in python, and let the base modal_form.html populate them. That way, most of our logic is in one place and we would also reduce the clutter in the templates.

In addition, the left and right part of the modal is consistently use. It make sense for us to make that the default template, and let users override the right part while keeping the left. But we also need to retain the ability to override entire thing if required. Something like this should suffice:

<div class="modal-body clearfix">
  {% block modal-body %}
 <div class="left">
   <fieldset>{% include "horizon/common/_form_fields.html" %}</fieldset>
 </div>
 <div class="right">
   {% block modal-body-right %}{% endblock %}
 </div>
  {% endblock %}
</div>

----------------------------------------------------------------------------------------------------------------------------------------------------
So what exactly am I proposing?

class ModalFormView:
  id - the unique identifier of this form
  name - the header of this form
  action_url - the url to trigger the confirm action
  success_url - the url to redirect for cancel action and success
  confirm_label - the label for the confirm button
  cancel_label - the label for the cancel button

Now a typical form can look like:

{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}
{% load url from future %}
{% block modal-body-right %}
    <h3>{% trans "Description" %}:</h3>
    <p>{% trans "From here you can edit the role's details." %}</p>
{% endblock %}

Specification URL (additional information):

None