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