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.

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                                                )
[6479]101                                                        .css('width', '30%')
[5739]102                        );
103
[3167]104        /* area: second (optional) column */
105        if (showAreaColumn)
106                element.append(
107                                                $('<td>' + areas[area_id].sigla + '</td>')
[6479]108                                                        .css('width', '10%')
[3167]109                                        );
110
[5242]111        /* login: show uid attribute */
112        element.append(
113                                        $('<td>' + areas[area_id].employees[user_id].uid + '</td>')
[6479]114                                                .css('width', '15%')
[5242]115                                        )
[6479]116                                       
117       
[3167]118        /* telephone: last column */
119        element.append(
120                                        $('<td>' + areas[area_id].employees[user_id].telephoneNumber + '</td>')
[6479]121                                                .css('width', '15%')
[3167]122                                        )
[6479]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
[3167]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');
[5739]147        var i, j, photo;
[3167]148
[5739]149        if ($('#photoVisibility').attr('checked'))
150           photo = true;
151        else
152           photo = false;
153
[3167]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(
[5739]161                                        $('<td colspan="2"></td>')
162                                                .css('font-weight', 'bold')
[3167]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++)
[5739]176                        table.append(createEmployeeRow(i, j, false, photo));
[3167]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');
[5739]190        var i, less, end, photo;
[3167]191
[5739]192        if ($('#photoVisibility').attr('checked'))
193           photo = true;
194        else
195           photo = false;
196
[3167]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 */
[5739]228                table.append(createEmployeeRow(less, areas[less].index, true, photo));
[3167]229                areas[less].index++;
230        }
231        $('#areas_content').append(table);
232}
233
234/**
235* Print me!
236*/
[795]237function printAction()
238{
239        window.print();
240}
241
[3167]242/**
243* Binding events to HTML elements
244*/
[795]245function bindEvents()
246{
247        $('#employeesVisibility').click(toggleEmployeesVisibility);
[5739]248        $('#photoVisibility').click(togglePhotoVisibility);
[3167]249        $('#groupByArea').click(toggleGroupByArea);
[795]250        $('#highlightSupervisor').click(toggleHighlightSupervisor);
251        $('#orgchartPathVisibility').click(toggleOrgchartPathVisibility);
252        $('#printButton').click(printAction);
253}
254
255function initialSetup()
256{
[3167]257        toggleGroupByArea();
[5739]258        togglePhotoVisibility();
[795]259        toggleEmployeesVisibility();
260        toggleHighlightSupervisor();
261        toggleOrgchartPathVisibility();
262}
263
[3167]264/**
265* Call setup functions on body onload.
266*/
[795]267function pageLoad()
268{
269        bindEvents();
270        initialSetup();
271}
272
273$(window).load(pageLoad);
Note: See TracBrowser for help on using the repository browser.