Mercurial > p > roundup > code
comparison website/issues/html/user_utils.js @ 4024:c2d0d3e9099d website
svn repository setup
| author | Stefan Seefeld <stefan@users.sourceforge.net> |
|---|---|
| date | Fri, 06 Feb 2009 13:16:31 +0000 |
| parents | |
| children | 248b7a754412 |
comparison
equal
deleted
inserted
replaced
| 4023:86c38b5aed66 | 4024:c2d0d3e9099d |
|---|---|
| 1 // User Editing Utilities | |
| 2 | |
| 3 /** | |
| 4 * for new users: | |
| 5 * Depending on the input field which calls it, takes the value | |
| 6 * and dispatches it to certain other input fields: | |
| 7 * | |
| 8 * address | |
| 9 * +-> username | |
| 10 * | `-> realname | |
| 11 * `-> organisation | |
| 12 */ | |
| 13 function split_name(that) { | |
| 14 var raw = that.value | |
| 15 var val = trim(raw) | |
| 16 if (val == '') { | |
| 17 return | |
| 18 } | |
| 19 var username='' | |
| 20 var realname='' | |
| 21 var address='' | |
| 22 switch (that.name) { | |
| 23 case 'address': | |
| 24 address=val | |
| 25 break | |
| 26 case 'username': | |
| 27 username=val | |
| 28 break | |
| 29 case 'realname': | |
| 30 realname=val | |
| 31 break | |
| 32 default: | |
| 33 alert('Ooops - unknown name field '+that.name+'!') | |
| 34 return | |
| 35 } | |
| 36 var the_form = that.form; | |
| 37 | |
| 38 function field_empty(name) { | |
| 39 return the_form[name].value == '' | |
| 40 } | |
| 41 | |
| 42 // no break statements - on purpose! | |
| 43 switch (that.name) { | |
| 44 case 'address': | |
| 45 var split1 = address.split('@') | |
| 46 if (field_empty('username')) { | |
| 47 username = split1[0] | |
| 48 the_form.username.value = username | |
| 49 } | |
| 50 if (field_empty('organisation')) { | |
| 51 the_form.organisation.value = default_organisation(split1[1]) | |
| 52 } | |
| 53 case 'username': | |
| 54 if (field_empty('realname')) { | |
| 55 realname = Cap(username.split('.').join(' ')) | |
| 56 the_form.realname.value = realname | |
| 57 } | |
| 58 case 'realname': | |
| 59 if (field_empty('username')) { | |
| 60 username = Cap(realname.replace(' ', '.')) | |
| 61 the_form.username.value = username | |
| 62 } | |
| 63 if (the_form.firstname && the_form.lastname) { | |
| 64 var split2 = realname.split(' ') | |
| 65 var firstname='', lastname='' | |
| 66 firstname = split2[0] | |
| 67 lastname = split2.slice(1).join(' ') | |
| 68 if (field_empty('firstname')) { | |
| 69 the_form.firstname.value = firstname | |
| 70 } | |
| 71 if (field_empty('lastname')) { | |
| 72 the_form.lastname.value = lastname | |
| 73 } | |
| 74 } | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 function SubCap(str) { | |
| 79 switch (str) { | |
| 80 case 'de': case 'do': case 'da': | |
| 81 case 'du': case 'von': | |
| 82 return str; | |
| 83 } | |
| 84 if (str.toLowerCase().slice(0,2) == 'mc') { | |
| 85 return 'Mc'+str.slice(2,3).toUpperCase()+str.slice(3).toLowerCase() | |
| 86 } | |
| 87 return str.slice(0,1).toUpperCase()+str.slice(1).toLowerCase() | |
| 88 } | |
| 89 | |
| 90 function Cap(str) { | |
| 91 var liz = str.split(' ') | |
| 92 for (var i=0; i<liz.length; i++) { | |
| 93 liz[i] = SubCap(liz[i]) | |
| 94 } | |
| 95 return liz.join(' ') | |
| 96 } | |
| 97 | |
| 98 /** | |
| 99 * Takes a domain name (behind the @ part of an email address) | |
| 100 * Customise this to handle the mail domains you're interested in | |
| 101 */ | |
| 102 function default_organisation(orga) { | |
| 103 switch (orga.toLowerCase()) { | |
| 104 case 'gmx': | |
| 105 case 'yahoo': | |
| 106 return '' | |
| 107 default: | |
| 108 return orga | |
| 109 } | |
| 110 } | |
| 111 |
