From fdca154e75a957b9f50072789bf25255f5d646ed Mon Sep 17 00:00:00 2001 From: Bill Fenner <fenner@fenron.net> Date: Sun, 10 Jun 2007 02:00:51 +0000 Subject: [PATCH] Implement custom form rendering for step 0. Implement javascript to disable form elements that aren't used when wg or non-wg items are selected. Implement javascript to reload the page with the right set of non-wg mailing lists to close. - Legacy-Id: 274 --- ietf/mailinglists/forms.py | 30 +++---- ietf/mailinglists/views.py | 13 ++- .../mailinglists/list_wizard_step0.html | 84 +++++++++++++++++++ 3 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 ietf/templates/mailinglists/list_wizard_step0.html diff --git a/ietf/mailinglists/forms.py b/ietf/mailinglists/forms.py index 0919e9dd4..3a526c16a 100644 --- a/ietf/mailinglists/forms.py +++ b/ietf/mailinglists/forms.py @@ -1,6 +1,7 @@ from django import newforms as forms from models import NonWgMailingList, ImportedMailingList from ietf.idtracker.models import PersonOrOrgInfo, IETFWG, Acronym +import re class NonWgStep1(forms.Form): add_edit = forms.ChoiceField(choices=( @@ -42,28 +43,27 @@ class ListReqStep1(forms.Form): ('newnon', 'Create new non-WG email list at selected domain above'), ('movenon', 'Move existing non-WG email list to selected domain above'), ('closenon', 'Close existing non-WG email list at selected domain above'), - ), widget=forms.RadioSelect) + ), widget=forms.RadioSelect()) #group = forms.ChoiceField(required=False) group = forms.ModelChoiceField(queryset=IETFWG.objects.all().select_related().order_by('acronym.acronym'), required=False, empty_label="-- Select Working Group") - domain_name = forms.ChoiceField(choices=DOMAIN_CHOICES, required=False) + domain_name = forms.ChoiceField(choices=DOMAIN_CHOICES, required=False, widget = forms.Select(attrs={'onChange': 'set_domain(this)'})) list_to_close = forms.ModelChoiceField(queryset=ImportedMailingList.objects.all(), required=False, empty_label="-- Select List To Close") def mail_type_fields(self): field = self['mail_type'] - return field.as_widget(field.field.widget) + # RadioSelect() doesn't pass its attributes through to the <input> + # elements, so in order to get the javascript onClick we add it here. + return [re.sub(r'input ','input onClick="activate_widgets()" ',str(i)) for i in field.as_widget(field.field.widget)] def __init__(self, *args, **kwargs): - dname = 'ietf.org' - if args and args[0]: - dn = 'domain_name' - if kwargs.has_key('prefix'): - dn = kwargs['prefix'] + '-' + dn - dname = args[0][dn] - dname = kwargs.get('dname', dname) + initial = kwargs.get('initial', None) + # could pass initial = None, so can't use a trick on the + # above get. + if initial: + dname = initial.get('domain_name', 'ietf.org') + else: + dname = 'ietf.org' super(ListReqStep1, self).__init__(*args, **kwargs) - #self.fields['group'].choices = [('', '-- Select Working Group')] + IETFWG.choices() - #self.fields['list_to_close'].choices = [('', '-- Select List To Close')] + ImportedMailingList.choices(dname) - #XXX This doesn't work yet. Maybe switch back to choices. self.fields['list_to_close'].queryset = ImportedMailingList.choices(dname) - print "dname %s list_to_close values: %s" % (dname, self.fields['list_to_close'].queryset) + self.fields['list_to_close'].widget.choices = self.fields['list_to_close'].choices self.fields['domain_name'].initial = dname def clean_group(self): group = self.clean_data['group'] @@ -181,7 +181,7 @@ class AdminRequestor(forms.MultiWidget): # check the checkbox, but for now let's try this. return ['', '', value] def __init__(self, attrs=None): - widgets = (forms.CheckboxInput(), forms.TextInput(attrs={'size': 55, 'disabled': True}), forms.Textarea(attrs=attrs)) + widgets = (forms.CheckboxInput(attrs={'onClick': 'checkthis()'}), forms.TextInput(attrs={'size': 55, 'disabled': True}), forms.Textarea(attrs=attrs)) super(AdminRequestor, self).__init__(widgets, attrs) def format_output(self, rendered_widgets): return u'<br/>\n'.join(["<label>%s Same as requestor</label>" % rendered_widgets[0]] + rendered_widgets[1:]) diff --git a/ietf/mailinglists/views.py b/ietf/mailinglists/views.py index 1048b3a62..635b20d0c 100644 --- a/ietf/mailinglists/views.py +++ b/ietf/mailinglists/views.py @@ -192,19 +192,14 @@ class ListReqWizard(wizard.Wizard): requestor_is_approver = False mlist_known = True def get_template(self): + '''Start with form class, then step number, then the base form.''' templates = [] - #if self.step > 0: - # action = {'add': 'addedit', 'edit': 'addedit', 'delete': 'delete'}[self.clean_forms[0].clean_data['add_edit']] - # templates.append("mailinglists/nwg_wizard_%s_step%d.html" % (action, self.step)) - # templates.append("mailinglists/nwg_wizard_%s.html" % (action)) c = self.form_list[self.step].__name__ templates.append("mailinglists/list_wizard_%s.html" % (c)) templates.append("mailinglists/list_wizard_step%d.html" % (self.step)) templates.append("mailinglists/list_wizard.html") - print templates return templates def render_template(self, *args, **kwargs): - #self.extra_context['clean_forms'] = self.clean_forms self.extra_context['mlist_known'] = self.mlist_known if self.step > self.main_step: self.extra_context['main_form'] = self.clean_forms[self.main_step] @@ -212,7 +207,11 @@ class ListReqWizard(wizard.Wizard): if self.step == self.main_step + 1: self.extra_context['list'] = self.getlist() return super(ListReqWizard, self).render_template(*args, **kwargs) - # want to implement parse_params to get domain for list + def parse_params(self, request, *args, **kwargs): + super(ListReqWizard, self).parse_params(request, *args, **kwargs) + if self.step == 0: + # allow javascript "redirects" to set initial values + self.initial[0] = request.GET def process_step(self, request, form, step): form.full_clean() if step == 0: diff --git a/ietf/templates/mailinglists/list_wizard_step0.html b/ietf/templates/mailinglists/list_wizard_step0.html new file mode 100644 index 000000000..7a8fa8b3d --- /dev/null +++ b/ietf/templates/mailinglists/list_wizard_step0.html @@ -0,0 +1,84 @@ +{% extends "mailinglists/list_wizard_base.html" %} + +{% block head %} +<script language="javascript"> +function get_mail_type() { + buttons = document.form_post["0-mail_type"] + selected = "" + for (i = 0; i < buttons.length; i++) + if (buttons[i].checked) + selected = buttons[i].value + return selected +} + +function set_domain (widget) { + loc = "./?domain_name=" + widget.options[widget.selectedIndex].value + mail_type = get_mail_type() + if (mail_type != "") + loc = loc + "&mail_type=" + mail_type + window.location = loc +} + +function activate_widgets() { + selected = get_mail_type() + if (selected == "") { + return + } + wg = (selected.substr(-2) == "wg") + document.form_post["0-group"].disabled = !wg + document.form_post["0-domain_name"].disabled = wg + document.form_post["0-list_to_close"].disabled = wg +} +</script> +{% endblock %} + +{% block body_attributes %}onLoad="activate_widgets()"{% endblock %} + +{% block mlform %} +<tr valign="top"><td bgcolor="#dfe9ef"><h3>WG email list +   +{{ form.group }} +{% if form.group.errors %} +<ul class="errorlist"> +{% for error in form.group.errors %} +<li>{{ error|escape }}</li> +{% endfor %} +</ul> +{% endif %} +</h3> + +{% if form.mail_type.errors %} +<ul class="errorlist"> +{% for error in form.mail_type.errors %} +<li>{{ error|escape }}</li> +{% endfor %} +</ul> +{% endif %} +{{ form.mail_type_fields.0 }}<br> +{{ form.mail_type_fields.1 }}<br> +{{ form.mail_type_fields.2 }}<br> +</td></tr> +<tr> +<td bgcolor="#ccdcec"><h3>Non-WG email list</h3> +<b>Select Domain Name: </b>{{ form.domain_name }}<br> +{{ form.mail_type_fields.3 }}<br> +{{ form.mail_type_fields.4 }}<br> +{{ form.mail_type_fields.5 }}<br> +{{ form.list_to_close }} +{% if form.list_to_close.errors %} +<ul class="errorlist"> +{% for error in form.list_to_close.errors %} +<li>{{ error|escape }}</li> +{% endfor %} +</ul> +{% endif %} +<br> +</td></tr> +<tr><td colspan="2"> +<font color="red">Note: Only members of the IAB (or their designees) and active +participants in the IRTF may create or close a mailing list at iab.org and irtf. +org, respectively, or move an existing list to one of these domains."</font> +<br><br> +</td></tr> + +{% endblock %}