Skip to content

Instantly share code, notes, and snippets.

@GlauberF
Created July 25, 2017 19:09
Show Gist options
  • Save GlauberF/8d76b145dbbc179b1fb9cab6b60a908d to your computer and use it in GitHub Desktop.
Save GlauberF/8d76b145dbbc179b1fb9cab6b60a908d to your computer and use it in GitHub Desktop.
(function ()
{
'use strict';
angular
.module('app.tabelasFixas.cest')
.controller('CestController', CestController);
/** @ngInject */
function CestController($state, Cest, $timeout, $http, $log)
{
// -------------------------- consts inicio ---------------------------------- //
var vm = this;
// -------------------------- consts final ---------------------------------- //
// -------------------------- Data inicio ----------------------------------- //
vm.cest = Cest;
vm.cestDetalhe = cestDetalhe;
vm.cestDeletar = cestDeletar;
// -------------------------- Data final ------------------------------------ //
// -------------------------- Methods inicio ------------------------------- //
function atualizarDados() {
$http.get('https://vimbo-gestao.ml/v1/cest/listar')
.then(function(resposta){
vm.cest = resposta.data;
})
}
vm.dtInstance = {};
vm.dtOptions = {
dom : 'rt<"bottom"<"left"<"length"l>><"right"<"info"i><"pagination"p>>>',
columnDefs : [
{
// Target the id column
targets: 0,
width : '72px'
},
{
// Target the image column
targets : 1,
filterable: false,
sortable : false,
width : '80px'
},
{
// Target the status column
targets : 4,
responsivePriority: 1,
filterable : false,
sortable : false
},
{
// Target the actions column
targets : 5,
responsivePriority: 1,
filterable : false,
sortable : false
}
],
initComplete: function ()
{
var api = this.api(),
searchBox = angular.element('body').find('#cest-buscar');
// Bind an external input as a table wide search box
if ( searchBox.length > 0 )
{
searchBox.on('keyup', function (event)
{
api.search(event.target.value).draw();
});
}
},
pagingType : 'simple',
lengthMenu : [10, 20, 30, 50, 100, 300],
pageLength : 10,
scrollY : 'auto',
responsive : true,
language: {
"sEmptyTable": "Nenhum registro encontrado",
"sInfo": "Mostrando de _START_ até _END_ de _TOTAL_ registros",
"sInfoEmpty": "Mostrando 0 até 0 de 0 registros",
"sInfoFiltered": "(Filtrados de _MAX_ registros)",
"sInfoPostFix": "",
"sInfoThousands": ".",
"sLengthMenu": "_MENU_ resultados por página",
"sLoadingRecords": "Carregando...",
"sProcessing": "Processando...",
"sZeroRecords": "Nenhum registro encontrado",
"sSearch": "Pesquisar",
"oPaginate": {
"sNext": "Próximo",
"sPrevious": "Anterior",
"sFirst": "Primeiro",
"sLast": "Último"
},
"oAria": {
"sSortAscending": ": Ordenar colunas de forma ascendente",
"sSortDescending": ": Ordenar colunas de forma descendente"
}
}
};
function cestDetalhe(id)
{
$state.go('app.tabelasFixas.cest.edit' , {id: id});
}
function cestDeletar(cest)
{
swal({
title: "Você tem certeza?",
text: "Deseja excluir permanentemente o CEST " + cest.ces_codigo,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Sim",
cancelButtonText: "Não",
closeOnConfirm: false,
closeOnCancel: true
},
function(){
var url = 'https://vimbo-gestao.ml/v1/cest/deletar?_id='+ cest._id;
$http.delete(url)
.then(function(res){
swal("Deletado!", 'O CEST ' + cest.ces_codigo + ' foi deletedado definitivamente com sucesso', "success");
//atualizarDados()
}, function(err) {
swal("Erro!", 'Não foi possível deletar O CEST ' + cest.ces_codigo + ', tente novamente mais tarde', "warning");
})
.catch(function(errLog) {
$log.info(errLog);
});
}
);
atualizarDados()
}
// -------------------------- Methods final ------------------------------- //
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment