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

Revision 1269, 16.8 KB checked in by rodsouza, 15 years ago (diff)

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