Merge "give a fullscreen attribute to workflow, for modal view"

This commit is contained in:
Jenkins 2014-01-27 18:37:29 +00:00 committed by Gerrit Code Review
commit 08c99d5d53
5 changed files with 63 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{% load i18n %}
{% with workflow.get_entry_point as entry_point %}
<div class="workflow {% if modal %}modal hide{% else %}static_page{% endif %}{% if workflow.wizard %} wizard{% endif %}">
<div class="workflow {{ layout|join:' ' }}">
<form {{ workflow.attr_string|safe }} action="{{ workflow.get_absolute_url }}" {% if add_to_field %}data-add-to-field="{{ add_to_field }}"{% endif %} method="POST"{% if workflow.multipart %} enctype="multipart/form-data"{% endif %}>{% csrf_token %}
{% if REDIRECT_URL %}<input type="hidden" name="{{ workflow.redirect_param_name }}" value="{{ REDIRECT_URL }}"/>{% endif %}
<div class="modal-header">

View File

@ -120,6 +120,17 @@ class TestWorkflowView(workflows.WorkflowView):
template_name = "workflow.html"
class TestFullscreenWorkflow(workflows.Workflow):
slug = 'test_fullscreen_workflow'
default_steps = (TestStepOne, TestStepTwo)
fullscreen = True
class TestFullscreenWorkflowView(workflows.WorkflowView):
workflow_class = TestFullscreenWorkflow
template_name = "workflow.html"
class WorkflowsTests(test.TestCase):
def setUp(self):
super(WorkflowsTests, self).setUp()
@ -263,3 +274,21 @@ class WorkflowsTests(test.TestCase):
flow = TestWorkflow(req, entry_point="test_action_two")
self.assertEqual(flow.get_entry_point(), "test_action_two")
def test_fullscreenworkflow_view(self):
view = TestFullscreenWorkflowView.as_view()
req = self.factory.get("/")
req.is_ajax = lambda: True
res = view(req)
output = res.render()
self.assertRegexpMatches(str(output),
'class="[^"]*\\bfullscreen\\b[^"]*"')
def test_notfullscreenworkflow_view(self):
view = TestWorkflowView.as_view()
req = self.factory.get("/")
req.is_ajax = lambda: True
res = view(req)
output = res.render()
self.assertNotRegexpMatches(str(output),
'class="[^"]*\\bfullscreen\\b[^"]*"')

View File

@ -580,6 +580,14 @@ class Workflow(html.HTMLElement):
Whether to present the workflow as a wizard, with "prev" and "next"
buttons and validation after every step.
.. attribute:: fullscreen
If the workflow is presented in a modal, and this attribute is
set to True, then the ``fullscreen`` css class will be added so
the modal can take advantage of the available screen estate.
Defaults to ``False``.
"""
__metaclass__ = WorkflowMetaclass
slug = None
@ -591,6 +599,7 @@ class Workflow(html.HTMLElement):
redirect_param_name = "next"
multipart = False
wizard = False
fullscreen = False
_registerable_class = Step
def __unicode__(self):

View File

@ -89,12 +89,28 @@ class WorkflowView(generic.TemplateView):
context[self.context_object_name] = workflow
next = self.request.REQUEST.get(workflow.redirect_param_name, None)
context['REDIRECT_URL'] = next
if self.request.is_ajax():
context['modal'] = True
context['layout'] = self.get_layout()
if ADD_TO_FIELD_HEADER in self.request.META:
context['add_to_field'] = self.request.META[ADD_TO_FIELD_HEADER]
return context
def get_layout(self):
"""returns classes for the workflow element in template based on
the workflow caracteristics
"""
if self.request.is_ajax():
layout = ['modal', 'hide', ]
if self.workflow_class.fullscreen:
layout += ['fullscreen', ]
else:
layout = ['static_page', ]
if self.workflow_class.wizard:
layout += ['wizard', ]
return layout
def get_template_names(self):
"""Returns the template name to use for this request."""
if self.request.is_ajax():

View File

@ -935,6 +935,12 @@ form label {
position: absolute;
}
.modal.fullscreen {
width: 90%;
margin: auto;
left: 5%;
}
.modal.loading {
width: 150px;
height: 150px;