Fixed mobile user pages for client role.
[timetracker.git] / WEB-INF / templates / mobile / user_edit.tpl
1 <script>
2 // Prepare an array of available roles. We need it for "is_client" property.
3 // It is used to selectively display client selector for client roles.
4 roles = new Array();
5 var idx = 0;
6 {foreach $active_roles as $active_role}
7 roles[idx] = new Array({$active_role.id}, '{$active_role.is_client}');
8 idx++;
9 {/foreach}
10
11 // Prepare an array of rates.
12 // Format: project_rates[0] = Array(100, '25.00'), project_rates[1] = Array(120, '30.00'), etc...
13 // First element = project_id, second element = rate for project. Quotes needed for string representation of rates.
14 project_rates = new Array();
15 var idx = 0;
16 {foreach $rates as $rate}
17 project_rates[idx] = new Array({$rate.id}, '{$rate.rate}');
18 idx++;
19 {/foreach}
20
21 // getRate - returns a rate for the project. If rate was set for user previously we'll get this old rate
22 // if project time entries for user exists. Otherwise return user default rate.
23 function getRate(project_id) {
24   var length = project_rates.length;
25   for(var i = 0; i < length; i++) {
26     if(project_rates[i][0] == project_id) {
27       return project_rates[i][1];
28     }
29   }
30   var default_rate = document.userForm.rate.value;
31   return default_rate;
32 }
33
34 // The setRate function sets / unsets user rate for a project when a corresponding checkbox is ticked.
35 function setRate(element) {
36   var default_rate = document.userForm.rate.value;
37   if (default_rate == '') {
38     // No default rate, nothing to do!
39     return;
40   }
41   // Iterate through elements of the form to find and set the project rate. 
42   for (var i = 0; i < userForm.elements.length; i++) {
43     if ((userForm.elements[i].type == 'text') && (userForm.elements[i].name == ('rate_'+element.value))) {
44       if (element.checked) {
45         userForm.elements[i].value = getRate(element.value);
46       } else {
47         userForm.elements[i].value = '';
48       }
49       break; // Element is found and set, nothing more to do, break out of the loop.
50     }
51   }
52 }
53
54 // handleClientControl - controls visibility of the client dropdown depending on the selected user role,
55 // also hides and unselects projects when "Client" user role is selected.
56 function handleClientControl() {
57   var selectedRoleId = document.getElementById("role").value;
58   var clientControl = document.getElementById("client");
59   var projectsControl = document.getElementById("projects_control");
60
61   var len = roles.length;
62   for (var i = 0; i < len; i++) {
63     if (selectedRoleId == roles[i][0]) {
64       var isClient = roles[i][1];
65       if (isClient == 1) {
66         clientControl.style.visibility = "visible";
67         projectsControl.style.display = "none";
68
69         // Uncheck all project checkboxes.
70         var checkboxes = document.getElementsByName("projects[]");
71         var j;
72         for (j = 0; j < checkboxes.length; j++) {
73           checkboxes[j].checked = false;
74         }
75       } else {
76         clientControl.value = "";
77         clientControl.style.visibility = "hidden";
78         projectsControl.style.display = "";
79       }
80       break;
81     }
82   }
83 }
84 </script>
85
86 {$forms.userForm.open}
87 <table cellspacing="4" cellpadding="7" border="0">
88   <table cellspacing="1" cellpadding="2" border="0">
89     <tr>
90       <td align="right">{$i18n.label.person_name} (*):</td>
91       <td>{$forms.userForm.name.control}</td>
92     </tr>
93     <tr>
94       <td align="right">{$i18n.label.login} (*):</td>
95       <td>{$forms.userForm.login.control}</td>
96     </tr>
97 {if !$auth_external}
98     <tr>
99       <td align="right">{$i18n.label.password} (*):</td>
100       <td>{$forms.userForm.pas1.control}</td>
101     </tr>
102     <tr>
103       <td align="right">{$i18n.label.confirm_password} (*):</td>
104       <td>{$forms.userForm.pas2.control}</td>
105     </tr>
106 {/if}
107     <tr>
108       <td align="right" nowrap>{$i18n.label.email}:</td>
109       <td>{$forms.userForm.email.control}</td>
110     </tr>
111 {if $user->id != $user_id}
112     <tr>
113       <td align="right">{$i18n.form.users.role}:</td>
114       <td>{$forms.userForm.role.control} {$forms.userForm.client.control}</td>
115     </tr>
116     <tr>
117       <td align="right">{$i18n.label.status}:</td>
118       <td>{$forms.userForm.status.control}</td>
119     </tr>
120 {/if}
121     <tr>
122       <td align="right">{$i18n.form.users.default_rate}&nbsp;(0{$user->decimal_mark}00):</td>
123       <td>{$forms.userForm.rate.control}</td>
124     </tr>
125 {if $show_quota}
126     <tr>
127       <td align="right">{$i18n.label.quota}&nbsp;(%):</td>
128       <td>{$forms.userForm.quota_percent.control}</td>
129     </tr>
130 {/if}
131 {if $show_projects}
132 <tbody id="projects_control">
133     <tr valign="top">
134       <td align="right">{$i18n.label.projects}:</td>
135       <td>{$forms.userForm.projects.control}</td>
136     </tr>
137 </tbody>
138 {/if}
139     <tr>
140       <td colspan="2" align="center">{$i18n.label.required_fields}</td>
141     </tr>
142     <tr>
143       <td colspan="2" align="center" height="50">{$forms.userForm.btn_submit.control} {$forms.userForm.btn_delete.control}</td>
144     </tr>
145   </table>
146 </table>
147 {$forms.userForm.close}