source: trunk/workflow/js/userinterface/orgchart.js @ 1276

Revision 1276, 17.4 KB checked in by rodsouza, 15 years ago (diff)

Ticket #589 - Adicionando paginacao para a listagem alfabetica

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 style="margin: 5px 5px 0 5px">Visualizar : <select>'
37        content += '<option onclick="getAlphabeticalEmployees( )">Alfabética</option>'
38        content += '<option onclick="getHierarchicalArea( );" selected="true">Áreas</option>'
39        content += '<option onclick="getCostCenters( );">Centros de Custo</option>'
40        content += '<option onclick="getManning( )">Lotação</option>'
41        content += '<option onclick="getAreaWithSubtituteBoss( )">Substituição de Chefia</option>'
42        content += '<option onclick="getUsefulPhones( );">Telefones Úteis</option>'
43        content += '<option onclick="getCategoriesList( )">Vínculos</option>'
44        content += '</select></li>';
45        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>';
46        content += '<li><a href="#" onclick="printArea(); return false;"><img src="templateFile.php?file=images/imprimir.png" width="16">&nbsp;&nbsp;Imprimir</a></li>';
47        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>';
48        content += '</ul>';
49        content += '<br/>';
50        content += '<br/>';
51
52        $('orgchartMenu').innerHTML = content;
53}
54
55/* load the initial data */
56function draw_orgchart_folder()
57{
58        $('orgchartMenu').innerHTML = '';
59        $('orgchartAreas').innerHTML = '';
60        $('orgchartEmployees').innerHTML = '<br/><br/><br/><br/><center><i>&nbsp;&nbsp;carregando...<br/><img src="templateFile.php?file=images/loading.gif"></i></center>';
61        $('orgchartFooter').innerHTML = '';
62        $('orgchartMenu').innerHTML = '';
63
64        cExecute("$this.bo_userinterface.orgchart", orgchart, "");
65}
66
67/* process the initial data */
68function orgchart(data)
69{
70        if (_checkError(data))
71                return;
72
73        /* in case of any warning */
74        if (data['warning'])
75        {
76                $('content_id_4').innerHTML = '<br/><br/><center><strong>' + data['warning'] + '</strong></center><br/><br/>';
77                return;
78        }
79
80        if (data['areas'].length == 0)
81        {
82                $('content_id_4').innerHTML = "<br/><br/><center><strong>Nenhuma área cadastrada.</strong></center><br/><br/>";
83                return;
84        }
85
86        /* continue displaying the data */
87        displayHierarchicalAreas(data['areas']);
88        createOrgchartMenu(data['organizacao_id'], data['url_imagem']);
89        $('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>';
90}
91
92function displayCostCenters(data)
93{
94        if (_checkError(data))
95                return;
96
97        var div = $('orgchartEmployees');
98        if (data.length == 0)
99        {
100                div.innerHTML = '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>';
101                return;
102        }
103
104        var content = '<center><h3>CENTROS DE CUSTO</strong></h3>';
105        content += '<table class="employeeList">';
106        content += '<tr><th>Nome</th><th>Número</th><th>Grupo</th></tr>';
107        var current;
108        var costCentersCount = data.length;
109        for (var i = 0; i < costCentersCount; i++)
110        {
111                current = data[i];
112                content += '<tr class="linha'+ i%2 + '">';
113                content += '<td>' + current['descricao'] + '</td>';
114                content += '<td>' + current['nm_centro_custo'] + '</td>';
115                content += '<td>' + current['grupo'] + '</td>';
116                content += '</tr>';
117        }
118        content += '</table>';
119        div.innerHTML = content;
120}
121
122function displayUsefulPhones( data )
123{
124        if ( _checkError( data ) )
125                return;
126
127        var div = $('orgchartEmployees');
128        if (data.length == 0)
129        {
130                div.innerHTML = '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>';
131                return;
132        }
133
134        var content = '';
135        content += '<table class="employeeList">';
136        content += '<tr><th>Localidade</th><th>Número</th></tr>';
137        var current;
138        var usefulPhoneCount = data.length;
139        for (var i = 0; i < usefulPhoneCount; i++)
140        {
141                current = data[i];
142                content += '<tr class="linha'+ i%2 + '">';
143                content += '<td>' + current[ 'descricao' ] + '</td>';
144                content += '<td>' + current[ 'numero' ] + '</td>';
145                content += '</tr>';
146        }
147        content += '</table>';
148        div.innerHTML = content;
149}
150
151function displayAreaWithSubtituteBoss( data )
152{
153        if ( _checkError( data ) )
154                return;
155
156        var div = $('orgchartEmployees');
157        if (data.length == 0)
158        {
159                div.innerHTML = '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>';
160                return;
161        }
162
163        var content = '';
164        content += '<table class="employeeList">';
165        content += '<tr><th>Área</th><th>Titular</th><th>Substituto</th></tr>';
166        var current;
167        var usefulPhoneCount = data.length;
168        for (var i = 0; i < usefulPhoneCount; i++)
169        {
170                current = data[i];
171                content += '<tr class="linha'+ i%2 + '">';
172                content += '<td>' + current['area'] + '</td>';
173                content += '<td>' + current['titular'] + '</td>';
174                content += '<td>' + current['substituto'] + '</td>';
175                content += '</tr>';
176        }
177        content += '</table>';
178        div.innerHTML = content;
179}
180
181function displayHierarchicalAreas(data)
182{
183        if (_checkError(data))
184                return;
185
186        function recursivePrint(subdata)
187        {
188                for (var i = 0; i < subdata.length; i++)
189                {
190                        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>';
191                        if (subdata[i]['children'].length > 0)
192                                recursivePrint(subdata[i]['children']);
193                }
194        }
195
196        var div = $('orgchartAreas');
197        div.innerHTML = "<center><strong>ÁREAS</strong></center>";
198        recursivePrint(data);
199}
200
201function getUsefulPhones( )
202{
203        cExecute("$this.bo_userinterface.getUsefulPhones", displayUsefulPhones, "");
204}
205
206function getAreaWithSubtituteBoss( )
207{
208        cExecute("$this.bo_userinterface.getAreaWithSubtituteBoss", displayAreaWithSubtituteBoss, "");
209}
210
211function getCostCenters()
212{
213        cExecute("$this.bo_userinterface.getCostCenters", displayCostCenters, "");
214}
215
216function getHierarchicalArea()
217{
218        cExecute("$this.bo_userinterface.getHierarchicalArea", displayHierarchicalAreas, "");
219}
220
221function getAreaList()
222{
223        cExecute("$this.bo_userinterface.getAreaList", displayHierarchicalAreas, "");
224}
225
226function getCategoriesList()
227{
228        function resultGetCategoriesList(data)
229        {
230                if (_checkError(data))
231                        return;
232
233                var content = '<center><strong>VÍNCULOS</strong></center>';
234                for (var i = 0; i < data.length; i++)
235                        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>';
236                content += '<br/><br/>';
237                $('orgchartAreas').innerHTML = content;
238        }
239
240        cExecute("$this.bo_userinterface.getCategoriesList", resultGetCategoriesList, "");
241}
242
243function getManning( )
244{
245        function resultGetManning( data )
246        {
247                if ( _checkError( data ) )
248                        return;
249
250                var content = '<center><strong>Lotalidades</strong></center>';
251                for ( var i = 0; i < data.length; i++ )
252                        content += '<br/>' + '&nbsp;<a href="javascript:void(0)" id="localidade_' + data[i]['localidade_id'] + '" onclick="tmp = $$(\'div#orgchartAreas a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); this.addClassName(\'destaque\');loadManningEmployees(' + data[i]['localidade_id'] + ')">' + data[i]['descricao'] + '</a>';
253
254                content += '<br/><br/>';
255
256                $('orgchartAreas').innerHTML = content;
257        }
258
259        cExecute("$this.bo_userinterface.getManning", resultGetManning, "");
260}
261
262function printEmployeesHandler(data)
263{
264        /* check for errors */
265        if (_checkError(data))
266                return;
267
268        var div = $('orgchartEmployees');
269
270        /* no employee to list */
271        if (data['employees'].length == 0)
272        {
273                div.innerHTML = '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>';
274                return;
275        }
276
277        /* initialize varivables */
278        var content = '';
279        var employees = data['employees'];
280        var useCategories = false;
281        var useArea = false;
282
283        /* check the informations that will be displayed */
284        if (data['categories'])
285                if (data['categories'].length > 1)
286                        useCategories = true;
287        if (employees[0]['area'])
288                useArea = true;
289
290        /* build the display table (headers)*/
291        content += '<table id="employeeList" class="employeeList" style="clear: both">';
292        content += '<tr>';
293        content += '<th>Funcionário</th>';
294        if (useArea)
295                content += '<th>Área</th>';
296        content += '<th>Telefone</th>';
297        content += '</tr>';
298
299        /* if available, insert a menu to filter the categories */
300        if (useCategories)
301        {
302                content += '<tr><td colspan="' + (useArea ? '3' : '2') + '">';
303                content += '<ul class="horizontalMenu">';
304                for (var i = 0; i < data['categories'].length; i++)
305                        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>';
306                content += '</ul>';
307                content += '</td></tr>';
308        }
309
310        /* list the employees */
311        var complement = '';
312        for (var i = 0; i < employees.length; i++)
313        {
314                if (employees[i]['chief'])
315                        complement = ' <strong>(' + ((employees[i]['chief'] == 1) ? 'Titular' : 'Substituto') + ')</strong>';
316                else
317                        complement = '';
318                if (employees[i]['removed'])
319                        complement += ' <font color="red">(excluído)</font>';
320                content += '<tr class="linha'+ i%2 + (useCategories ? ' categoria_' + employees[i]['funcionario_categoria_id'] : '') + '">';
321                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>';
322                if (useArea)
323                        content += '<td>' + employees[i]['area'] + '</td>';
324                content += '<td align="center">' + employees[i]['telephoneNumber'] + '</td>';
325                content += '</tr>';
326        }
327        content += '</table>';
328
329        /* display the employees list and go to the top of the page */
330        div.innerHTML = content;
331        window.scrollTo(0,0);
332}
333
334function highlightCategory(categoryID)
335{
336        var rows = $('employeeList').childNodes[0].childNodes;
337        var categoryClass = 'categoria_' + categoryID;
338
339        var highlightClass = '';
340        var row;
341        for (var i = 1; i < rows.length; i++)
342        {
343                row = $(rows[i]);
344                /* in case alternated color rows are needed, just change the second 'highlight0' to something else (e.g. 'highlight1' which is alread defined) */
345                highlightClass = row.hasClassName('linha0') ? 'highlight0' : 'highlight0';
346                if (row.hasClassName(categoryClass))
347                        row.addClassName(highlightClass);
348                else
349                        row.removeClassName(highlightClass);
350        }
351}
352
353function loadAreaEmployees(areaID)
354{
355        workflowUserInterfaceCurrentAreaID = areaID;
356        cExecute('$this.bo_userinterface.getAreaEmployees', printEmployeesHandler, 'areaID=' + areaID);
357}
358
359function loadCategoryEmployees(categoryID)
360{
361        workflowUserInterfaceCurrentAreaID = 0;
362        cExecute('$this.bo_userinterface.getCategoryEmployees', printEmployeesHandler, 'categoryID=' + categoryID);
363}
364
365function loadManningEmployees( locationID )
366{
367        workflowUserInterfaceCurrentAreaID = 0;
368        cExecute('$this.bo_userinterface.getManningEmployees', printEmployeesHandler, 'locationID=' + locationID);
369}
370
371function getAlphabeticalEmployees( )
372{
373        workflowUserInterfaceCurrentAreaID = 0;
374
375        var div = $('orgchartEmployees');
376        div.innerHTML = '';
377
378        var p_page = 0;
379        if ( arguments.length )
380        {
381                p_page = parseInt(arguments[ 0 ]);
382                if ( isNaN( p_page ) )
383                        p_page = 0;
384        }
385        cExecute('$this.bo_userinterface.getAlphabeticalEmployees', function( data )
386        {
387                var pagingData = data['paging_links'];
388                var output = '';
389                if (pagingData)
390                {
391                        var pagingSize = pagingData.length;
392                        for (var i = 0; i < pagingSize; i++)
393                        {
394                                if (pagingData[i].do_link == true)
395                                        output += '<a style="font-size: medium" href="#" onclick="getAlphabeticalEmployees(' + pagingData[i].p_page + ');">' + pagingData[i].name + '</a>&nbsp;';
396                                else
397                                        output += '<strong style="font-size: large">' + pagingData[i].name + '</strong>&nbsp;';
398                        }
399                }
400
401                printEmployeesHandler( data );
402
403                div.innerHTML += '<br /><center>' + output + '</center>';
404        }, 'p_page='+p_page);
405}
406
407function orgchartSearchEmployee(searchTerm)
408{
409        workflowUserInterfaceCurrentAreaID = 0;
410        cExecute('$this.bo_userinterface.searchEmployee', printEmployeesHandler, 'searchTerm=' + searchTerm);
411}
412
413function printArea()
414{
415        if (workflowUserInterfaceCurrentAreaID == 0)
416                if (!confirm('Tem certeza de que deseja imprimir todo o Organograma?'))
417                        return false;
418        var endereco = '../index.php?menuaction=workflow.ui_userinterface.printArea&areaID=' + workflowUserInterfaceCurrentAreaID;
419        window.open(endereco, 'extwindow');
420}
421
422function getEmployeeInfoTimer(e, employeeID)
423{
424        var div = $('employeeInfo');
425        div.style.left = (Event.pointerX(e) + 20) + 'px';
426        div.style.top = (Event.pointerY(e) + 14) + 'px';
427
428        if (workflowUserInterfaceEmployeeInfoTimer != null)
429        {
430                workflowUserInterfaceEmployeeInfoTimer = clearTimeout(workflowUserInterfaceEmployeeInfoTimer);
431                workflowUserInterfaceEmployeeInfoTimer = null;
432        }
433
434        workflowUserInterfaceEmployeeInfoTimer = setTimeout('getEmployeeInfo(' + employeeID + ')', 500);
435}
436
437function getEmployeeInfo(employeeID)
438{
439        function resultGetEmployeeInfo(data)
440        {
441                if (workflowUserInterfaceEmployeeInfoTimer == null)
442                        return;
443
444                workflowUserInterfaceEmployeeInfoTimer = clearTimeout(workflowUserInterfaceEmployeeInfoTimer);
445                workflowUserInterfaceEmployeeInfoTimer = null;
446
447                var content = '';
448                content += '<table><tr><td valign="top">';
449                content += '<img src="showUserPicture.php?userID=' + employeeID + '"/>';
450                content += '</td><td valign="top" style="padding-left: 12px;">';
451                for (var i = 0; i < data['info'].length; i++)
452                        content += '<strong>' + data['info'][i]['name'] + '</strong>: ' + data['info'][i]['value'] + '<br/>';
453
454                content += '</td></tr></table>';
455                var pageYLimit = document.body.scrollTop + document.body.clientHeight;
456                var div = $('employeeInfo');
457                div.innerHTML = content;
458
459                if ((parseInt(div.style.top.replace(/px/g, '')) + div.getHeight()) > pageYLimit)
460                        div.style.top = (parseInt(div.style.top.replace(/px/g, '')) - (div.getHeight())) + 'px';
461                div.show();
462        }
463        cExecute('$this.bo_userinterface.getEmployeeInfo', resultGetEmployeeInfo, 'funcionario_id=' + employeeID);
464}
465
466function hideEmployeeInfo()
467{
468        if (workflowUserInterfaceEmployeeInfoTimer != null)
469        {
470                workflowUserInterfaceEmployeeInfoTimer = clearTimeout(workflowUserInterfaceEmployeeInfoTimer);
471                workflowUserInterfaceEmployeeInfoTimer = null;
472        }
473        $('employeeInfo').hide();
474}
475
476function getAreaInfoTimer(e, areaID)
477{
478        var div = $('areaInfo');
479        div.style.left = (Event.pointerX(e) + 20) + 'px';
480        div.style.top = (Event.pointerY(e) + 14) + 'px';
481
482        if (workflowUserInterfaceAreaInfoTimer != null)
483        {
484                workflowUserInterfaceAreaInfoTimer = clearTimeout(workflowUserInterfaceAreaInfoTimer);
485                workflowUserInterfaceAreaInfoTimer = null;
486        }
487
488        workflowUserInterfaceAreaInfoTimer = setTimeout('getAreaInfo(' + areaID + ')', 500);
489}
490
491function getAreaInfo(areaID)
492{
493        function resultGetAreaInfo(data)
494        {
495                if (workflowUserInterfaceAreaInfoTimer == null)
496                        return;
497
498                workflowUserInterfaceAreaInfoTimer = clearTimeout(workflowUserInterfaceAreaInfoTimer);
499                workflowUserInterfaceAreaInfoTimer = null;
500
501                var content = '';
502                content += '<table><tr>';
503                content += '<td valign="top" style="padding-left: 12px;">';
504                for (var i = 0; i < data['info'].length; i++)
505                        content += '<strong>' + data['info'][i]['name'] + '</strong>: ' + data['info'][i]['value'] + '<br/>';
506
507                content += '</td></tr></table>';
508                var pageYLimit = document.body.scrollTop + document.body.clientHeight;
509                var div = $('areaInfo');
510                div.innerHTML = content;
511
512                if ((parseInt(div.style.top.replace(/px/g, '')) + div.getHeight()) > pageYLimit)
513                        div.style.top = (parseInt(div.style.top.replace(/px/g, '')) - (div.getHeight())) + 'px';
514                div.show();
515        }
516        cExecute('$this.bo_userinterface.getAreaInfo', resultGetAreaInfo, 'area_id=' + areaID);
517}
518
519function hideAreaInfo()
520{
521        if (workflowUserInterfaceAreaInfoTimer != null)
522        {
523                workflowUserInterfaceAreaInfoTimer = clearTimeout(workflowUserInterfaceAreaInfoTimer);
524                workflowUserInterfaceAreaInfoTimer = null;
525        }
526        $('areaInfo').hide();
527}
Note: See TracBrowser for help on using the repository browser.