Premiere version : mise en route du suivi.
[auf_roundup.git] / share / roundup / templates / classic / html / user_utils.js
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 case 'firstname':
33 case 'lastname':
34 return
35 default:
36 alert('Ooops - unknown name field '+that.name+'!')
37 return
38 }
39 var the_form = that.form;
40
41 function field_empty(name) {
42 return the_form[name].value == ''
43 }
44
45 // no break statements - on purpose!
46 switch (that.name) {
47 case 'address':
48 var split1 = address.split('@')
49 if (field_empty('username')) {
50 username = split1[0]
51 the_form.username.value = username
52 }
53 if (field_empty('organisation')) {
54 the_form.organisation.value = default_organisation(split1[1])
55 }
56 case 'username':
57 if (field_empty('realname')) {
58 realname = Cap(username.split('.').join(' '))
59 the_form.realname.value = realname
60 }
61 case 'realname':
62 if (field_empty('username')) {
63 username = Cap(realname.replace(' ', '.'))
64 the_form.username.value = username
65 }
66 if (the_form.firstname && the_form.lastname) {
67 var split2 = realname.split(' ')
68 var firstname='', lastname=''
69 firstname = split2[0]
70 lastname = split2.slice(1).join(' ')
71 if (field_empty('firstname')) {
72 the_form.firstname.value = firstname
73 }
74 if (field_empty('lastname')) {
75 the_form.lastname.value = lastname
76 }
77 }
78 }
79 }
80
81 function SubCap(str) {
82 switch (str) {
83 case 'de': case 'do': case 'da':
84 case 'du': case 'von':
85 return str;
86 }
87 if (str.toLowerCase().slice(0,2) == 'mc') {
88 return 'Mc'+str.slice(2,3).toUpperCase()+str.slice(3).toLowerCase()
89 }
90 return str.slice(0,1).toUpperCase()+str.slice(1).toLowerCase()
91 }
92
93 function Cap(str) {
94 var liz = str.split(' ')
95 for (var i=0; i<liz.length; i++) {
96 liz[i] = SubCap(liz[i])
97 }
98 return liz.join(' ')
99 }
100
101 /**
102 * Takes a domain name (behind the @ part of an email address)
103 * Customise this to handle the mail domains you're interested in
104 */
105 function default_organisation(orga) {
106 switch (orga.toLowerCase()) {
107 case 'gmx':
108 case 'yahoo':
109 return ''
110 default:
111 return orga
112 }
113 }
114