source: trunk/workflow/js/userinterface/orgchartPrint.js @ 5739

Revision 5739, 5.7 KB checked in by adeildosantos, 12 years ago (diff)

Ticket #2530 - Adicionada a opção de incluir as fotos dos usuários na lista

RevLine 
[3167]1/**
2* Show / Hide all employees
3*/
[795]4function 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]16function 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]27function 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*/
43function 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*/
62function 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]76function 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 + '"/>';
90                element.append($('<td>' + content + '</td>').css('width', '8%'));
91        }
92
93        /* name: first column */
94        element.append(
95                                $('<td></td>')
96                                        .append(
97                                                $('<span></span>')
98                                                        .addClass(class_name)
99                                                        .append(areas[area_id].employees[user_id].cn)
100                                                )
101                                                        .css('width', '55%')
102                        );
103
[3167]104        /* area: second (optional) column */
105        if (showAreaColumn)
106                element.append(
107                                                $('<td>' + areas[area_id].sigla + '</td>')
108                                                        .css('width', '15%')
109                                        );
110
[5242]111        /* login: show uid attribute */
112        element.append(
113                                        $('<td>' + areas[area_id].employees[user_id].uid + '</td>')
114                                                .css('width', '10%')
115                                        )
116
[3167]117        /* telephone: last column */
118        element.append(
119                                        $('<td>' + areas[area_id].employees[user_id].telephoneNumber + '</td>')
120                                                .css('width', '20%')
121                                        )
122                                .addClass('employees');
123
124        return element;
125}
126
127/**
128* Creating a employee table grouped by area
129*/
130function showGroupedByArea()
131{
132        var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table');
[5739]133        var i, j, photo;
[3167]134
[5739]135        if ($('#photoVisibility').attr('checked'))
136           photo = true;
137        else
138           photo = false;
139
[3167]140        /* iterating over areas */
141        for (i=0; i < areas.length; i++) {
142
143                /* inserting area header */
144                table.append(
145                                $('<tr></tr>')
146                                .append(
[5739]147                                        $('<td colspan="2"></td>')
148                                                .css('font-weight', 'bold')
[3167]149                                                .css('text-align', 'left')
150                                                .css('height', '30')
151                                                .append(
152                                                        $('<span></span>')
153                                                                .addClass('orgchartPath')
154                                                                .append(areas[i].orgchartPath)
155                                                                )
156                                                .append(areas[i].sigla)
157                                        )
158                );
159
160                /* creating employee rows */
161                for (j=0; j < areas[i].employees.length; j++)
[5739]162                        table.append(createEmployeeRow(i, j, false, photo));
[3167]163        }
164        $('#areas_content').append(table);
165}
166
167/**
168* Creating employess ordered alphabetically and ungrouped. In this
169* function we implemented a 'merge' of all area's employee arrays.
170*
171* Be careful if you are going to update this code... =)
172*/
173function showUngrouped()
174{
175        var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table');
[5739]176        var i, less, end, photo;
[3167]177
[5739]178        if ($('#photoVisibility').attr('checked'))
179           photo = true;
180        else
181           photo = false;
182
[3167]183        /* creating and reseting indexes */
184        for (i=0; i < areas.length; i++)
185                areas[i].index = 0;
186
187        /* */
188        while (true) {
189                less = -1;
190                end = true;
191
192                /* searching the area with smallest employee name */
193                for (i=0; i < areas.length; i++) {
194
195                        /* if this area have employees left */
196                        if (areas[i].employees.length > areas[i].index) {
197
198                                /* if it's the first area reached in this iteration */
199                                if (less == -1)
200                                        less = i;
201
202                                /* updating less */
203                                if (areas[i].employees[areas[i].index].cn < areas[less].employees[areas[less].index].cn)
204                                        less = i;
205
206                                /* so, we are not done */
207                                end = false;
208                        }
209                }
210                /* if we are done */
211                if (end) break;
212
213                /* inserting the row */
[5739]214                table.append(createEmployeeRow(less, areas[less].index, true, photo));
[3167]215                areas[less].index++;
216        }
217        $('#areas_content').append(table);
218}
219
220/**
221* Print me!
222*/
[795]223function printAction()
224{
225        window.print();
226}
227
[3167]228/**
229* Binding events to HTML elements
230*/
[795]231function bindEvents()
232{
233        $('#employeesVisibility').click(toggleEmployeesVisibility);
[5739]234        $('#photoVisibility').click(togglePhotoVisibility);
[3167]235        $('#groupByArea').click(toggleGroupByArea);
[795]236        $('#highlightSupervisor').click(toggleHighlightSupervisor);
237        $('#orgchartPathVisibility').click(toggleOrgchartPathVisibility);
238        $('#printButton').click(printAction);
239}
240
241function initialSetup()
242{
[3167]243        toggleGroupByArea();
[5739]244        togglePhotoVisibility();
[795]245        toggleEmployeesVisibility();
246        toggleHighlightSupervisor();
247        toggleOrgchartPathVisibility();
248}
249
[3167]250/**
251* Call setup functions on body onload.
252*/
[795]253function pageLoad()
254{
255        bindEvents();
256        initialSetup();
257}
258
259$(window).load(pageLoad);
Note: See TracBrowser for help on using the repository browser.