lorduakiti

table

Jan 30th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function createInputs(arrInputs){
  3.         //(_global.debug) ?  console.log('AQUI!!!<br><br> '  + JSON.stringify(arrInputs)) : '' ;
  4.         var strHtml = '';
  5.         var acts    = {
  6.             form:       false,
  7.             formGroup:  false,
  8.             table:      false,
  9.             nav:        false,
  10.             collapse:   false,
  11.             div:        false
  12.         };
  13.        
  14.         if(item.obj == 'table'){
  15.                     strHtml += (acts['div'])       ?  '</div>'  : '' ;
  16.                     strHtml += (acts['formGroup']) ?  '</div>'   : '' ;
  17.                     strHtml += (acts['table'])     ?  '</table>' : '' ;
  18.  
  19.                     item.id         = (item.id          === undefined  ||  item.id          === null) ? ''      : item.id ;
  20.                     item.size       = (item.size        === undefined  ||  item.size        === null) ? ''      : item.size ;
  21.                     item.preSize    = (item.preSize     === undefined  ||  item.preSize     === null) ? ''      : item.preSize ;
  22.                     item.autocLose  = (item.autocLose   === undefined  ||  item.autocLose   === null) ? false   : item.autocLose ;
  23.                     item.columns    = (item.columns     === undefined  ||  item.columns     === null) ? []      : item.columns ;
  24.                     item.remove     = (item.remove      === undefined  ||  item.remove      === null) ? ''      : item.remove ;
  25.                     item.order      = (item.order       === undefined  ||  item.order       === null) ? ''      : item.order ;
  26.                     item.idadd      = (item.idadd       === undefined  ||  item.idadd       === null) ? ''      : item.idadd ;
  27.                     item.textadd    = (item.textadd     === undefined  ||  item.textadd     === null) ? ''      : item.textadd ;
  28.                     item.classadd   = (item.classadd    === undefined  ||  item.classadd    === null) ? ''      : item.classadd ;
  29.                    
  30.                     item.size = (item.preSize != '') ?  (item.size + '-' + item.preSize)  :  item.size  ;
  31.                    
  32.                     strHtml  += createTable(item.id, item.size, item.autocLose, item.columns, item.remove, item.order, item.idadd, item.textadd, item.classadd);
  33.                     acts['table'] = true;
  34.         }
  35. }
  36.  
  37. function createTable(id, size, autoClose, columns, remove, order, idAdd, textAdd, classadd){
  38.             var k = 0;
  39.             var auxColumns  = '';
  40.             var auxHtml     = '';
  41.             var auxHtmlHide = '';
  42.             var td = false;
  43.             for(var k=0; k < columns.length; k++){
  44.                 if(columns[k].obj !== undefined){
  45.                     if(columns[k].type == 'hidden'){
  46.                         auxHtmlHide += window[_global.objVars.mints].custom.createInputs( [ columns[k] ] );
  47.                         td = false;
  48.                     } else {
  49.                         var textColum = (columns[k].columname === undefined) ? ''   : columns[k].columname ;
  50.                         var columsize = (columns[k].columsize === undefined) ? '12' : columns[k].columsize ;
  51.                         var auxSize   = this.size( columsize );
  52.                        
  53.                         auxColumns += '<th class="tableColumn">' + textColum + '</th>'
  54.                        
  55.                         auxHtml += (td) ? '</td>' : '' ;
  56.                         auxHtml += '<td  class="fs-v-align-middle ' + auxSize + '">';
  57.                         td = true;
  58.                        
  59.                         auxHtml     += window[_global.objVars.mints].custom.createInputs( [ columns[k] ] );
  60.                     }
  61.                 }
  62.             }
  63.            
  64.             var htmlFirstColum  = '<td class="bpm-mobile-trash-column"><div class="hidden-inputs">' + auxHtmlHide + '</div>';
  65.             var auxHtmlOrder    = '';
  66.             if(order === true){
  67.                 auxHtmlOrder = '' +
  68.                     '<div class="col-lg-2  col-md-2  col-sm-2  col-xs-12"  style="padding-top:7px">' +
  69.                     '   <label  name="contador" id="contador"  class="control-label" value="">0</label>' +
  70.                     '</div>';
  71.             }
  72.             htmlFirstColum += auxHtmlOrder;
  73.             var auxHtmlRemove   = '';
  74.             if(remove !== undefined  &&  remove !== ''){
  75.                 auxHtmlRemove += '' +
  76.                 '<div class="col-lg-8  col-md-8  col-sm-8  col-xs-12" >' +
  77.                     '<span class="fluig-style-guide fs-display-block fs-xs-space">' +
  78.                     '   <i class="fluigicon fluigicon-trash fluigicon-md" onclick="Javascript:' + remove + '" style="cursor:pointer"></i>'+
  79.                     '</span>'+
  80.                 '</div>';
  81.             }
  82.             htmlFirstColum += auxHtmlRemove;
  83.             htmlFirstColum += '</td>';
  84.  
  85.  
  86.             var htmlLastColum = '';
  87.            
  88.            
  89.             if(order === true){
  90.                 auxColumns  = '' +
  91.                     '<th >' +
  92.                     '   <div class="col-lg-2  col-md-2  col-sm-2  col-xs-12">Nº</div>' +
  93.                     '   <div class="col-lg-10 col-md-10 col-sm-10 col-xs-12"> </div>' +
  94.                     '</th>' + auxColumns;
  95.             } else {
  96.                 auxColumns  = '<th></th>' + auxColumns;
  97.             }              
  98.             auxHtml = htmlFirstColum + auxHtml + htmlLastColum;
  99.            
  100.            
  101.            
  102.             //auxHtml += window[_global.objVars.mints].custom.createInputs( columns );
  103. //console.log(auxHtml);
  104.  
  105.             var aux = '' +
  106. //              '<div class="form-field" data-type="tabledetail" data-show-properties="" data-field-name="' + id + '">' +
  107.                 '   <div class="form-input">' +
  108.                 '       <div class="table-responsive">' +
  109.                 '           <table tablename="' + id + '"  id="' + id + '" class="table table-condensed table-hover" onRemoveRow="' + remove + '" noAddButton="false" noDeleteButton="true" noOrder="true">' +
  110.                 '               <thead>' +
  111.                 '                   <tr class="tableHeadRow" >' +
  112.                 '                       ' + auxColumns +
  113.                 '                   </tr>' +
  114.                 '               </thead>' +
  115.                 '               <tbody>' +
  116.                 '                   <tr class="tableBodyRow"  data-order="0"  style="display:none;" >' +
  117.                 '                       ' + auxHtml +
  118.                 '                   </tr>' +
  119.                 '               </tbody>' +
  120.                 '           </table>' +
  121.                 '       </div>';
  122.             if((idAdd != '')  &&  (idAdd !== undefined)){
  123.                 aux += '' + this.button(idAdd, textAdd, '12', '', '', '', 'btn btn-default form-control ' + classadd, true, true);
  124.             }
  125.             aux += '' +
  126.             '   </div>';
  127. //              '</div>';
  128.            
  129.             size    = (size !== undefined  &&  size !== '') ?  this.size( size ) : '' ;
  130.             aux = (this.div('', size, false, 'tabledetail', ' data-show-properties="" data-field-name="' + id + '" ', 'form-field') + aux + '</div>');
  131.             return aux;
  132.         }  
  133.                
  134.  
  135. var props = {
  136.         target:                 'divApp',
  137.         models:                 ['LISTA_FUNCIONARIOS'],
  138.         id: {
  139.             div: {
  140.                 listTeachers:   'divListaFuncionarios',
  141.                 msg:            'divMsgListaFuncionarios',
  142.                 alert:          'divMsgAlertaListaFuncionarios'
  143.             },
  144.             panel: {
  145.                 prefixHeading:  'Heading',
  146.                 prefixBody:     'Body',
  147.                 teachers:       'panelListaFuncionarios',
  148.                 cadastre:       'panelCadastro',
  149.                 address:        'panelEndereco'
  150.             },
  151.             table: {
  152.                 teachers:       'tableFuncionarios',
  153.             },
  154.             button:{
  155.                 editTeacher:    'submitEditaFuncionario',
  156.                 newTeacher:     'submitNovoFuncionario',
  157.                 submit:{
  158.                     top:        'submitTop',
  159.                     bottom:     'submitBottom'
  160.                 }              
  161.             },
  162.             input: {
  163.                 idJoin:         'idVinculo',
  164.                 codPerson:      'codVinculoPessoa',
  165.                 codSchool:      'codVinculoEscola',
  166.                 name:           'txtNome',
  167.                 cpf:            'numCpf',
  168.                 email:          'txtEmail',
  169.                 role:           'txtCargo',
  170.  
  171.             },
  172.             select: {
  173.                 role:           'selCargo',
  174.                 active:         'selCargoAtivo'
  175.             },
  176.             zoom: {
  177.             }
  178.         },
  179.         link: {
  180.             defaul:             '#'
  181.         },
  182.         text: {
  183.             msgTitle:           'Funcionario.',
  184.             msg:                '...',
  185.             alert:              '...',
  186.             edit:               'Editar',
  187.             newTeacher:         'Novo Funcionario',
  188.             panelTeachers:      'Funcionarios Vinculados',
  189.         }
  190.     }
  191.  
  192.  
  193.  
  194.  
  195. function populateTable(){
  196.     var table       = $('#' + idTarget).find('table')
  197.     var tableRow    = table.find('tbody tr[data-order=0]');
  198.     var auxHtml     = myFuns.custom.createInputs( columns );
  199.     var dp_Funcionarios = fnConsultaParceiros(codCfo, codPessoa, cargo);
  200.  
  201.     var n = 1;
  202.     if(DatasetPublic.validateReturn(dp_Funcionarios)){
  203.         if(dp_Funcionarios.rowsCount > 0){
  204.             for(var i=0; i < dp_Funcionarios.rowsCount; i++){
  205.                 if(retiraCargos.toLowerCase().indexOf(',' + dp_Funcionarios.values[i]['CARGO'].toLowerCase() + ',') == -1){
  206.                     //var row = wdkAddChild(ListaFuncionarios.props.id.table.teachers);
  207.                     var auxRow = tableRow.clone(false, false).attr('data-order', n);               
  208.                     auxRow.find('[id!=_]').each(function(){
  209.                         var id = $(this).attr('id');
  210.                         (id == 'contador') ? $(this).html( n ) : '';
  211.                         if(id !== undefined){
  212.                             $(this).attr('id', id + '___' + n);
  213.                         }
  214.                     });
  215.                     auxRow.show();
  216.                    
  217.                     for (var idModel in dp_Funcionarios.values[i]) {
  218.                         var value = dp_Funcionarios.values[i][idModel];
  219.                         idModel = ((idModel.indexOf('VINCULO_') == -1) ? 'VINCULO_' : '' ) + idModel
  220.                         var item  = auxRow.find('[data-rel-value=' + idModel + ']');
  221.                        
  222.                         item.val( '' );
  223.                         item.val( value  );
  224.                     }
  225.                     table.find('tbody').append(auxRow);
  226.                    
  227.                     // Bloqueia cargos utilizados pelo sistema educacional
  228.                     if(bloqueiaCargos.toLowerCase().indexOf(',' + dp_Funcionarios.values[i]['CARGO'].toLowerCase() + ',') != -1){
  229.                         $('#' + ListaFuncionarios.props.id.button.editTeacher + '___' + n).attr('disabled', true).addClass('btn-primary');
  230.                     }
  231.                    
  232.                     n++;
  233.                 }
  234.             }
  235.         } else {
  236.             msgErro = 'Não foi encontrado Funcionarios vinculados!';
  237.         }
  238.     } else {
  239.         msgErro = 'Não foi possível encontrar Funcionarios vinculados para a escola selecionada!';
  240.     }
  241. }
  242.  
  243.  
  244.  
  245.         var itens = new Array();
  246.         var ids   = props.id;
  247. itens = [
  248.                    {obj: 'table',
  249.                        id:      ids.table.teachers,
  250.                        idadd:   ids.button.newTeacher,
  251.                        textadd: this.props.text.newTeacher,
  252.                        classadd:'btn-success',
  253.                        remove:  '', //'fnWdkRemoveChild(this)',
  254.                        order:   true,
  255.                        columns: [
  256.                             {id: ids.input.idJoin,      obj: 'input',   type: 'hidden', value: '',      relValue: 'VINCULO_IDVINCULO',  size: '',   required: false,    readonly: true,     text: '',       columname: '',          columsize: '0',     div: false },
  257.                             {id: ids.input.codPerson,   obj: 'input',   type: 'hidden', value: '',      relValue: 'VINCULO_CODPESSOA',  size: '',   required: true,     readonly: true,     text: '',       columname: '',          columsize: '0',     div: false },
  258.                             {id: ids.input.codSchool,   obj: 'input',   type: 'hidden', value: '',      relValue: 'VINCULO_CODCFO',     size: '',   required: false,    readonly: true,     text: '',       columname: '',          columsize: '0',     div: false },
  259.                             {id: ids.input.name,        obj: 'input',   type: 'text',   value: '',      relValue: 'VINCULO_NOME_PESSOA',size: '',   required: true,     readonly: true,     text: '',       columname: 'Funcionario', columsize: '4',   div: true, maxlength: '100' },
  260.                             {id: ids.input.cpf,         obj: 'input',   type: 'text',   value: '',      relValue: 'VINCULO_CPF',        size: '',   required: true,     readonly: true,     text: '',       columname: 'CPF',       columsize: '2',     div: true, maxlength: '20', mask: '999.999.999-99',  placeholder: '___.___.___-__', addclass: 'cpf' },
  261.                             {id: ids.input.email,       obj: 'input',   type: 'email',  value: '',      relValue: 'VINCULO_EMAIL',      size: '',   required: true,     readonly: true,     text: '',       columname: 'E-mail',    columsize: '2',     div: true, maxlength: '60', addclass: 'email' },
  262.                             {id: ids.select.role,       obj: 'select',  type: 'text',   value: '',      relValue: 'VINCULO_CARGO',      size: '',   required: true,     readonly: true,     text: '',       columname: 'Cargo',     columsize: '2',     div: true, options: window[_global.objVars.data].modelItens.CARGOS() },
  263.                             {id: ids.select.active,     obj: 'select',  type: 'text',   value: '1',     relValue: 'VINCULO_ATIVO',      size: '',   required: true,     readonly: true,     text: '',       columname: 'Ativo',     columsize: '1',     div: true, options: window[_global.objVars.data].modelItens.ATIVO },
  264.                             {id: ids.button.editTeacher,obj: 'button',  type: 'text',   value: '',      relValue: 'VINCULO_CODPESSOA',  size: '12', required: false,    readonly: false,    text: 'Editar', columname: '',          columsize: '1',     div: false  }
  265.                         ]
  266.                    },
  267. //                 {id: ids.button.newTeacher,  obj: 'button',  type: 'text',   value: '-1',  size: '12',   text: this.props.text.newTeacher,   div: true,    addclass: 'btn-success'  }
  268.                 ];
  269.  
  270. // chama funções
  271. createInputs(itens);
  272. populateTable()
Add Comment
Please, Sign In to add comment