Created
July 11, 2013 19:23
-
-
Save franklinbr/5978440 to your computer and use it in GitHub Desktop.
prototip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var App = { | |
modulo: 'galeria', | |
tipoDestaque: 'unico', | |
// tipoDestaque: 'varios', | |
delay: null, | |
requisicao: null, | |
pagina_corrente: 0, | |
Init: function() { | |
App.Paginacao(); | |
App.PaginacaoTools(); | |
App.Destaque(); | |
App.Editar(); | |
App.Deletar(); | |
App.Desdeletar(); | |
App.Adicionar(); | |
App.Titulo(); | |
App.Atualizar(); | |
App.Tipo(); | |
App.Sair(); | |
App.Select(); | |
}, | |
Paginacao: function () { | |
var busca = $('input[name=field_busca]').val(); | |
var filtro_select = $('select[name=filtro] > option:selected').data('valor_select'); | |
var campo_select = $('select[name=filtro] > option:selected').data('campo_select'); | |
App.requisicao = $.ajax({ | |
type: "POST", | |
url: "index.php", | |
cache: false, | |
data: {tipo: 'paginacao', busca: busca, filtro_select: filtro_select, campo_select: campo_select, pagina_corrente: App.pagina_corrente}, | |
dataType: 'json', | |
beforeSend: function() { | |
/* mostra loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderShow(); | |
} | |
}, | |
success: function(dados){ | |
/* popula grid */ | |
$('.container-grid').html(dados.template); | |
/* anterior */ | |
if(dados.pagina_corrente > 0) { | |
$('div[class*=container-paginador-box] > a:first').removeClass('disabled'); | |
} | |
else { | |
$('div[class*=container-paginador-box] > a:first').addClass('disabled'); | |
} | |
/* proximo */ | |
if(dados.proximo == 'verdadeiro') { | |
$('div[class*=container-paginador-box] > a:last').removeClass('disabled'); | |
} | |
else { | |
$('div[class*=container-paginador-box] > a:last').addClass('disabled'); | |
} | |
/* mensagem de quantidade */ | |
if(dados.total_itens > 0) { | |
$('div[class=paginador-display]').html('<strong>'+dados.passo_inicial+'</strong>-<strong>'+dados.passo_final+'</strong> de <strong>'+dados.total_itens+'</strong>'); | |
} | |
else { | |
$('div[class=paginador-display]').html('<strong>Nenhum Registro</strong>'); | |
} | |
/* reseta quantidade selecionada de deletar */ | |
$('span[class=quantidade-selecionado]').text('0'); | |
/* apenas um recurso para trabalhar confortavelmente com modulo em aba separado */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.IframeAltura(App.modulo); | |
} | |
/* esconde loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderHide(); | |
} | |
App.requisicao = null; | |
}, | |
error: function(){ | |
/* empty */ | |
} | |
}); | |
}, | |
PaginacaoTools: function() { | |
/* funcao para retorno temporizado */ | |
var delay = (function(){ | |
var timer = 0; | |
return function(callback, ms){ | |
clearTimeout (timer); | |
timer = setTimeout(callback, ms); | |
}; | |
})(); | |
/* retornar */ | |
$('div[class*=container-paginador-box] > a:first').on('click', function(){ | |
if(!$(this).hasClass('disabled')) { | |
$('div[class*=container-paginador-box] > a').addClass('disabled'); | |
App.pagina_corrente--; | |
App.Paginacao(); | |
} | |
}); | |
/* avancar */ | |
$('div[class*=container-paginador-box] > a:last').on('click', function(){ | |
if(!$(this).hasClass('disabled')) { | |
$('div[class*=container-paginador-box] > a').addClass('disabled'); | |
App.pagina_corrente++; | |
App.Paginacao(); | |
} | |
}); | |
/* temporizador */ | |
$('input[name=field_busca]').keyup(function(e) { | |
if(e.keyCode != 38 && e.keyCode != 40 && e.keyCode != 39 && e.keyCode != 37 && e.keyCode != 13) { | |
delay(function(){ | |
App.pagina_corrente = 0; | |
App.Paginacao(); | |
}, 1000); | |
} | |
}); | |
/* dispara paginador para alteracoes no filtro select */ | |
$('select[name=filtro]').on('change', function(){ | |
if($(this).val() == 'deletados') { | |
$('button[class*=btn-desdeletar]').css('visibility', 'visible'); | |
} | |
else { | |
$('button[class*=btn-desdeletar]').css('visibility', 'hidden'); | |
} | |
App.Paginacao(); | |
}); | |
}, | |
Titulo: function() { | |
$(document).on({ | |
mouseenter: function() { | |
$(this).find('div[class=pelicula-dados]').stop().fadeIn(); | |
if($('select[name=filtro] > option:selected').text() != 'Deletados') { | |
$(this).find('ul[class=navPainel] > li:lt(4)').stop().fadeIn(); | |
} | |
else { | |
$(this).find('ul[class=navPainel] > li:gt(3)').stop().fadeIn(); | |
} | |
}, | |
mouseleave: function() { | |
$(this).find('div[class=pelicula-dados]').stop().fadeOut(); | |
$(this).find('ul[class=navPainel] > li').stop().fadeOut(); | |
$(this).find('div[class*=popover-tipo]').hide(); | |
$(this).find('div[class*=popover-deletar]').hide(); | |
} | |
}, 'div[class=box-grid]'); | |
}, | |
Destaque: function () { | |
/* funcao para retorno temporizado */ | |
var delay = (function(){ | |
var timer = 0; | |
return function(callback, ms){ | |
clearTimeout (timer); | |
timer = setTimeout(callback, ms); | |
}; | |
})(); | |
$(document).on('click', 'li[class*=galeria-destaque]', function(){ | |
that = $(this); | |
if($(this).hasClass('galeria-destaque-ativado')) { | |
$(this).removeClass('galeria-destaque-ativado'); | |
$(this).parents('.box-grid').data('destaque', 'nao'); | |
} | |
else { | |
if(App.tipoDestaque == 'unico') { | |
$('li[class*=galeria-destaque]').removeClass('galeria-destaque-ativado'); | |
} | |
$(this).addClass('galeria-destaque-ativado'); | |
$(this).parents('.box-grid').data('destaque', 'sim'); | |
} | |
delay(function(){ | |
var destaque = that.parents('.box-grid').data('destaque'); | |
var cod = that.parents('.box-grid').data('cod'); | |
App.requisicao = $.ajax({ | |
type: "POST", | |
url: "index.php", | |
cache: false, | |
data: {tipo: 'destaque', cod: cod, destaque: destaque, tipoDestaque: App.tipoDestaque}, | |
dataType: 'json', | |
beforeSend: function() { | |
/* mostra loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderShow(); | |
} | |
}, | |
success: function(dados){ | |
if(dados.status) { | |
/* apenas um recurso para trabalhar confortavelmente com modulo em aba separado */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.IframeAltura(App.modulo); | |
} | |
/* esconde loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderHide(); | |
} | |
App.requisicao = null; | |
} | |
}, | |
error: function(){ | |
/* empty */ | |
} | |
}); | |
}, 2000); | |
}); | |
}, | |
Editar: function() { | |
$(document).on('click', 'li[class=galeria-editar]', function(){ | |
var cod = $(this).parents('div[class*=box-grid]').data('cod'); | |
window.location.href = "editar.php?cod="+cod; | |
}); | |
}, | |
Deletar: function() { | |
$(document).on('click', 'li[class*=galeria-deletar]', function(){ | |
var cod = $(this).parents('div[class*=box-grid]').data('cod'); | |
App.requisicao = $.ajax({ | |
type: "POST", | |
url: "index.php", | |
cache: false, | |
data: {tipo: 'deletar', cod: cod}, | |
dataType: 'json', | |
context: $(this), | |
beforeSend: function() { | |
/* mostra loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderShow(); | |
} | |
}, | |
success: function(dados){ | |
if(dados.status) { | |
$(this).parents('div[class*=box-grid]').hide('fast', function(){ | |
$(this).remove(); | |
}); | |
/* apenas um recurso para trabalhar confortavelmente com modulo em aba separado */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.IframeAltura(App.modulo); | |
} | |
/* esconde loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderHide(); | |
} | |
App.requisicao = null; | |
} | |
}, | |
error: function(){ | |
/* empty */ | |
} | |
}); | |
}); | |
}, | |
Desdeletar: function() { | |
$(document).on('click', 'li[class*=galeria-desdeletar]', function(){ | |
var cod = $(this).parents('div[class*=box-grid]').data('cod'); | |
App.requisicao = $.ajax({ | |
type: "POST", | |
url: "index.php", | |
cache: false, | |
data: {tipo: 'desdeletar', cod: cod}, | |
dataType: 'json', | |
context: $(this), | |
beforeSend: function() { | |
/* mostra loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderShow(); | |
} | |
}, | |
success: function(dados){ | |
if(dados.status) { | |
$(this).parents('div[class*=box-grid]').hide('fast', function(){ | |
$(this).remove(); | |
}); | |
/* apenas um recurso para trabalhar confortavelmente com modulo em aba separado */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.IframeAltura(App.modulo); | |
} | |
/* esconde loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderHide(); | |
} | |
App.requisicao = null; | |
} | |
}, | |
error: function(){ | |
/* empty */ | |
} | |
}); | |
}); | |
}, | |
Adicionar: function() { | |
$(document).on('click', 'img[class*=galeria-adicionar]', function(){ | |
window.location.href = "inserir.php"; | |
}); | |
}, | |
Atualizar: function() { | |
$(document).on('click', 'a[class*=btn-atualizar]', function(){ | |
App.Paginacao(); | |
}); | |
}, | |
Tipo: function() { | |
/* funcao para retorno temporizado */ | |
var delay = (function(){ | |
var timer = 0; | |
return function(callback, ms){ | |
clearTimeout (timer); | |
timer = setTimeout(callback, ms); | |
}; | |
})(); | |
$(document).on('click', 'li[class*=galeria-tipo]', function(){ | |
if($(this).parent().siblings('div[class*=popover-tipo]').is(':visible')) { | |
$(this).parent().siblings('div[class*=popover-tipo]').hide(); | |
} | |
else { | |
$('.popover-deletar').hide(); | |
$(this).parent().siblings('div[class*=popover-tipo]').show(); | |
} | |
}); | |
$(document).on('click', '.btn-site', function(){ | |
if(!$(this).hasClass('active')) { | |
$(this).parents('.box-grid').data('site', 'sim'); | |
} | |
else { | |
$(this).parents('.box-grid').data('site', 'nao'); | |
} | |
}); | |
$(document).on('click', '.btn-mobile', function(){ | |
if(!$(this).hasClass('active')) { | |
$(this).parents('.box-grid').data('mobile', 'sim'); | |
} | |
else { | |
$(this).parents('.box-grid').data('mobile', 'nao'); | |
} | |
}); | |
$(document).on('click', '.btn-site, .btn-mobile', function(){ | |
that = $(this); | |
delay(function(){ | |
var site = that.parents('.box-grid').data('site'); | |
var mobile = that.parents('.box-grid').data('mobile'); | |
var cod = that.parents('.box-grid').data('cod'); | |
App.requisicao = $.ajax({ | |
type: "POST", | |
url: "index.php", | |
cache: false, | |
data: {tipo: 'disponivel', cod: cod, site: site, mobile: mobile}, | |
dataType: 'json', | |
beforeSend: function() { | |
/* mostra loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderShow(); | |
} | |
}, | |
success: function(dados){ | |
if(dados.status) { | |
/* apenas um recurso para trabalhar confortavelmente com modulo em aba separado */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.IframeAltura(App.modulo); | |
} | |
/* esconde loader */ | |
if((window.location != window.parent.location) == true) { | |
window.parent.LoaderHide(); | |
} | |
App.requisicao = null; | |
} | |
}, | |
error: function(){ | |
/* empty */ | |
} | |
}); | |
}, 2000); | |
}); | |
}, | |
Sair: function() { | |
/* fechar iframe */ | |
$('.btn-sair').on('click', function(){ | |
window.parent.FecharAba(); | |
}); | |
}, | |
Select: function() { | |
/* select customizado */ | |
$("select[name=filtro]").selectpicker(); | |
} | |
} | |
$(document).ready(function() { | |
App.Init(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment