| Server IP : 54.233.248.239 / Your IP : 172.28.20.13 Web Server : Apache System : Linux ip-172-28-29-189 6.5.0-1014-aws #14~22.04.1-Ubuntu SMP Thu Feb 15 15:27:06 UTC 2024 x86_64 User : www-data ( 33) PHP Version : 7.2.34-43+ubuntu22.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /var/www/html/vinumday2_0/public/js/admin/ |
Upload File : |
function serialize(obj, prefix) {
var str = [],
p;
for (p in obj) {
if (obj.hasOwnProperty(p)) {
var k = prefix ? prefix + "[" + p + "]" : p,
v = obj[p];
str.push((v !== null && typeof v === "object") ?
serialize(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
}
function carregarFiltrosSelecionados(){
var filtro = '';
var prefix = '';
var tipo = '';
var value = '';
var val1 = '';
var val2 = '';
var filtroSelecionado = {};
var filtros = $('.list-admin').data('filtros');
filtros = filtros.split(',');
var i = 0;
var item = '';
for(i=0;i<filtros.length;i++){
item = $('[data-filter="'+filtros[i]+'"]');
filtro = $(item).attr('data-filter');
tipo = $(item).find('li i.active').closest('li').data('tipo');
value = $(item).find('li i.active').closest('li').find('.input-item').val();
if(tipo == undefined){
tipo = $(item).attr('data-tipo');
value = $(item).attr('data-default');
}
if(tipo == 'entre'){
val1 = $(item).find('li i.active').closest('li').find('[name="entre-first"]').val();
val2 = $(item).find('li i.active').closest('li').find('[name="entre-last"]').val();
value = val1 + ',' + val2;
}
if(tipo == 'drop-down'){
filtroSelecionado[filtro] = value;
}else{
filtroSelecionado[filtro] = tipo + ':' + value;
}
}
filtroSelecionado['pesquisa'] = $('#search-filtros').val();
return filtroSelecionado;
}
function recarregaLinhas(that){
$('.selected-box').removeClass('active');
$('.linhas .linha .check.active').trigger('click');
var $modulo = $('.list-admin').data('modulo');
var page = that.page ? that.page : $('.centered').find('span.active').data('page');
var pagesize = that.pagesize ? that.pagesize : $(that).closest('.box').find('#itens-pagesize').val();
var column = that.column ? that.column : $('.list-admin').data('col-order');
var order = that.order ? that.order : $('.list-admin').data('order');
var term_limit = that.term_limit ? that.term_limit : $('.list-admin').data('term-limit');
var filtroSelecionado = carregarFiltrosSelecionados();
var rota = that.rota ? that.rota : $('.list-admin').data('rota');
var tipo = that.tipo ? that.tipo : $('.list-admin').data('tipo');
var status = that.status ? that.status : $('.list-admin').data('status');
if(page == undefined){ page = 1;}
if(pagesize == undefined){ pagesize = $('.list-admin').data('pagesize');}
$.ajax({
url: '/admin/' + $modulo + '/' + rota,
type: 'GET',
data : 'format=json&page=' + page + '&tipo=' + tipo + '&rota=' + rota + '&pagesize=' + pagesize + '&column=' + column + '&order=' + order + '&status=' + status + '&term_limit=' + term_limit + '&' + serialize(filtroSelecionado),
beforeSend:function(){
$(that).closest('.box').find('.loading-linhas').addClass('active');
},
success:function(data){
$(that).closest('.box').find('.loading-linhas').removeClass('active');
$('.list-admin').find('#table-box').html(data.html);
}
});
}
function deleteLista(){
var $modulo = $('.list-admin').data('modulo');
var sel = $('.linhas .linha .check.active');
var sel = $('.linhas .linha .check.active').length;
var itens_selecionados = [];
var $id = 0;
if(sel > 0){
$('.linhas .linha .check.active').each(function(){
$id = $(this).closest('.linha').data('id');
itens_selecionados.push($id);
});
}else{
$id = $('[excluir-box]').data('id');
itens_selecionados.push($id);
}
console.log(itens_selecionados);
//Ajax Delete Lista Ofertas
ApiRequest.sendRequest({
'method' : 'POST',
'url' : "/admin/" + $modulo + "/delete",
'data' : {ids: itens_selecionados}
}).then(data => {
if(data.status){
alertUtil.alertSuccess(data.message);
}else{
alertUtil.alertError(data.message);
}
}).catch(error => {
//TRATAMENTO ERROS
alertUtil.alertError('Falha ao tentar excluir registro(s)!');
});
}
function preencheNumber(item){
var filtro = $(item).closest('.filtro-item').attr('data-filter');
var prefix = $(item).closest('.filtro-item').attr('data-prefix');
var tipo = $(item).closest('li').attr('data-tipo');
var value = $(item).val();
var StringPrefix = (prefix != '' ? prefix + ' ' : '');
if(tipo == "menor"){
$(item).closest('.filtro-item').find('.filtro-text strong').text('menor que ' + StringPrefix + value);
}else if(tipo == "maior"){
$(item).closest('.filtro-item').find('.filtro-text strong').text('maior que ' + StringPrefix + value);
}else if(tipo == "entre"){
var val1 = $(item).closest('li').find('[name="entre-first"]').val();
var val2 = $(item).closest('li').find('[name="entre-last"]').val();
value = val1 + ',' + val2;
$(item).closest('.filtro-item').find('.filtro-text strong').text('entre ' + StringPrefix + val1 + ' e ' + StringPrefix + val2);
}
/** Ajax filtra com opções de numeros */
/// aqui, vars: filtro, tipo, value
recarregaLinhas(this);
}
$(document).ready(function(){
/** Funcionamento das tabs */
$(document).on('click', '.tabs-novo-list li', function(){
var tab = $(this).data('tab');
$('.tabs-novo-list li, .tabs-novo').removeClass('active');
$(this).addClass('active');
$('.tabs-novo[data-tab="' + tab + '"]').addClass('active');
});
/** Form fixo flutuante */
$(document).on('click', '[open-form-add]', function(){
var $id = $(this).data('id');
var $modulo = $('.list-admin').data('modulo');
var tipoOferta = $(this).data('tipo') ?? false;
console.log(tipoOferta);
if($modulo == 'oferta'){
Oferta.loadFormOferta($id, tipoOferta);
}else if($modulo == 'ordem-compra'){
OrdemCompra.loadFormOrdemCompra($id);
}else{
alert('Módulo Não Implementado - File: playground.js');
}
});
$(document).on('click', '.form-add-box .top-add-form img, .form-add-mask', function(){
$('body').removeClass('add-form-box-active');
});
$(document).on('click', '.open-modal', function(e){
e.preventDefault();
var $url = $(this).attr('href');
console.log($url);
$.ajax({
url: $url,
type: 'GET',
beforeSend:function(){
$('.carregando').fadeIn();
},
success:function(data){
$('.carregando').fadeOut();
$('.mask-new-drop').click();
$('#conteudo-modal-evento').html(data);
}
});
$('#modal-evento').modal('show');
});
$(document).on('click', '.pagin-linhas .centered > span', function(e){
$('.pagin-linhas .centered > span').removeClass('active');
$(this).addClass('active');
recarregaLinhas(this);
});
/** Seleção de itens */
$(document).on('click', '.linhas .linha .check', function(e){
$(this).toggleClass('active');
$(this).closest('.linha').toggleClass('selected');
var all = $('.linhas .linha .check').length;
var sel = $('.linhas .linha .check.active').length;
if(sel < (all/2)){
$('.topo-linhas .check').removeClass('active');
}else{
$('.topo-linhas .check').addClass('active');
}
if(sel >= 1){
$('.selected-box').addClass('active');
$('.selected-box [data-quant-selec]').text(sel);
}else{
$('.selected-box').removeClass('active');
}
});
$(document).on('click', '.topo-linhas .check', function(e){
$(this).toggleClass('active');
var all = $('.linhas .linha .check').length;
var sel = $('.linhas .linha .check.active').length;
if(sel < (all/2)){
$('.linhas .linha .check:not(.active)').trigger('click');
}else{
$('.linhas .linha .check.active').trigger('click');
}
});
$(document).on('mouseenter', '.main-sidebar.v2 li', function(){
$('.main-sidebar.v2 .slimScrollDiv .sidebar').addClass('open');
});
$(document).on('mouseleave', '.main-sidebar.v2 li', function(){
$('.main-sidebar.v2 .slimScrollDiv .sidebar').removeClass('open');
});
/** Confirmação */
$(document).on('click', '[excluir-link]', function(){
console.log('[excluir-link]');
//reset
$('[excluir-box] strong i').text(1);
$('[excluir-box]').removeData('id');
//endreset
var sel = $('.linhas .linha .check.active').length;
$('[excluir-box]').addClass('active');
$('.confirm-mask').addClass('active');
if(sel > 1){
$('[excluir-box] strong i').text(sel);
}else if(sel == 0){
var $id = $(this).parent('ul').data('id');
$('[excluir-box]').data('id', $id);
}
setTimeout(() => {
$('.mask-new-drop').trigger('click');
$('.mask-new-drop').removeClass('active');
}, 1);
});
$(document).on('click', '.confirm-mask, .confirm-no', function(){
$('[excluir-box]').removeClass('active');
$('.confirm-mask').removeClass('active');
$('.mask-new-drop').trigger('click');
});
$(document).on('click', '.toggle-filter', function(){
$('body').toggleClass('filter-mob-active');
$('.toggle-filter').toggleClass('ocultar');
});
/** Filtros padrão listagem */
$(document).on('click', '.filtro-item .drop-new span', function(){
var texto = $(this).text();
var valor = $(this).parent().attr('data-value');
var filtro = $(this).closest('.filtro-item').attr('data-filter');
console.log('valor: ' + valor);
var filtro = $(this).closest('.filtro-item').attr('data-default', valor);
$(this).closest('.filtro-item').addClass('active');
$(this).closest('.filtro-item').find('.filtro-text strong').text(texto);
$(this).closest('.drop-new').toggleClass('active');
$('.drop-new').removeClass('active');
$('body').removeClass('drop-new-opened');
$('.mask-new-drop').toggleClass('active');
/** Ajax de filtro */
/// aqui, vars: texto, valor, filtro
recarregaLinhas(this);
});
$(document).on('click', '.rmv-filter', function(){
var filtro = $(this).closest('.filtro-item').attr('data-filter');
$(this).closest('.filtro-item').removeClass('active');
$(this).closest('.filtro-item').find('.filtro-text strong').html('qualquer');
setTimeout(() => {
$(this).closest('.filtro-item').find('.drop-new').removeClass('active');
$('.drop-new').removeClass('active');
$('body').removeClass('drop-new-opened');
$('.mask-new-drop').removeClass('active');
}, 1);
/** Ajax limpra filtro */
/// aqui, vars: filtro
recarregaLinhas(this);
});
/** Mais filtros */
$(document).on('click', '.mais-filtros .drop-new span,.mais-filtros .drop-new i', function(){
var texto = $(this).text();
var filt = $(this).parent().attr('data-value');
$(this).parent().find('i').toggleClass('active');
$('.filtro-item[data-filter="' + filt + '"]').toggleClass('disabled');
});
/** Filtros com opções de números */
$(document).on('click', '.number-options .drop-new li', function(){
$(this).closest('.filtro-item').addClass('active');
$(this).closest('.filtro-item').find('.check').removeClass('active');
$(this).find('.check').addClass('active');
$(this).siblings('li').find('.input-item').val('');
});
$(document).on('keyup', '.number-options .input-item', function(e){
if(e.which == 13){
preencheNumber(this);
}
});
$(document).on('blur', '.number-options .input-item', function(e){
preencheNumber(this);
});
/** Ordenação listagem */
$(document).on('click', '.topo-linhas .order', function(e){
var orderActive = $('.topo-linhas').find('.order.active');
var columnActive = orderActive.closest('.col').data('col');
$('.topo-linhas .order').removeClass('active');
$(this).addClass('active');
var column = $(this).closest('.col').data('col');
var order = $(this).closest('.col').data('order');
this.column = column;
this.order = order;
if(columnActive == column){
if(order == 'asc'){
$('.topo-linhas').find('.order.active').closest('.col').data('order', 'desc');
$('.topo-linhas').find('.order.active').find('i.fa').removeClass('fa-chevron-up');
$('.topo-linhas').find('.order.active').find('i.fa').addClass('fa-chevron-down');
}else{
$('.topo-linhas').find('.order.active').closest('.col').data('order', 'asc');
$('.topo-linhas').find('.order.active').find('i.fa').removeClass('fa-chevron-down');
$('.topo-linhas').find('.order.active').find('i.fa').addClass('fa-chevron-up');
}
}else{
this.order = order == 'asc' ? 'desc' : 'asc';
}
recarregaLinhas(this);
});
$(document).on('click', '.confirm-yes', function(e){
$('.confirm-mask').trigger('click');
deleteLista();
recarregaLinhas(this);
});
$(document).on('change', '#go-page', function(e){
this.page = $('#go-page').val();
console.log(this.page);
recarregaLinhas(this);
});
$(document).on('change', '#itens-pagesize', function(e){
this.pagesize = $('#itens-pagesize').val();
console.log(this.pagesize);
recarregaLinhas(this);
});
$(document).on('click', '.pager.r-btn, .pager.l-btn', function(e){
this.page = $(this).data('page');
console.log(this.page);
if(this.page != ""){
recarregaLinhas(this);
}
});
$(document).on('click', '#search-btn', function(e){
recarregaLinhas(this);
});
$(document).on('keyup', '#search-filtros', function(e){
if(e.which == 13){
recarregaLinhas(this);
}
});
});