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

Revision 6479, 6.0 KB checked in by leticiabohnert, 12 years ago (diff)

Ticket #2851 - Inclusão do arquivo orgchartPrint.js que estava faltando.

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