Added custom field controls on user_add.php.
[timetracker.git] / WEB-INF / templates / user_add.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 // The setDefaultRate function sets / unsets default rate for a project
12 // when a corresponding checkbox is ticked.
13 function setDefaultRate(element) {
14   var default_rate = document.userForm.rate.value;
15   if (default_rate == '') {
16     // No default rate, nothing to do!
17     return;
18   }
19   // Iterate through elements of the form to find and set the project rate. 
20   for (var i = 0; i < userForm.elements.length; i++) {
21     if ((userForm.elements[i].type == 'text') && (userForm.elements[i].name == ('rate_'+element.value))) {
22       if (element.checked) {
23         userForm.elements[i].value = default_rate;
24       } else {
25         userForm.elements[i].value = '';
26       }
27       break; // Element is found and set, nothing more to do, break out of the loop.
28     }
29   }
30 }
31
32 // handleClientControl - controls visibility of the client dropdown depending on the selected user role,
33 // also hides and unselects projects when "Client" user role is selected.
34 function handleClientControl() {
35   var selectedRoleId = document.getElementById("role").value;
36   var clientControl = document.getElementById("client");
37   var nonClientBlock = document.getElementById("non_client_block");
38   var projectsControl = document.getElementById("projects_control");
39
40   var len = roles.length;
41   for (var i = 0; i < len; i++) {
42     if (selectedRoleId == roles[i][0]) {
43       var isClient = roles[i][1];
44       if (isClient == 1) {
45         clientControl.style.visibility = "visible";
46         nonClientBlock.style.display = "none";
47         projectsControl.style.display = "none";
48
49         // Uncheck all project checkboxes.
50         var checkboxes = document.getElementsByName("projects[]");
51         var j;
52         for (j = 0; j < checkboxes.length; j++) {
53           checkboxes[j].checked = false;
54         }
55       } else {
56         clientControl.value = "";
57         clientControl.style.visibility = "hidden";
58         nonClientBlock.style.display = "";
59         projectsControl.style.display = "";
60       }
61       break;
62     }
63   }
64 }
65 </script>
66
67 {$forms.userForm.open}
68 <table cellspacing="4" cellpadding="7" border="0">
69   <table cellspacing="1" cellpadding="2" border="0">
70     <tr>
71       <td align="right">{$i18n.label.person_name} (*):</td>
72       <td>{$forms.userForm.name.control}</td>
73     </tr>
74     <tr>
75       <td align="right">{$i18n.label.login} (*):</td>
76       <td>{$forms.userForm.login.control}</td>
77     </tr>
78 {if !$auth_external}
79     <tr>
80       <td align="right">{$i18n.label.password} (*):</td>
81       <td>{$forms.userForm.pas1.control}</td>
82     </tr>
83     <tr>
84       <td align="right">{$i18n.label.confirm_password} (*):</td>
85       <td>{$forms.userForm.pas2.control}</td>
86     </tr>
87 {/if}
88     <tr>
89       <td align="right" nowrap>{$i18n.label.email}:</td>
90       <td>{$forms.userForm.email.control}</td>
91     </tr>
92     <tr>
93       <td align="right">{$i18n.form.users.role}:</td>
94       <td>{$forms.userForm.role.control} {$forms.userForm.client.control}</td>
95     </tr>
96 <tbody id="non_client_block">
97 {if $show_quota}
98     <tr>
99       <td align="right">{$i18n.label.quota}&nbsp;(%):</td>
100       <td>{$forms.userForm.quota_percent.control} <a href="https://www.anuko.com/lp/tt_27.htm" target="_blank">{$i18n.label.what_is_it}</a></td>
101     </tr>
102 {/if}
103 {if $custom_fields && $custom_fields->userFields}
104   {foreach $custom_fields->userFields as $userField}
105     <tr>
106       <td align="right">{$userField['label']|escape}{if $userField['required']} (*){/if}:</td>
107       {assign var="control_name" value='user_field_'|cat:$userField['id']}
108       <td>{$forms.userForm.$control_name.control}</td>
109     </tr>
110   {/foreach}
111 {/if}
112
113
114     <tr>
115       <td align="right">{$i18n.form.users.default_rate}&nbsp;(0{$user->getDecimalMark()}00):</td>
116       <td>{$forms.userForm.rate.control}</td>
117     </tr>
118 </tbody>
119 {if $show_projects}
120 <tbody id="projects_control">
121     <tr><td>&nbsp;</td></tr>
122     <tr valign="top">
123       <td align="right">{$i18n.label.projects}:</td>
124       <td>{$forms.userForm.projects.control}</td>
125     </tr>
126 </tbody>
127 {/if}
128     <tr>
129       <td colspan="2" align="center">{$i18n.label.required_fields}</td>
130     </tr>
131     <tr>
132       <td colspan="2" align="center" height="50">{$forms.userForm.btn_submit.control}</td>
133     </tr>
134   </table>
135 </table>
136 {$forms.userForm.close}