admin: popup with different form options

This commit is contained in:
Frédéric Péters 2012-08-14 11:29:31 +02:00
parent 05d07f0b99
commit 9fcc40aa69
2 changed files with 81 additions and 13 deletions

View File

@ -275,7 +275,7 @@ class FormDefPage(Directory):
'archive', 'invite', 'enable', 'workflow', 'category',
'recipient', ('workflow-options', 'workflow_options'),
('workflow-status-remapping', 'workflow_status_remapping'),
'roles', 'title']
'roles', 'title', 'options']
def __init__(self, component):
try:
@ -290,6 +290,7 @@ class FormDefPage(Directory):
html_top('forms', title = self.formdef.name)
get_response().filter['sidebar'] = self.get_sidebar()
get_response().add_javascript(['jquery.js', 'widget_list.js'])
DateWidget.prepare_javascript()
'<h2>%s - ' % _('Form')
self.formdef.name
@ -366,7 +367,8 @@ class FormDefPage(Directory):
'<div class="splitcontent-right">'
'<div class="bo-block">'
'<h3>%s</h3>' % _('Options')
'<h3>%s' % _('Options')
' <span class="change">(<a rel="popup" href="options">change</a>)</span></h3>'
'<ul>'
if self.formdef.confirmation:
'<li>%s</li>' % _('Include confirmation page')
@ -386,7 +388,7 @@ class FormDefPage(Directory):
'(<a href="%s">' % self.formdef.disabled_redirection
_('redirection')
'</a>) '
'<a href="enable">%s</a></li>' % _('Enable')
' (<a href="enable">%s</a>)</li>' % _('enable')
if self.formdef.publication_date:
'<li>%s</li>' % _('Publication Date: %s') % self.formdef.publication_date
if self.formdef.expiration_date:
@ -503,6 +505,61 @@ class FormDefPage(Directory):
'<p>%s</p>' % _('Choose a title for this form')
form.render()
def options [html] (self):
form = Form(enctype='multipart/form-data')
form.add(CheckboxWidget, 'confirmation', title=_('Include confirmation page'),
value=self.formdef.confirmation)
form.add(SingleSelectWidget, 'signing', title=_('Signature'),
value=self.formdef.signing,
options = [
(None, _('None')),
('optional', _('Optional')),
('compulsory', _('Compulsary'))])
form.add(CheckboxWidget, 'private_status_and_history',
title=_('Keep workflow status and history private'),
hint=_('Restrict the possibility to see status and history to the recipients'),
value=self.formdef.private_status_and_history)
form.add(CheckboxWidget, 'only_allow_one',
title=_('Only allow one form per user'),
value=self.formdef.only_allow_one)
form.add(CheckboxWidget, 'allow_drafts',
title=_('Allow user to keep drafts'),
value=self.formdef.allow_drafts)
form.add(CheckboxWidget, 'disabled',
title=_('Disable access to form'),
value=self.formdef.disabled)
form.add(StringWidget, 'disabled_redirection',
title=_('If disabled, redirect to this URL'), size=40,
hint=_('Redirection will only be performed if the form is disabled and a URL is given. '\
'Common substitution variables are available with the [variable] syntax.'),
value=self.formdef.disabled_redirection)
form.add(DateWidget, 'publication_date',
title=_('Publication Date'),
value=self.formdef.publication_date)
form.add(DateWidget, 'expiration_date',
title=_('Expiration Date'),
value=self.formdef.expiration_date)
form.add_submit('submit', _('Submit'))
form.add_submit('cancel', _('Cancel'))
if form.get_widget('cancel').parse():
return redirect('.')
if form.is_submitted() and not form.has_errors():
for f in ('confirmation', 'signing', 'only_allow_one', 'disabled',
'allow_drafts', 'private_status_and_history',
'disabled_redirection', 'publication_date', 'expiration_date'):
widget = form.get_widget(f)
if widget:
setattr(self.formdef, str(f), widget.parse())
self.formdef.store()
redirect('.')
get_response().breadcrumb.append( ('options', _('Options')) )
html_top('forms', title=self.formdef.name)
'<h2>%s</h2>' % _('Options')
form.render()
def workflow [html] (self):
form = Form(enctype='multipart/form-data')
workflows = get_workflows(condition=lambda x: x.possible_status)

View File

@ -648,13 +648,7 @@ class DateWidget(StringWidget):
self.error = _('invalid date; date must be on or before %s') % strftime(
format_string, datetime.datetime(*self.maximum_date[:6]))
def render_content(self):
self.attrs['id'] = 'id_%s' % self.name
self.attrs['class'] = 'date-pick'
if self.attrs.get('readonly') or not self.jquery:
return StringWidget.render_content(self)
def prepare_javascript(cls):
get_response().add_javascript(['jquery.js',
'bgiframe/jquery.bgiframe.min.js', 'methods/date.js'])
current_language = get_request().language
@ -686,6 +680,20 @@ $.dpText = {
get_response().add_javascript(['datePicker/jquery.datePicker.js'])
get_response().add_css_include('datePicker.css')
prepare_javascript = classmethod(prepare_javascript)
def render_content(self):
self.attrs['id'] = 'id_%s' % self.name
self.attrs['class'] = 'date-pick'
if self.attrs.get('readonly') or not self.jquery:
return StringWidget.render_content(self)
self.prepare_javascript()
date_format = misc.date_format().replace('%Y', 'yyyy').replace(
'%m', 'mm').replace('%d', 'dd')
args = []
if self.minimum_date:
start_date = date_format.replace(
@ -708,14 +716,17 @@ $.dpText = {
else:
args = ''
get_response().add_javascript_code('''
if get_request().get_header('x-popup') == 'true':
# unfortunately we cannot add a popup calendar inside a popup :/
return StringWidget.render_content(self)
else:
get_response().add_javascript_code('''
$(function() {
$('#%(id)s').datePicker(%(args)s).next().html(
'<img src="%(root_url)sjs/calendar.png" width="16" height="16" />');
});''' % {'id': self.attrs['id'], 'args': args,
'root_url': get_publisher().get_root_url() + get_publisher().qommon_static_dir})
return StringWidget.render_content(self)
return StringWidget.render_content(self)
class RegexStringWidget(StringWidget):