<?xml version="1.0" encoding="UTF-8"?>
<panel-form xmlns="http://www.davinti.com.br/vitruvio/form/panel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.davinti.com.br/vitruvio/form/panel https://bitbucket.org/davinTI/vitruvio-xds/raw/master/vitruvio-panel-form.xsd">
   <form formKey="formCadastroPadrao" height="100%" width="100%">
      <name>Sócios</name>
      <description>Cadastro de sócios</description>
      <afterFormRenderScript language="JavaScript">
         <![CDATA[
            var config = { "tabela" :
                              {
                                 "conexao"     : "vitruvio",
                                 "nome"        : "socios" ,
                                 "sequence"    : "socio_seq" ,
                                 "idTabela"    : "CODIGO",
                                 "campos"      : ["CODIGO", "NOME", "PERCENTUAL_PARTICIPACAO" ],
                                 "camposTable" : ["CODIGO", "NOME", "PERCENTUAL_PARTICIPACAO" ],
								 "condicao"	   : "CODIGO > 0"

                              },
                                 "relaciona" : [ ["CODIGO","idChave","Number"] ,
                                                 ["NOME","idDescricao","String"],
												 ["PERCENTUAL_PARTICIPACAO","idParticipacao","Number" ]                                          
                                               ] ,
                                "validacaoExclusao" : [ ["SELECT 0 AS CONTAR FROM SOCIOS WHERE CODIGO = ", "Existem registros ligados a esta tabela"],
                                						["SELECT COUNT(CHAVE_RESPONSAVEL) AS CONTAR FROM CONTROLE_DESPESAS_PESSOAIS WHERE CHAVE_RESPONSAVEL = ", "Existem registros ligados a esta tabela."]
                                                      ],
                                'painel' :
                                {
                                   'titulo' : 'Cadastro de Sócios',
                                   'icone'  : 'data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZ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CZsfI3Qb6UaNj92QdPsND4absrowyV6dUjf2Ynjp+bokH2QzRtMxf8dvla3um3PHBIKOs0QAmiI89oDfo1U3dg2PkDM3xe1JcRcFoMLsDmrVUabV2o/wD+gOZRQ4qPiVjIHyWRZXvAp/srcGoDeRlbsPugnUEkW65rOtVVcnebbNA8nLL7Te2bWotc1loin5dQcZaOKEH/AFEinsTX5Ae3fvTV1c3QbGIY8hn3SfFcaQd2Ty6BVsarFoUaEI0IRoQgiuhCTOa+2tlyC6jy1jcNieQ29DBkYR9RT6BKopu2+DdwOnbprx9XNp8uyTuLMSHUPS8dUu3dl/6BmjNgl7jY0+hslHRXKnpuAKNtPwTUFJOyXcy7OFW+9e3g3szjsJenM5y5ObzzsZDPLUxRue7KHLM7/wAbn4AamjBZ1xX3b8c1rtbzqcqRTXqsUa9QjQhGhC//2Q=='
                                }
                         };
            function run() 
            {        
               engine.setGlobalVariable('config', config);     
            }
         ]]>
         
      </afterFormRenderScript>
      <initScript language="JavaScript">
      <![CDATA[
         importClass(Packages.br.com.davinti.base.vaadin.components.icons.IconFactory);
         importClass(Packages.br.com.davinti.base.vaadin.components.resources.icons16x16.IconLibraryAPISmall);
         importClass(Packages.java.util.Calendar);
         importClass(Packages.br.com.davinti.base.vaadin.components.layout.MessageBox);
         importClass(Packages.com.vaadin.ui.Notification);  
         
         
         var getDataAtual = function() {
            var c = java.util.Calendar.getInstance();
            c.setTime(new java.util.Date());
            c.set(Calendar.HOUR_OF_DAY, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND, 0);
            
            return c.getTime();
         }
         
         
         var fncLimpaCampos = function(){
            var config = engine.getGlobalVariable('config');
            var lib = libService.loadScript('lib_cadastro_padrao');
            var retorno = lib.fncLimpaCampos(config);
         };
         
         var habilitaCampos = function(lHabilita){
            var botaoNovo    = engine.getWidgetController('btnNovo').getButton();
            var botaoSalvar  = engine.getWidgetController('btnSalvar').getButton();                                                                                  
            var botaoExcluir = engine.getWidgetController('btnExcluir').getButton();
            var botaoVoltar = engine.getWidgetController('btnVoltar').getButton();                                    
            
            botaoNovo.setEnabled(true);
            botaoSalvar.setEnabled(lHabilita);
            botaoExcluir.setEnabled(lHabilita);
           
            if(engine.getGlobalVariable('painelLista') == 1) {
            	botaoVoltar.setVisible(false);
            	botaoSalvar.setVisible(false);
            	botaoExcluir.setVisible(false);
            } else {
            	botaoVoltar.setVisible(true);
            	botaoSalvar.setVisible(true);
            	botaoExcluir.setVisible(true);
            }
           
            var config = engine.getGlobalVariable('config');
            var lib = libService.loadScript('lib_cadastro_padrao');
            var retorno = lib.fncHabilitaCampos(config, lHabilita);
            
            engine.getField('idChave').setEnabled(false);
            
            engine.getField('listaPrincipal').refresh();                                                
         };
         
         var novoRegistro = function() {           
            fncLimpaCampos(); 
            
            habilitaCampos(true);      
            engine.getLayout('pnlTitulo').getRootComposition().setVisible(false);
            engine.getLayout('pnlInclusao').getRootComposition().setVisible(true);           
            engine.getWidgetController('btnVoltar').getButton().setVisible(true); 
            engine.getField('idPesquisaLista')['setValue(java.lang.String)'](null);
            engine.getField('listaPrincipal').refresh();
            engine.getField('idPesquisa')['setValue(java.lang.Object)'](null);
            
            engine.getField('idChave').focus(); 
                           
         };
         
         var carregarCampos = function(id) {                         
            
            var config = engine.getGlobalVariable('config');
            var lib = libService.loadScript('lib_cadastro_padrao');
            var sql = lib.fncCarregarCampos(config, id);
            
         };
         
         var telaInicial = function() {
            engine.getLayout('pnlTitulo').getRootComposition().setVisible(true);
            engine.getLayout('pnlInclusao').getRootComposition().setVisible(false);
            var botaoNovo    = engine.getWidgetController('btnNovo').getButton();
            var botaoSalvar  = engine.getWidgetController('btnSalvar').getButton();                                                                                  
            var botaoExcluir = engine.getWidgetController('btnExcluir').getButton();
            var botaoVoltar  = engine.getWidgetController('btnVoltar').getButton();                                    
            
            botaoNovo.setVisible(true);
            botaoNovo.setEnabled(true);
            botaoSalvar.setVisible(false);
            botaoExcluir.setVisible(false);
            botaoVoltar.setVisible(false);
         
         }
         
         var deletarRegistro = function(id) {
            var config = engine.getGlobalVariable('config');
            var lib = libService.loadScript('lib_cadastro_padrao');
            var retorno = lib.fncDeletarRegistro(config, id);
            if (retorno) {
               //engine.getField('idChave').setValue(params.get('id'));              
               engine.getGlobalVariable('fncLimpaCampos')();
               engine.getGlobalVariable('habilitaCampos')(false); 
            }
         } 
         
         var validarDuplicidade = function(valor) {
         	var sql = "Select count(nome) ct from socios where NOME = '" + valor + "'";
         	var db = libService.loadScript('db');
			var dbVitruvio = new db('vitruvio');
			var row = dbVitruvio.queryRow(sql);
			if (row.ct == 0 ) {
				return false;
			} else {
				if (engine.getField('idChave').getValue()) {
					engine.getField('idPesquisa')['setValue(java.lang.Object)'](null);
					return false;
				} else {
					return true;
				}
			}
          }
          
          var validarPercentual = function(id) {
          	var sql = "Select sum(percentual_participacao) ct from socios where codigo > 0 and codigo <> " + id;
         	var db = libService.loadScript('db');
			var dbVitruvio = new db('vitruvio');
			var row = dbVitruvio.queryRow(sql);
			if ((parseFloat(row.ct) + parseFloat(engine.getField('idParticipacao').getValue())) > 100) {
				return false;
			} else {
				return true
			}
          }
        
         
         function run() {     
            var config = engine.getGlobalVariable('config');
            var titulo = config['painel'].titulo;
            var icone  = config['painel'].icone;
           engine.getLabel('Descricaocadastro').setValue('<p align="center"><img align="left" alt="" src="'+ icone + '" width="56" /><p align="center"><font color="Gray" face="Calibri" size="6" >&nbsp;&nbsp;' + titulo + '</font></p></p>');
            engine.getLabel('DescricaocadastroDentro').setValue('<p align="center"><img align="left" alt="" src="'+ icone + '" width="56" /><p align="center"><font color="Gray" face="Calibri" size="6" >&nbsp;&nbsp;' + titulo + '</font></p></p>');
            engine.setGlobalVariable('novoRegistro', novoRegistro);
            engine.setGlobalVariable('carregarCampos', carregarCampos);          
            engine.setGlobalVariable('habilitaCampos', habilitaCampos);          
            engine.setGlobalVariable('fncLimpaCampos', fncLimpaCampos);
            engine.setGlobalVariable('telaInicial', telaInicial); 
            engine.setGlobalVariable('deletarRegistro', deletarRegistro);
            engine.setGlobalVariable('validarDuplicidade', validarDuplicidade);
            engine.setGlobalVariable('painelLista',1);
            engine.setGlobalVariable('validarPercentual',validarPercentual);
            
            habilitaCampos(false);
            
            engine.getWidgetController('btnSalvar').getButton().setIcon(IconFactory.instance().getIconAsResource(IconLibraryAPISmall.APLICAR));
            engine.getWidgetController('btnNovo').getButton().setIcon(IconFactory.instance().getIconAsResource(IconLibraryAPISmall.CRIAR));
            engine.getWidgetController('btnExcluir').getButton().setIcon(IconFactory.instance().getIconAsResource(IconLibraryAPISmall.REMOVER));
            engine.getWidgetController('btnVoltar').getButton().setIcon(IconFactory.instance().getIconAsResource(IconLibraryAPISmall.VOLTAR));
            //engine.getFieldLocked('idAjuda', false);  // pode ser erro no componente, aberto caso Eduardo = 20108
            telaInicial(); 
                  
         }
      ]]>
      </initScript>
      <components>
         <VerticalLayout spacing="false" margin="false" height="100%" width="100%" align="TOP_LEFT" >
            <Panel width="100%" caption="" height="100%" expandRatio="1" margin="false" id="pnlTitulo" align="TOP_LEFT" >
               <VerticalLayout width="100%" expandRatio="1" margin="true">
                  <Label id="Descricaocadastro" contentMode="HTML" align="MIDDLE_CENTER" width="100%" > </Label>
                  <TextField id="idPesquisaLista" caption="Digite aqui para pesquisar:" type="string" width="100%" visible="true" immediate="true">
                     <events>
                        <valueChange>
                          <script language="JavaScript">
                              <![CDATA[
                                 function run(){
                                 	engine.getField('listaPrincipal').refresh();
                                 }
                              ]]>
                           </script>
                        </valueChange>
                     </events> 
                  </TextField>
                  <DBTable id="listaPrincipal" type="number" visible="true" width="100%" immediate="true" rows="5" selectable="false" multivalue="false" showRowCount="true">
                     <datasource>
                        <sqlBuilderDataSource connection-key="vitruvio" language="JavaScript">
                           <![CDATA[
                              
                              var getSql = function() {
                           
                             var config = { "tabela" :
                              {
                                 "conexao"     : "vitruvio",
                                 "nome"        : "socios" ,
                                 "sequence"    : "socio_seq" ,
                                 "idTabela"    : "CODIGO",
                                 "campos"      : ["CODIGO", "NOME", "PERCENTUAL_PARTICIPACAO" ],
                                 "camposTable" : ["CODIGO", "NOME", "PERCENTUAL_PARTICIPACAO" ],
								 "condicao"	   : "CODIGO > 0"

                              },
                                 "relaciona" : [ ["CODIGO","idChave","Number"] ,
                                                 ["NOME","idDescricao","String"],
                                                 ["PERCENTUAL_PARTICIPACAO","idParticipacao","Number"]                                           
                                               ] ,

                                    "validacaoExclusao" : 
                                         [ ["SELECT 0 AS CONTAR FROM SOCIOS WHERE CODIGO = ", "Existem registros ligados a esta tabela"],
                                         	["SELECT COUNT(CHAVE_RESPONSAVEL) AS CONTAR FROM CONTROLE_DESPESAS_PESSOAIS WHERE CHAVE_RESPONSAVEL = ", "Existem registros ligados a esta tabela."]
                                        ],
                                    'painel' :
                                    {
                                       'titulo' : 'Cadastro de Sócios',
                                       'icone'  : 'data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjMtYzAxMSA2Ni4xNDU2NjEsIDIwMTIvMDIvMDYtMTQ6NTY6MjcgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN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+hslHRXKnpuAKNtPwTUFJOyXcy7OFW+9e3g3szjsJenM5y5ObzzsZDPLUxRue7KHLM7/wAbn4AamjBZ1xX3b8c1rtbzqcqRTXqsUa9QjQhGhC//2Q=='
                                    }
                                        
                                       
                                };
                                 var lib = libService.loadScript('lib_cadastro_padrao');
                                 return lib.table(config, 'camposTable');
                              }
                              
                              function buildSQL(params) {
                                 var sql = getSql();
                                 if(engine) {
                                    var idPesquisaLista  = engine.getField('idPesquisaLista').getValue();
                                    if (idPesquisaLista != null) {
                                       sql = "SELECT * FROM ( " +  sql + " ) T WHERE T.NOME LIKE UPPER('%" +  idPesquisaLista + "%')";
                                    }
                                 }
                                 return sql;
                              }
                           ]]>
                        </sqlBuilderDataSource>
                        
                     </datasource>  
                     <key-field>CODIGO</key-field>
                     <columns>                                            
                        <!-- icone de edição -->
                        <generated name="Editar" align="CENTER" >
                           <scriptColumnGenerator language="JavaScript">
                              <![CDATA[
                                 importClass(Packages.br.com.davinti.base.vaadin.components.resources.icons16x16.IconLibraryAPISmall);
                                 importClass(Packages.br.com.davinti.base.vaadin.components.icons.IconFactory);   
                                 
                                 function Generator() {
                                     var comp = libService.loadScript('vaadinComponents');                                    
                                     this.generate = function (itemId, columnId, item, container) {
                                          var btn = comp.buttonIcon('editar', function () {   
                                                                               
                                          var id = itemId;
                                          engine.getField('idChave').setValue(id);
                                          
                                          if (id != null) {
                                          	 engine.setGlobalVariable('painelLista',0);                                     
                                             engine.getGlobalVariable('carregarCampos')(id);
                                             engine.getGlobalVariable('habilitaCampos')(true);   
                                             engine.getLayout('pnlInclusao').getRootComposition().setVisible(true);
                                             engine.getLayout('pnlTitulo').getRootComposition().setVisible(false);                                   
                                          }
                                                                                 
                                         }, 'pencil');                                            
                                      
                                         return btn;
                                     }
                                 }
                                 var script = new Generator();
                              ]]>
                           </scriptColumnGenerator>
                        </generated>
                        
                        <!-- icone de exclusão -->    
                        <generated name="Excluir" align="CENTER" >
                           <scriptColumnGenerator language="JavaScript">
                              <![CDATA[
                                 importClass(Packages.br.com.davinti.base.vaadin.components.layout.ConfirmationBox);
                                 importClass(Packages.br.com.davinti.base.vaadin.components.resources.icons16x16.IconLibraryAPISmall);
                                 importClass(Packages.br.com.davinti.base.vaadin.components.icons.IconFactory);                                 
                                 
                                 function Generator() {
                                     var comp = libService.loadScript('vaadinComponents');                                    
                                     this.generate = function (itemId, columnId, item, container) {
                                         var btn = comp.buttonIcon('excluir', function () {  
                                          
                                          var deletar = engine.getGlobalVariable('deletarRegistro');                                                       
                                          var registro = item.getItemProperty('CODIGO') + " - " + item.getItemProperty('NOME');                                            
                                          var msg = 'Confirma a exclusão das informações para \n'; 
                                          msg = msg.concat(registro, "?"); 
                                                                                                       
                                          ConfirmationBox.show( 'Confirmar operação'
                                                         , msg
                                                         , new ConfirmationBox.ConfirmationBoxListener() {
                                                               dialogEnd: function(context, action) {
                                                                  if(action == ConfirmationBox.Action.YES) {
                                                                     if(deletar){
                                                                     	engine.setGlobalVariable('painelLista',1);
                                                                        deletar(itemId);   
                                                                        engine.getField('listaPrincipal').refresh();                                                                        
                                                                     }
                                                                  }
                                                               }
                                                            }
                                                         ); 
                                         }, 'trash');                                          
                                      
                                         return btn;
                                     }
                                 }
                                 var script = new Generator();
                              ]]>
                           </scriptColumnGenerator>
                        </generated>                         
                        <column name="CODIGO" caption="Código"/>  
                        <column name="NOME" caption="Descrição"/>
                        <column name="PERCENTUAL_PARTICIPACAO" caption="% Participação"/>
                     </columns>
                  </DBTable>  
               </VerticalLayout>
            </Panel>
            
            <Panel width="100%" height="100%" expandRatio="1" caption="" margin="false" id="pnlInclusao">
               <VerticalLayout width="100%" margin="true">
                  <Label id="DescricaocadastroDentro" contentMode="HTML" align="MIDDLE_CENTER" width="100%" > </Label>
                  <TabLayout height="100%" width="100%">
                     <Tab caption="Dados" >
                        <VerticalLayout width="70%" margin="true" spacing="true"> 
                        	<DBSearchField type="number" id="idPesquisa" expandRatio="1" caption="Pesquisar sócio" width="100%" searchCaption="Nome do sócio" searchViewWidth="85%"	description="Selecione um fornecedor" >
								<datasource>
									<freeQuery connection-key="vitruvio">
										<![CDATA[
											SELECT * FROM socios WHERE CODIGO > 0
										]]>
									</freeQuery>
								</datasource>
								<loadItemQuery>
									<![CDATA[
										SELECT *
											  FROM socios
											   nome = ? WHERE CODIGO > 0 ORDER BY codigo
									]]>
								</loadItemQuery>
								<key-field>CODIGO</key-field>
								<caption-field>NOME</caption-field>
								<columns>
									<column name="CODIGO" caption="Código" />
									<column name="NOME" caption="Descrição" />
								</columns>
								<filterProperties filterRequired="false">
									<value>CODIGO</value>
									<value>NOME</value>
								</filterProperties>
								<events>
									<valueChange>
										<script language="JavaScript">
											<![CDATA[
												function run() {
													//engine.getGlobalVariable('fncLimpaCampos')();
													engine.getGlobalVariable('carregarCampos')(engine.getField('idPesquisa').getValue());
												}
											]]>
										</script>
									</valueChange>
								</events>
							</DBSearchField> 
							<HorizontalLayout spacing="true" width="100%">
								<TextField id="idChave" type="number" caption="Código" width="100%" expandRatio="0.08" />                              
                           		<TextField id="idDescricao" type="string" text-transform="uppercase" caption="Nome" required="true" width="100%" expandRatio="1"  />
                           		<DecimalField type="decimal" id="idParticipacao" caption="% Participação" maximumValue="100" maxLength="6" width="100%" expandRatio="0.15" />
							</HorizontalLayout>
							<TextField id="idRateio" type="number" visible="false" />                   
                        </VerticalLayout>  
                     </Tab>
                  </TabLayout>
               </VerticalLayout>

            </Panel>
            <Panel width="100%" margin="false" id="pnlBotoes" >
            	<VerticalLayout width="100%">
	               <HorizontalLayout spacing="true" margin="true" align="MIDDLE_CENTER" >
	                  <ButtonWidget id="btnSalvar" caption="Salvar" expandRatio="0.2" description="Salva os dados das Informações Adicionais do Cargo " align="MIDDLE_CENTER">
	                     <onClickScript language="JavaScript">
	                        <![CDATA[
	                           importClass(Packages.br.com.davinti.base.vaadin.components.layout.MessageBox);
	                           	
	                           	function run() {
	                              if (engine.isValid()) {
	                              	if ((engine.getGlobalVariable('validarDuplicidade')(engine.getField('idDescricao').getValue())) && (!engine.getField('idChave').getValue())) {
	                              		MessageBox.show(MessageBox.BoxType.INFO, 'Atenção', 'Já existe um sócio cadastrado com este nome.');
	                              	} else {
	                              		 var socio = engine.getField('idChave').getValue();
	                              		 if (!socio) {
	                              		 	socio = 0;
	                              		 }
										 if (engine.getGlobalVariable('validarPercentual')(socio)) {	                              		
			                                 var config = engine.getGlobalVariable('config');
			                                 var id     = engine.getField('idChave').getConvertedValue();
			                                 var lib = libService.loadScript('lib_cadastro_padrao');
			                                 var retorno = lib.fncGravarRegistro(config, id);
			                                
			                                 if (retorno) {
			                                    engine.getGlobalVariable('fncLimpaCampos')();
			                                 }
			                            } else {
			                            	MessageBox.show(MessageBox.BoxType.INFO, 'Atenção', 'Percentual de participação dos sócios ultrapassa 100%.');
			                            }
	                                 }
	                              }
	                           	}
	                        ]]>
	                     </onClickScript>
	                  </ButtonWidget>
	                  <ButtonWidget caption="Novo" id="btnNovo" expandRatio="0.2" description="Novo cadastro" align="MIDDLE_CENTER">
	                     <onClickScript language="JavaScript">
	                        <![CDATA[
	                           function run() {
	                           	  engine.setGlobalVariable('painelLista',0);
	                              engine.getGlobalVariable('novoRegistro')();
	                           }
	                        ]]>
	                     </onClickScript>
	                  </ButtonWidget>
	                  <ButtonWidget caption="Excluir" id="btnExcluir" expandRatio="0.2" description="Excluir os dados atuais" align="MIDDLE_CENTER">
	                     <onClickScript language="JavaScript">
	                        <![CDATA[
	                           importClass(Packages.br.com.davinti.base.vaadin.components.layout.MessageBox);
	                           importClass(Packages.br.com.davinti.base.vaadin.components.layout.ConfirmationBox);
	                           importClass(Packages.com.vaadin.ui.Notification);
	      
	                           function run() {
	                              if(engine.isValid()) {
	                                 var deletar = engine.getGlobalVariable('deletarRegistro');
	                                 var listener = new ConfirmationBox.ConfirmationBoxListener() {
	                                    dialogEnd: function(context, action) {
	                                       if(action == ConfirmationBox.Action.YES) {
	                                          var id = engine.getField('idChave').getConvertedValue();
	                                          if(deletar){
	                                          	 engine.setGlobalVariable('painelLista',0);                                       
	                                             deletar(id);
	                                          }   
	                                       }     
	                                    }
	                                 };
	                                 
	                                 ConfirmationBox.show(ConfirmationBox.DialogIcon.WARNING, 'Confirmar exclusão do registro?', 'Tem certeza de que deseja excluir o tipo de ocorrência selecionado?', listener, ConfirmationBox.ACTION_YES_CANCEL);                                   
	                              }
	                           }
	                        ]]>
	                     </onClickScript>
	                  </ButtonWidget>
	                  <ButtonWidget caption="Voltar" id="btnVoltar" expandRatio="0.2" description="Voltar a tela inicial" align="MIDDLE_CENTER">
	                     <onClickScript language="JavaScript">
	                        <![CDATA[
	                           function run() {
	                           	  engine.setGlobalVariable('painelLista',1);
	                              engine.getGlobalVariable('fncLimpaCampos')();
	                              newRecord  = false;
	                              saveStatus = false;
	                              engine.getGlobalVariable('telaInicial')();
	                              engine.getField('listaPrincipal').refresh();
	                           }
	                        ]]>
	                     </onClickScript>
	                  </ButtonWidget>
	               </HorizontalLayout>
               </VerticalLayout>
            </Panel>
         </VerticalLayout>
      </components>
   </form>
</panel-form>