source: trunk/workflow/js/orgchart/organization.js @ 1245

Revision 1245, 37.9 KB checked in by rodsouza, 15 years ago (diff)

Ticket #589 - itens (doc. anexo ao ticket) 1, 2, 3, 4 e 5 integralmente e item 6 parcialmente.

  • Property svn:executable set to *
Line 
1String.prototype.repeat = function(l)
2{
3        return new Array(l+1).join(this);
4};
5
6var workflowOrgchartAdminEmployeeInfoTimer = null;
7var workflowOrgchartAdminAreaInfoTimer = null;
8
9var CadastroAjax = Class.create();
10
11CadastroAjax.prototype =
12{
13        initialize: function()
14        {
15                this.name = '';
16                this.required = new Array();
17                this.tableHeader = new Array();
18                this.combo = new Array();
19        },
20
21        add: function()
22        {
23                for (var i = 0; i < this.required.length; i++)
24                {
25                        if ($F(this.required[i]) == '')
26                        {
27                                alert("Campo necessário ausente: " + $(this.required[i]).parentNode.parentNode.childNodes[0].childNodes[0].innerHTML);
28                                $(this.required[i]).focus();
29                                return;
30                        }
31                }
32                var cb = function(data)
33                {
34                        if (!handleError(data))
35                                return;
36
37                        /* update the screen info */
38                        if (this.name.toLowerCase() == "organization")
39                                listOrganizations();
40                        else
41                        {
42                                if ($('organizacao_id'))
43                                {
44                                        var index = $F('organizacao_id');
45                                        if (refreshAreas[index])
46                                                refreshAreas[index]();
47                                }
48                        }
49
50                        valid.deactivate();
51                };
52
53                return this.ajaxAction('add', cb, Form.serialize($('orgchartForm')));
54        },
55
56        update: function()
57        {
58                for (var i = 0; i < this.required.length; i++)
59                {
60                        if ($F(this.required[i]) == '')
61                        {
62                                alert("Campo necessário ausente: " + $(this.required[i]).parentNode.parentNode.childNodes[0].childNodes[0].innerHTML);
63                                $(this.required[i]).focus();
64                                return;
65                        }
66                }
67                var cb = function(data)
68                {
69                        if (!handleError(data))
70                                return;
71
72                        /* update the screen info */
73                        if (this.name.toLowerCase() == "organization")
74                                listOrganizations();
75                        else
76                        {
77                                if ($('organizacao_id'))
78                                {
79                                        var index = $F('organizacao_id');
80                                        if (refreshAreas[index])
81                                                refreshAreas[index]();
82                                }
83                        }
84
85                        valid.deactivate();
86                };
87
88                return this.ajaxAction('update', cb, Form.serialize($('orgchartForm')));
89        },
90
91        remove: function(params, linkRemove)
92        {
93
94                if (linkRemove.addClassName)
95                        linkRemove.addClassName('alerta');
96                if (confirm("Tem certeza que deseja excluir o registro selecionado?"))
97                {
98                        var cb = function(data)
99                        {
100                                if (!handleError(data))
101                                        return;
102
103                                /* update the screen info */
104                                if (this.name.toLowerCase() == "organization")
105                                        listOrganizations();
106                                else
107                                {
108                                        var index = $('organizacao_id') ? $F('organizacao_id') : params['organizacao_id'];
109                                        if (refreshAreas[index])
110                                                refreshAreas[index]();
111                                }
112
113                                if ($('lbContent'))
114                                        valid.deactivate();
115                        };
116                        return this.ajaxAction('remove', cb, $H(params).toQueryString());
117                }
118                else
119                        if (linkRemove.removeClassName)
120                                linkRemove.removeClassName('alerta');
121        },
122
123        list: function(callback, params)
124        {
125                return this.ajaxAction('list', callback, $H(params).toQueryString());
126        },
127
128        generateTable: function(params, displayArea)
129        {
130                tableHeader = this.tableHeader;
131                var tableResult = function(data)
132                {
133                        if (!handleError(data))
134                                return;
135
136                        if (data.length == 0)
137                        {
138                                displayArea.innerHTML += '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>';
139                                return true;
140                        }
141
142                        for (var i = 0; i < data.length; i++)
143                        {
144                                data[i]['tr_attributes'] = new Array();
145                                data[i]['tr_attributes']['class'] = "linha" + i%2;;
146                                data[i]['tr_attributes']['className'] = "linha" + i%2;;
147                        }
148
149                        var tableAtributes = new Array();
150                        tableAtributes['id'] = this.name + 'List';
151                        tableAtributes['class'] = 'organizationList';
152                        tableAtributes['className'] = 'organizationList';
153                        displayArea.appendChild(constructTable(tableHeader, data, tableAtributes));
154                };
155                this.list(tableResult, params);
156        },
157
158        generateUpdateTable: function(params, displayArea)
159        {
160                tableHeader = this.tableHeader;
161                if (!tableHeader['actions'])
162                        tableHeader['actions'] = "Ações";
163                name = this.name.charAt(0).capitalize() + this.name.substr(1);
164                var tableResult = function(data)
165                {
166                        if (!handleError(data))
167                                return;
168
169                        if (data.length == 0)
170                        {
171                                displayArea.innerHTML += '<br/><br/><center><strong>Nenhum registro encontrado</strong></center>';
172                                return true;
173                        }
174
175                        for (var i = 0; i < data.length; i++)
176                        {
177                                var dataHash = new Hash();
178                                for (j in data[i])
179                                        if (typeof data[i][j] != "function")
180                                        {
181                                                dataHash[j] = data[i][j];
182                                                if ( dataHash[j] == null )
183                                                        dataHash[j] = '';
184                                        }
185
186                                for (j in tableHeader)
187                                        if (typeof tableHeader[j] != "function")
188                                                if (j != 'actions')
189                                                        data[i][j] = '<a href="#" onclick="obj' + name + '.fillForm(' + dataHash.customInspect() + '); return false;">' + data[i][j] + '</a>';
190
191                                data[i]['tr_attributes'] = new Array();
192                                data[i]['tr_attributes']['class'] = "linha" + i%2;
193                                data[i]['tr_attributes']['className'] = "linha" + i%2;
194                                data[i]['actions'] = '<a href="#" onclick="obj' + name + '.remove(' + dataHash.customInspect() + ' , this.parentNode.parentNode); return false;"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/button_cancel.png" /></a>';
195                        }
196
197                        var tableAtributes = new Array();
198                        tableAtributes['id'] = this.name + 'List';
199                        tableAtributes['class'] = 'orgchartUpdateTable';
200                        tableAtributes['className'] = 'orgchartUpdateTable';
201                        displayArea.appendChild(constructTable(tableHeader, data, tableAtributes));
202                };
203                this.list(tableResult, params);
204        },
205
206        fillForm: function(dataHash)
207        {
208                dataHash = $H(dataHash);
209                dataHash.each(function(pair)
210                {
211                        var campo = $(pair.key);
212                        if (campo)
213                        {
214                                if ((campo.nodeName == "SELECT") && (pair.value == null))
215                                        campo.value = campo.firstChild.value;
216                                else
217                                        if (pair.value != null)
218                                                campo.value = pair.value;
219                        }
220                        else
221                                new Insertion.Bottom($('orgchartForm'), '<input type="hidden" name="' + pair.key + '" id="' + pair.key + '" value="' + pair.value + '" />');
222                });
223                if (!$('updateOrgchart'))
224                        new Insertion.Bottom($('orgchartForm'), '<input type="hidden" name="updateOrgchart" id="updateOrgchart" value="true" />');
225                var saveButton = $('inserir');
226                saveButton.innerHTML = "Salvar";
227                var name = this.name;
228                saveButton.onclick = function(){ eval('obj' + name.charAt(0).capitalize() + name.substr(1) + '.update();')};
229                var titleObject = $('modalTitle');
230                var title = titleObject.innerHTML.split(' ');
231                title[0] = "Atualizar";
232                titleObject.innerHTML = title.join(' ');
233                $('lightbox').scrollTop = 0;
234        },
235
236        generateComboBox: function(params, displayArea, includeNull, name, callback)
237        {
238                if (!name)
239                        name = this.combo['id'];
240                combo = this.combo;
241                var comboResult = function(data)
242                {
243                        if (!handleError(data))
244                                return;
245
246                        var newFormat = new Array();
247                        if (includeNull)
248                                newFormat['NULL'] = "Nenhum";
249                        for (var i = 0; i < data.length; i++)
250                                newFormat[data[i][combo['id']]] = data[i][combo['name']];
251                        if ((newFormat.length > 0) || includeNull)
252                                displayArea.innerHTML = constructSelectBox(name, newFormat);
253                        else
254                                displayArea.innerHTML = '<i>nenhum registro encontado</i><input type="hidden" id="' + name + '" value=""/>';
255                        if (callback)
256                                callback();
257                };
258                this.list(comboResult, params);
259        },
260
261        ajaxAction: function(action, callback, params)
262        {
263                if (params == "")
264                        cExecute('$this.bo_orgchart.' + action + this.name.charAt(0).capitalize() + this.name.substr(1), callback);
265                else
266                        cExecute('$this.bo_orgchart.' + action + this.name.charAt(0).capitalize() + this.name.substr(1), callback, params);
267        }
268
269};
270
271var CadastroOrganization =
272{
273        name: 'organization',
274        required: new Array('nome', 'descricao', 'ativa'),
275        tableHeader: {'nome': 'Organização'},
276        combo: {'id': 'organizacao_id', 'name': 'nome'}
277};
278var objOrganization = new CadastroAjax();
279Object.extend(objOrganization, CadastroOrganization);
280
281var CadastroEmployeeStatus =
282{
283        name: 'employeeStatus',
284        required: new Array('descricao', 'exibir'),
285        tableHeader: {'descricao': 'Status de Funcionário'},
286        combo: {'id': 'funcionario_status_id', 'name': 'descricao'}
287};
288var objEmployeeStatus = new CadastroAjax();
289Object.extend(objEmployeeStatus, CadastroEmployeeStatus);
290
291var CadastroEmployeeCategory =
292{
293        name: 'employeeCategory',
294        required: new Array('organizacao_id', 'descricao'),
295        tableHeader: {'descricao': 'Nome'},
296        combo: {'id': 'funcionario_categoria_id', 'name': 'descricao'}
297};
298var objEmployeeCategory = new CadastroAjax();
299Object.extend(objEmployeeCategory, CadastroEmployeeCategory);
300
301var CadastroJobTitle =
302{
303        name: 'jobTitle',
304        required: new Array('organizacao_id', 'descricao'),
305        tableHeader: {'descricao': 'Nome'},
306        combo: {'id': 'cargo_id', 'name': 'descricao'}
307};
308var objJobTitle = new CadastroAjax();
309Object.extend(objJobTitle, CadastroJobTitle);
310
311var CadastroAreaStatus =
312{
313        name: 'areaStatus',
314        required: new Array('organizacao_id', 'descricao', 'nivel'),
315        tableHeader: {'descricao': 'Nome', 'nivel': 'Nível'},
316        combo: {'id': 'area_status_id', 'name': 'descricao'}
317};
318var objAreaStatus = new CadastroAjax();
319Object.extend(objAreaStatus, CadastroAreaStatus);
320
321var CadastroCostCenter =
322{
323        name: 'costCenter',
324        required: new Array('organizacao_id', 'nm_centro_custo', 'descricao', 'grupo'),
325        tableHeader: {'nm_centro_custo': 'Número', 'descricao': 'Nome', 'grupo': 'Grupo'},
326        combo: {'id': 'centro_custo_id', 'name': 'descricao'}
327};
328var objCostCenter = new CadastroAjax();
329Object.extend(objCostCenter, CadastroCostCenter);
330
331var CadastroLocal =
332{
333        name: 'local',
334        required: new Array('organizacao_id', 'descricao'),
335        tableHeader: {'descricao': 'Localidade'},
336        combo: {'id': 'localidade_id', 'name': 'descricao'}
337};
338var objLocal = new CadastroAjax();
339Object.extend(objLocal, CadastroLocal);
340
341var CadastroEmployee =
342{
343        name: 'employee',
344        required: new Array('funcionario_id', 'organizacao_id', 'funcionario_status_id', 'centro_custo_id', 'localidade_id', 'area_id'),
345        tableHeader: {'funcionario_id': 'Funcionário'},
346        combo: {'id': 'funcionario_id', 'name': 'funcionario_id'}
347};
348var objEmployee = new CadastroAjax();
349Object.extend(objEmployee, CadastroEmployee);
350
351var CadastroArea =
352{
353        name: 'area',
354        required: new Array('organizacao_id', 'area_status_id', 'centro_custo_id', 'superior_area_id', 'sigla', 'descricao', 'ativa'),
355        tableHeader: {'sigla': 'Área'},
356        combo: {'id': 'area_id', 'name': 'sigla'}
357};
358var objArea = new CadastroAjax();
359Object.extend(objArea, CadastroArea);
360
361var CadastroTelefone =
362{
363        name: 'telephones',
364        required: new Array('organizacao_id', 'descricao', 'numero'),
365        tableHeader: {'descricao': 'Descrição', 'numero': 'Telefones'},
366        combo: {'id': 'telefone_id', 'name': 'descricao'}
367};
368var objTelephones = new CadastroAjax();
369Object.extend(objTelephones, CadastroTelefone);
370
371function createOrganizationLayout(organizationID, organizationDiv)
372{
373        organizationDiv.innerHTML = '<div id="orgchartMenu_' + organizationID + '"></div>';
374        organizationDiv.innerHTML += '<div class="orgchartAreas" id="orgchartAreas_' + organizationID + '"></div>';
375        organizationDiv.innerHTML += '<div class="orgchartEmployees" id="orgchartEmployees_' + organizationID + '"></div>';
376        organizationDiv.innerHTML += '<div class="orgchartFooter"></div>';
377        organizationDiv.innerHTML += '<div id="employeeInfo" class="employeeInfo" style="display: none;"></div>';
378        organizationDiv.innerHTML += '<div id="areaInfo" class="employeeInfo" style="display: none;"></div>';
379
380        createOrganizationMenu(organizationID, $('orgchartMenu_' + organizationID));
381        loadOrganizationAreas(organizationID, $('orgchartAreas_' + organizationID));
382        lb_initialize();
383}
384
385function createOrganizationMenu(organizationID, div)
386{
387        var content = '<ul class="horizontalMenu">';
388        content += '<li><a href="#" onclick="loadAddEmployeeStatusUI(' + organizationID  + '); return false;" class="lbOn">Status de Funcionário</a></li>';
389        content += '<li><a href="#" onclick="loadAddEmployeeCategoryUI(' + organizationID  + '); return false;" class="lbOn">Categorias</a></li>';
390        content += '<li><a href="#" onclick="loadAddJobTitleUI(' + organizationID  + '); return false;" class="lbOn">Cargos</a></li>';
391        content += '<li><a href="#" onclick="loadAddAreaStatusUI(' + organizationID  + '); return false;" class="lbOn">Status de Área</a></li>';
392        content += '<li><a href="#" onclick="loadAddCostCenterUI(' + organizationID  + '); return false;" class="lbOn">Centros de Custo</a></li>';
393        content += '<li><a href="#" onclick="loadAddLocalUI(' + organizationID  + '); return false;" class="lbOn">Localidade</a></li>';
394        content += '<li><a href="#" onclick="loadAddAreaUI(' + organizationID  + '); return false;" class="lbOn">Áreas</a></li>';
395        content += '<li><a href="#" onclick="loadAddEmployeeUI(' + organizationID  + '); return false;" class="lbOn">Funcionários</a></li>';
396        content += '<li><a href="#" onclick="loadAddTelephoneUI(' + organizationID  + '); return false;" class="lbOn">Telefones</a></li>';
397        content += '<li><a><input type="text" name="search_term" id="search_term" onkeypress="if (((window.Event) ? event.which : event.keyCode) == 13) $(\'search_span_' + organizationID  + '\').onclick(); return true;" /> <span id="search_span_' + organizationID + '" onclick="tmp = $$(\'div#orgchartAreas_' + organizationID + ' a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); searchEmployee(' + organizationID + ', $(\'orgchartEmployees_' + organizationID + '\')); return false;">busca</span></a></li>';
398        content += '</ul>';
399        content += '<br/>';
400        content += '<br/>';
401        div.innerHTML = content;
402}
403
404function loadOrganizationAreas(organizationID, div)
405{
406        var loadOrganizationAreasResult = function(data)
407        {
408                function recursivePrint(subdata)
409                {
410                        for (var i = 0; i < subdata.length; i++)
411                        {
412                                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'] + ', ' + organizationID + '); return false;" onmouseout="hideAreaInfo(); return false;" onclick="tmp = $$(\'div#orgchartAreas_' + organizationID + ' a.destaque\'); if (tmp[0]) tmp[0].removeClassName(\'destaque\'); this.addClassName(\'destaque\'); loadAreaEmployees(' + organizationID + ', ' + subdata[i]['area_id'] + ', $(\'orgchartEmployees_' + organizationID + '\'))">' + subdata[i]['sigla'] + '</a>';
413                                if (subdata[i]['children'].length > 0)
414                                        recursivePrint(subdata[i]['children']);
415                        }
416                }
417
418                if (!handleError(data))
419                        return;
420
421                if (data.length == 0)
422                {
423                        div.innerHTML = "<br/><br/><center><strong>Nenhuma área cadastrada.</strong></center><br/><br/>";
424                        return;
425                }
426
427                div.innerHTML = "<center><strong>ÁREAS</strong></center>";
428                recursivePrint(data);
429                if (refreshEmployees[organizationID])
430                        refreshEmployees[organizationID]();
431        };
432
433        objArea.ajaxAction('listHierarchical', loadOrganizationAreasResult, $H({'organizacao_id': organizationID}).toQueryString());
434        refreshAreas[organizationID] = function(){objArea.ajaxAction('listHierarchical', loadOrganizationAreasResult, $H({'organizacao_id': organizationID}).toQueryString());};
435}
436
437function searchEmployee(organizationID, div)
438{
439        var searchEmployeeResult = function(data)
440        {
441                if (!handleError(data))
442                        return;
443
444                div.innerHTML = "";
445                if (data.length == 0)
446                {
447                        div.innerHTML = "<br/><br/><center><strong>Nenhum funcionário encontrado.</strong></center>";
448                        return;
449                }
450
451                var tableHeader = new Array();
452                tableHeader['funcionario_id_desc'] = 'Funcionário';
453                tableHeader['area_sigla'] = 'Área';
454                tableHeader['uid'] = 'UID';
455                tableHeader['actions'] = 'Ações';
456                for (var i = 0; i < data.length; i++)
457                {
458                        var dataHash = new Hash();
459                        for (j in data[i])
460                                if (typeof data[i][j] != "function")
461                                        dataHash[j] = data[i][j];
462
463                        data[i]['tr_attributes'] = new Array();
464                        data[i]['tr_attributes']['class'] = "linha" + i%2;
465                        data[i]['tr_attributes']['className'] = "linha" + i%2;
466                        data[i]['funcionario_id_desc'] = '<a href="javascript:void(0)" class="lbOn" onmouseover="getEmployeeInfoTimer(event, ' + data[i]['funcionario_id'] + ', ' + organizationID + '); return false;" onmouseout="hideEmployeeInfo(); return false;" onclick="loadAddEmployeeUI(' + organizationID + ', function(){objEmployee.fillForm(' + dataHash.customInspect() + ')}); $(\'addEmployeeLink\').parentNode.removeChild($(\'addEmployeeLink\')); return false;">' + data[i]['funcionario_id_desc'] + '</a>' + (data[i]['removed'] ? ' <font color="red">(excluído)</font>' : '');
467                        data[i]['actions'] = '<a href="#" onclick="objEmployee.remove({\'funcionario_id\': ' + data[i]['funcionario_id'] + ', \'organizacao_id\': ' + organizationID + '} , this.parentNode.parentNode); return false;"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/button_cancel.png" /></a>';
468                }
469
470                var tableAtributes = new Array();
471                tableAtributes['class'] = 'employeeList';
472                tableAtributes['className'] = 'employeeList';
473                div.appendChild(constructTable(tableHeader, data, tableAtributes));
474                lb_initialize();
475        };
476
477        objEmployee.ajaxAction('search', searchEmployeeResult, $H({'organizacao_id': organizationID, 'search_term': $F('search_term')}).toQueryString());
478        refreshEmployees[organizationID] = function(){objEmployee.ajaxAction('search', searchEmployeeResult, $H({'organizacao_id': organizationID, 'search_term': $F('search_term')}).toQueryString());};
479}
480
481function loadAreaEmployees(organizationID, areaID, div)
482{
483        var loadAreaEmployeesResult = function(data)
484        {
485                if (!handleError(data))
486                        return;
487
488                var areaLink = $('area_' + areaID);
489                if (!areaLink.hasClassName('destaque'))
490                        areaLink.addClassName('destaque');
491
492                div.innerHTML = "";
493                if (data.length == 0)
494                {
495                        div.innerHTML = "<br/><br/><center><strong>Nenhum funcionário alocado nesta área.</strong></center>";
496                        return;
497                }
498
499                var tableHeader = new Array();
500                tableHeader['funcionario_id_desc'] = 'Funcionário';
501                tableHeader['uid'] = 'UID';
502                tableHeader['actions'] = 'Ações';
503                for (var i = 0; i < data.length; i++)
504                {
505                        var dataHash = new Hash();
506                        for (j in data[i])
507                                if (typeof data[i][j] != "function")
508                                        dataHash[j] = data[i][j];
509
510                        data[i]['tr_attributes'] = new Array();
511                        data[i]['tr_attributes']['class'] = "linha" + i%2;
512                        data[i]['tr_attributes']['className'] = "linha" + i%2;
513                        data[i]['funcionario_id_desc'] = '<a href="javascript:void(0)" class="lbOn" onmouseover="getEmployeeInfoTimer(event, ' + data[i]['funcionario_id'] + ', ' + organizationID + '); return false;" onmouseout="hideEmployeeInfo(); return false;" onclick="loadAddEmployeeUI(' + organizationID + ', function(){objEmployee.fillForm(' + dataHash.customInspect() + ')}); $(\'addEmployeeLink\').parentNode.removeChild($(\'addEmployeeLink\')); return false;">' + data[i]['funcionario_id_desc'] + '</a>' + (data[i]['removed'] ? ' <font color="red">(excluído)</font>' : '');
514                        data[i]['actions'] = '<a href="#" onclick="objEmployee.remove({\'funcionario_id\': ' + data[i]['funcionario_id'] + ', \'organizacao_id\': ' + organizationID + '} , this.parentNode.parentNode); return false;"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/button_cancel.png" /></a>';
515                        window.scrollTo(0,0);
516                }
517
518                var tableAtributes = new Array();
519                tableAtributes['class'] = 'employeeList';
520                tableAtributes['className'] = 'employeeList';
521                div.appendChild(constructTable(tableHeader, data, tableAtributes));
522
523                lb_initialize();
524        };
525
526        objEmployee.ajaxAction('listArea', loadAreaEmployeesResult, $H({'area_id': areaID, 'organizacao_id': organizationID}).toQueryString());
527        refreshEmployees[organizationID] = function(){objEmployee.ajaxAction('listArea', loadAreaEmployeesResult, $H({'area_id': areaID, 'organizacao_id': organizationID}).toQueryString());};
528}
529
530function loadAddEmployeeStatusUI(organizationID)
531{
532        var valoresSimNao = new Array();
533        valoresSimNao['S'] = 'Sim';
534        valoresSimNao['N'] = 'Não';
535
536        var content;
537        content = '<h2 id="modalTitle">Adicionar Status de Funcionário</h2>';
538        content += '<form name="orgchartForm" id="orgchartForm">';
539        content += '<input type="hidden" name="organizacao_id" id="organizacao_id" value="' + organizationID + '" />';
540        content += "<table>";
541        content += '<tr><td><label for="descricao">Nome</label></td><td><input type="text" name="descricao" id="descricao" size="30" /></td></tr>';
542        content += '<tr><td><label for="exibir">Exibir para o usuário</label></td>' + constructSelectBox('exibir', valoresSimNao) + '</td></tr>';
543        content += "</table>";
544        content += '</form>';
545        content += '<button id="inserir" onclick="objEmployeeStatus.add(); return false;">Inserir</button>';
546        content += '<button onclick="valid.deactivate(); return false;">Cancelar</button>';
547
548        var divLB = $('lbContent');
549        divLB.innerHTML = content;
550        $('descricao').focus();
551        objEmployeeStatus.generateUpdateTable({'organizacao_id': organizationID}, divLB);
552}
553
554function loadAddEmployeeCategoryUI(organizationID)
555{
556        var content;
557        content = '<h2 id="modalTitle">Adicionar Categoria</h2>';
558        content += '<form name="orgchartForm" id="orgchartForm">';
559        content += '<input type="hidden" name="organizacao_id" id="organizacao_id" value="' + organizationID + '" />';
560        content += '<table>';
561        content += '<tr><td><label for="descricao">Nome</label></td><td><input type="text" name="descricao" id="descricao" size="30" /></td></tr>';
562        content += "</table>";
563        content += '</form>';
564        content += '<button id="inserir" onclick="objEmployeeCategory.add(); return false;">Inserir</button>';
565        content += '<button onclick="valid.deactivate(); return false;">Cancelar</button>';
566
567        var divLB = $('lbContent');
568        divLB.innerHTML = content;
569        $('descricao').focus();
570        objEmployeeCategory.generateUpdateTable({'organizacao_id': organizationID}, divLB);
571}
572
573function loadAddJobTitleUI(organizationID)
574{
575        var content;
576        content = '<h2 id="modalTitle">Adicionar Cargos</h2>';
577        content += '<form name="orgchartForm" id="orgchartForm">';
578        content += '<input type="hidden" name="organizacao_id" id="organizacao_id" value="' + organizationID + '" />';
579        content += '<table>';
580        content += '<tr><td><label for="descricao">Nome</label></td><td><input type="text" name="descricao" id="descricao" size="30" /></td></tr>';
581        content += "</table>";
582        content += '</form>';
583        content += '<button id="inserir" onclick="objJobTitle.add(); return false;">Inserir</button>';
584        content += '<button onclick="valid.deactivate(); return false;">Cancelar</button>';
585
586        var divLB = $('lbContent');
587        divLB.innerHTML = content;
588        $('descricao').focus();
589        objJobTitle.generateUpdateTable({'organizacao_id': organizationID}, divLB);
590}
591
592function loadAddAreaStatusUI(organizationID)
593{
594        var content;
595        content = '<h2 id="modalTitle">Adicionar Status de Área</h2>';
596        content += '<form name="orgchartForm" id="orgchartForm">';
597        content += '<input type="hidden" name="organizacao_id" id="organizacao_id" value="' + organizationID + '" />';
598        content += '<table>';
599        content += '<tr><td><label for="descricao">Nome</label></td><td><input type="text" name="descricao" id="descricao" size="30" /></td></tr>';
600        content += '<tr><td><label for="nivel">Nível</label></td><td><input type="text" name="nivel" id="nivel" size="3" /></td></tr>';
601        content += "</table>";
602        content += '</form>';
603        content += '<button id="inserir" onclick="objAreaStatus.add(); return false;">Inserir</button>';
604        content += '<button onclick="valid.deactivate(); return false;">Cancelar</button>';
605
606        var divLB = $('lbContent');
607        divLB.innerHTML = content;
608        $('descricao').focus();
609        objAreaStatus.generateUpdateTable({'organizacao_id': organizationID}, divLB);
610}
611
612function loadAddCostCenterUI(organizationID)
613{
614        var content;
615        content = '<h2 id="modalTitle">Adicionar Centro de Custo</h2>';
616        content += '<form name="orgchartForm" id="orgchartForm">';
617        content += '<input type="hidden" name="organizacao_id" id="organizacao_id" value="' + organizationID + '" />';
618        content += "<table>";
619        content += '<tr><td><label for="nm_centro_custo">Número</label></td><td><input type="text" name="nm_centro_custo" id="nm_centro_custo" size="4" /></td></tr>';
620        content += '<tr><td><label for="descricao">Nome</label></td><td><input type="text" name="descricao" id="descricao" size="30" /></td></tr>';
621        content += '<tr><td><label for="grupo">Grupo</label></td><td><input type="text" name="grupo" id="grupo" size="10" /></td></tr>';
622        content += "</table>";
623        content += '</form>';
624        content += '<button id="inserir" onclick="objCostCenter.add(); return false;">Inserir</button>';
625        content += '<button onclick="valid.deactivate(); return false;">Cancelar</button>';
626
627        var divLB = $('lbContent');
628        divLB.innerHTML = content;
629        $('nm_centro_custo').focus();
630        objCostCenter.generateUpdateTable({'organizacao_id': organizationID}, divLB);
631}
632
633function loadAddLocalUI(organizationID)
634{
635        var content;
636        content = '<h2 id="modalTitle">Adicionar Localidade</h2>';
637        content += '<form name="orgchartForm" id="orgchartForm">';
638        content += '<input type="hidden" name="organizacao_id" id="organizacao_id" value="' + organizationID + '" />';
639        content += "<table>";
640        content += '<tr><td><label for="descricao">Nome</label></td><td><input type="text" name="descricao" id="descricao" size="30" /></td></tr>';
641
642        content += '<tr><td><label for="empresa">Empresa</label></td><td><input type="text" name="empresa" id="empresa" size="80" /></td></tr>';
643        content += '<tr><td><label for="endereco">Endereço</label></td><td><input type="text" name="endereco" id="endereco" size="80" /></td></tr>';
644        content += '<tr><td><label for="complemento">Complemento</label></td><td><input type="text" name="complemento" id="complemento" size="50" /></td></tr>';
645        content += '<tr><td><label for="cep">Cep</label></td><td><input type="text" name="cep" id="cep" size="10" /></td></tr>';
646        content += '<tr><td><label for="bairro">Bairro</label></td><td><input type="text" name="bairro" id="bairro" size="30" /></td></tr>';
647        content += '<tr><td><label for="cidade">Cidade</label></td><td><input type="text" name="cidade" id="cidade" size="50" /></td></tr>';
648        content += '<tr><td><label for="uf">UF</label></td><td><input type="text" name="uf" id="uf" size="2" maxlength="2" /></td></tr>';
649
650        content += '<tr><td><label for="centro_custo_id">Centro de Custo</label></td><td id="comboCentroCusto"><i>carregando</i></td></tr>';
651        content += "</table>";
652        content += '</form>';
653        content += '<button id="inserir" onclick="objLocal.add(); return false;">Inserir</button>';
654        content += '<button onclick="valid.deactivate(); return false;">Cancelar</button>';
655
656        var divLB = $('lbContent');
657        divLB.innerHTML = content;
658        $('descricao').focus();
659        objCostCenter.generateComboBox({'organizacao_id': organizationID}, $('comboCentroCusto'), true, null,
660                function()
661                {
662                        objLocal.generateUpdateTable({'organizacao_id': organizationID}, divLB);
663                }
664        );
665}
666
667function loadAddEmployeeUI(organizationID, callback)
668{
669        var content;
670        content = '<h2 id="modalTitle">Adicionar Funcionário</h2>';
671        content += '<form name="orgchartForm" id="orgchartForm">';
672        content += '<input type="hidden" name="organizacao_id" id="organizacao_id" value="' + organizationID + '" />';
673        content += "<table>";
674        content += '<tr><td><label for="funcionario_id_desc">Funcionário</label></td><td>';
675        content += '<input type="hidden" name="funcionario_id" id="funcionario_id" value="" />';
676        content += '<input type="input" name="funcionario_id_desc" id="funcionario_id_desc" value="" readonly="true" size="40" />';
677        content += '<a href="javascript:void(0)" onclick="openParticipants(\'funcionario_id\', \'uid=1&hidegroups=1\');" id="addEmployeeLink"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/add_user.png" /></a>';
678        content += '</td></tr>';
679        content += '<tr><td><label for="funcionario_status_id">Status</label></td><td id="comboStatus"><i>carregando</i></td></tr>';
680        content += '<tr><td><label for="funcionario_categoria_id">Categoria</label></td><td id="comboFuncionarioCategoria"><i>carregando</i></td></tr>';
681        content += '<tr><td><label for="cargo_id">Cargo</label></td><td id="comboCargo"><i>carregando</i></td></tr>';
682
683        content += '<tr><td><label for="titulo">T&iacute;tulo</label></td><td><input type="text" size="30" name="titulo" id="titulo"/></td></tr>';
684
685        content += '<tr><td><label for="nivel">Nível</label></td><td><input type="text" size="3" name="nivel" id="nivel"/></td></tr>';
686        content += '<tr><td><label for="area_id">Área</label></td><td id="comboArea"><i>carregando</i></td></tr>';
687        content += '<tr><td><label for="centro_custo_id">Centro de Custo</label></td><td id="comboCentroCusto"><i>carregando</i></td></tr>';
688        content += '<tr><td><label for="localidade_id">Localidade</label></td><td id="comboLocalidade"><i>carregando</i></td></tr>';
689        content += "</table>";
690        content += '</form>';
691        content += '<button id="inserir" onclick="objEmployee.add(); return false;">Inserir</button>';
692        content += '<button onclick="valid.deactivate(); return false;">Cancelar</button>';
693
694        var divLB = $('lbContent');
695        divLB.innerHTML = content;
696
697        objEmployeeStatus.generateComboBox({'organizacao_id': organizationID}, $('comboStatus'), false, null,
698                function()
699                {
700                        objEmployeeCategory.generateComboBox({'organizacao_id': organizationID}, $('comboFuncionarioCategoria'), true, null,
701                                function()
702                                {
703                                        objJobTitle.generateComboBox({'organizacao_id': organizationID}, $('comboCargo'), true, null,
704                                                function()
705                                                {
706                                                        objArea.generateComboBox({'organizacao_id': organizationID}, $('comboArea'), false, null,
707                                                                function()
708                                                                {
709                                                                        objCostCenter.generateComboBox({'organizacao_id': organizationID}, $('comboCentroCusto'), true, null,
710                                                                                function()
711                                                                                {
712                                                                                        objLocal.generateComboBox({'organizacao_id': organizationID}, $('comboLocalidade'), false, null, callback);
713                                                                                }
714                                                                        )
715                                                                }
716                                                        )
717                                                }
718                                        )
719                                }
720                        )
721                }
722        );
723}
724
725function loadAddAreaUI(organizationID)
726{
727        var valoresSimNao = new Array();
728        valoresSimNao['S'] = 'Sim';
729        valoresSimNao['N'] = 'Não';
730
731        var content;
732        content = '<h2 id="modalTitle">Adicionar Área</h2>';
733        content += '<form name="orgchartForm" id="orgchartForm">';
734        content += '<input type="hidden" name="organizacao_id" id="organizacao_id" value="' + organizationID + '" />';
735        content += "<table>";
736        content += '<tr><td><label for="sigla">Sigla</label></td><td><input type="text" name="sigla" id="sigla" size="15" /></td></tr>';
737        content += '<tr><td><label for="descricao">Nome</label></td><td><input type="text" name="descricao" id="descricao" size="30" /></td></tr>';
738        content += '<tr><td><label for="titular_funcionario_id">Titular</label></td><td>';
739        content += '<input type="hidden" name="titular_funcionario_id" id="titular_funcionario_id" value="" />';
740        content += '<input type="input" name="titular_funcionario_id_desc" id="titular_funcionario_id_desc" value="" readonly="true" size="40" />';
741        content += '<a href="javascript:void(0)" onclick="openParticipants(\'titular_funcionario_id\', \'uid=1&hidegroups=1\');"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/add_user.png" /></a>';
742        content += ' <a href="javascript:void(0)" onclick="$(\'titular_funcionario_id\').value=\'\'; $(\'titular_funcionario_id_desc\').value=\'\'; return false;"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/delete_user.png" /></a>';
743        content += '</td></tr>';
744        content += '<tr><td><label for="substituto_funcionario_id">Substituto</label></td><td>';
745        content += '<input type="hidden" name="substituto_funcionario_id" id="substituto_funcionario_id" value="" />';
746        content += '<input type="input" name="substituto_funcionario_id_desc" id="substituto_funcionario_id_desc" value="" readonly="true" size="40" />';
747        content += '<a href="javascript:void(0)" onclick="openParticipants(\'substituto_funcionario_id\', \'uid=1&hidegroups=1\');"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/add_user.png" /></a>';
748        content += ' <a href="javascript:void(0)" onclick="$(\'substituto_funcionario_id\').value=\'\'; $(\'substituto_funcionario_id_desc\').value=\'\'; return false;"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/delete_user.png" /></a>';
749        content += '</td></tr>';
750        content += '<tr><td><label for="auxiliar_funcionario_id">Auxiliar Administrativo</label></td><td>';
751        content += '<input type="hidden" name="auxiliar_funcionario_id" id="auxiliar_funcionario_id" value="" />';
752        content += '<input type="input" name="auxiliar_funcionario_id_desc" id="auxiliar_funcionario_id_desc" value="" readonly="true" size="40" />';
753        content += '<a href="javascript:void(0)" onclick="openParticipants(\'auxiliar_funcionario_id\', \'uid=1&hidegroups=1\');"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/add_user.png" /></a>';
754        content += ' <a href="javascript:void(0)" onclick="$(\'auxiliar_funcionario_id\').value=\'\'; $(\'auxiliar_funcionario_id_desc\').value=\'\'; return false;"><img border="0" width="16" height="16" src="workflow/templateFile.php?file=images/delete_user.png" /></a>';
755        content += '</td></tr>';
756        content += '<tr><td><label for="area_status_id">Status</label></td><td id="comboStatus"><i>carregando</i></td></tr>';
757        content += '<tr><td><label for="superior_area_id">Área Superior</label></td><td id="comboArea"><i>carregando</i></td></tr>';
758        content += '<tr><td><label for="centro_custo_id">Centro de Custo</label></td><td id="comboCentroCusto"><i>carregando</i></td></tr>';
759        content += '<tr><td><label for="ativa">Ativa</label></td><td>' + constructSelectBox('ativa', valoresSimNao) + '</td></tr>';
760        content += "</table>";
761        content += '</form>';
762        content += '<button id="inserir" onclick="objArea.add(); return false;">Inserir</button>';
763        content += '<button onclick="valid.deactivate(); return false;">Cancelar</button>';
764
765        var divLB = $('lbContent');
766        divLB.innerHTML = content;
767        $('sigla').focus();
768
769        objAreaStatus.generateComboBox({'organizacao_id': organizationID}, $('comboStatus'), false, null,
770                function()
771                {
772                        objArea.generateComboBox({'organizacao_id': organizationID}, $('comboArea'), true, 'superior_area_id',
773                                function()
774                                {
775                                        objCostCenter.generateComboBox({'organizacao_id': organizationID}, $('comboCentroCusto'), false, null,
776                                                function()
777                                                {
778                                                        objArea.generateUpdateTable({'organizacao_id': organizationID}, divLB);
779                                                }
780                                        )
781                                }
782                        )
783                }
784        );
785}
786
787function loadAddTelephoneUI(organizationID)
788{
789        var content;
790        content = '<h2 id="modalTitle">Adicionar Telefones da Organização</h2>';
791        content += '<form name="orgchartForm" id="orgchartForm">';
792        content += '<input type="hidden" name="organizacao_id" id="organizacao_id" value="' + organizationID + '" />';
793        content += '<table>';
794        content += '<tr><td><label for="descricao">Descrição</label></td><td><input type="text" name="descricao" id="descricao" size="50" /></td></tr>';
795        content += '<tr><td><label for="nivel">Telefones</label></td><td><input type="text" name="numero" id="numero" size="50" /></td></tr>';
796        content += "</table>";
797        content += '</form>';
798        content += '<button id="inserir" onclick="objTelephones.add(); return false;">Inserir</button>';
799        content += '<button onclick="valid.deactivate(); return false;">Cancelar</button>';
800
801        var divLB = $( 'lbContent' );
802        divLB.innerHTML = content;
803        $( 'descricao' ).focus( );
804        objTelephones.generateUpdateTable( { 'organizacao_id' : organizationID }, divLB );
805}
806
807function getEmployeeInfoTimer(e, employeeID, organizationID)
808{
809        var div = $('employeeInfo');
810        div.style.left = (Event.pointerX(e) + 20) + 'px';
811        div.style.top = (Event.pointerY(e) + 14) + 'px';
812
813        if (workflowOrgchartAdminEmployeeInfoTimer != null)
814        {
815                workflowOrgchartAdminEmployeeInfoTimer = clearTimeout(workflowOrgchartAdminEmployeeInfoTimer);
816                workflowOrgchartAdminEmployeeInfoTimer = null;
817        }
818
819        workflowOrgchartAdminEmployeeInfoTimer = setTimeout('getEmployeeInfo(' + employeeID + ', ' + organizationID + ' )', 500);
820}
821
822function getEmployeeInfo(employeeID, organizationID)
823{
824        function resultGetEmployeeInfo(data)
825        {
826                if (workflowOrgchartAdminEmployeeInfoTimer == null)
827                        return;
828
829                workflowOrgchartAdminEmployeeInfoTimer = clearTimeout(workflowOrgchartAdminEmployeeInfoTimer);
830                workflowOrgchartAdminEmployeeInfoTimer = null;
831
832                var content = '';
833                content += '<table><tr><td valign="top">';
834                content += '<img src="workflow/showUserPicture.php?userID=' + employeeID + '"/>';
835                content += '</td><td valign="top" style="padding-left: 12px;">';
836                for (var i = 0; i < data['info'].length; i++)
837                        content += '<strong>' + data['info'][i]['name'] + '</strong>: ' + data['info'][i]['value'] + '<br/>';
838                content += '</td></tr></table>';
839                var pageYLimit = document.body.scrollTop + document.body.clientHeight;
840                var div = $('employeeInfo');
841                div.innerHTML = content;
842
843                if ((parseInt(div.style.top.replace(/px/g, '')) + div.getHeight()) > pageYLimit)
844                        div.style.top = (parseInt(div.style.top.replace(/px/g, '')) - (div.getHeight())) + 'px';
845
846                div.show();
847        }
848        cExecute('$this.bo_orgchart.getEmployeeInfo', resultGetEmployeeInfo, 'funcionario_id=' + employeeID + '&organizacao_id=' + organizationID);
849}
850
851function hideEmployeeInfo()
852{
853        if (workflowOrgchartAdminEmployeeInfoTimer != null)
854        {
855                workflowOrgchartAdminEmployeeInfoTimer = clearTimeout(workflowOrgchartAdminEmployeeInfoTimer);
856                workflowOrgchartAdminEmployeeInfoTimer = null;
857        }
858        $('employeeInfo').hide();
859}
860
861function getAreaInfoTimer(e, areaID, organizationID)
862{
863        var div = $('areaInfo');
864        div.style.left = (Event.pointerX(e) + 20) + 'px';
865        div.style.top = (Event.pointerY(e) + 14) + 'px';
866
867        if (workflowOrgchartAdminAreaInfoTimer != null)
868        {
869                workflowOrgchartAdminAreaInfoTimer = clearTimeout(workflowOrgchartAdminAreaInfoTimer);
870                workflowOrgchartAdminAreaInfoTimer = null;
871        }
872
873        workflowOrgchartAdminAreaInfoTimer = setTimeout('getAreaInfo(' + areaID + ', ' + organizationID + ' )', 500);
874}
875
876function getAreaInfo(areaID, organizationID)
877{
878        function resultGetAreaInfo(data)
879        {
880                if (workflowOrgchartAdminAreaInfoTimer == null)
881                        return;
882
883                workflowOrgchartAdminAreaInfoTimer = clearTimeout(workflowOrgchartAdminAreaInfoTimer);
884                workflowOrgchartAdminAreaInfoTimer = null;
885
886                var content = '';
887                content += '<table><tr>';
888                content += '<td valign="top" style="padding-left: 12px;">';
889                for (var i = 0; i < data['info'].length; i++)
890                        content += '<strong>' + data['info'][i]['name'] + '</strong>: ' + data['info'][i]['value'] + '<br/>';
891                content += '</td></tr></table>';
892                var pageYLimit = document.body.scrollTop + document.body.clientHeight;
893                var div = $('areaInfo');
894                div.innerHTML = content;
895
896                if ((parseInt(div.style.top.replace(/px/g, '')) + div.getHeight()) > pageYLimit)
897                        div.style.top = (parseInt(div.style.top.replace(/px/g, '')) - (div.getHeight())) + 'px';
898
899                div.show();
900        }
901        cExecute('$this.bo_orgchart.getAreaInfo', resultGetAreaInfo, 'area_id=' + areaID + '&organizacao_id=' + organizationID);
902}
903
904function hideAreaInfo()
905{
906        if (workflowOrgchartAdminAreaInfoTimer != null)
907        {
908                workflowOrgchartAdminAreaInfoTimer = clearTimeout(workflowOrgchartAdminAreaInfoTimer);
909                workflowOrgchartAdminAreaInfoTimer = null;
910        }
911        $('areaInfo').hide();
912}
Note: See TracBrowser for help on using the repository browser.