backoffice: make submission sidebar items configurable (#84494)
gitea/wcs/pipeline/head This commit looks good
Details
gitea/wcs/pipeline/head This commit looks good
Details
(also #58888)
This commit is contained in:
parent
291fea5b8b
commit
ae29ab13bb
|
@ -273,6 +273,46 @@ def test_forms_edit_management(pub, formdef):
|
|||
assert FormDef.get(1).management_sidebar_items == set()
|
||||
|
||||
|
||||
def test_forms_edit_backoffice_submission(pub, formdef):
|
||||
create_superuser(pub)
|
||||
create_role(pub)
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/forms/1/')
|
||||
|
||||
assert 'Backoffice submission' not in resp.text
|
||||
formdef.backoffice_submission_roles = ['x']
|
||||
formdef.store()
|
||||
|
||||
resp = app.get('/backoffice/forms/1/')
|
||||
assert_option_display(resp, 'Backoffice submission', 'Default')
|
||||
resp = resp.click('Backoffice submission', href='options/backoffice-submission')
|
||||
assert resp.forms[0]['submission_sidebar_items$elementgeneral'].checked is True
|
||||
assert resp.forms[0]['submission_sidebar_items$elementsubmission-context'].checked is True
|
||||
assert resp.forms[0]['submission_sidebar_items$elementuser'].checked is True
|
||||
assert resp.forms[0]['submission_sidebar_items$elementcustom-template'].checked is True
|
||||
resp.forms[0]['submission_sidebar_items$elementuser'].checked = False
|
||||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://example.net/backoffice/forms/1/'
|
||||
resp = resp.follow()
|
||||
assert_option_display(resp, 'Backoffice submission', 'Custom')
|
||||
assert 'general' in FormDef.get(1).submission_sidebar_items
|
||||
assert 'user' not in FormDef.get(1).submission_sidebar_items
|
||||
|
||||
resp = resp.click('Backoffice submission', href='options/backoffice-submission')
|
||||
resp.forms[0]['submission_sidebar_items$elementuser'].checked = True
|
||||
resp = resp.forms[0].submit().follow()
|
||||
assert FormDef.get(1).submission_sidebar_items == {'__default__'}
|
||||
|
||||
# unselect all
|
||||
resp = resp.click('Backoffice submission', href='options/backoffice-submission')
|
||||
for field in resp.forms[0].fields:
|
||||
if field.startswith('submission_sidebar_items$'):
|
||||
resp.forms[0][field].checked = False
|
||||
resp = resp.forms[0].submit().follow()
|
||||
assert FormDef.get(1).submission_sidebar_items == set()
|
||||
|
||||
|
||||
def test_forms_edit_tracking_code(pub, formdef):
|
||||
create_superuser(pub)
|
||||
create_role(pub)
|
||||
|
|
|
@ -2293,3 +2293,27 @@ def test_backoffice_submission_then_front(pub):
|
|||
f'with the number {formdata.get_display_id()}. It has been submitted for you by '
|
||||
f'admin after a phone call.'
|
||||
)
|
||||
|
||||
|
||||
def test_backoffice_submission_sidebar_elements(pub):
|
||||
user = create_user(pub)
|
||||
|
||||
FormDef.wipe()
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form title'
|
||||
formdef.fields = [
|
||||
fields.PageField(id='0', label='1st page'),
|
||||
fields.StringField(id='1', label='Field on 1st page'),
|
||||
]
|
||||
formdef.backoffice_submission_roles = user.roles[:]
|
||||
formdef.workflow_roles = {'_receiver': 1}
|
||||
formdef.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get(formdef.get_submission_url(backoffice=True))
|
||||
assert resp.pyquery('.submit-user-selection')
|
||||
|
||||
formdef.submission_sidebar_items = ['general', 'custom-template']
|
||||
formdef.store()
|
||||
resp = app.get(formdef.get_submission_url(backoffice=True))
|
||||
assert not resp.pyquery('.submit-user-selection')
|
||||
|
|
|
@ -243,6 +243,7 @@ class OptionsDirectory(Directory):
|
|||
category_class = Category
|
||||
category_empty_choice = _('Select a category for this form')
|
||||
section = 'forms'
|
||||
backoffice_submission_options_label = _('Backoffice submission')
|
||||
|
||||
_q_exports = [
|
||||
'confirmation',
|
||||
|
@ -256,6 +257,7 @@ class OptionsDirectory(Directory):
|
|||
'appearance',
|
||||
'templates',
|
||||
'user_support',
|
||||
('backoffice-submission', 'backoffice_submission'),
|
||||
]
|
||||
|
||||
def __init__(self, formdef, formdefui):
|
||||
|
@ -368,6 +370,18 @@ class OptionsDirectory(Directory):
|
|||
)
|
||||
return self.handle(form, _('Management'))
|
||||
|
||||
def backoffice_submission(self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.add(
|
||||
CheckboxesWidget,
|
||||
'submission_sidebar_items',
|
||||
title=_('Sidebar elements'),
|
||||
options=[(x[0], x[1], x[0]) for x in self.formdef.get_submission_sidebar_available_items()],
|
||||
value=self.formdef.get_submission_sidebar_items(),
|
||||
inline=False,
|
||||
)
|
||||
return self.handle(form, self.backoffice_submission_options_label)
|
||||
|
||||
def online_status(self):
|
||||
form = Form(enctype='multipart/form-data')
|
||||
form.add(CheckboxWidget, 'disabled', title=_('Disable access to form'), value=self.formdef.disabled)
|
||||
|
@ -519,6 +533,7 @@ class OptionsDirectory(Directory):
|
|||
'drafts_max_per_user',
|
||||
'user_support',
|
||||
'management_sidebar_items',
|
||||
'submission_sidebar_items',
|
||||
'history_pane_default_mode',
|
||||
]
|
||||
for attr in attrs:
|
||||
|
@ -533,6 +548,10 @@ class OptionsDirectory(Directory):
|
|||
new_value = set(new_value or [])
|
||||
if new_value == self.formdef.get_default_management_sidebar_items():
|
||||
new_value = {'__default__'}
|
||||
if attr == 'submission_sidebar_items':
|
||||
new_value = set(new_value or [])
|
||||
if new_value == self.formdef.get_default_submission_sidebar_items():
|
||||
new_value = {'__default__'}
|
||||
if attr == 'digest_template':
|
||||
if self.formdef.default_digest_template != new_value:
|
||||
self.changed = True
|
||||
|
@ -837,6 +856,16 @@ class FormDefPage(Directory, TempfileDirectoryMixin, DocumentableMixin):
|
|||
and self.formdef.appearance_keywords
|
||||
or pgettext_lazy('appearance', 'Standard'),
|
||||
),
|
||||
'backoffice_submission_options': self.add_option_line(
|
||||
'options/backoffice-submission',
|
||||
self.options_directory_class.backoffice_submission_options_label,
|
||||
_('Custom')
|
||||
if (
|
||||
self.formdef.submission_sidebar_items
|
||||
not in ({'__default__'}, self.formdef.get_default_submission_sidebar_items())
|
||||
)
|
||||
else _('Default'),
|
||||
),
|
||||
}
|
||||
unknown_wf = self.formdef.workflow.id == Workflow.get_unknown_workflow().id
|
||||
if get_publisher().get_backoffice_root().is_accessible('workflows') and not unknown_wf:
|
||||
|
|
|
@ -43,6 +43,7 @@ class CardDefUI(FormDefUI):
|
|||
class CardDefOptionsDirectory(OptionsDirectory):
|
||||
category_class = CardDefCategory
|
||||
category_empty_choice = _('Select a category for this card model')
|
||||
backoffice_submission_options_label = _('Submission')
|
||||
section = 'cards'
|
||||
|
||||
def get_templates_form(self):
|
||||
|
|
|
@ -235,6 +235,8 @@ class FormFillPage(PublicFormFillPage):
|
|||
def get_sidebar(self, data):
|
||||
r = TemplateIO(html=True)
|
||||
|
||||
sidebar_items = self.formdef.get_submission_sidebar_items()
|
||||
|
||||
formdata = None
|
||||
if self.edit_mode:
|
||||
formdata = self.edited_data
|
||||
|
@ -249,12 +251,13 @@ class FormFillPage(PublicFormFillPage):
|
|||
if formdata and self.selected_user_id:
|
||||
formdata.user_id = self.selected_user_id
|
||||
|
||||
if self.formdef.enable_tracking_codes and not self.edit_mode:
|
||||
r += htmltext('<h3>%s</h3>') % _('Tracking Code')
|
||||
if formdata and formdata.tracking_code:
|
||||
r += htmltext('<p>%s</p>') % formdata.tracking_code
|
||||
else:
|
||||
r += htmltext('<p>-</p>')
|
||||
if 'general' in sidebar_items:
|
||||
if self.formdef.enable_tracking_codes and not self.edit_mode:
|
||||
r += htmltext('<h3>%s</h3>') % _('Tracking Code')
|
||||
if formdata and formdata.tracking_code:
|
||||
r += htmltext('<p>%s</p>') % formdata.tracking_code
|
||||
else:
|
||||
r += htmltext('<p>-</p>')
|
||||
|
||||
if formdata and self.on_validation_page:
|
||||
if self.has_channel_support and self.selected_submission_channel:
|
||||
|
@ -269,13 +272,16 @@ class FormFillPage(PublicFormFillPage):
|
|||
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_context_bar(parent=self)
|
||||
else:
|
||||
if (
|
||||
formdata
|
||||
'submission-context' in sidebar_items
|
||||
and formdata
|
||||
and formdata.submission_context
|
||||
and set(formdata.submission_context.keys()).difference({'return_url', 'cancel_url'})
|
||||
):
|
||||
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_submission_context_bar()
|
||||
|
||||
if formdata and formdata.submission_channel:
|
||||
if 'submission-context' not in sidebar_items:
|
||||
pass
|
||||
elif formdata and formdata.submission_channel:
|
||||
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_submission_channel_bar()
|
||||
elif self.has_channel_support:
|
||||
r += htmltext('<div class="submit-channel-selection" style="display: none;">')
|
||||
|
@ -292,16 +298,16 @@ class FormFillPage(PublicFormFillPage):
|
|||
r += htmltext('</select>')
|
||||
r += htmltext('</div>')
|
||||
|
||||
if formdata and formdata.user_id:
|
||||
if 'user' in sidebar_items and formdata and formdata.user_id:
|
||||
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_submission_user_id_bar(
|
||||
parent=self
|
||||
)
|
||||
elif self.has_user_support:
|
||||
elif 'user' in sidebar_items and self.has_user_support:
|
||||
r += FormBackOfficeStatusPage(self.formdef, formdata).get_extra_submission_user_selection_bar(
|
||||
parent=self
|
||||
)
|
||||
|
||||
if self.formdef.submission_lateral_template:
|
||||
if 'custom-template' in sidebar_items and self.formdef.submission_lateral_template:
|
||||
r += htmltext(
|
||||
'<div data-async-url="%slateral-block?ctx=%s"></div>'
|
||||
% (
|
||||
|
|
|
@ -177,6 +177,7 @@ class FormDef(StorableObject):
|
|||
has_captcha = False
|
||||
skip_from_360_view = False
|
||||
management_sidebar_items = {'__default__'}
|
||||
submission_sidebar_items = {'__default__'}
|
||||
include_download_all_button = False
|
||||
appearance_keywords = None
|
||||
digest_templates = None
|
||||
|
@ -334,6 +335,34 @@ class FormDef(StorableObject):
|
|||
return self.get_default_management_sidebar_items()
|
||||
return self.management_sidebar_items or []
|
||||
|
||||
def get_default_submission_sidebar_items(self):
|
||||
return {
|
||||
'general',
|
||||
'submission-context',
|
||||
'user',
|
||||
'custom-template',
|
||||
}
|
||||
|
||||
def get_submission_sidebar_available_items(self):
|
||||
return [
|
||||
('general', _('General Information')),
|
||||
('submission-context', _('Submission context')),
|
||||
('user', _('Associated User')),
|
||||
('custom-template', _('Custom template')),
|
||||
]
|
||||
|
||||
def submission_sidebar_items_labels(self):
|
||||
# return ordered labels
|
||||
submission_sidebar_items = self.get_submission_sidebar_items()
|
||||
for key, label in self.get_submission_sidebar_available_items():
|
||||
if key in submission_sidebar_items:
|
||||
yield label
|
||||
|
||||
def get_submission_sidebar_items(self):
|
||||
if self.submission_sidebar_items == {'__default__'}:
|
||||
return self.get_default_submission_sidebar_items()
|
||||
return self.submission_sidebar_items or []
|
||||
|
||||
@property
|
||||
def data_class_name(self):
|
||||
return '_wcs_%s' % self.url_name.title()
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
<ul class="biglist optionslist">
|
||||
{{ options.templates|safe }}
|
||||
{{ options.user_support|safe }}
|
||||
{% if formdef.backoffice_submission_roles %}{{ options.backoffice_submission_options|safe }}{% endif %}
|
||||
{{ options.management|safe }}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
{{ options.confirmation|safe }}
|
||||
{{ options.only_allow_one|safe }}
|
||||
{% if formdef.roles %}{{ options.always_advertise|safe }}{% endif %}
|
||||
{% if formdef.backoffice_submission_roles %}{{ options.backoffice_submission_options|safe }}{% endif %}
|
||||
{{ options.management|safe }}
|
||||
{{ options.tracking_code|safe }}
|
||||
{% if has_captcha_option %}{{ options.captcha|safe }}{% endif %}
|
||||
|
|
Loading…
Reference in New Issue