function checkError(data) { if (data['error']) { alert(data['error']); return true; } return false; } function buildLayout() { var content = ''; content += ''; content += '
'; content += '
'; content += '    
'; content += '
'; content += ''; content += ''; content += ''; $('conteudo').innerHTML = content; $('post_div').hide(); $('image_div').hide(); loadExternalApplications(); } function clearApplicationData() { $('name').value = ''; $('description').value = ''; $('address').value = ''; $('authentication').checked = false; $('post').value = ''; $('external_application_id').value = ''; $('image').value = ''; $('image_tmp').value = ''; $('current_image').src = ''; $('remove_current_image').checked = false; $('post_div').hide(); $('image_div').hide(); if (!$('externalApplicationData').visible()) Effect.BlindDown('externalApplicationData'); } function getExternalApplication(externalApplicationID) { function resultGetExternalApplication(data) { if (checkError(data)) return; if (!data) return; clearApplicationData(); $('name').value = data['name']; $('description').value = data['description']; $('address').value = data['address']; $('intranet_only').checked = (data['intranet_only'] == '1')? true : false; $('authentication').checked = (data['authentication'] == '1')? true : false; if ($('authentication').checked) $('post_div').show(); else $('post_div').hide(); $('post').value = data['post']; $('external_application_id').value = data['external_application_id']; if (data['image']) { $('current_image').src = _web_server_url + '/workflow/redirect.php?file=/external_applications/' + data['image']; $('image_div').show(); } } cExecute('$this.bo_external_applications.getExternalApplication', resultGetExternalApplication, 'external_application_id=' + externalApplicationID); } function loadExternalApplications() { function resultLoadExternalApplications(data) { var output = ''; for (var i = 0; i < data.length; i++) output += ''; var obj = $('externalApplications'); /* IE MAGIC */ if (obj.outerHTML) { obj.innerHTML = ''; obj.outerHTML = obj.outerHTML.match(/]*>/gi) + output + ''; } else obj.innerHTML = output; } cExecute('$this.bo_external_applications.getExternalApplications', resultLoadExternalApplications); } function sendContents() { if ($F('name') == '') { alert('É necessário informar um nome para a aplicação externa.'); return; } if ($F('address') == '') { alert('É necessário informar um endereço para a aplicação externa.'); return; } var address = $F('address'); if (address.match(/^[a-zA-Z]+:\/\//) == null) { alert('Aparentemente a URL informada não está formatada corretamente.\nTente utilizar o endereço completo. Exemplo:\nhttp://expresso.pr.gov.br'); return; } function resultSendContents(data) { if (checkError(data)) return; Effect.BlindUp('externalApplicationData'); loadExternalApplications(); } if (($F('image_tmp') != '') && ($F('image') == '')) $('image_tmp_form').submit(); else { var params = 'name=' + escape($F('name')); params += '&description=' + escape($F('description')); params += '&address=' + escape($F('address')); params += '&intranet_only=' + (($F('intranet_only') == 'on') ? '1' : '0'); params += '&authentication=' + (($F('authentication') == 'on') ? '1' : '0'); params += '&post=' + escape($F('post')); params += '&image=' + $F('image'); if ($F('external_application_id') != '') // update cExecute('$this.bo_external_applications.updateExternalApplication', resultSendContents, params + '&external_application_id=' + $F('external_application_id') + '&remove_current_image=' + (($F('remove_current_image') == 'on') ? '1' : '0')); else //insert cExecute('$this.bo_external_applications.addExternalApplication', resultSendContents, params + '&external_application_id=' + $F('external_application_id')); } } function removeExternalApplication(externalApplicationID) { if (externalApplicationID == '') return; function resultRemoveExternalApplication(data) { if (checkError(data)) return; loadExternalApplications(); } if (confirm('Tem certeza que deseja excluir a Aplicação Externa selecionada?')) { cExecute('$this.bo_external_applications.removeExternalApplication', resultRemoveExternalApplication, 'external_application_id=' + externalApplicationID); Effect.BlindUp('externalApplicationData'); } } Event.observe(window, 'load', function() { buildLayout(); });