controller.js
5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
angular.module('focaAbmChofer')
.controller('focaAbmChoferesController', [
'$scope', 'focaAbmChoferService', '$location', '$uibModal',
'focaModalService', 'focaBotoneraLateralService', '$timeout',
function($scope, focaAbmChoferService, $location, $uibModal, focaModalService,
focaBotoneraLateralService, $timeout) {
$scope.now = new Date();
$scope.filters = '';
$scope.choferes = [];
$scope.botonera = ['Transportista'];
$scope.focused = 1;
//SETEO BOTONERA LATERAL
$timeout(function() {
focaBotoneraLateralService.showSalir(true);
focaBotoneraLateralService.showPausar(false);
focaBotoneraLateralService.showCancelar(false);
focaBotoneraLateralService.showGuardar(false);
});
if(focaAbmChoferService.transportistaSeleccionado.COD) {
elegirTransportista(focaAbmChoferService.transportistaSeleccionado);
}
$scope.editar = function(id) {
$location.path('/chofer/' + id + '/' + $scope.idTransportista);
};
$scope.solicitarConfirmacion = function(chofer) {
focaModalService.confirm('¿Está seguro que desea borrar el chofer ' +
chofer.nombre + ' ?').then(function(confirmed) {
if(confirmed) {
focaAbmChoferService.deleteChofer(chofer.id);
$scope.choferes.splice($scope.choferes.indexOf(chofer), 1);
}
});
};
$scope.seleccionarTransportista = function() {
var modalInstance = $uibModal.open(
{
ariaLabelledBy: 'Busqueda de Transportista',
templateUrl: 'modal-proveedor.html',
controller: 'focaModalProveedorCtrl',
size: 'lg',
resolve: {
transportista: function() {
return true;
}
}
}
);
modalInstance.result.then(
function(transportista) {
elegirTransportista(transportista);
focaAbmChoferService.transportistaSeleccionado = transportista;
}, function() {}
);
};
function elegirTransportista(transportista) {
buscar(transportista.COD);
var codigo = ('00000' + transportista.COD).slice(-5);
$scope.idTransportista = transportista.COD;
$timeout(function() {
$scope.$broadcast('addCabecera', {
label: 'Transportista:',
valor: codigo + ' - ' + transportista.NOM
});
});
}
function buscar(id) {
focaAbmChoferService.getChoferPorTransportista(id).then(function(res) {
$scope.choferes = res.data;
});
}
}
])
.controller('focaAbmChoferController', [
'$scope', 'focaAbmChoferService', '$routeParams',
'$location', 'focaBotoneraLateralService', '$timeout',
function($scope, focaAbmChoferService, $routeParams,
$location, focaBotoneraLateralService, $timeout) {
$scope.nuevo = $routeParams.id === '0';
$scope.chofer = {};
$scope.transportistas = [];
$scope.now = new Date();
$scope.next = function(key) {
if (key === 13) $scope.focused++;
};
//SETEO BOTONERA LATERAL
$timeout(function() {
focaBotoneraLateralService.showSalir(false);
focaBotoneraLateralService.showPausar(true);
focaBotoneraLateralService.showCancelar(true);
focaBotoneraLateralService.showGuardar(true, $scope.guardar);
});
if($scope.nuevo) {
focaAbmChoferService
.getTransportistaPorId($routeParams.idTransportista)
.then(function(res) {
var codigo = ('00000' + res.data.COD).slice(-5);
$scope.chofer.idTransportista = res.data.COD;
$scope.chofer.transportista = res.data;
$scope.$broadcast('addCabecera', {
label: 'Transportista:',
valor: codigo + ' - ' + res.data.NOM
});
});
}
focaAbmChoferService.getChofer($routeParams.id).then(function(res) {
if(res.data) {
var codigo = ('00000' + res.data.transportista.COD).slice(-5);
$scope.chofer = res.data;
$scope.$broadcast('addCabecera', {
label: 'Transportista:',
valor: codigo + ' - ' + res.data.transportista.NOM
});
}
});
focaAbmChoferService.getTransportistas().then(function(res) {
$scope.transportistas = res.data;
});
$scope.cancelar = function() {
$location.path('/chofer');
};
$scope.guardar = function() {
$scope.chofer.idTransportista = $routeParams.idTransportista;
delete $scope.chofer.transportista;
focaAbmChoferService.guardarChofer($scope.chofer).then(function() {
$location.path('/chofer');
});
};
}
]);