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

Line 
1/**
2* Show / Hide all employees
3*/
4function toggleEmployeesVisibility()
5{
6        if ($('#employeesVisibility').attr('checked'))
7                $('tr.employees').show();
8        else
9                $('tr.employees').hide();
10}
11
12
13/**
14* Highlight supervisor names?
15*/
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
24/**
25* Show / Hide orgchart area path visibility
26*/
27function toggleOrgchartPathVisibility()
28{
29        if ($('#orgchartPathVisibility').attr('checked'))
30                $('span.orgchartPath').css('visibility', 'visible').show();
31        else {
32                if ($('#orgchartPathIndentation').attr('checked'))
33                        $('span.orgchartPath').show().css('visibility', 'hidden');
34                else
35                        $('span.orgchartPath').hide();
36        }
37}
38
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
58
59/**
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/**
73* Centralize the creation of table rows for employees.
74* 'showAreaColumn' specifies whether the second column will be shown
75*/
76function createEmployeeRow(area_id, user_id, showAreaColumn, showUserPhoto)
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. */
84        element = $('<tr></tr>');
85
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
104        /* area: second (optional) column */
105        if (showAreaColumn)
106                element.append(
107                                                $('<td>' + areas[area_id].sigla + '</td>')
108                                                        .css('width', '15%')
109                                        );
110
111        /* login: show uid attribute */
112        element.append(
113                                        $('<td>' + areas[area_id].employees[user_id].uid + '</td>')
114                                                .css('width', '10%')
115                                        )
116
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');
133        var i, j, photo;
134
135        if ($('#photoVisibility').attr('checked'))
136           photo = true;
137        else
138           photo = false;
139
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(
147                                        $('<td colspan="2"></td>')
148                                                .css('font-weight', 'bold')
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++)
162                        table.append(createEmployeeRow(i, j, false, photo));
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');
176        var i, less, end, photo;
177
178        if ($('#photoVisibility').attr('checked'))
179           photo = true;
180        else
181           photo = false;
182
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 */
214                table.append(createEmployeeRow(less, areas[less].index, true, photo));
215                areas[less].index++;
216        }
217        $('#areas_content').append(table);
218}
219
220/**
221* Print me!
222*/
223function printAction()
224{
225        window.print();
226}
227
228/**
229* Binding events to HTML elements
230*/
231function bindEvents()
232{
233        $('#employeesVisibility').click(toggleEmployeesVisibility);
234        $('#photoVisibility').click(togglePhotoVisibility);
235        $('#groupByArea').click(toggleGroupByArea);
236        $('#highlightSupervisor').click(toggleHighlightSupervisor);
237        $('#orgchartPathVisibility').click(toggleOrgchartPathVisibility);
238        $('#printButton').click(printAction);
239}
240
241function initialSetup()
242{
243        toggleGroupByArea();
244        togglePhotoVisibility();
245        toggleEmployeesVisibility();
246        toggleHighlightSupervisor();
247        toggleOrgchartPathVisibility();
248}
249
250/**
251* Call setup functions on body onload.
252*/
253function pageLoad()
254{
255        bindEvents();
256        initialSetup();
257}
258
259$(window).load(pageLoad);
Note: See TracBrowser for help on using the repository browser.