source: branches/1.2/workflow/js/userinterface/orgchart.js @ 1349

Revision 1349, 13.9 KB checked in by niltonneto, 15 years ago (diff)

Ticket #561 - Inclusão do módulo Workflow faltante nessa versão.

Line 
1var workflowUserInterfaceEmployeeInfoTimer = null;
2var workflowUserInterfaceAreaInfoTimer = null;
3var workflowUserInterfaceCurrentAreaID = 0;
4
5String.prototype.repeat = function(l)
6{
7        return new Array(l+1).join(this);
8};
9
10/* define the orgchart layout */
11function createOrgchartLayout()
12{
13        var content = '<div id="orgchartMenu"></div>';
14        content += '<div class="orgchartAreas" id="orgchartAreas"></div>';
15        content += '<div class="orgchartEmployees" id="orgchartEmployees"></div>';
16        content += '<div class="orgchartFooter" id="orgchartFooter"></div>';
17        content += '<div id="employeeInfo" class="employeeInfo" style="display: none;"></div>';
18        content += '<div id="areaInfo" class="employeeInfo" style="display: none;"></div>';
19
20        var div = $('content_id_4');
21        div.innerHTML = content;
22
23        draw_orgchart_folder();
24}
25
26/* generates the orgchart menu */
27function createOrgchartMenu(organizationID, imagemURL)
28{
29        var enderecoImagem = '';
30        if ((imagemURL != null) && (imagemURL != ''))
31                enderecoImagem = imagemURL;
32        else
33                enderecoImagem = '../index.php?menuaction=workflow.ui_orgchart.graph&organizationID=' + organizationID;
34
35        var content = '<ul class="horizontalMenu">';
36        content += '<li><a href="#" onclick="window.open(\'' + enderecoImagem + '\', \'extwindow\'); return false;"><img src="templateFile.php?file=images/Process.gif">&nbsp;&nbsp;Gráfico</a></li>';
37        content += '<li><a href="#" onclick="getCostCenters(); return false;"><img src="templateFile.php?file=images/coins.png">&nbsp;Centros de Custo</a></li>';
38        content += '<li><a href="#" onclick="getHierarchicalArea(); return false;"><img src="templateFile.php?file=images/orgchart_tree.png">Lista Hierárquica</a></li>';
39        content += '<li><a href="#" onclick="getAreaList(); return false;"><img src="templateFile.php?file=images/orgchart_list.png">&nbsp;&nbsp;Lista Alfabética</a></li>';
40        content += '<li><a href="#" onclick="getCategoriesList(); return false;"><img src="templateFile.php?file=images/folder_green.png">&nbsp;&nbsp;Listar Vínculos</a></li>';
41        content += '<li><a href="#" onclick="printArea(); return false;"><img src="templateFile.php?file=images/imprimir.png" width="16">&nbsp;&nbsp;Imprimir</a></li>';
42        content += '<li><a><input type="text" name="search_term" id="search_term" onkeypress="if (((event.which) ? event.which : event.keyCode) == 13) $(\'search_span\').onclick(); return true;" /><span id="search_span" style="cursor: pointer;" onclick="tmp = $$(\'div#orgchartAreas a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); orgchartSearchEmployee($F(\'search_term\')); return false;">&nbsp;busca</span></a></li>';
43        content += '</ul>';
44        content += '<br/>';
45        content += '<br/>';
46
47        $('orgchartMenu').innerHTML = content;
48}
49
50/* load the initial data */
51function draw_orgchart_folder()
52{
53        $('orgchartMenu').innerHTML = '';
54        $('orgchartAreas').innerHTML = '';
55        $('orgchartEmployees').innerHTML = '<br/><br/><br/><br/><center><i>&nbsp;&nbsp;carregando...<br/><img src="templateFile.php?file=images/loading.gif"></i></center>';
56        $('orgchartFooter').innerHTML = '';
57        $('orgchartMenu').innerHTML = '';
58
59        cExecute("$this.bo_userinterface.orgchart", orgchart, "");
60}
61
62/* process the initial data */
63function orgchart(data)
64{
65        if (_checkError(data))
66                return;
67
68        /* in case of any warning */
69        if (data['warning'])
70        {
71                $('content_id_4').innerHTML = '<br/><br/><center><strong>' + data['warning'] + '</strong></center><br/><br/>';
72                return;
73        }
74
75        if (data['areas'].length == 0)
76        {
77                $('content_id_4').innerHTML = "<br/><br/><center><strong>Nenhuma área cadastrada.</strong></center><br/><br/>";
78                return;
79        }
80
81        /* continue displaying the data */
82        displayHierarchicalAreas(data['areas']);
83        createOrgchartMenu(data['organizacao_id'], data['url_imagem']);
84        $('orgchartEmployees').innerHTML = '<br/><br/><br/><br/><center><i>faça uma busca ou clique em uma área para ver a lista de funcionários</i></center>';
85}
86
87function displayCostCenters(data)
88{
89        if (_checkError(data))
90                return;
91
92        var div = $('orgchartEmployees');
93        if (data.length == 0)
94        {
95                div.innerHTML = '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>';
96                return;
97        }
98
99        var content = '<center><h3>CENTROS DE CUSTO</strong></h3>';
100        content += '<table class="employeeList">';
101        content += '<tr><th>Nome</th><th>Número</th><th>Grupo</th></tr>';
102        var current;
103        var costCentersCount = data.length;
104        for (var i = 0; i < costCentersCount; i++)
105        {
106                current = data[i];
107                content += '<tr class="linha'+ i%2 + '">';
108                content += '<td>' + current['descricao'] + '</td>';
109                content += '<td>' + current['nm_centro_custo'] + '</td>';
110                content += '<td>' + current['grupo'] + '</td>';
111                content += '</tr>';
112        }
113        content += '</table>';
114        div.innerHTML = content;
115}
116
117function displayHierarchicalAreas(data)
118{
119        if (_checkError(data))
120                return;
121
122        function recursivePrint(subdata)
123        {
124                for (var i = 0; i < subdata.length; i++)
125                {
126                        div.innerHTML += '<br />' + '&nbsp;&nbsp;&nbsp;&nbsp;'.repeat(subdata[i]['depth']) + '<a href="javascript:void(0)" id="area_' + subdata[i]['area_id'] + '" onmouseover="getAreaInfoTimer(event, ' + subdata[i]['area_id'] + '); return false;" onmouseout="hideAreaInfo(); return false;" onclick="tmp = $$(\'div#orgchartAreas a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); this.addClassName(\'destaque\'); loadAreaEmployees(' + subdata[i]['area_id'] + ')">' + subdata[i]['sigla'] + '</a>';
127                        if (subdata[i]['children'].length > 0)
128                                recursivePrint(subdata[i]['children']);
129                }
130        }
131
132        var div = $('orgchartAreas');
133        div.innerHTML = "<center><strong>ÁREAS</strong></center>";
134        recursivePrint(data);
135}
136
137function getCostCenters()
138{
139        cExecute("$this.bo_userinterface.getCostCenters", displayCostCenters, "");
140}
141
142function getHierarchicalArea()
143{
144        cExecute("$this.bo_userinterface.getHierarchicalArea", displayHierarchicalAreas, "");
145}
146
147function getAreaList()
148{
149        cExecute("$this.bo_userinterface.getAreaList", displayHierarchicalAreas, "");
150}
151
152function getCategoriesList()
153{
154        function resultGetCategoriesList(data)
155        {
156                if (_checkError(data))
157                        return;
158
159                var content = '<center><strong>VÍNCULOS</strong></center>';
160                for (var i = 0; i < data.length; i++)
161                        content += '<br/>' + '&nbsp;&nbsp;<a href="javascript:void(0)" id="categoria_' + data[i]['funcionario_categoria_id'] + '" onclick="tmp = $$(\'div#orgchartAreas a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); this.addClassName(\'destaque\'); loadCategoryEmployees(' + data[i]['funcionario_categoria_id'] + ')">' + data[i]['descricao'] + ' (' + data[i]['contagem'] + ')</a>';
162                content += '<br/><br/>';
163                $('orgchartAreas').innerHTML = content;
164        }
165
166        cExecute("$this.bo_userinterface.getCategoriesList", resultGetCategoriesList, "");
167}
168
169function printEmployeesHandler(data)
170{
171        /* check for errors */
172        if (_checkError(data))
173                return;
174
175        var div = $('orgchartEmployees');
176
177        /* no employee to list */
178        if (data['employees'].length == 0)
179        {
180                div.innerHTML = '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>';
181                return;
182        }
183
184        /* initialize varivables */
185        var content = '';
186        var employees = data['employees'];
187        var useCategories = false;
188        var useArea = false;
189
190        /* check the informations that will be displayed */
191        if (data['categories'])
192                if (data['categories'].length > 1)
193                        useCategories = true;
194        if (employees[0]['area'])
195                useArea = true;
196
197        /* build the display table (headers)*/
198        content += '<table id="employeeList" class="employeeList" style="clear: both">';
199        content += '<tr>';
200        content += '<th>Funcionário</th>';
201        if (useArea)
202                content += '<th>Área</th>';
203        content += '<th>Telefone</th>';
204        content += '</tr>';
205
206        /* if available, insert a menu to filter the categories */
207        if (useCategories)
208        {
209                content += '<tr><td colspan="' + (useArea ? '3' : '2') + '">';
210                content += '<ul class="horizontalMenu">';
211                for (var i = 0; i < data['categories'].length; i++)
212                        content += '<li><a href="#" style="height: 2em; line-height: 2em;" onclick="highlightCategory(' + data['categories'][i]['funcionario_categoria_id'] + '); return false;">' + data['categories'][i]['descricao'] + ' (' + data['categories'][i]['contagem'] + ')</a></li>';
213                content += '</ul>';
214                content += '</td></tr>';
215        }
216
217        /* list the employees */
218        var complement = '';
219        for (var i = 0; i < employees.length; i++)
220        {
221                if (employees[i]['chief'])
222                        complement = ' <strong>(' + ((employees[i]['chief'] == 1) ? 'Titular' : 'Substituto') + ')</strong>';
223                else
224                        complement = '';
225                if (employees[i]['removed'])
226                        complement += ' <font color="red">(excluído)</font>';
227                content += '<tr class="linha'+ i%2 + (useCategories ? ' categoria_' + employees[i]['funcionario_categoria_id'] : '') + '">';
228                content += '<td><a href="javascript:void(0);" onmouseover="getEmployeeInfoTimer(event, ' + employees[i]['funcionario_id'] + '); return false;" onmouseout="hideEmployeeInfo(); return false;">' + employees[i]['cn'] + complement + '</a></td>';
229                if (useArea)
230                        content += '<td>' + employees[i]['area'] + '</td>';
231                content += '<td align="center">' + employees[i]['telephoneNumber'] + '</td>';
232                content += '</tr>';
233        }
234        content += '</table>';
235
236        /* display the employees list and go to the top of the page */
237        div.innerHTML = content;
238        window.scrollTo(0,0);
239}
240
241function highlightCategory(categoryID)
242{
243        var rows = $('employeeList').childNodes[0].childNodes;
244        var categoryClass = 'categoria_' + categoryID;
245
246        var highlightClass = '';
247        var row;
248        for (var i = 1; i < rows.length; i++)
249        {
250                row = $(rows[i]);
251                /* in case alternated color rows are needed, just change the second 'highlight0' to something else (e.g. 'highlight1' which is alread defined) */
252                highlightClass = row.hasClassName('linha0') ? 'highlight0' : 'highlight0';
253                if (row.hasClassName(categoryClass))
254                        row.addClassName(highlightClass);
255                else
256                        row.removeClassName(highlightClass);
257        }
258}
259
260function loadAreaEmployees(areaID)
261{
262        workflowUserInterfaceCurrentAreaID = areaID;
263        cExecute('$this.bo_userinterface.getAreaEmployees', printEmployeesHandler, 'areaID=' + areaID);
264}
265
266function loadCategoryEmployees(categoryID)
267{
268        workflowUserInterfaceCurrentAreaID = 0;
269        cExecute('$this.bo_userinterface.getCategoryEmployees', printEmployeesHandler, 'categoryID=' + categoryID);
270}
271
272function orgchartSearchEmployee(searchTerm)
273{
274        workflowUserInterfaceCurrentAreaID = 0;
275        cExecute('$this.bo_userinterface.searchEmployee', printEmployeesHandler, 'searchTerm=' + searchTerm);
276}
277
278function printArea()
279{
280        if (workflowUserInterfaceCurrentAreaID == 0)
281                if (!confirm('Tem certeza de que deseja imprimir todo o Organograma?'))
282                        return false;
283        var endereco = '../index.php?menuaction=workflow.ui_userinterface.printArea&areaID=' + workflowUserInterfaceCurrentAreaID;
284        window.open(endereco, 'extwindow');
285}
286
287function getEmployeeInfoTimer(e, employeeID)
288{
289        var div = $('employeeInfo');
290        div.style.left = (Event.pointerX(e) + 20) + 'px';
291        div.style.top = (Event.pointerY(e) + 14) + 'px';
292
293        if (workflowUserInterfaceEmployeeInfoTimer != null)
294        {
295                workflowUserInterfaceEmployeeInfoTimer = clearTimeout(workflowUserInterfaceEmployeeInfoTimer);
296                workflowUserInterfaceEmployeeInfoTimer = null;
297        }
298
299        workflowUserInterfaceEmployeeInfoTimer = setTimeout('getEmployeeInfo(' + employeeID + ')', 500);
300}
301
302function getEmployeeInfo(employeeID)
303{
304        function resultGetEmployeeInfo(data)
305        {
306                if (workflowUserInterfaceEmployeeInfoTimer == null)
307                        return;
308
309                workflowUserInterfaceEmployeeInfoTimer = clearTimeout(workflowUserInterfaceEmployeeInfoTimer);
310                workflowUserInterfaceEmployeeInfoTimer = null;
311
312                var content = '';
313                content += '<table><tr><td valign="top">';
314                content += '<img src="showUserPicture.php?userID=' + employeeID + '"/>';
315                content += '</td><td valign="top" style="padding-left: 12px;">';
316                for (var i = 0; i < data['info'].length; i++)
317                        content += '<strong>' + data['info'][i]['name'] + '</strong>: ' + data['info'][i]['value'] + '<br/>';
318
319                content += '</td></tr></table>';
320                var pageYLimit = document.body.scrollTop + document.body.clientHeight;
321                var div = $('employeeInfo');
322                div.innerHTML = content;
323
324                if ((parseInt(div.style.top.replace(/px/g, '')) + div.getHeight()) > pageYLimit)
325                        div.style.top = (parseInt(div.style.top.replace(/px/g, '')) - (div.getHeight())) + 'px';
326                div.show();
327        }
328        cExecute('$this.bo_userinterface.getEmployeeInfo', resultGetEmployeeInfo, 'funcionario_id=' + employeeID);
329}
330
331function hideEmployeeInfo()
332{
333        if (workflowUserInterfaceEmployeeInfoTimer != null)
334        {
335                workflowUserInterfaceEmployeeInfoTimer = clearTimeout(workflowUserInterfaceEmployeeInfoTimer);
336                workflowUserInterfaceEmployeeInfoTimer = null;
337        }
338        $('employeeInfo').hide();
339}
340
341function getAreaInfoTimer(e, areaID)
342{
343        var div = $('areaInfo');
344        div.style.left = (Event.pointerX(e) + 20) + 'px';
345        div.style.top = (Event.pointerY(e) + 14) + 'px';
346
347        if (workflowUserInterfaceAreaInfoTimer != null)
348        {
349                workflowUserInterfaceAreaInfoTimer = clearTimeout(workflowUserInterfaceAreaInfoTimer);
350                workflowUserInterfaceAreaInfoTimer = null;
351        }
352
353        workflowUserInterfaceAreaInfoTimer = setTimeout('getAreaInfo(' + areaID + ')', 500);
354}
355
356function getAreaInfo(areaID)
357{
358        function resultGetAreaInfo(data)
359        {
360                if (workflowUserInterfaceAreaInfoTimer == null)
361                        return;
362
363                workflowUserInterfaceAreaInfoTimer = clearTimeout(workflowUserInterfaceAreaInfoTimer);
364                workflowUserInterfaceAreaInfoTimer = null;
365
366                var content = '';
367                content += '<table><tr>';
368                content += '<td valign="top" style="padding-left: 12px;">';
369                for (var i = 0; i < data['info'].length; i++)
370                        content += '<strong>' + data['info'][i]['name'] + '</strong>: ' + data['info'][i]['value'] + '<br/>';
371
372                content += '</td></tr></table>';
373                var pageYLimit = document.body.scrollTop + document.body.clientHeight;
374                var div = $('areaInfo');
375                div.innerHTML = content;
376
377                if ((parseInt(div.style.top.replace(/px/g, '')) + div.getHeight()) > pageYLimit)
378                        div.style.top = (parseInt(div.style.top.replace(/px/g, '')) - (div.getHeight())) + 'px';
379                div.show();
380        }
381        cExecute('$this.bo_userinterface.getAreaInfo', resultGetAreaInfo, 'area_id=' + areaID);
382}
383
384function hideAreaInfo()
385{
386        if (workflowUserInterfaceAreaInfoTimer != null)
387        {
388                workflowUserInterfaceAreaInfoTimer = clearTimeout(workflowUserInterfaceAreaInfoTimer);
389                workflowUserInterfaceAreaInfoTimer = null;
390        }
391        $('areaInfo').hide();
392}
Note: See TracBrowser for help on using the repository browser.