Skip to content

Commit 199e469

Browse files
committed
Convert the Cc: field into an editable textarea. Fixes ietf-tools#647
- Legacy-Id: 3029
1 parent 400fe65 commit 199e469

2 files changed

Lines changed: 41 additions & 15 deletions

File tree

ietf/liaisons/forms.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LiaisonForm(forms.ModelForm):
2323
replyto = forms.CharField(label=u'Reply to')
2424
organization = forms.ChoiceField()
2525
to_poc = forms.CharField(widget=ReadOnlyWidget, label="POC", required=False)
26-
cc1 = forms.CharField(widget=ReadOnlyWidget, label="CC", required=False)
26+
cc1 = forms.CharField(widget=forms.Textarea, label="CC", required=False, help_text='Please insert one email address per line')
2727
purpose_text = forms.CharField(widget=forms.Textarea, label='Other purpose')
2828
deadline_date = forms.DateField(label='Deadline')
2929
title = forms.CharField(label=u'Title')
@@ -171,10 +171,30 @@ def get_to_entity(self):
171171
def get_poc(self, organization):
172172
return ', '.join([i.email()[1] for i in organization.get_poc()])
173173

174+
def clean_cc1(self):
175+
value = self.cleaned_data.get('cc1', '')
176+
result = []
177+
errors = []
178+
for address in value.split('\n'):
179+
address = address.strip();
180+
if not address:
181+
continue
182+
try:
183+
self.check_email(address)
184+
except forms.ValidationError:
185+
errors.append(address)
186+
result.append(address)
187+
if errors:
188+
raise forms.ValidationError('Invalid email addresses: %s' % ', '.join(errors))
189+
return ','.join(result)
190+
174191
def get_cc(self, from_entity, to_entity):
175-
persons = to_entity.get_cc(self.person)
176-
persons += from_entity.get_from_cc(self.person)
177-
return ', '.join(['%s <%s>' % i.email() for i in persons])
192+
#Old automatic Cc code, now we retrive it from cleaned_data
193+
#persons = to_entity.get_cc(self.person)
194+
#persons += from_entity.get_from_cc(self.person)
195+
#return ', '.join(['%s <%s>' % i.email() for i in persons])
196+
cc = self.cleaned_data.get('cc1', '')
197+
return cc
178198

179199
def save(self, *args, **kwargs):
180200
liaison = super(LiaisonForm, self).save(*args, **kwargs)

static/js/liaisons.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,15 @@
150150
config.info_update_url = confcontainer.find('.info_update_url').text();
151151
};
152152

153-
var render_mails_into = function(container, person_list) {
153+
var render_mails_into = function(container, person_list, as_html) {
154154
var html='';
155155

156156
$.each(person_list, function(index, person) {
157-
html += person[0] + ' &lt;<a href="mailto:'+person[1]+'">'+person[1]+'</a>&gt;<br />';
157+
if (as_html) {
158+
html += person[0] + ' &lt;<a href="mailto:'+person[1]+'">'+person[1]+'</a>&gt;<br />';
159+
} else {
160+
html += person[0] + ' &lt;'+person[1]+'&gt;\n';
161+
}
158162
});
159163
container.html(html);
160164
};
@@ -204,7 +208,7 @@
204208
updateReplyTo();
205209
};
206210

207-
var updateInfo = function() {
211+
var updateInfo = function(first_time) {
208212
var entity = organization;
209213
var to_entity = from;
210214
var url = config.info_update_url;
@@ -218,8 +222,10 @@
218222
from_entity_id: to_entity.val()},
219223
success: function(response){
220224
if (!response.error) {
221-
render_mails_into(cc, response.cc);
222-
render_mails_into(poc, response.poc);
225+
if (!first_time || !cc.text()) {
226+
render_mails_into(cc, response.cc, false);
227+
}
228+
render_mails_into(poc, response.poc, true);
223229
toggleApproval(response.needs_approval);
224230
checkPostOnly(response.post_only);
225231
userSelect(response.full_list);
@@ -317,10 +323,10 @@
317323
return false;
318324
};
319325

320-
var checkFrom = function() {
326+
var checkFrom = function(first_time) {
321327
var reduce_options = form.find('.reducedToOptions');
322328
if (!reduce_options.length) {
323-
updateInfo();
329+
updateInfo(first_time);
324330
return;
325331
}
326332
var to_select = organization;
@@ -341,13 +347,13 @@
341347
to_select.find('optgroup').show();
342348
to_select.find('option').show();
343349
}
344-
updateInfo();
350+
updateInfo(first_time);
345351
};
346352

347353
var initTriggers = function() {
348-
organization.change(updateInfo);
354+
organization.change(function() {updateInfo(false);});
349355
organization.change(checkOtherSDO);
350-
from.change(checkFrom);
356+
from.change(function() {checkFrom(false);});
351357
reply.keyup(updateFrom);
352358
purpose.change(updatePurpose);
353359
cancel.click(cancelForm);
@@ -357,7 +363,7 @@
357363

358364
var updateOnInit = function() {
359365
updateFrom();
360-
checkFrom();
366+
checkFrom(true);
361367
updatePurpose();
362368
checkOtherSDO();
363369
};

0 commit comments

Comments
 (0)