Created
May 6, 2018 19:39
-
-
Save kleberksms/4890644f9d60ae840183ff55cebc1b87 to your computer and use it in GitHub Desktop.
sj
This file contains hidden or 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
jQuery(function ($) { | |
$(document).ready(function () { | |
$('.modal-loading').show(); | |
//########## Manipulação HTML ########## | |
getUf(); | |
getBancos(); | |
getAcao(); | |
getPublicacao(); | |
getTipo(); | |
getClassificacao(); | |
//getData(); | |
getAdvogados(); | |
//########## Alteração de Propriedades ########## | |
getActive(); | |
//########## Busca combos de configurações preferidas ########## | |
getAll(); | |
$(".modal-loading").delay(1500).fadeOut(); | |
//########## Sortables ########## | |
$(".sortable-geral").sortable({ | |
update: function () { | |
configurationName = 'temp'; | |
save(updateConfig()); | |
} | |
}).disableSelection(); | |
$("body").on("click", ".sortable-geral", function () { | |
$(this).find('#sortable-acao').sortable({ | |
update: function () { | |
configurationName = 'temp'; | |
save(updateConfig()); | |
} | |
}).disableSelection(); | |
$(this).find('#sortable-tipo').sortable({ | |
update: function () { | |
configurationName = 'temp'; | |
save(updateConfig()); | |
} | |
}).disableSelection(); | |
$(this).find('#sortable-publicacao').sortable({ | |
update: function () { | |
configurationName = 'temp'; | |
save(updateConfig()); | |
} | |
}).disableSelection(); | |
$(this).find('#sortable-classificacao').sortable({ | |
update: function () { | |
configurationName = 'temp'; | |
save(updateConfig()); | |
} | |
}).disableSelection(); | |
$(this).find('#sortable-bancos').sortable({ | |
update: function () { | |
configurationName = 'temp'; | |
save(updateConfig()); | |
} | |
}).disableSelection(); | |
$(this).find('#sortable-uf').sortable({ | |
update: function () { | |
configurationName = 'temp'; | |
save(updateConfig()); | |
} | |
}).disableSelection(); | |
$(this).find('#sortable-advogados').sortable({ | |
update: function () { | |
configurationName = 'temp'; | |
save(updateConfig()); | |
} | |
}).disableSelection(); | |
setConfigurationList(this); | |
}); | |
}); | |
//########## Propriedades ########## | |
var urlWs = "/app/areaadministrativa/Services/ControlePainelLeituraService.asmx"; | |
var config; | |
var advogados = { | |
Karine: "Karine", | |
Cristiane: "Cristiane", | |
Flaviano: "Flaviano", | |
Pio: "Pio", | |
Patricia: "Patricia", | |
Gilbertto: "Gilberto", | |
Gustavo: "Gustavo", | |
Janaina: "Janaina" | |
}; | |
var madeconfiguration = false; | |
var configurationId; | |
var configurationName = 'temp'; | |
var ufs = {}; | |
var bancos = {}; | |
var estados = { | |
BR: 'Âmbito Federal = BR', | |
AC: 'Acre', | |
AL: 'Alagoas', | |
AP: 'Amapá', | |
AM: 'Amazonas', | |
BA: 'Bahia', | |
CE: 'Ceará', | |
DF: 'Distrito Federal', | |
ES: 'Espírito Santo', | |
GO: 'Goiás', | |
MA: 'Maranhão', | |
MT: 'Mato Grosso', | |
MS: 'Mato Grosso do Sul', | |
MG: 'Minas Gerais', | |
PA: 'Pará', | |
PB: 'Paraiba', | |
PR: 'Paraná', | |
PE: 'Pernambuco', | |
PI: 'Piauí', | |
RJ: 'Rio de Janeiro', | |
RN: 'Rio Grande do Norte', | |
RS: 'Rio Grande do Sul', | |
RO: 'Rondônia', | |
RR: 'Roraima', | |
SC: 'Santa Catarina', | |
SP: 'São Paulo', | |
SE: 'Sergipe', | |
TO: 'Tocantins' | |
}; | |
var acao = { | |
ativa: 'Ativa', | |
passiva: 'Passiva' | |
}; | |
var publicacao = { | |
pendentes: 'Pendentes', | |
lidas: 'Lidas', | |
descartadas: 'Descartadas' | |
}; | |
var tipo = { | |
inconsistencia: 'Inconsistência', | |
intimacoes: 'Intimações' | |
}; | |
var classificacao = { | |
projudi: 'Processos Eletrônicos', | |
processos: 'Processos' | |
}; | |
var data = { | |
dataPublicacao: 'Data Publicação', | |
dataImportacao: 'Data Importação' | |
}; | |
function getAcao() { | |
mountHtmlList(acao, "acao"); | |
} | |
function getPublicacao() { | |
mountHtmlList(publicacao, "publicacao"); | |
} | |
function getTipo() { | |
mountHtmlList(tipo, "tipo"); | |
} | |
function getClassificacao() { | |
mountHtmlList(classificacao, "classificacao"); | |
} | |
function getData() { | |
mountHtmlList(data, "data"); | |
} | |
function getAdvogados() { | |
mountHtmlList(advogados, "advogados"); | |
} | |
function getBancos() { | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/BuscarBancos', | |
dataType: "json", | |
data: {}, | |
contentType: "application/json; charset=utf-8", | |
success: function (e) { | |
mountHtmlList(hydrateBanco(e), "bancos"); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
} | |
function hydrateBanco(data) { | |
var obj = JSON.parse(data.d); | |
bancos = {}; | |
$.each(obj, function (key, value) { | |
if (value.Ativo) { | |
bancos[value.Nome] = value.Nome; | |
} | |
}); | |
return bancos; | |
} | |
function getUf() { | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + "/BuscarUFs", | |
dataType: "json", | |
data: {}, | |
contentType: "application/json; charset=utf-8", | |
success: function (e) { | |
mountHtmlList(hydrateUf(e), 'uf'); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
} | |
function hydrateUf(data) { | |
var obj = JSON.parse(data.d); | |
ufs = {}; | |
$.each(obj, function (key, value) { | |
ufs[value.Uf] = estados[value.Uf]; | |
}); | |
return ufs; | |
} | |
//########## Check true ou false para listas internas ########## | |
$("body").on("click", ".list-click-painel-controle-leitura-status", function () { | |
configurationName = 'temp'; | |
var value = $(this).attr('data-togglelistgroup'); | |
var liclassfalse = "li-group-has-danger has-error"; | |
var glyphiconfalse = "glyphicon-remove"; | |
var liclasstrue = "li-group-has-success has-success"; | |
var glyphicontrue = "glyphicon-ok"; | |
if (value == 'true') { | |
$(this).attr('data-togglelistgroup', false); | |
$(this).removeClass(glyphicontrue); | |
$(this).parent().removeClass(liclasstrue); | |
$(this).addClass(glyphiconfalse); | |
$(this).parent().addClass(liclassfalse); | |
save(updateConfig()); | |
return; | |
} | |
$(this).attr('data-togglelistgroup', true); | |
$(this).removeClass(glyphiconfalse); | |
$(this).parent().removeClass(liclassfalse); | |
$(this).addClass(glyphicontrue); | |
$(this).parent().addClass(liclasstrue); | |
save(updateConfig()); | |
return; | |
}); | |
//########## CRUD ########## | |
function getActive() { | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/BuscarConfiguracaoAtiva', | |
dataType: "json", | |
data: {}, | |
contentType: "application/json; charset=utf-8", | |
success: function (e) { | |
config = returnObjConfigutarion(e); | |
mountActiveConfiguration(config); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
} | |
function getAll() { | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/BuscarTodasConfiguracoes', | |
dataType: "json", | |
data: {}, | |
contentType: "application/json; charset=utf-8", | |
success: function (e) { | |
mountCombosConfigurationsList(e); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
} | |
function save(data) { | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/Salvar', | |
dataType: "text", | |
data: { config: data, name: configurationName }, | |
success: function () { | |
saveOkAlert(); | |
getAll(); | |
}, | |
error: function (err) { | |
console.log('Error: ' + err); | |
} | |
}); | |
return true; | |
} | |
function removeItem(data) { | |
if (window.confirm("Tem certeza que deseja remover as configurações do " + data + "?")) { | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/RemoverConfiguracao', | |
dataType: "text", | |
data: { param: data }, | |
success: function () { | |
getAll(); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
return true; | |
} | |
return false; | |
} | |
//## pulo e Descarte | |
function ativarInativarResposta(id, b) { | |
b = b ? false : true; | |
var d = {id:id,b:b}; | |
var dados = JSON.stringify(d); | |
$.ajax({ | |
type: "POST", | |
async: true, | |
url: urlWs + '/AlterarStatusResposta', | |
dataType: "text", | |
data: { param: dados }, | |
success: function () { | |
getPulo(); | |
saveOkAlert(); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
} | |
$("body").on("click", "span", function () { | |
var element = $(this).parent().find('.airesp'); | |
var id = element.data('cdresposta'); | |
var b = element.data('respostac'); | |
ativarInativarResposta(id, b); | |
}); | |
getPulo(); | |
getDescarte(); | |
var respostasPulo = {}; | |
var tablePulos = ''; | |
function getPulo() { | |
tablePulos = ''; | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/RespotasPulo', | |
dataType: "json", | |
data: {}, | |
contentType: "application/json; charset=utf-8", | |
success: function (e) { | |
respostasPulo = JSON.parse(e.d); | |
for (var index = 0; index < respostasPulo.length; ++index) { | |
var i = "<i class='glyphicon glyphicon-ok' title='Ativar resposta' ></i>"; | |
if (respostasPulo[index].Ativo) { | |
i = "<i class='glyphicon glyphicon-remove' title='Inativar resposta' ></i>"; | |
} | |
tablePulos += "<tr><td>" + respostasPulo[index].Descricao + "</td><td><span class='btn btn-default airesp' data-cdresposta='" + respostasPulo[index].CdResposta + "' data-respostac='" + respostasPulo[index].Ativo + "'>" + i + "</span></td></tr>"; | |
} | |
$('#content-pulo').html(tablePulos); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
} | |
var respostasDescartes = {}; | |
var tableDescartes = ''; | |
function getDescarte() { | |
tableDescartes = ''; | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/RespotasDescarte', | |
dataType: "json", | |
data: {}, | |
contentType: "application/json; charset=utf-8", | |
success: function (e) { | |
respostasDescartes = JSON.parse(e.d); | |
for (var index = 0; index < respostasDescartes.length; ++index) { | |
var i = "<i class='glyphicon glyphicon-ok' title='Ativar resposta' ></i>"; | |
if (respostasDescartes[index].Ativo) { | |
i = "<i class='glyphicon glyphicon-remove' title='Inativar resposta' ></i>"; | |
} | |
tableDescartes += "<tr><td>" + respostasDescartes[index].Descricao + "</td><td><span class='btn btn-default airesp' data-cdresposta='" + respostasDescartes[index].CdResposta + "' data-respostac='" + respostasDescartes[index].Ativo + "'>" + i + "</span></td></tr>"; | |
} | |
$('#content-descarte').html(tableDescartes); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
} | |
//########## Funções de apoio ao layout ########## | |
$("body").on("click", ".remove-combo-list", function () { | |
var value = $(this).data('removeitemcombo'); | |
configurationName = 'temp'; | |
save(updateConfig()); | |
removeItem(value); | |
}); | |
$("body").on("click", ".edit-combo-list", function () { | |
var value = $(this).data('editaritemcombo'); | |
if (window.confirm("Tem certeza que atribuir estas configurações ao " + value + "?")) { | |
configurationName = value; | |
save(updateConfig()); | |
} | |
}); | |
$("body").on("click", ".btn-combo-list", function () { | |
var value = $(this).data('config'); | |
changeActive(value); | |
$(".btn-combo-list").each(function () { | |
$(this).removeClass('btn-success'); | |
$(this).addClass('btn-default'); | |
}); | |
$(this).removeClass('btn-default'); | |
$(this).addClass('btn-success'); | |
}); | |
function changeActive(data) { | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/MudarAtiva', | |
dataType: "text", | |
data: { name: data }, | |
success: function () { | |
//Por causa do envio tipo text, não é possível retornar o json e montar o layout a partir deste, por isto chamo o getActive | |
getActive(); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
} | |
var $newConfig = $('#save-new-configuration'); | |
$newConfig.click(function () { | |
var nameNc = $('#text-new-configuration').val(); | |
$('#text-new-configuration').val(''); | |
if ('' === nameNc) { | |
alert('Campo nome não pode ser vazio'); | |
return false; | |
}; | |
if ('temp' === nameNc) { | |
alert('Nome inválido'); | |
return false; | |
}; | |
configurationName = nameNc; | |
save(updateConfig()); | |
return true; | |
}); | |
function updateConfig() { | |
var upConfig = {}; | |
$(".order").each(function () { | |
var order = $(this).data('order'); | |
var inside = {}; | |
$("." + order).each(function () { | |
var insideElement = $(this); | |
var optional = insideElement.find('span').attr('data-togglelistgroup'); | |
if (typeof optional === 'undefined') { | |
inside[insideElement.data(order)] = insideElement.data(order); | |
} else { | |
inside[insideElement.data(order)] = optional; | |
} | |
}); | |
upConfig[order] = inside; | |
}); | |
return JSON.stringify(upConfig); | |
} | |
function returnObjConfigutarion(e) { | |
var obj = JSON.parse(e.d); | |
//### Carrega nome e id da configuração ativa ### | |
configurationId = obj.CdControle; | |
configurationName = obj.Nome; | |
return JSON.parse(obj.Configuracao); | |
}; | |
//########## Manipulação layout ########## | |
$("#distribuicao-aleatoria").bootstrapSwitch({ | |
size: "mini", | |
}); | |
function mountCombosConfigurationsList(e) { | |
$('#group-lista-preferida').html(''); | |
var obj = JSON.parse(e.d); | |
var aux = blocoComboListPreferida; | |
var finalLayout = ''; | |
$.each(obj, function (i, item) { | |
if ('temp' !== item.Nome) { | |
var aux2 = aux; | |
var btnnow = 'btn-default'; | |
if (item.Ativo) { | |
btnnow = 'btn-success'; | |
} | |
aux2 = aux2.replace('<{%NAMEBTN%}>', btnnow); | |
aux2 = aux2.replace('<{%NAMEREMOVECONFIG%}>', item.Nome); | |
aux2 = aux2.replace('<{%NAMEEDITCONFIG%}>', item.Nome); | |
aux2 = aux2.replace('<{%NAMECONFIG%}>', item.Nome); | |
aux2 = aux2.replace('<{%NAMECONFIGSHOW%}>', item.Nome); | |
finalLayout += aux2; | |
} | |
}); | |
$('#group-lista-preferida').html(finalLayout); | |
} | |
function mountHtmlList(obj, type) { | |
var aux = insideListBoolean; | |
aux = aux.replace('<{%CHX-BOOLEAN%}>', 'true'); | |
aux = aux.replace('<{%CHX-DATA%}>', 'data-' + type); | |
aux = aux.replace('<{%CHX%}>', type); | |
var finalLayout = ''; | |
$.each(obj, function (i, item) { | |
var aux2 = aux; | |
aux2 = aux2.replace('<{%CHX-VALUE%}>', i); | |
aux2 = aux2.replace('<{%CHX-DESCRIPTION%}>', item); | |
finalLayout += aux2; | |
}); | |
$('#sortable-' + type).html(finalLayout); | |
} | |
//########## Reordenação das configurações ########## | |
function mountActiveConfiguration(c) { | |
reorderGeneralGroup(c); | |
} | |
function reorderGeneralGroup(g) { | |
var sortableGroups = {}; | |
$.each(g, function (i, item) { | |
if ((typeof i) === 'string') { | |
sortableGroups[i] = ''; | |
} | |
}); | |
var collection = $(".order"); | |
collection.each(function () { | |
var auxLi = contentGeralLi; | |
var valueInside = $(this).html(); | |
auxLi = auxLi.replace('<{%CONTENTGENERALORDER%}>', valueInside); | |
auxLi = auxLi.replace('<{%ORDER-DATA%}>', $(this).data('order')); | |
sortableGroups[$(this).data('order')] = auxLi; | |
}); | |
var html = ''; | |
$.each(sortableGroups, function (i, item) { | |
html += item; | |
}); | |
$('.sortable-geral').html(html); | |
} | |
function setConfigurationList(thiis) { | |
if (madeconfiguration) { | |
return false; | |
} | |
madeconfiguration = true; | |
var stringType; | |
var $thiis; | |
var $currentLi; | |
var $tglChck; | |
$.each(config, function (i, item) { | |
if ((typeof i) === 'string') { | |
$thiis = $(thiis).find('#sortable-' + i); | |
stringType = i; | |
} | |
if ((typeof item) === 'object') { | |
var $objLi = ''; | |
$.each(item, function (list, status) { | |
$currentLi = $thiis.find("[data-" + stringType + "='" + list + "']"); | |
if (status == 'false') { | |
$currentLi.removeClass('li-group-has-success'); | |
$currentLi.removeClass('has-success'); | |
$currentLi.addClass('li-group-has-danger'); | |
$currentLi.addClass('has-error'); | |
$tglChck = $currentLi.find("span"); | |
$tglChck.removeClass('glyphicon-ok'); | |
$tglChck.addClass('glyphicon-remove'); | |
$tglChck.attr('data-togglelistgroup', false); | |
} | |
$objLi += $('<div>').append($currentLi.clone()).html(); | |
}); | |
$thiis.html($objLi); | |
} | |
}); | |
return true; | |
} | |
//########## Html para front ########## | |
var contentGeralLi = "<li class='panel panel-default order ui-sortable-handle' data-order='<{%ORDER-DATA%}>'><{%CONTENTGENERALORDER%}></li>"; | |
var insideListBoolean = "<li class='list-group-item li-group-has-success has-success <{%CHX%}>' <{%CHX-DATA%}>='<{%CHX-VALUE%}>'>" + | |
"<i class='move-sortable glyphicon glyphicon-resize-vertical'></i> <{%CHX-DESCRIPTION%}>" + | |
"<span data-togglelistgroup='<{%CHX-BOOLEAN%}>' class='glyphicon glyphicon-ok form-control-feedback list-click-painel-controle-leitura-status'></span>" + | |
"</li>"; | |
var blocoComboListPreferida = "<div class='col-md-3 configuration-button'>" + | |
"<div class='button-configuration-button'>" + | |
"<button type='button' class='btn <{%NAMEBTN%}> btn-lg btn-combo-list' data-config='<{%NAMECONFIG%}>'><{%NAMECONFIGSHOW%}></button>" + | |
"<i data-editaritemcombo='<{%NAMEEDITCONFIG%}>' class='glyphicon glyphicon-pencil link-edit-configuration-button edit-combo-list'></i>" + | |
"<i data-removeitemcombo='<{%NAMEREMOVECONFIG%}>' class='glyphicon glyphicon-remove link-remove-configuration-button remove-combo-list'></i>" + | |
"</div>" + | |
"</div>"; | |
//########## PULO e DESCARTE ########## | |
$('#insere-pulo').submit(function () { | |
var dados = JSON.stringify($(this).serializeObject()); | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/AddEditResposta', | |
dataType: "text", | |
data: { param: dados }, | |
success: function () { | |
getPulo(); | |
saveOkAlert(); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
return false; | |
}); | |
$('#insere-descarte').submit(function () { | |
var dados = JSON.stringify($(this).serializeObject()); | |
$.ajax( | |
{ | |
type: "POST", | |
async: true, | |
url: urlWs + '/AddEditResposta', | |
dataType: "text", | |
data: { param: dados }, | |
success: function () { | |
getDescarte(); | |
saveOkAlert(); | |
}, | |
error: function (e) { | |
console.log("Error:" + JSON.stringify(e)); | |
} | |
}); | |
return false; | |
}); | |
//########## GLOBAL ########## | |
$.fn.serializeObject = function () { | |
var o = {}; | |
var a = this.serializeArray(); | |
$.each(a, function () { | |
if (o[this.name] !== undefined) { | |
if (!o[this.name].push) { | |
o[this.name] = [o[this.name]]; | |
} | |
o[this.name].push(this.value || ''); | |
} else { | |
o[this.name] = this.value || ''; | |
} | |
}); | |
return o; | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment