source: branches/2.2/workflow/js/userinterface/orgchartPrint.js @ 3167

Revision 3167, 4.8 KB checked in by viani, 14 years ago (diff)

Ticket #1135 - Merged r1990:3166 from /trunk/workflow into /branches/2.2/workflow

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* Highlight supervisor names?
14*/
15function toggleHighlightSupervisor()
16{
17        if ($('#highlightSupervisor').attr('checked'))
18                $('span.employeesupervisor').css('font-weight', 'bold');
19        else
20                $('span.employeesupervisor').css('font-weight', 'normal');
21}
22
23/**
24* Show / Hide orgchart area path visibility
25*/
26function toggleOrgchartPathVisibility()
27{
28        if ($('#orgchartPathVisibility').attr('checked'))
29                $('span.orgchartPath').css('visibility', 'visible').show();
30        else {
31                if ($('#orgchartPathIndentation').attr('checked'))
32                        $('span.orgchartPath').show().css('visibility', 'hidden');
33                else
34                        $('span.orgchartPath').hide();
35        }
36}
37
38/**
39* Group by area or show a single list alphabetically ordered
40* For large sets of data this function may be potencially slow
41*/
42function toggleGroupByArea()
43{
44        /* remove the table and compute it again */
45        $('#employee_table').remove();
46
47        if ($('#groupByArea').attr('checked'))
48                showGroupedByArea();
49        else
50                showUngrouped();
51
52        /* updating supervisor highlight and orgchart path visibility */
53        toggleHighlightSupervisor();
54        toggleOrgchartPathVisibility();
55}
56
57/**
58* Centralize the creation of table rows for employees.
59* 'showAreaColumn' specifies whether the second column will be shown
60*/
61function createEmployeeRow(area_id, user_id, showAreaColumn)
62{
63        /* set a special 'class' if the employee is a supervisor one */
64        class_name = 'employee';
65        if (areas[area_id].titular_funcionario_id == areas[area_id].employees[user_id].funcionario_id)
66                class_name += 'supervisor';
67
68        /* creating the row. */
69        element = $('<tr></tr>')
70                                /* name: first column */
71                                .append(
72                                                $('<td></td>')
73                                                        .append(
74                                                                $('<span></span>')
75                                                                        .addClass(class_name)
76                                                                        .append(areas[area_id].employees[user_id].cn)
77                                                        )
78                                                        .css('width', '70%')
79                                                );
80
81        /* area: second (optional) column */
82        if (showAreaColumn)
83                element.append(
84                                                $('<td>' + areas[area_id].sigla + '</td>')
85                                                        .css('width', '15%')
86                                        );
87
88        /* telephone: last column */
89        element.append(
90                                        $('<td>' + areas[area_id].employees[user_id].telephoneNumber + '</td>')
91                                                .css('width', '20%')
92                                        )
93                                .addClass('employees');
94
95        return element;
96}
97
98/**
99* Creating a employee table grouped by area
100*/
101function showGroupedByArea()
102{
103        var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table');
104        var i, j;
105
106        /* iterating over areas */
107        for (i=0; i < areas.length; i++) {
108
109                /* inserting area header */
110                table.append(
111                                $('<tr></tr>')
112                                .append(
113                                        $('<th></th>')
114                                                .css('text-align', 'left')
115                                                .css('height', '30')
116                                                .append(
117                                                        $('<span></span>')
118                                                                .addClass('orgchartPath')
119                                                                .append(areas[i].orgchartPath)
120                                                                )
121                                                .append(areas[i].sigla)
122                                        )
123                );
124
125                /* creating employee rows */
126                for (j=0; j < areas[i].employees.length; j++)
127                        table.append(createEmployeeRow(i, j));
128        }
129        $('#areas_content').append(table);
130}
131
132/**
133* Creating employess ordered alphabetically and ungrouped. In this
134* function we implemented a 'merge' of all area's employee arrays.
135*
136* Be careful if you are going to update this code... =)
137*/
138function showUngrouped()
139{
140        var table = $('<table></table>').css('width', '90%').attr('id', 'employee_table');
141        var i, less, end;
142
143        /* creating and reseting indexes */
144        for (i=0; i < areas.length; i++)
145                areas[i].index = 0;
146
147        /* */
148        while (true) {
149                less = -1;
150                end = true;
151
152                /* searching the area with smallest employee name */
153                for (i=0; i < areas.length; i++) {
154
155                        /* if this area have employees left */
156                        if (areas[i].employees.length > areas[i].index) {
157
158                                /* if it's the first area reached in this iteration */
159                                if (less == -1)
160                                        less = i;
161
162                                /* updating less */
163                                if (areas[i].employees[areas[i].index].cn < areas[less].employees[areas[less].index].cn)
164                                        less = i;
165
166                                /* so, we are not done */
167                                end = false;
168                        }
169                }
170                /* if we are done */
171                if (end) break;
172
173                /* inserting the row */
174                table.append(createEmployeeRow(less, areas[less].index, true));
175                areas[less].index++;
176        }
177        $('#areas_content').append(table);
178}
179
180/**
181* Print me!
182*/
183function printAction()
184{
185        window.print();
186}
187
188/**
189* Binding events to HTML elements
190*/
191function bindEvents()
192{
193        $('#employeesVisibility').click(toggleEmployeesVisibility);
194        $('#groupByArea').click(toggleGroupByArea);
195        $('#highlightSupervisor').click(toggleHighlightSupervisor);
196        $('#orgchartPathVisibility').click(toggleOrgchartPathVisibility);
197        $('#printButton').click(printAction);
198}
199
200function initialSetup()
201{
202        toggleGroupByArea();
203        toggleEmployeesVisibility();
204        toggleHighlightSupervisor();
205        toggleOrgchartPathVisibility();
206}
207
208/**
209* Call setup functions on body onload.
210*/
211function pageLoad()
212{
213        bindEvents();
214        initialSetup();
215}
216
217$(window).load(pageLoad);
Note: See TracBrowser for help on using the repository browser.