[3167] | 1 | /** |
---|
| 2 | * Show / Hide all employees |
---|
| 3 | */ |
---|
[795] | 4 | function toggleEmployeesVisibility() |
---|
| 5 | { |
---|
| 6 | if ($('#employeesVisibility').attr('checked')) |
---|
[3167] | 7 | $('tr.employees').show(); |
---|
[795] | 8 | else |
---|
[3167] | 9 | $('tr.employees').hide(); |
---|
[795] | 10 | } |
---|
| 11 | |
---|
[3167] | 12 | /** |
---|
| 13 | * Highlight supervisor names? |
---|
| 14 | */ |
---|
[795] | 15 | function toggleHighlightSupervisor() |
---|
| 16 | { |
---|
| 17 | if ($('#highlightSupervisor').attr('checked')) |
---|
| 18 | $('span.employeesupervisor').css('font-weight', 'bold'); |
---|
| 19 | else |
---|
| 20 | $('span.employeesupervisor').css('font-weight', 'normal'); |
---|
| 21 | } |
---|
| 22 | |
---|
[3167] | 23 | /** |
---|
| 24 | * Show / Hide orgchart area path visibility |
---|
| 25 | */ |
---|
[795] | 26 | function toggleOrgchartPathVisibility() |
---|
| 27 | { |
---|
| 28 | if ($('#orgchartPathVisibility').attr('checked')) |
---|
| 29 | $('span.orgchartPath').css('visibility', 'visible').show(); |
---|
[3167] | 30 | else { |
---|
[795] | 31 | if ($('#orgchartPathIndentation').attr('checked')) |
---|
| 32 | $('span.orgchartPath').show().css('visibility', 'hidden'); |
---|
| 33 | else |
---|
| 34 | $('span.orgchartPath').hide(); |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | |
---|
[3167] | 38 | /** |
---|
| 39 | * Group by area or show a single list alphabetically ordered |
---|
| 40 | * For large sets of data this function may be potencially slow |
---|
| 41 | */ |
---|
| 42 | function toggleGroupByArea() |
---|
| 43 | { |
---|
| 44 | /* remove the table and compute it again */ |
---|
| 45 | $('#employee_table').remove(); |
---|
| 46 | |
---|
| 47 | if ($('#groupByArea').attr('checked')) |
---|
| 48 | showGroupedByArea(); |
---|
| 49 | else |
---|
| 50 | showUngrouped(); |
---|
| 51 | |
---|
| 52 | /* updating supervisor highlight and orgchart path visibility */ |
---|
| 53 | toggleHighlightSupervisor(); |
---|
| 54 | toggleOrgchartPathVisibility(); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | /** |
---|
| 58 | * Centralize the creation of table rows for employees. |
---|
| 59 | * 'showAreaColumn' specifies whether the second column will be shown |
---|
| 60 | */ |
---|
| 61 | function createEmployeeRow(area_id, user_id, showAreaColumn) |
---|
| 62 | { |
---|
| 63 | /* set a special 'class' if the employee is a supervisor one */ |
---|
| 64 | class_name = 'employee'; |
---|
| 65 | if (areas[area_id].titular_funcionario_id == areas[area_id].employees[user_id].funcionario_id) |
---|
| 66 | class_name += 'supervisor'; |
---|
| 67 | |
---|
| 68 | /* creating the row. */ |
---|
| 69 | element = $('<tr></tr>') |
---|
| 70 | /* name: first column */ |
---|
| 71 | .append( |
---|
| 72 | $('<td></td>') |
---|
| 73 | .append( |
---|
| 74 | $('<span></span>') |
---|
| 75 | .addClass(class_name) |
---|
| 76 | .append(areas[area_id].employees[user_id].cn) |
---|
| 77 | ) |
---|
[5242] | 78 | .css('width', '60%') |
---|
[3167] | 79 | ); |
---|
| 80 | |
---|
| 81 | /* area: second (optional) column */ |
---|
| 82 | if (showAreaColumn) |
---|
| 83 | element.append( |
---|
| 84 | $('<td>' + areas[area_id].sigla + '</td>') |
---|
| 85 | .css('width', '15%') |
---|
| 86 | ); |
---|
| 87 | |
---|
[5242] | 88 | /* login: show uid attribute */ |
---|
| 89 | element.append( |
---|
| 90 | $('<td>' + areas[area_id].employees[user_id].uid + '</td>') |
---|
| 91 | .css('width', '10%') |
---|
| 92 | ) |
---|
| 93 | |
---|
[3167] | 94 | /* telephone: last column */ |
---|
| 95 | element.append( |
---|
| 96 | $('<td>' + areas[area_id].employees[user_id].telephoneNumber + '</td>') |
---|
| 97 | .css('width', '20%') |
---|
| 98 | ) |
---|
| 99 | .addClass('employees'); |
---|
| 100 | |
---|
| 101 | return element; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /** |
---|
| 105 | * Creating a employee table grouped by area |
---|
| 106 | */ |
---|
| 107 | function showGroupedByArea() |
---|
| 108 | { |
---|
| 109 | var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table'); |
---|
| 110 | var i, j; |
---|
| 111 | |
---|
| 112 | /* iterating over areas */ |
---|
| 113 | for (i=0; i < areas.length; i++) { |
---|
| 114 | |
---|
| 115 | /* inserting area header */ |
---|
| 116 | table.append( |
---|
| 117 | $('<tr></tr>') |
---|
| 118 | .append( |
---|
| 119 | $('<th></th>') |
---|
| 120 | .css('text-align', 'left') |
---|
| 121 | .css('height', '30') |
---|
| 122 | .append( |
---|
| 123 | $('<span></span>') |
---|
| 124 | .addClass('orgchartPath') |
---|
| 125 | .append(areas[i].orgchartPath) |
---|
| 126 | ) |
---|
| 127 | .append(areas[i].sigla) |
---|
| 128 | ) |
---|
| 129 | ); |
---|
| 130 | |
---|
| 131 | /* creating employee rows */ |
---|
| 132 | for (j=0; j < areas[i].employees.length; j++) |
---|
| 133 | table.append(createEmployeeRow(i, j)); |
---|
| 134 | } |
---|
| 135 | $('#areas_content').append(table); |
---|
| 136 | } |
---|
| 137 | |
---|
| 138 | /** |
---|
| 139 | * Creating employess ordered alphabetically and ungrouped. In this |
---|
| 140 | * function we implemented a 'merge' of all area's employee arrays. |
---|
| 141 | * |
---|
| 142 | * Be careful if you are going to update this code... =) |
---|
| 143 | */ |
---|
| 144 | function showUngrouped() |
---|
| 145 | { |
---|
| 146 | var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table'); |
---|
| 147 | var i, less, end; |
---|
| 148 | |
---|
| 149 | /* creating and reseting indexes */ |
---|
| 150 | for (i=0; i < areas.length; i++) |
---|
| 151 | areas[i].index = 0; |
---|
| 152 | |
---|
| 153 | /* */ |
---|
| 154 | while (true) { |
---|
| 155 | less = -1; |
---|
| 156 | end = true; |
---|
| 157 | |
---|
| 158 | /* searching the area with smallest employee name */ |
---|
| 159 | for (i=0; i < areas.length; i++) { |
---|
| 160 | |
---|
| 161 | /* if this area have employees left */ |
---|
| 162 | if (areas[i].employees.length > areas[i].index) { |
---|
| 163 | |
---|
| 164 | /* if it's the first area reached in this iteration */ |
---|
| 165 | if (less == -1) |
---|
| 166 | less = i; |
---|
| 167 | |
---|
| 168 | /* updating less */ |
---|
| 169 | if (areas[i].employees[areas[i].index].cn < areas[less].employees[areas[less].index].cn) |
---|
| 170 | less = i; |
---|
| 171 | |
---|
| 172 | /* so, we are not done */ |
---|
| 173 | end = false; |
---|
| 174 | } |
---|
| 175 | } |
---|
| 176 | /* if we are done */ |
---|
| 177 | if (end) break; |
---|
| 178 | |
---|
| 179 | /* inserting the row */ |
---|
| 180 | table.append(createEmployeeRow(less, areas[less].index, true)); |
---|
| 181 | areas[less].index++; |
---|
| 182 | } |
---|
| 183 | $('#areas_content').append(table); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | /** |
---|
| 187 | * Print me! |
---|
| 188 | */ |
---|
[795] | 189 | function printAction() |
---|
| 190 | { |
---|
| 191 | window.print(); |
---|
| 192 | } |
---|
| 193 | |
---|
[3167] | 194 | /** |
---|
| 195 | * Binding events to HTML elements |
---|
| 196 | */ |
---|
[795] | 197 | function bindEvents() |
---|
| 198 | { |
---|
| 199 | $('#employeesVisibility').click(toggleEmployeesVisibility); |
---|
[3167] | 200 | $('#groupByArea').click(toggleGroupByArea); |
---|
[795] | 201 | $('#highlightSupervisor').click(toggleHighlightSupervisor); |
---|
| 202 | $('#orgchartPathVisibility').click(toggleOrgchartPathVisibility); |
---|
| 203 | $('#printButton').click(printAction); |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | function initialSetup() |
---|
| 207 | { |
---|
[3167] | 208 | toggleGroupByArea(); |
---|
[795] | 209 | toggleEmployeesVisibility(); |
---|
| 210 | toggleHighlightSupervisor(); |
---|
| 211 | toggleOrgchartPathVisibility(); |
---|
| 212 | } |
---|
| 213 | |
---|
[3167] | 214 | /** |
---|
| 215 | * Call setup functions on body onload. |
---|
| 216 | */ |
---|
[795] | 217 | function pageLoad() |
---|
| 218 | { |
---|
| 219 | bindEvents(); |
---|
| 220 | initialSetup(); |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | $(window).load(pageLoad); |
---|