Refactoring - white space
[timetracker.git] / WEB-INF / templates / user_edit.tpl
1 <script>
2 // Prepare an array of rates.
3 // Format: project_rates[0] = Array(100, '25.00'), project_rates[1] = Array(120, '30.00'), etc...
4 // First element = project_id, second element = rate for project. Quotes needed for string representation of rates.
5 project_rates = new Array();
6 var idx = 0;
7 {foreach $rates as $rate}
8 project_rates[idx] = new Array({$rate.id}, '{$rate.rate}');
9 idx++;
10 {/foreach}
11
12 // getRate - returns a rate for the project. If rate was set for user previously we'll get this old rate
13 // if project time entries for user exists. Otherwise return user default rate.
14 function getRate(project_id) {
15   var length = project_rates.length;
16   for(var i = 0; i < length; i++) {
17     if(project_rates[i][0] == project_id) {
18       return project_rates[i][1];
19     }
20   }
21   var default_rate = document.userForm.rate.value;
22   return default_rate;
23 }
24
25 // The setRate function sets / unsets user rate for a project when a corresponding checkbox is ticked.
26 function setRate(element) {
27   var default_rate = document.userForm.rate.value;
28   if (default_rate == '') {
29     // No default rate, nothing to do!
30     return;
31   }
32   // Iterate through elements of the form to find and set the project rate. 
33   for (var i = 0; i < userForm.elements.length; i++) {
34     if ((userForm.elements[i].type == 'text') && (userForm.elements[i].name == ('rate_'+element.value))) {
35       if (element.checked) {
36         userForm.elements[i].value = getRate(element.value);
37       } else {
38         userForm.elements[i].value = '';
39       }
40       break; // Element is found and set, nothing more to do, break out of the loop.
41     }
42   }
43 }
44
45 // handleClientControl - controls visibility of the client dropdown depending on the selected user role.
46 // We need to show it only when the "Client" user role is selected.
47 function handleClientControl() {
48   var clientControl = document.getElementById("client");
49   if ("16" == document.getElementById("role").value)
50     clientControl.style.visibility = "visible";
51   else
52     clientControl.style.visibility = "hidden";
53 }
54 </script>
55
56 {$forms.userForm.open}
57 <table cellspacing="4" cellpadding="7" border="0">
58   <table cellspacing="1" cellpadding="2" border="0">
59     <tr>
60       <td align="right">{$i18n.label.person_name} (*):</td>
61       <td>{$forms.userForm.name.control}</td>
62     </tr>
63     <tr>
64       <td align="right">{$i18n.label.login} (*):</td>
65       <td>{$forms.userForm.login.control}</td>
66     </tr>
67 {if !$auth_external}
68     <tr>
69       <td align="right">{$i18n.label.password} (*):</td>
70       <td>{$forms.userForm.pas1.control}</td>
71     </tr>
72     <tr>
73       <td align="right">{$i18n.label.confirm_password} (*):</td>
74       <td>{$forms.userForm.pas2.control}</td>
75     </tr>
76 {/if}
77     <tr>
78       <td align="right" nowrap>{$i18n.label.email}:</td>
79       <td>{$forms.userForm.email.control}</td>
80     </tr>
81 {if $user->isManager() && ($user->id != $user_id)}
82     <tr>
83       <td align="right">{$i18n.form.users.role}:</td>
84       <td>{$forms.userForm.role.control} {$forms.userForm.client.control}</td>
85     </tr>
86 {/if}
87 {* Prohibit deactivating team manager. Deactivating others is ok. *}
88 {if $user->canManageTeam() && !($user->isManager() && $user->id == $user_id)}
89     <tr>
90       <td align="right">{$i18n.label.status}:</td>
91       <td>{$forms.userForm.status.control}</td>
92     </tr>
93 {/if}
94     <tr>
95       <td align="right">{$i18n.form.users.default_rate}&nbsp;(0{$user->decimal_mark}00):</td>
96       <td>{$forms.userForm.rate.control}</td>
97     </tr>
98 {if ($smarty.const.MODE_PROJECTS == $user->tracking_mode || $smarty.const.MODE_PROJECTS_AND_TASKS == $user->tracking_mode)}
99     <tr valign="top">
100       <td align="right">{$i18n.label.projects}:</td>
101       <td>{$forms.userForm.projects.control}</td>
102     </tr>
103 {/if}
104     <tr>
105       <td colspan="2" align="center">{$i18n.label.required_fields}</td>
106     </tr>
107     <tr>
108       <td colspan="2" align="center" height="50">{$forms.userForm.btn_submit.control}</td>
109     </tr>
110   </table>
111 </table>
112 {$forms.userForm.close}