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

Revision 6568, 6.5 KB checked in by leticiabohnert, 12 years ago (diff)

Ticket #2851 - Corrigidos inserts e selects com data_adm e html da função.

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 valign="top">' + content + '</td>').css('width', '8%'));
91        }
92
93        /* name: first column */
94        element.append(
95                                $('<td valign="top"></td>')
96                                        .append(
97                                                $('<span></span>')
98                                                        .addClass(class_name)
99                                                        .append(areas[area_id].employees[user_id].cn)
100                                                )
101                                                        .css('width', '23.5%')
102                        );
103
104        /* area: second (optional) column */
105        if (showAreaColumn)
106                element.append(
107                                                $('<td>' + areas[area_id].sigla + '</td>')
108                                        );
109
110        /* login: show uid attribute */
111        element.append(
112                                        $('<td valign="top">' + areas[area_id].employees[user_id].uid + '</td>')
113                                                .css('width', '11%')
114                                        )
115                                       
116       
117        /* telephone: last column */
118        element.append(
119                                        $('<td valign="top">' + areas[area_id].employees[user_id].telephoneNumber + '</td>')
120                                                .css('width', '9.75%')
121                                        )
122                                       
123        /* Vínculo: show cargo vínculo */
124        element.append(
125                                        $('<td valign="top">' + areas[area_id].employees[user_id].vinculo + '</td>')
126                                                .css('width', '9%')
127                                        )
128
129        /* Cargo: show cargo attribute */
130        element.append(
131                                        $('<td valign="top">' + areas[area_id].employees[user_id].cargo + '</td>')
132                                                .css('width', '12.5%')
133                                        )
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(
143                                $('<td valign="top"> ' + areas[area_id].employees[user_id].funcao + ' </td>')
144                                                .css('width', '26%')
145                                        )
146
147
148                                .addClass('employees');
149
150        return element;
151}
152
153/**
154* Creating a employee table grouped by area
155*/
156function showGroupedByArea()
157{
158        var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table');
159        var i, j, photo;
160
161        if ($('#photoVisibility').attr('checked'))
162           photo = true;
163        else
164           photo = false;
165
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(
173                                        $('<td colspan="2"></td>')
174                                                .css('font-weight', 'bold')
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++)
188                        table.append(createEmployeeRow(i, j, false, photo));
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*/
199function showUngrouped()
200{
201        var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table');
202        var i, less, end, photo;
203
204        if ($('#photoVisibility').attr('checked'))
205           photo = true;
206        else
207           photo = false;
208
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 */
240                table.append(createEmployeeRow(less, areas[less].index, true, photo));
241                areas[less].index++;
242        }
243        $('#areas_content').append(table);
244}
245
246/**
247* Print me!
248*/
249function printAction()
250{
251        window.print();
252}
253
254/**
255* Binding events to HTML elements
256*/
257function bindEvents()
258{
259        $('#employeesVisibility').click(toggleEmployeesVisibility);
260        $('#photoVisibility').click(togglePhotoVisibility);
261        $('#groupByArea').click(toggleGroupByArea);
262        $('#highlightSupervisor').click(toggleHighlightSupervisor);
263        $('#orgchartPathVisibility').click(toggleOrgchartPathVisibility);
264        $('#printButton').click(printAction);
265}
266
267function initialSetup()
268{
269        toggleGroupByArea();
270        togglePhotoVisibility();
271        toggleEmployeesVisibility();
272        toggleHighlightSupervisor();
273        toggleOrgchartPathVisibility();
274}
275
276/**
277* Call setup functions on body onload.
278*/
279function pageLoad()
280{
281        bindEvents();
282        initialSetup();
283}
284
285$(window).load(pageLoad);
Note: See TracBrowser for help on using the repository browser.