Commit d1411789ec8978a49f8cfd350b130be34c9a66e1

Authored by Jose Pinto
1 parent 26e51263bb
Exists in master and in 1 other branch develop

boton con imagen

Showing 1 changed file with 4 additions and 1 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .controller('focaAbmVehiculosController', [ 2 .controller('focaAbmVehiculosController', [
3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', 3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService',
4 '$uibModal', 'focaBotoneraLateralService', '$timeout', 4 '$uibModal', 'focaBotoneraLateralService', '$timeout',
5 function($scope, focaAbmVehiculoService, $location, focaModalService, 5 function($scope, focaAbmVehiculoService, $location, focaModalService,
6 $uibModal, focaBotoneraLateralService, $timeout) { 6 $uibModal, focaBotoneraLateralService, $timeout) {
7 7
8 $scope.now = new Date(); 8 $scope.now = new Date();
9 $scope.botonera = ['Transportista']; 9 $scope.botonera = [{
10 label: 'Transportista',
11 image: 'cliente.png'
12 }];
10 13
11 //SETEO BOTONERA LATERAL 14 //SETEO BOTONERA LATERAL
12 focaBotoneraLateralService.showSalir(true); 15 focaBotoneraLateralService.showSalir(true);
13 focaBotoneraLateralService.showPausar(false); 16 focaBotoneraLateralService.showPausar(false);
14 focaBotoneraLateralService.showCancelar(false); 17 focaBotoneraLateralService.showCancelar(false);
15 focaBotoneraLateralService.showGuardar(false); 18 focaBotoneraLateralService.showGuardar(false);
16 19
17 if(focaAbmVehiculoService.transportistaSeleccionado.COD) { 20 if(focaAbmVehiculoService.transportistaSeleccionado.COD) {
18 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); 21 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado);
19 } 22 }
20 23
21 $scope.editar = function(id) { 24 $scope.editar = function(id) {
22 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); 25 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista);
23 }; 26 };
24 $scope.solicitarConfirmacion = function(vehiculo) { 27 $scope.solicitarConfirmacion = function(vehiculo) {
25 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + 28 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
26 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( 29 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
27 function(data) { 30 function(data) {
28 if(data) { 31 if(data) {
29 focaAbmVehiculoService.deleteVehiculo(vehiculo.id); 32 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
30 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 33 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
31 } 34 }
32 } 35 }
33 ); 36 );
34 }; 37 };
35 $scope.seleccionarTransportista = function() { 38 $scope.seleccionarTransportista = function() {
36 var modalInstance = $uibModal.open( 39 var modalInstance = $uibModal.open(
37 { 40 {
38 ariaLabelledBy: 'Busqueda de Transportista', 41 ariaLabelledBy: 'Busqueda de Transportista',
39 templateUrl: 'modal-proveedor.html', 42 templateUrl: 'modal-proveedor.html',
40 controller: 'focaModalProveedorCtrl', 43 controller: 'focaModalProveedorCtrl',
41 size: 'lg', 44 size: 'lg',
42 resolve: { 45 resolve: {
43 transportista: function() { 46 transportista: function() {
44 return true; 47 return true;
45 } 48 }
46 } 49 }
47 } 50 }
48 ); 51 );
49 modalInstance.result.then( 52 modalInstance.result.then(
50 function(transportista) { 53 function(transportista) {
51 elegirTransportista(transportista); 54 elegirTransportista(transportista);
52 focaAbmVehiculoService.transportistaSeleccionado = transportista; 55 focaAbmVehiculoService.transportistaSeleccionado = transportista;
53 }, function() { 56 }, function() {
54 57
55 } 58 }
56 ); 59 );
57 }; 60 };
58 61
59 function elegirTransportista(transportista) { 62 function elegirTransportista(transportista) {
60 var codigo = ('00000' + transportista.COD).slice(-5); 63 var codigo = ('00000' + transportista.COD).slice(-5);
61 $scope.idTransportista = transportista.COD; 64 $scope.idTransportista = transportista.COD;
62 $scope.filtros = transportista.NOM.trim(); 65 $scope.filtros = transportista.NOM.trim();
63 $timeout(function() { 66 $timeout(function() {
64 $scope.$broadcast('addCabecera', { 67 $scope.$broadcast('addCabecera', {
65 label: 'Transportista:', 68 label: 'Transportista:',
66 valor: codigo + ' - ' + transportista.NOM 69 valor: codigo + ' - ' + transportista.NOM
67 }); 70 });
68 }); 71 });
69 buscar(transportista.COD); 72 buscar(transportista.COD);
70 } 73 }
71 74
72 function buscar(idTransportista) { 75 function buscar(idTransportista) {
73 focaAbmVehiculoService 76 focaAbmVehiculoService
74 .getVehiculosPorTransportista(idTransportista) 77 .getVehiculosPorTransportista(idTransportista)
75 .then(function(datos) { 78 .then(function(datos) {
76 $scope.vehiculos = datos.data; 79 $scope.vehiculos = datos.data;
77 }); 80 });
78 } 81 }
79 } 82 }
80 ]) 83 ])
81 .controller('focaAbmVehiculoController', [ 84 .controller('focaAbmVehiculoController', [
82 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 85 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
83 'focaModalService', '$timeout', 'focaBotoneraLateralService', 86 'focaModalService', '$timeout', 'focaBotoneraLateralService',
84 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 87 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
85 focaModalService, $timeout, focaBotoneraLateralService) { 88 focaModalService, $timeout, focaBotoneraLateralService) {
86 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; 89 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
87 $scope.now = new Date(); 90 $scope.now = new Date();
88 $scope.focused = 1; 91 $scope.focused = 1;
89 92
90 $timeout(function() { 93 $timeout(function() {
91 focaBotoneraLateralService.showSalir(false); 94 focaBotoneraLateralService.showSalir(false);
92 focaBotoneraLateralService.showPausar(false); 95 focaBotoneraLateralService.showPausar(false);
93 focaBotoneraLateralService.showCancelar(true, '/vehiculo'); 96 focaBotoneraLateralService.showCancelar(true, '/vehiculo');
94 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 97 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
95 }); 98 });
96 99
97 if($scope.nuevo) { 100 if($scope.nuevo) {
98 focaAbmVehiculoService 101 focaAbmVehiculoService
99 .getTransportistaPorId($routeParams.idTransportista) 102 .getTransportistaPorId($routeParams.idTransportista)
100 .then(function(res) { 103 .then(function(res) {
101 var codigo = ('00000' + res.data.COD).slice(-5); 104 var codigo = ('00000' + res.data.COD).slice(-5);
102 $scope.vehiculo.idTransportista = res.data.COD; 105 $scope.vehiculo.idTransportista = res.data.COD;
103 $scope.vehiculo.transportista = res.data; 106 $scope.vehiculo.transportista = res.data;
104 $scope.$broadcast('addCabecera', { 107 $scope.$broadcast('addCabecera', {
105 label: 'Transportista:', 108 label: 'Transportista:',
106 valor: codigo + ' - ' + res.data.NOM 109 valor: codigo + ' - ' + res.data.NOM
107 }); 110 });
108 }); 111 });
109 } 112 }
110 $scope.vehiculo = {}; 113 $scope.vehiculo = {};
111 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 114 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
112 if(res.data) { 115 if(res.data) {
113 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 116 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
114 $scope.vehiculo = res.data; 117 $scope.vehiculo = res.data;
115 $scope.$broadcast('addCabecera', { 118 $scope.$broadcast('addCabecera', {
116 label: 'Transportista:', 119 label: 'Transportista:',
117 valor: codigo + ' - ' + res.data.transportista.NOM 120 valor: codigo + ' - ' + res.data.transportista.NOM
118 }); 121 });
119 $scope.$broadcast('addCabecera', { 122 $scope.$broadcast('addCabecera', {
120 label: 'Unidad:', 123 label: 'Unidad:',
121 valor: res.data.codigo 124 valor: res.data.codigo
122 }); 125 });
123 } 126 }
124 }); 127 });
125 focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo) 128 focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo)
126 .then(function(res) { 129 .then(function(res) {
127 $scope.cisternas = res.data; 130 $scope.cisternas = res.data;
128 }); 131 });
129 $scope.next = function(key) { 132 $scope.next = function(key) {
130 if (key === 13) $scope.focused++; 133 if (key === 13) $scope.focused++;
131 }; 134 };
132 $scope.cancelar = function() { 135 $scope.cancelar = function() {
133 $location.path('/vehiculo'); 136 $location.path('/vehiculo');
134 }; 137 };
135 $scope.editar = function(id) { 138 $scope.editar = function(id) {
136 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/' + id); 139 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/' + id);
137 }; 140 };
138 $scope.guardar = function() { 141 $scope.guardar = function() {
139 //Valida si existe numero de unidad 142 //Valida si existe numero de unidad
140 existeCodigoUnidad().then(function() { 143 existeCodigoUnidad().then(function() {
141 delete $scope.vehiculo.transportista; 144 delete $scope.vehiculo.transportista;
142 delete $scope.vehiculo.cisternas; 145 delete $scope.vehiculo.cisternas;
143 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) 146 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
144 .then(function(res){ 147 .then(function(res){
145 if($scope.nuevo) { 148 if($scope.nuevo) {
146 $location.path('/vehiculo/' + res.data.id + 149 $location.path('/vehiculo/' + res.data.id +
147 '/' + res.data.idTransportista); 150 '/' + res.data.idTransportista);
148 } else { 151 } else {
149 $location.path('/vehiculo'); 152 $location.path('/vehiculo');
150 } 153 }
151 }); 154 });
152 }, function(){ 155 }, function(){
153 focaModalService.alert('Código de unidad existente'); 156 focaModalService.alert('Código de unidad existente');
154 }); 157 });
155 158
156 }; 159 };
157 $scope.solicitarConfirmacionCisterna = function(cisterna) { 160 $scope.solicitarConfirmacionCisterna = function(cisterna) {
158 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + 161 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
159 cisterna.id + ' ' + cisterna.codigo + ' ?').then( 162 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
160 function(data) { 163 function(data) {
161 if(data) { 164 if(data) {
162 focaAbmVehiculoService.deleteCisterna(cisterna.id); 165 focaAbmVehiculoService.deleteCisterna(cisterna.id);
163 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1); 166 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1);
164 } 167 }
165 } 168 }
166 ); 169 );
167 }; 170 };
168 $scope.seleccionarTransportista = function() { 171 $scope.seleccionarTransportista = function() {
169 var modalInstance = $uibModal.open( 172 var modalInstance = $uibModal.open(
170 { 173 {
171 ariaLabelledBy: 'Busqueda de Transportista', 174 ariaLabelledBy: 'Busqueda de Transportista',
172 templateUrl: 'modal-proveedor.html', 175 templateUrl: 'modal-proveedor.html',
173 controller: 'focaModalProveedorCtrl', 176 controller: 'focaModalProveedorCtrl',
174 size: 'lg', 177 size: 'lg',
175 resolve: { 178 resolve: {
176 transportista: function() { 179 transportista: function() {
177 return true; 180 return true;
178 } 181 }
179 } 182 }
180 } 183 }
181 ); 184 );
182 modalInstance.result.then( 185 modalInstance.result.then(
183 function(transportista) { 186 function(transportista) {
184 $scope.vehiculo.idTransportista = transportista.COD; 187 $scope.vehiculo.idTransportista = transportista.COD;
185 $scope.vehiculo.transportista = transportista; 188 $scope.vehiculo.transportista = transportista;
186 }, function() { 189 }, function() {
187 190
188 } 191 }
189 ); 192 );
190 }; 193 };
191 194
192 function existeCodigoUnidad(){ 195 function existeCodigoUnidad(){
193 return new Promise(function(resolve, reject) { 196 return new Promise(function(resolve, reject) {
194 focaAbmVehiculoService 197 focaAbmVehiculoService
195 .getVehiculosPorTransportista($routeParams.idTransportista) 198 .getVehiculosPorTransportista($routeParams.idTransportista)
196 .then(function(res){ 199 .then(function(res){
197 //Valida si existe numero de unidad 200 //Valida si existe numero de unidad
198 var existe = res.data.filter(function(vehiculo) { 201 var existe = res.data.filter(function(vehiculo) {
199 return vehiculo.codigo === $scope.vehiculo.codigo && 202 return vehiculo.codigo === $scope.vehiculo.codigo &&
200 vehiculo.id !== $scope.vehiculo.id; 203 vehiculo.id !== $scope.vehiculo.id;
201 }); 204 });
202 205
203 if(existe.length){ 206 if(existe.length){
204 reject(existe); 207 reject(existe);
205 } else { 208 } else {
206 resolve(); 209 resolve();
207 } 210 }
208 }); 211 });
209 }); 212 });
210 } 213 }
211 } 214 }
212 ]); 215 ]);
213 216