Created
March 16, 2016 14:39
-
-
Save fernandolopes/51bfa6a8c8829bd3a477 to your computer and use it in GitHub Desktop.
controller
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
'use strict'; | |
/** | |
* @ngdoc function | |
* @name VR.controller:ChecklistoperadorCtrl | |
* @description | |
* # ChecklistoperadorCtrl | |
* Controller of the VR | |
*/ | |
angular.module('VR') | |
.controller('CheckListOperadorCtrl', function ($scope, $location, $compile, $log, $http, $sessionStorage, $routeParams, jqWindow, $timeout) { | |
$scope.tableId = 'grid-checklist-operador'; | |
$scope.pagerId = 'pager-checklist-operador'; | |
var func = this.cliente = function(){ | |
alert('lll'); | |
}; | |
$scope.verificarGrupo = function(){ | |
$http.get('api/users/is_grupo/CLIENTE') | |
.success(function(data){ | |
if(data.result == false){ | |
$location.path('/checklist_operador'); | |
} | |
}); | |
}; | |
$scope.verificarGrupo(); | |
this.checklistStatus = function(cellvalue, options, rowObject) { | |
var url = 'images/'; | |
if(cellvalue == 'VERIFICANDO') { | |
var img = url + 'status_verificando.png'; | |
var html = '<p style="text-align: center;margin: 0px"><a data-toggle="tooltip" title="CHECKLIST EM VERIFICAÇÃO" href="#"><img src="'+ img +'"/></a></p>'; | |
} else if(cellvalue == 'EM_TESTE') { | |
var img = url + 'status_em_teste.png'; | |
var html = '<p style="text-align: center;margin: 0px"><a data-toggle="tooltip" title="CHECKLIST EM TESTE" href="#"><img src="'+ img +'"/></a></p>'; | |
} else if(cellvalue == 'APROVADO') { | |
var img = url + 'status_aprovado.png'; | |
var html = '<p style="text-align: center;margin: 0px"><a data-toggle="tooltip" title="CHECKLIST APROVADO" href="#"><img src="'+ img +'"/></a></p>'; | |
} else if(cellvalue == 'REPROVADO') { | |
var img = url + 'status_reprovado.png'; | |
var html = '<p style="text-align: center;margin: 0px"><a data-toggle="tooltip" title="CHECKLIST REPROVADO" href="#"><img src="'+ img +'"/></a></p>'; | |
} else if(cellvalue == 'PENDENTE') { | |
var img = url + 'status_pendente.png'; | |
var html = '<p style="text-align: center;margin: 0px"><a data-toggle="tooltip" title="CHECKLIST PENDENTE" href="#"><img src="'+ img +'"/></a></p>'; | |
} else if(cellvalue == 'LIBERADO') { | |
var img = url + 'status_liberado.png'; | |
var html = '<p style="text-align: center;margin: 0px"><a data-toggle="tooltip" title="CHECKLIST LIBERADO" href="#"><img src="'+ img +'"/></a></p>'; | |
} else if(cellvalue == 'CANCELADO') { | |
var img = url + 'status_cancelado.png'; | |
var html = '<p style="text-align: center;margin: 0px"><a data-toggle="tooltip" title="CHECKLIST CANCELADO" href="#"><img src="'+ img +'"/></a></p>'; | |
} else if(cellvalue == 'EXPIRADO') { | |
var img = url + 'status_expirado.png'; | |
var html = '<p style="text-align: center;margin: 0px"><a data-toggle="tooltip" title="CHECKLIST EXPIRADO" href="#"><img src="'+ img +'"/></a></p>'; | |
} else if(cellvalue == 'MANUTENCAO') { | |
var img = url + 'status_manutencao.png'; | |
var html = '<p style="text-align: center;margin: 0px"><a data-toggle="tooltip" title="CHECKLIST EM MANUTENÇÃO" href="#"><img src="'+ img +'"/></a></p>'; | |
} | |
return html; | |
}; | |
this.modalCancelar = function(){ | |
$scope.showModalCancelar(true, 1, null); | |
}; | |
this.checklistComandos = function( cellvalue, options, rowObject ) { | |
var grid_selector = "#"+$scope.gridId; | |
if(rowObject.status == 'VERIFICANDO') { | |
var html = '<span title="VEÍCULO SEM ESPELHAMENTO" style="cursor: pointer;" class="infor-1" id="'+rowObject.id+'"><img src="images/sem_sinal_1.png"/></span>'; | |
html += '<span title="VEÍCULO SEM CONFIGURAÇÃO" style="margin-left:5px; cursor: pointer;" id="'+rowObject.id+'" class="infor-2"><img src="images/sem_configuracao.png"/></span>'; | |
html += '<span title="VEÍCULO ESPELHADO E CONFIGURADO" style="margin-left:5px; cursor: pointer;" class="info3" id="'+rowObject.id+'"><img src="images/positivo_4.png"/></span>'; | |
html += '<span title="CANCELAR CHECKLIST DO VEÍCULO" style="margin-left:5px; cursor: pointer;" dialog="true" cancelar="true" action="#action4" onclick="this.modalCancelar()" class="cancelar" id="'+rowObject.id+'"><img src="images/status_cancelado.png"/></span>'; | |
} else if(rowObject.status == 'APROVADO' || rowObject.status == 'LIBERADO' || rowObject.status == 'CANCELADO' || rowObject.status == 'EXPIRADO' ) { | |
var html = '<span style="text-align: center;margin: 0px; cursor: pointer;" title="VISUALIZAR CHECKLIST" class="visualizar" id="'+rowObject.id+'" ><img src="images/visualizar.png"/></span>'; | |
} else if(rowObject.status == 'REPROVADO') { | |
var html = '<span style="text-align: center;margin: 0px; cursor: pointer;" title="LIBERAR CHECKLIST" class="liberar" id="'+rowObject.id+'"><img src="images/liberar.png"/></span>'; | |
html += '<span style="margin-left:10px; cursor: pointer;" title="EDITAR CHECKLIST" class="edit" id="'+rowObject.id+'" ><img src="images/visualizar.png"/></span>'; | |
} else if(rowObject.status == 'MANUTENCAO') { | |
var html = '<span style="text-align: center;margin: 0px; cursor: pointer;" title="MANUTENÇÃO DO CHECKLIST" class="testar" id="'+rowObject.id+'"><img src="images/visualizar.png"/></span>'; | |
} else { | |
var html = '<span style="text-align: center;margin: 0px; cursor: pointer;" class="testar" title="EDITAR CHECKLIST" id="'+rowObject.id+'"><img src="images/visualizar.png"/></span>'; | |
} | |
return "<p style=\"text-align: center;margin: 0px\">"+html+"</p>"; | |
}; | |
var date = new Date(); | |
var ano = date.getFullYear(); | |
var mes = date.getMonth() + 1; | |
if(mes < 10) { | |
mes = '0' + mes; | |
} | |
var lastDay = (new Date(ano, mes, 0)).getDate(); | |
var maxDate = date.getDate() + '/' + mes + '/' + ano; | |
var startDate = '01/' + mes + '/' + ano; | |
var endDate = lastDay + '/' + mes + '/' + ano; | |
var rangePicker; | |
this.dateRangePick = function(elem) { | |
rangePicker = $(elem).daterangepicker({ | |
format: 'DD/MM/YYYY', | |
startDate: startDate, | |
maxDate: maxDate, | |
'applyClass' : 'btn-sm btn-success', | |
'cancelClass' : 'btn-sm btn-default', | |
language: 'pt-BR', | |
locale : { fromLabel: 'DE', cancelLabel : 'Cancelar', applyLabel : 'Aplicar', toLabel : 'PARA'} | |
}).on('apply.daterangepicker', function(ev, picker) { | |
var d = picker.startDate.format('DD/MM/YYYY') + ' - ' + picker.endDate.format('DD/MM/YYYY'); | |
$('#'+$scope.tableId)[0].p.search = true; | |
jQuery.extend($('#'+$scope.tableId)[0].p.postData,{data_cadastro:JSON.stringify(d)}); | |
$('#'+$scope.tableId).trigger("reloadGrid") | |
}); | |
}; | |
var searchValue = ':FILA;TODOS:TODOS;VERIFICANDO:VERIFICANDO;EM_TESTE:EM TESTE;PENDENTE:PENDENTE;APROVADO:APROVADO;REPROVADO:REPROVADO;MANUTENCAO:MANUTENCAO;LIBERADO:LIBERADO;CANCELADO:CANCELADO;EXPIRADO:EXPIRADO'; | |
var searchIgnicao = ':TODOS;true:LIGADA;false:DESLIGADA'; | |
$scope.config = { | |
url : 'api/check_lists/operador', | |
datatype: "json", | |
mtype: "GET", | |
height: 'auto', | |
autowidth: true, | |
sortable: true, | |
sortname: 'id', | |
sortorder: 'DESC', | |
shrinkToFit: false, | |
viewrecords : true, | |
rowNum: 18, | |
rowList: [18,20,30,50,100], | |
scrollOffset: 0, | |
width: '100%', | |
altRows: true, | |
pager : '#'+ $scope.pagerId, | |
colNames:['ID', 'AÇÕES', 'PLACA', 'TERMINAL', 'TECNOLOGIA', 'VINCULO', 'CLIENTE', 'STATUS', 'CADASTRADO POR', 'PROTOCOLO' ,'DATA DE CADASTRO', 'DATA VALIDADE', 'DATA FINALIZADO', 'TEMPO VERIFICAÇÃO', 'TEMPO EM TESTE', 'TEMPO DECORRIDO'], | |
colModel: [ | |
{name:'id',index:'id', width:100, sorttype:"int", sortable:true }, | |
{name:'cmd',index:'', width:115, fixed:true, search: false, sortable:false, resize:false, formatter:this.checklistComandos}, | |
{name:'placa', index:'placa', width:100, sortable:false, searchoptions:{ }}, | |
{name:'terminal', index:'terminal', width:150, sortable:false}, | |
{name:'tecnologia', index:'tecnologia', width:150, sortable:false}, | |
{name:'vinculo', index:'vinculo', width:100, sortable:false}, | |
{name:'cliente', index:'cliente', width:300, sortable:true}, | |
{name:'status', index:'status', sortable:false, width:180, formatter:this.checklistStatus, stype: 'select', searchoptions: { value:searchValue, sopt:['eq'] } }, | |
{name:'username_add', index:'username_add', width:150}, | |
{name:'protocolo', index:'protocolo', width:100}, | |
{name:'data_cadastro', index:'data_cadastro', width:150, sortable:true, formatter:'date', formatoptions:{ | |
srcformat: 'Y-m-d H:i:s', | |
newformat: 'd/m/Y H:i:s' | |
}, searchoptions:{ | |
defaultValue: startDate + ' - ' + maxDate, | |
dataInit:this.dateRangePick, | |
att:{ | |
title:'selecione a data' | |
} | |
} | |
}, | |
{name:'data_validade', index:'data_validade', width:130, search: false, sortable:false, formatter:'date',formatoptions:{ | |
srcformat: 'Y-m-d', | |
newformat: 'd/m/Y' | |
}}, | |
{name:'data_finalizado', index:'data_finalizado', width:150, search: false, sortable:false, formatter:'date',formatoptions:{ | |
srcformat: 'Y-m-d', | |
newformat: 'd/m/Y' | |
}}, | |
{name:'tempo_verificacao', index:'tempo_verificacao', width:150, search: false, sortable:false }, | |
{name:'tempo_em_teste', index:'tempo_em_teste', width:150, search: false, sortable:false }, | |
{name:'tempo_decorrido', index:'tempo_decorrido', width:150, search: false, sortable:false } | |
], | |
loadBeforeSend: function(xhr) { | |
if($sessionStorage.usuario == undefined){ | |
$location.path('/login'); | |
} | |
xhr.setRequestHeader("Authorization", $sessionStorage.usuario.token); | |
}, | |
loadError: function(response){ | |
if(response.status === 401 || response.status === 403) { | |
$location.path('/login'); | |
} | |
}, | |
loadComplete: function() { | |
var table = this; | |
setTimeout(function() { | |
updatePagerIcons(table); | |
$('.testar').click(function(){ | |
var id = $(this).attr('id'); | |
var config = { | |
width : '80%', | |
height : '60%', | |
title : 'Teste' | |
}; | |
var window = jqWindow.add('cliente', config); | |
var content = $compile('<teste-form entity="'+id+'" window="'+window.id+'"></teste-form>')($scope); | |
window.setContent(content); | |
window.show(); | |
}); | |
$('.visualizar').click(function(){ | |
var id = $(this).attr('id'); | |
var config = { | |
width : '80%', | |
height : '60%', | |
title : 'Visualizar' | |
}; | |
var window = jqWindow.add('cliente', config); | |
var content = $compile('<visualizar-form entity="'+id+'" window="'+window.id+'"></visualizar-form>')($scope); | |
window.setContent(content); | |
window.show(); | |
}); | |
$('.edit').click(function(){ | |
var id = $(this).attr('id'); | |
var config = { | |
width : '80%', | |
height : '60%', | |
title : 'Editar Teste' | |
}; | |
var window = jqWindow.add('cliente', config); | |
var content = $compile('<teste-form entity="'+id+'" window="'+window.id+'"></teste-form>')($scope); | |
window.setContent(content); | |
window.show(); | |
}); | |
// enableTooltips(table); | |
}, 0); | |
}, | |
onSelectRow: function(rowId) { | |
}, | |
ondblClickRow: function(rowId, iRow, iCol, e) { | |
$scope.showModal(true, rowId, null); | |
}, | |
onRightClickRow: function(rowId, iRow, iCol, e) { | |
}, | |
contextMenu : function(table) { | |
$(".jqgrow", table).contextMenu('contextMenu', { | |
menuStyle : { | |
width : "150px" | |
}, | |
bindings : { | |
'add': function (t) { | |
var config = { | |
width : '80%', | |
height : '60%', | |
title : 'Checklist' | |
}; | |
var window = jqWindow.add('cliente', config); | |
var content = $compile('<cliente-form window="'+window.id+'"></cliente-form>')($scope); | |
window.setContent(content); | |
window.show(); | |
}, | |
'visualizar': function (t) { | |
var rowId = $(table).jqGrid('getGridParam', 'selrow'); | |
var config = { | |
width : '70%', | |
height : '65%', | |
title : 'Visualizar Checklist' | |
}; | |
var window = jqWindow.add('visualizar-checklist', config); | |
var content = $compile('<visualizar-checklist entity="' + rowId + '"></visualizar-checklist>')($scope); | |
window.setContent(content); | |
window.show(); | |
} | |
}, | |
onContextMenu: function (event, menu) { | |
var rowId = $(event.target).parent("tr").attr("id"); | |
var grid = $(table); | |
grid.setSelection(rowId); | |
return true; | |
} | |
}); | |
} | |
}; | |
$scope.addButtons = function(){ | |
var navButton = $('#'+$scope.tableId).jqGrid('navGrid','#'+$scope.pagerId,{edit:false,add:false,del:false,refresh:false,search:false,autocomplete:false}); | |
navButton.navButtonAdd( '#'+$scope.pagerId, { | |
caption:"", | |
title: "Adicionar", | |
buttonicon:"ico-sm-incluir", | |
href: '#', | |
onClickButton: function(){ | |
var config = { | |
width : '80%', | |
height : '60%', | |
title : 'Checklist' | |
}; | |
var window = jqWindow.add('cliente', config); | |
var content = $compile('<checklist-form window="'+window.id+'"></checklist-form>')($scope); | |
window.setContent(content); | |
window.show(); | |
}, | |
position:"last" | |
}); | |
navButton.navButtonAdd( '#'+$scope.pagerId, { | |
caption:"", | |
title: "Visualizar", | |
buttonicon:"ico-sm-visualizar", | |
href: '#', | |
onClickButton: function(){ | |
var rowId = $('#grid-cliente').jqGrid('getGridParam', 'selrow'); | |
var config = { | |
width : '80%', | |
height : '60%', | |
title : 'Checklist' | |
}; | |
var window = jqWindow.add('cliente', config); | |
var content = $compile('<checklist-form window="'+window.id+'" entity="'+rowId+'"></checklist-form>')($scope); | |
window.setContent(content); | |
window.show(); | |
} | |
}); | |
$('#alertmod_'+$scope.tableId).remove(); | |
}; | |
$scope.gridComplete = function() | |
{ | |
if ($('#'+this.tableId).jqGrid('getGridParam','records') == 0) { | |
$(".ui-jqgrid-hdiv").css("overflow-x", "auto"); | |
$('#'+this.tableId).jqGrid().addRowData(0, {}); | |
$('tr[id=0]', $('#'+this.tableId).jqGrid()).html('<td colspan="13">NENHUM CHECKLIST FOI ENCONTRADO NESTA PESQUISA...</td>'); | |
} else { | |
$(".ui-jqgrid-hdiv").css("overflow-x", "hidden"); | |
} | |
} | |
function updatePagerIcons(table) { | |
$scope.gridComplete(); | |
var replacement = | |
{ | |
'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140', | |
'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140', | |
'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140', | |
'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140' | |
}; | |
$('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function() { | |
var icon = $(this); | |
var $class = $.trim(icon.attr('class').replace('ui-icon', '')); | |
if($class in replacement) { | |
icon.attr('class', 'ui-icon '+replacement[$class]); | |
} | |
}); | |
} | |
$timeout( | |
function(){ | |
$scope.addButtons(); | |
$('input').attr('autocomplete','off'); | |
}, | |
1000); | |
function enableTooltips(table) { | |
$('.ui-pg-button').tooltip({ | |
hide: { | |
effect: "explode", | |
delay: 250 | |
}, | |
container:'body' | |
}); | |
$('.ui-pg-div').tooltip({ | |
hide: { | |
effect: "explode", | |
delay: 250 | |
}, | |
container:'body' | |
}); | |
$('[data-toggle="tooltip"]').tooltip({ | |
hide: { | |
effect: "explode", | |
delay: 250 | |
}, | |
container:'body' | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment