<?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>Funcionários</name>
      <description>Cadastro de funcionários</description>
      <afterFormRenderScript language="JavaScript">
         <![CDATA[
            var config = { "tabela" :
                              {
                                 "conexao"     : "vitruvio",
                                 "nome"        : "funcionario" ,
                                 "sequence"    : "funcionario_seq" ,
                                 "idTabela"    : "CODIGO",
                                 "campos"      : ["CODIGO", "NOME","VENCIMENTO_CNH","CNH","ADMISSAO","IDENTIDADE","CPF","DATA_NASCIMENTO","NAO_CARREGAR_FRETE","INATIVO"],
                                 "camposTable" : ["CODIGO", "NOME","VENCIMENTO_CNH","CNH","ADMISSAO","IDENTIDADE","CPF","DATA_NASCIMENTO","NAO_CARREGAR_FRETE","INATIVO"]

                              },
                                 "relaciona" : [ ["CODIGO","idChave","Number"] ,
                                                 ["NOME","idDescricao","String"],
                                                 ["VENCIMENTO_CNH","idVencimento","Date"],
                                                 ["CNH","idCNH","Number"],
                                                 ["ADMISSAO","idAdmissao","Date"],
                                                 ["IDENTIDADE","idIdentidade","String"],
                                                 ["CPF","idCpf","String"],
                                                 ["DATA_NASCIMENTO","idNascimento","Date"],
                                                 ["NAO_CARREGAR_FRETE","idNaoCarregarFrete","Boolean"]  ,
                                                 ["INATIVO","idInativo","Boolean"]   
                                               ] ,
                                "validacaoExclusao" : [ ["SELECT 0 AS CONTAR FROM FUNCIONARIO WHERE CODIGO = ", "Existem registros ligados a esta tabela!"],
                                						["SELECT COUNT(CHAVE_FUNCIONARIO) AS CONTAR FROM CONTROLE_DESPESAS_OPERACIONAIS WHERE CHAVE_FUNCIONARIO = ", "Existem registros ligados a esta tabela!"],
                                						["SELECT COUNT(CHAVE_FUNCIONARIO) AS CONTAR FROM CONTROLE_RECEITAS_FRETES WHERE CHAVE_FUNCIONARIO = ", "Existem registros ligados a esta tabela!"]
                                                      ],
                                'painel' :
                                {
                                   'titulo' : 'Cadastro de Funcionários',
                                   'icone'  : 'data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjMtYzAxMSA2Ni4xNDU2NjEsIDIwMTIvMDIvMDYtMTQ6NTY6MjcgICAgICAgICI+IDxyZGY6UkRGIHhtbG5zOnJkZj0iaHR0cDovL3d3dy53My5vcmcvMTk5OS8wMi8yMi1yZGYtc3ludGF4LW5zIyI+IDxyZGY6RGVzY3JpcHRpb24gcmRmOmFib3V0PSIiIHhtbG5zOnhtcD0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLyIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bXA6Q3JlYXRvclRvb2w9IkFkb2JlIFBob3Rvc2hvcCBDUzYgKFdpbmRvd3MpIiB4bXBNTTpJbnN0YW5jZUlEPSJ4bXAuaWlkOjgzODU4QTk2OTc1QjExRTg4Qzk4RkUzQzc5RTIwMEJFIiB4bXBNTTpEb2N1bWVudElEPSJ4bXAuZGlkOjgzODU4QTk3OTc1QjExRTg4Qzk4RkUzQzc5RTIwMEJFIj4gPHhtcE1NOkRlcml2ZWRGcm9tIHN0U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8aAX9zXB22BQkUaopCpj6fY2r/ABKpawP1rDSpQV3iptWFgfknbTAyYsbNKIWJe8j20sW4fFQFWuWn08bMcsdlanW/eldlmltpQbvFfGsDZ4niwIRBDLI0rqLnU7c2Ym5JrpGKjgjSUnJ1bqNfb+1a1bGpmzoHZTpNj0NALQ2CHCxs5zO7PkK7MHN1BseQ9aAy+I5az7XDoaSLQSsxiJQNxvY3HA8fWgJ7HlyruG4RLkvGVYlOTAtqI9yt8vbQEN/yGbOwEeZ5maQdzVYLcsLaVHBRa9AR8h23OlgWPDx17Tyq0gU6bWPP0oBhw8VJQrGMKfp9KAMY+MqgWFAa9HttQEZIgaAwZOCsgIYXFAZVwBChWNQAeNrdTQAvB8cjxdwnzAWaSf5qxJUeg6UBdneO4mbkw5E0QMkBvE3HgaAKw4Z0gNxoDbDjBelAaVS1AToCLUBU9AVNQFdASHOgLU50BctATFAdQH//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);
               engine.getField('idCNH')['setValue(java.lang.String)'](null);
            };
            
            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('idCNH')['setValue(java.lang.String)'](null);
               engine.getField('idCpf')['setValue(java.lang.String)'](null);
               engine.getField('idInativo').setValue(false);
               engine.getField('idNaoCarregarFrete').setValue(false);
               
               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.getGlobalVariable('fncLimpaCampos')();
                  engine.getGlobalVariable('habilitaCampos')(false); 
               }
            }
            
            var validarDuplicidade = function(valor) {
            	var sql = "Select count(nome) ct from FUNCIONARIO 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;
   				}
   			}
             }      
           
            
            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);
               
               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"        : "funcionario" ,
                                      "sequence"    : "funcionario_seq" ,
                                      "idTabela"    : "CODIGO",
                                      "campos"      : ["CODIGO", "NOME", "VENCIMENTO_CNH", "CNH", "ADMISSAO","IDENTIDADE","CPF","DATA_NASCIMENTO","NAO_CARREGAR_FRETE","INATIVO"],
                                      "camposTable" : ["CODIGO", "NOME", "VENCIMENTO_CNH", "CNH", "ADMISSAO","IDENTIDADE","CPF","DATA_NASCIMENTO","NAO_CARREGAR_FRETE","INATIVO"]
                                    },
                                    "relaciona" : [ ["CODIGO","idChave","Number"] ,
                                                    ["NOME","idDescricao","String"],
                                                    ["VENCIMENTO_CNH","idVencimento","Date"],
                                                    ["CNH","idCNH","Number"],
                                                    ["ADMISSAO","idAdmissao","Date"],
                                                    ["IDENTIDADE","idIdentidade","String"],
	                                                 ["CPF","idCpf","String"],
	                                                 ["DATA_NASCIMENTO","idNascimento","Date"],
                                                    ["NAO_CARREGAR_FRETE","idNaoCarregarFrete","Boolean"],
                                                    ["INATIVO","idInativo","Boolean"]                                               
                                                  ] ,

                                    "validacaoExclusao" : 
                                         [ ["SELECT 0 AS CONTAR FROM FUNCIONARIO WHERE CODIGO = ", "Existem registros ligados a esta tabela!"],
                                						["SELECT COUNT(CHAVE_FUNCIONARIO) AS CONTAR FROM CONTROLE_DESPESAS_OPERACIONAIS WHERE CHAVE_FUNCIONARIO = ", "Existem registros ligados a esta tabela!"],
                                						["SELECT COUNT(CHAVE_FUNCIONARIO) AS CONTAR FROM CONTROLE_RECEITAS_FRETES WHERE CHAVE_FUNCIONARIO = ", "Existem registros ligados a esta tabela!"]
                                        ],
                                    'painel' :
                                    {
                                       'titulo' : 'Cadastro de Funcionários',
                                       'icone'  : 'data:image/jpeg;base64,/9j/4QAYRXhpZgAASUkqAAgAAAAAAAAAAAAAAP/sABFEdWNreQABAAQAAAA8AAD/4QMraHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wLwA8P3hwYWNrZXQgYmVnaW49Iu+7vyIgaWQ9Ilc1TTBNcENlaGlIenJlU3pOVGN6a2M5ZCI/PiA8eDp4bXBtZXRhIHhtbG5zOng9ImFkb2JlOm5zOm1ldGEvIiB4OnhtcHRrPSJBZG9iZSBYTVAgQ29yZSA1LjMtYzAxMSA2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3HgaAKw4Z0gNxoDbDjBelAaVS1AToCLUBU9AVNQFdASHOgLU50BctATFAdQH//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="Nome"/>
                        <column name="CNH" caption="CNH"/>
                        <column name="VENCIMENTO_CNH" caption="Vencimento CNH" format="dd/MM/yyyy"/>
                        <column name="ADMISSAO" caption="Data admissão" format="dd/MM/yyyy"/>
                        <column name="IDENTIDADE" caption="RG" format="dd/MM/yyyy"/>
                        <column name="CPF" caption="CPF" editMask="###.###.###-##" />
                        <column name="DATA_NASCIMENTO" caption="Data nascimento" format="dd/MM/yyyy"/>
                        
                     </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 funcionário" width="100%" searchCaption="Nome do funcionário" searchViewWidth="85%"	description="Selecione um fornecedor" >
								<datasource>
									<freeQuery connection-key="vitruvio">
										<![CDATA[
											SELECT * FROM funcionario
										]]>
									</freeQuery>
								</datasource>
								<loadItemQuery>
									<![CDATA[
										SELECT *
											  FROM funcionario
											   nome = ? 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('carregarCampos')(engine.getField('idPesquisa').getValue());
												}
											]]>
										</script>
									</valueChange>
								</events>
							</DBSearchField>
                     
                     <HorizontalLayout width="100%" spacing="true">                    
                        <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"  /> 
                        <CheckBox id="idInativo" caption="Inativar" type="boolean" expandRatio="0.1"></CheckBox>
                     </HorizontalLayout>
                     
                     <HorizontalLayout width="70%" spacing="true">
                     	 <DateField id="idAdmissao" type="date" caption="Admissão" resolution="DAY" width="100%" expandRatio="0.4"/>
                     	 <NumericField type="number" caption="CNH" id="idCNH" width="100%" expandRatio="1" maxLength="11" />
                         <DateField id="idVencimento" type="date" caption="Vencimento CNH" resolution="DAY" width="100%" expandRatio="0.4"/>
                      </HorizontalLayout>
                        
                      <HorizontalLayout spacing="true" align="MIDDLE_LEFT">
                         <TextField id="idIdentidade" type="string" caption="RG" maxLength="11" align="MIDDLE_LEFT" />
                         <MaskedField type="string" id="idCpf" caption="CPF" mask="###.###.###-##" maxLength="11" align="MIDDLE_LEFT" />
                         <!-- <NumericField type="number" caption="CPF" id="idCpf" width="100%" expandRatio="1" maxLength="11"  inputPrompt="99.999.999-99" /> -->
                         <DateField id="idNascimento" type="date" caption="Data Nascimento" resolution="DAY" align="MIDDLE_LEFT" />
                         <CheckBox id="idNaoCarregarFrete" caption="Não carregar frete automaticamente" type="boolean"></CheckBox>
                      </HorizontalLayout> 
                        
                  </VerticalLayout>  
               </Tab>
            </TabLayout>
         </VerticalLayout>

            </Panel>
            <Panel width="100%" margin="false" id="pnlBotoes" >
            	<VerticalLayout width="100%">
	               <HorizontalLayout margin="true" spacing="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())) {
	                              		MessageBox.show(MessageBox.BoxType.INFO, 'Atenção', 'Já existe um funcionário cadastrado com este nome.');
	                              	} else {
		                                 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')();
		                                 }
	                                 }
	                              }
	                           	}
	                        ]]>
	                     </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>