25
26
ADD_TO_FIELD_HEADER = "HTTP_X_HORIZON_ADD_TO_FIELD"
29
class ModalBackdropMixin(object):
30
"""This mixin class is to be used for together with ModalFormView and
31
WorkflowView classes to augment them with modal_backdrop context data.
33
.. attribute: modal_backdrop (optional)
35
The appearance and behavior of backdrop under the modal element.
37
* 'true' - show backdrop element outside the modal, close the modal
38
after clicking on backdrop (the default one);
39
* 'false' - do not show backdrop element, do not close the modal after
40
clicking outside of it;
41
* 'static' - show backdrop element outside the modal, do not close
42
the modal after clicking on backdrop.
44
modal_backdrop = 'static'
47
super(ModalBackdropMixin, self).__init__()
48
config = getattr(settings, 'HORIZON_CONFIG', {})
49
if 'modal_backdrop' in config:
50
self.modal_backdrop = config['modal_backdrop']
52
def get_context_data(self, **kwargs):
53
context = super(ModalBackdropMixin, self).get_context_data(**kwargs)
54
context['modal_backdrop'] = self.modal_backdrop
28
58
class ModalFormMixin(object):
29
59
def get_template_names(self):
30
60
if self.request.is_ajax():
50
class ModalFormView(ModalFormMixin, generic.FormView):
80
class ModalFormView(ModalBackdropMixin, ModalFormMixin, generic.FormView):
51
81
"""The main view class from which all views which handle forms in Horizon
52
82
should inherit. It takes care of all details with processing
53
83
:class:`~horizon.forms.base.SelfHandlingForm` classes, and modal concerns
61
91
/en/dev/ref/class-based-views/generic-editing/#formview>`_ class for
94
.. attribute: modal_id (recommended)
96
The HTML element id of this modal.
98
.. attribute: modal_header (recommended)
100
The title of this modal.
102
.. attribute: form_id (recommended)
104
The HTML element id of the form in this modal.
106
.. attribute: submit_url (required)
108
The url for a submit action.
64
110
.. attribute: submit_label (optional)
66
112
The label for the submit button. This label defaults to ``Submit``.
78
124
if ommitted. Note that the cancel_url redirect is nullified when
79
125
shown in a modal dialog.
81
132
submit_label = _("Submit")
82
133
cancel_label = _("Cancel")
85
136
def get_context_data(self, **kwargs):
86
137
context = super(ModalFormView, self).get_context_data(**kwargs)
138
context['modal_id'] = self.modal_id
139
context['modal_header'] = self.modal_header
140
context['form_id'] = self.form_id
141
context['submit_url'] = self.submit_url
87
142
context['submit_label'] = self.submit_label
88
143
context['cancel_label'] = self.cancel_label
89
144
context['cancel_url'] = self.get_cancel_url()