Add javascript code to split name/email pairs in maintainer fields

In the submit layer form, if a user pastes/types in a name/email pair
(e.g. My Name <my.email@example.com>) then this will automatically be
split into the name and email input fields, saving the user from doing
this by hand (since this is a common notation within repositories and
documentation.)

Additionally, if there is any text after the email address then move it
into the responsibility field unless the responsibility has been entered
by the user.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2013-02-26 15:00:19 +00:00
parent 4756fed86f
commit 431f2fba17
2 changed files with 29 additions and 1 deletions

View File

@ -85,7 +85,7 @@ class LayerMaintainer(models.Model):
('I', 'Inactive'),
)
layer = models.ForeignKey(LayerItem)
name = models.CharField(max_length=50)
name = models.CharField(max_length=255)
email = models.CharField(max_length=255)
responsibility = models.CharField(max_length=200, blank=True, help_text='Specific area(s) this maintainer is responsible for, if not the entire layer')
status = models.CharField(max_length=1, choices=MAINTAINER_STATUS_CHOICES, default='A')

View File

@ -111,6 +111,34 @@
}
};
split_email = function() {
// Split email name/email address pairs
name_input = $(this)
split_regex = /^"?([^"@$<>]+)"? *<([^<> ]+)>[ -]*(.*)?$/
matches = split_regex.exec(name_input.val())
if( matches ){
name_input.val($.trim(matches[1]))
email_id = name_input.attr('id').replace('-name', '-email')
$('#' + email_id).val($.trim(matches[2]))
resp_id = email_id.replace('-email', '-responsibility')
currval = $('#' + resp_id).val()
// Set the responsibility with the remainder of the value unless the user has entered a value for
// responsibility already
if( currval == window['last_' + resp_id] || currval == "" ) {
newval = $.trim(matches[3])
$('#' + resp_id).val(newval)
window['last_' + resp_id] = newval
}
}
}
for(i=0;i<{{ maintainerformset.total_form_count }};i++) {
name_input = $('#id_layermaintainer_set-' + i + '-name')
name_input.change(split_email)
resp_id = 'id_layermaintainer_set-' + i + '-responsibility'
window['last_' + resp_id] = ""
}
$(document).ready(function() {
$('#id_vcs_url').change(auto_web_fields)
});