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
This commit is contained in:
parent
ebe29bc1af
commit
fdca154e75
|
@ -1,6 +1,7 @@
|
||||||
from django import newforms as forms
|
from django import newforms as forms
|
||||||
from models import NonWgMailingList, ImportedMailingList
|
from models import NonWgMailingList, ImportedMailingList
|
||||||
from ietf.idtracker.models import PersonOrOrgInfo, IETFWG, Acronym
|
from ietf.idtracker.models import PersonOrOrgInfo, IETFWG, Acronym
|
||||||
|
import re
|
||||||
|
|
||||||
class NonWgStep1(forms.Form):
|
class NonWgStep1(forms.Form):
|
||||||
add_edit = forms.ChoiceField(choices=(
|
add_edit = forms.ChoiceField(choices=(
|
||||||
|
@ -42,28 +43,27 @@ class ListReqStep1(forms.Form):
|
||||||
('newnon', 'Create new non-WG email list at selected domain above'),
|
('newnon', 'Create new non-WG email list at selected domain above'),
|
||||||
('movenon', 'Move existing non-WG email list to 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'),
|
('closenon', 'Close existing non-WG email list at selected domain above'),
|
||||||
), widget=forms.RadioSelect)
|
), widget=forms.RadioSelect())
|
||||||
#group = forms.ChoiceField(required=False)
|
#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")
|
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")
|
list_to_close = forms.ModelChoiceField(queryset=ImportedMailingList.objects.all(), required=False, empty_label="-- Select List To Close")
|
||||||
def mail_type_fields(self):
|
def mail_type_fields(self):
|
||||||
field = self['mail_type']
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
dname = 'ietf.org'
|
initial = kwargs.get('initial', None)
|
||||||
if args and args[0]:
|
# could pass initial = None, so can't use a trick on the
|
||||||
dn = 'domain_name'
|
# above get.
|
||||||
if kwargs.has_key('prefix'):
|
if initial:
|
||||||
dn = kwargs['prefix'] + '-' + dn
|
dname = initial.get('domain_name', 'ietf.org')
|
||||||
dname = args[0][dn]
|
else:
|
||||||
dname = kwargs.get('dname', dname)
|
dname = 'ietf.org'
|
||||||
super(ListReqStep1, self).__init__(*args, **kwargs)
|
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)
|
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
|
self.fields['domain_name'].initial = dname
|
||||||
def clean_group(self):
|
def clean_group(self):
|
||||||
group = self.clean_data['group']
|
group = self.clean_data['group']
|
||||||
|
@ -181,7 +181,7 @@ class AdminRequestor(forms.MultiWidget):
|
||||||
# check the checkbox, but for now let's try this.
|
# check the checkbox, but for now let's try this.
|
||||||
return ['', '', value]
|
return ['', '', value]
|
||||||
def __init__(self, attrs=None):
|
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)
|
super(AdminRequestor, self).__init__(widgets, attrs)
|
||||||
def format_output(self, rendered_widgets):
|
def format_output(self, rendered_widgets):
|
||||||
return u'<br/>\n'.join(["<label>%s Same as requestor</label>" % rendered_widgets[0]] + rendered_widgets[1:])
|
return u'<br/>\n'.join(["<label>%s Same as requestor</label>" % rendered_widgets[0]] + rendered_widgets[1:])
|
||||||
|
|
|
@ -192,19 +192,14 @@ class ListReqWizard(wizard.Wizard):
|
||||||
requestor_is_approver = False
|
requestor_is_approver = False
|
||||||
mlist_known = True
|
mlist_known = True
|
||||||
def get_template(self):
|
def get_template(self):
|
||||||
|
'''Start with form class, then step number, then the base form.'''
|
||||||
templates = []
|
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__
|
c = self.form_list[self.step].__name__
|
||||||
templates.append("mailinglists/list_wizard_%s.html" % (c))
|
templates.append("mailinglists/list_wizard_%s.html" % (c))
|
||||||
templates.append("mailinglists/list_wizard_step%d.html" % (self.step))
|
templates.append("mailinglists/list_wizard_step%d.html" % (self.step))
|
||||||
templates.append("mailinglists/list_wizard.html")
|
templates.append("mailinglists/list_wizard.html")
|
||||||
print templates
|
|
||||||
return templates
|
return templates
|
||||||
def render_template(self, *args, **kwargs):
|
def render_template(self, *args, **kwargs):
|
||||||
#self.extra_context['clean_forms'] = self.clean_forms
|
|
||||||
self.extra_context['mlist_known'] = self.mlist_known
|
self.extra_context['mlist_known'] = self.mlist_known
|
||||||
if self.step > self.main_step:
|
if self.step > self.main_step:
|
||||||
self.extra_context['main_form'] = self.clean_forms[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:
|
if self.step == self.main_step + 1:
|
||||||
self.extra_context['list'] = self.getlist()
|
self.extra_context['list'] = self.getlist()
|
||||||
return super(ListReqWizard, self).render_template(*args, **kwargs)
|
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):
|
def process_step(self, request, form, step):
|
||||||
form.full_clean()
|
form.full_clean()
|
||||||
if step == 0:
|
if step == 0:
|
||||||
|
|
84
ietf/templates/mailinglists/list_wizard_step0.html
Normal file
84
ietf/templates/mailinglists/list_wizard_step0.html
Normal file
|
@ -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 %}
|
Loading…
Reference in a new issue