Commit 025d712e32b912a2be88557eec4fd35ecb84c95c
Exists in
master
Merge branch 'master' into 'master'
Master See merge request !23
Showing
2 changed files
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 = [{ | 9 | $scope.botonera = [{ |
| 10 | label: 'Transportista', | 10 | label: 'Transportista', |
| 11 | image: 'cliente.png' | 11 | image: 'cliente.png' |
| 12 | }]; | 12 | }]; |
| 13 | 13 | ||
| 14 | focaAbmVehiculoService.cleanCisternas(); | ||
| 15 | |||
| 14 | //SETEO BOTONERA LATERAL | 16 | //SETEO BOTONERA LATERAL |
| 15 | focaBotoneraLateralService.showSalir(false); | 17 | focaBotoneraLateralService.showSalir(false); |
| 16 | focaBotoneraLateralService.showPausar(false); | 18 | focaBotoneraLateralService.showPausar(false); |
| 17 | focaBotoneraLateralService.showCancelar(false); | 19 | focaBotoneraLateralService.showCancelar(false); |
| 18 | focaBotoneraLateralService.showGuardar(false); | 20 | focaBotoneraLateralService.showGuardar(false); |
| 19 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 20 | 22 | ||
| 21 | if(focaAbmVehiculoService.transportistaSeleccionado.COD) { | 23 | if(focaAbmVehiculoService.transportistaSeleccionado.COD) { |
| 22 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
| 23 | } | 25 | } |
| 24 | $scope.editar = function(id) { | 26 | $scope.editar = function(id) { |
| 25 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
| 26 | }; | 28 | }; |
| 27 | $scope.solicitarConfirmacion = function(vehiculo) { | 29 | $scope.solicitarConfirmacion = function(vehiculo) { |
| 28 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
| 29 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
| 30 | function(data) { | 32 | function(data) { |
| 31 | if(data) { | 33 | if(data) { |
| 32 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); |
| 33 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
| 34 | } | 36 | } |
| 35 | } | 37 | } |
| 36 | ); | 38 | ); |
| 37 | }; | 39 | }; |
| 38 | $scope.seleccionarTransportista = function() { | 40 | $scope.seleccionarTransportista = function() { |
| 39 | var modalInstance = $uibModal.open( | 41 | var modalInstance = $uibModal.open( |
| 40 | { | 42 | { |
| 41 | ariaLabelledBy: 'Busqueda de Transportista', | 43 | ariaLabelledBy: 'Busqueda de Transportista', |
| 42 | templateUrl: 'modal-proveedor.html', | 44 | templateUrl: 'modal-proveedor.html', |
| 43 | controller: 'focaModalProveedorCtrl', | 45 | controller: 'focaModalProveedorCtrl', |
| 44 | size: 'lg', | 46 | size: 'lg', |
| 45 | resolve: { | 47 | resolve: { |
| 46 | transportista: function() { | 48 | transportista: function() { |
| 47 | return true; | 49 | return true; |
| 48 | } | 50 | } |
| 49 | } | 51 | } |
| 50 | } | 52 | } |
| 51 | ); | 53 | ); |
| 52 | modalInstance.result.then( | 54 | modalInstance.result.then( |
| 53 | function(transportista) { | 55 | function(transportista) { |
| 54 | elegirTransportista(transportista); | 56 | elegirTransportista(transportista); |
| 55 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 57 | focaAbmVehiculoService.transportistaSeleccionado = transportista; |
| 56 | }, function() { | 58 | }, function() { |
| 57 | 59 | ||
| 58 | } | 60 | } |
| 59 | ); | 61 | ); |
| 60 | }; | 62 | }; |
| 61 | 63 | ||
| 62 | function elegirTransportista(transportista) { | 64 | function elegirTransportista(transportista) { |
| 63 | var codigo = ('00000' + transportista.COD).slice(-5); | 65 | var codigo = ('00000' + transportista.COD).slice(-5); |
| 64 | $scope.idTransportista = transportista.COD; | 66 | $scope.idTransportista = transportista.COD; |
| 65 | $scope.filtros = transportista.NOM.trim(); | 67 | $scope.filtros = transportista.NOM.trim(); |
| 66 | $timeout(function() { | 68 | $timeout(function() { |
| 67 | $scope.$broadcast('addCabecera', { | 69 | $scope.$broadcast('addCabecera', { |
| 68 | label: 'Transportista:', | 70 | label: 'Transportista:', |
| 69 | valor: codigo + ' - ' + transportista.NOM | 71 | valor: codigo + ' - ' + transportista.NOM |
| 70 | }); | 72 | }); |
| 71 | }); | 73 | }); |
| 72 | buscar(transportista.COD); | 74 | buscar(transportista.COD); |
| 73 | } | 75 | } |
| 74 | 76 | ||
| 75 | function buscar(idTransportista) { | 77 | function buscar(idTransportista) { |
| 76 | focaAbmVehiculoService | 78 | focaAbmVehiculoService |
| 77 | .getVehiculosPorTransportista(idTransportista) | 79 | .getVehiculosPorTransportista(idTransportista) |
| 78 | .then(function(datos) { | 80 | .then(function(datos) { |
| 79 | $scope.vehiculos = datos.data; | 81 | $scope.vehiculos = datos.data; |
| 80 | }); | 82 | }); |
| 81 | } | 83 | } |
| 82 | function salir() { | 84 | function salir() { |
| 83 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 85 | focaAbmVehiculoService.transportistaSeleccionado = {}; |
| 84 | $location.path('/'); | 86 | $location.path('/'); |
| 85 | } | 87 | } |
| 86 | } | 88 | } |
| 87 | ]) | 89 | ]) |
| 88 | .controller('focaAbmVehiculoController', [ | 90 | .controller('focaAbmVehiculoController', [ |
| 89 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 91 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 90 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', | 92 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', |
| 91 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 93 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 92 | focaModalService, $timeout, focaBotoneraLateralService, $window) { | 94 | focaModalService, $timeout, focaBotoneraLateralService, $window) { |
| 93 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 95 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
| 94 | $scope.now = new Date(); | 96 | $scope.now = new Date(); |
| 95 | $scope.focused = 1; | 97 | $scope.focused = 1; |
| 96 | $scope.transportistaStamp = ''; | 98 | $scope.transportistaStamp = ''; |
| 97 | $scope.cisternas = []; | 99 | $scope.cisternas = []; |
| 98 | 100 | ||
| 99 | $timeout(function() { | 101 | $timeout(function() { |
| 100 | focaBotoneraLateralService.showSalir(false); | 102 | focaBotoneraLateralService.showSalir(false); |
| 101 | focaBotoneraLateralService.showPausar(false); | 103 | focaBotoneraLateralService.showPausar(false); |
| 102 | focaBotoneraLateralService.showCancelar(false); | 104 | focaBotoneraLateralService.showCancelar(false); |
| 103 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 105 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 104 | focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); | 106 | focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); |
| 105 | }); | 107 | }); |
| 106 | 108 | ||
| 107 | if($scope.nuevo) { | 109 | if($scope.nuevo) { |
| 108 | focaAbmVehiculoService | 110 | focaAbmVehiculoService |
| 109 | .getTransportistaPorId($routeParams.idTransportista) | 111 | .getTransportistaPorId($routeParams.idTransportista) |
| 110 | .then(function(res) { | 112 | .then(function(res) { |
| 111 | var codigo = ('00000' + res.data.COD).slice(-5); | 113 | var codigo = ('00000' + res.data.COD).slice(-5); |
| 112 | $scope.vehiculo.idTransportista = res.data.COD; | 114 | $scope.vehiculo.idTransportista = res.data.COD; |
| 113 | $scope.vehiculo.transportista = res.data; | 115 | $scope.vehiculo.transportista = res.data; |
| 114 | $scope.$broadcast('addCabecera', { | 116 | $scope.$broadcast('addCabecera', { |
| 115 | label: 'Transportista:', | 117 | label: 'Transportista:', |
| 116 | valor: codigo + ' - ' + res.data.NOM | 118 | valor: codigo + ' - ' + res.data.NOM |
| 117 | }); | 119 | }); |
| 118 | }); | 120 | }); |
| 119 | } | 121 | } |
| 120 | $scope.vehiculo = {}; | 122 | $scope.vehiculo = {}; |
| 121 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 123 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 122 | if(res.data) { | 124 | if(res.data) { |
| 123 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 125 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); |
| 124 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 126 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; |
| 125 | 127 | ||
| 126 | $scope.vehiculo = res.data; | 128 | $scope.vehiculo = res.data; |
| 127 | $scope.$broadcast('addCabecera', { | 129 | $scope.$broadcast('addCabecera', { |
| 128 | label: 'Transportista:', | 130 | label: 'Transportista:', |
| 129 | valor: $scope.transportistaStamp | 131 | valor: $scope.transportistaStamp |
| 130 | }); | 132 | }); |
| 131 | $scope.$broadcast('addCabecera', { | 133 | $scope.$broadcast('addCabecera', { |
| 132 | label: 'Unidad:', | 134 | label: 'Unidad:', |
| 133 | valor: res.data.codigo | 135 | valor: res.data.codigo |
| 134 | }); | 136 | }); |
| 135 | focaAbmVehiculoService | 137 | focaAbmVehiculoService |
| 136 | .getCisternas($routeParams.idVehiculo) | 138 | .getCisternas($routeParams.idVehiculo) |
| 137 | .then(function(res) { | 139 | .then(function(res) { |
| 138 | $scope.cisternas = res; | 140 | $scope.cisternas = res; |
| 139 | $scope.$apply(); | 141 | $scope.$apply(); |
| 140 | }); | 142 | }); |
| 141 | } | 143 | } |
| 142 | }); | 144 | }); |
| 143 | 145 | ||
| 144 | $scope.next = function(key) { | 146 | $scope.next = function(key) { |
| 145 | if (key === 13) $scope.focused++; | 147 | if (key === 13) $scope.focused++; |
| 146 | }; | 148 | }; |
| 147 | $scope.cancelar = function() { | 149 | $scope.cancelar = function() { |
| 148 | $location.path('/vehiculo'); | 150 | $location.path('/vehiculo'); |
| 149 | }; | 151 | }; |
| 150 | $scope.editar = function(key) { | 152 | $scope.editar = function(key) { |
| 151 | if(key) { | 153 | if(key) { |
| 152 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 154 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
| 153 | '/cisterna/' + key); | 155 | '/cisterna/' + key); |
| 154 | }else { | 156 | }else { |
| 155 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 157 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); |
| 156 | } | 158 | } |
| 157 | }; | 159 | }; |
| 158 | $scope.guardar = function(key) { | 160 | $scope.guardar = function(key) { |
| 159 | key = (typeof key === 'undefined') ? 13 : key; | 161 | key = (typeof key === 'undefined') ? 13 : key; |
| 160 | if(key === 13) { | 162 | if(key === 13) { |
| 161 | //Valida si existe numero de unidad | 163 | //Valida si existe numero de unidad |
| 162 | if(!validaTotalCargas() && !$scope.nuevo) { | 164 | if(!validaTotalCargas() && !$scope.nuevo) { |
| 163 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 165 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
| 164 | ' debe ser igual a la capacidad total del vehículo'); | 166 | ' debe ser igual a la capacidad total del vehículo'); |
| 165 | return; | 167 | return; |
| 166 | } | 168 | } |
| 167 | validaCodigoUnidad().then(function() { | 169 | validaCodigoUnidad().then(function() { |
| 168 | delete $scope.vehiculo.transportista; | 170 | delete $scope.vehiculo.transportista; |
| 169 | delete $scope.vehiculo.cisternas; | 171 | delete $scope.vehiculo.cisternas; |
| 170 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 172 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) |
| 171 | .then(function(res) { | 173 | .then(function(res) { |
| 172 | if($scope.nuevo) { | 174 | if($scope.nuevo) { |
| 173 | $location.path('/vehiculo/' + res.data.id + | 175 | $location.path('/vehiculo/' + res.data.id + |
| 174 | '/' + res.data.idTransportista); | 176 | '/' + res.data.idTransportista); |
| 175 | }else { | 177 | }else { |
| 176 | guardarCisternas().then(function() { | 178 | guardarCisternas().then(function() { |
| 177 | $window.location.assign('/#!/vehiculo'); | 179 | $window.location.assign('/#!/vehiculo'); |
| 178 | }); | 180 | }); |
| 179 | } | 181 | } |
| 180 | }); | 182 | }); |
| 181 | }, function() { | 183 | }, function() { |
| 182 | focaModalService.alert('Código de unidad existente'); | 184 | focaModalService.alert('Código de unidad existente'); |
| 183 | }); | 185 | }); |
| 184 | } | 186 | } |
| 185 | 187 | ||
| 186 | }; | 188 | }; |
| 187 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 189 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { |
| 188 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 190 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + |
| 189 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 191 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( |
| 190 | function(data) { | 192 | function(data) { |
| 191 | if(data) { | 193 | if(data) { |
| 192 | focaAbmVehiculoService.deleteCisterna(idx); | 194 | focaAbmVehiculoService.deleteCisterna(idx); |
| 193 | focaAbmVehiculoService | 195 | focaAbmVehiculoService |
| 194 | .getCisternas($routeParams.idVehiculo) | 196 | .getCisternas($routeParams.idVehiculo) |
| 195 | .then(function(res) { | 197 | .then(function(res) { |
| 196 | $scope.cisternas = res; | 198 | $scope.cisternas = res; |
| 197 | }); | 199 | }); |
| 198 | } | 200 | } |
| 199 | } | 201 | } |
| 200 | ); | 202 | ); |
| 201 | }; | 203 | }; |
| 202 | 204 | ||
| 203 | function validaCodigoUnidad() { | 205 | function validaCodigoUnidad() { |
| 204 | return new Promise(function(resolve, reject) { | 206 | return new Promise(function(resolve, reject) { |
| 205 | focaAbmVehiculoService | 207 | focaAbmVehiculoService |
| 206 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 208 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) |
| 207 | .then(function(res) { | 209 | .then(function(res) { |
| 208 | //Valida si existe numero de unidad | 210 | //Valida si existe numero de unidad |
| 209 | var existe = res.data.filter(function(vehiculo) { | 211 | var existe = res.data.filter(function(vehiculo) { |
| 210 | return vehiculo.codigo === $scope.vehiculo.codigo && | 212 | return vehiculo.codigo === $scope.vehiculo.codigo && |
| 211 | vehiculo.id !== $scope.vehiculo.id; | 213 | vehiculo.id !== $scope.vehiculo.id; |
| 212 | }); | 214 | }); |
| 213 | 215 | ||
| 214 | if(existe.length) { | 216 | if(existe.length) { |
| 215 | reject(existe); | 217 | reject(existe); |
| 216 | }else { | 218 | }else { |
| 217 | resolve(); | 219 | resolve(); |
| 218 | } | 220 | } |
| 219 | }); | 221 | }); |
| 220 | }); | 222 | }); |
| 221 | } | 223 | } |
| 222 | 224 | ||
| 223 | function validaTotalCargas() { | 225 | function validaTotalCargas() { |
| 224 | var total = 0; | 226 | var total = 0; |
| 225 | $scope.cisternas.forEach(function(cisterna) { | 227 | $scope.cisternas.forEach(function(cisterna) { |
| 226 | if(!cisterna.desactivado) { | 228 | if(!cisterna.desactivado) { |
| 227 | total += parseInt(cisterna.capacidad); | 229 | total += parseInt(cisterna.capacidad); |
| 228 | } | 230 | } |
| 229 | }); | 231 | }); |
| 230 | return $scope.vehiculo.capacidad == total; | 232 | return $scope.vehiculo.capacidad == total; |
| 231 | } | 233 | } |
| 232 | 234 | ||
| 233 | function guardarCisternas() { | 235 | function guardarCisternas() { |
| 234 | var cisternas = $scope.cisternas.map(function(cisterna) { | 236 | var cisternas = $scope.cisternas.map(function(cisterna) { |
| 235 | return { | 237 | return { |
| 236 | id: cisterna.id, | 238 | id: cisterna.id, |
| 237 | capacidad: parseFloat(cisterna.capacidad), | 239 | capacidad: parseFloat(cisterna.capacidad), |
| 238 | codigo: cisterna.codigo, | 240 | codigo: cisterna.codigo, |
| 239 | idUnidadMedida: cisterna.idUnidadMedida, | 241 | idUnidadMedida: cisterna.idUnidadMedida, |
| 240 | idVehiculo: $routeParams.idVehiculo, | 242 | idVehiculo: $routeParams.idVehiculo, |
| 241 | desactivado: cisterna.desactivado | 243 | desactivado: cisterna.desactivado |
| 242 | }; | 244 | }; |
| 243 | }); | 245 | }); |
| 244 | 246 | ||
| 245 | return focaAbmVehiculoService.guardarCisternas(cisternas); | 247 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
| 246 | } | 248 | } |
| 247 | } | 249 | } |
| 248 | ]); | 250 | ]); |
| 249 | 251 |
src/js/service.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') |
| 2 | .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { |
| 3 | var cisternas = []; | 3 | var cisternas = []; |
| 4 | return { | 4 | return { |
| 5 | getVehiculos: function() { | 5 | getVehiculos: function() { |
| 6 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); | 6 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); |
| 7 | }, | 7 | }, |
| 8 | getVehiculo: function(id) { | 8 | getVehiculo: function(id) { |
| 9 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); | 9 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); |
| 10 | }, | 10 | }, |
| 11 | getTransportistas: function() { | 11 | getTransportistas: function() { |
| 12 | return $http.get(API_ENDPOINT.URL + '/transportista'); | 12 | return $http.get(API_ENDPOINT.URL + '/transportista'); |
| 13 | }, | 13 | }, |
| 14 | guardarVehiculo: function(vehiculo) { | 14 | guardarVehiculo: function(vehiculo) { |
| 15 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); | 15 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); |
| 16 | }, | 16 | }, |
| 17 | deleteVehiculo: function(id) { | 17 | deleteVehiculo: function(id) { |
| 18 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); | 18 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); |
| 19 | }, | 19 | }, |
| 20 | getCisternas: function(idVehiculo) { | 20 | getCisternas: function(idVehiculo) { |
| 21 | if(cisternas.length) { | 21 | if(cisternas.length) { |
| 22 | return Promise.resolve(angular.copy(cisternas)); | 22 | return Promise.resolve(angular.copy(cisternas)); |
| 23 | }else { | 23 | }else { |
| 24 | return new Promise(function(resolve, reject) { | 24 | return new Promise(function(resolve, reject) { |
| 25 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) | 25 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) |
| 26 | .then(function(res) { | 26 | .then(function(res) { |
| 27 | cisternas = res.data; | 27 | cisternas = res.data; |
| 28 | resolve(res.data); | 28 | resolve(res.data); |
| 29 | }); | 29 | }); |
| 30 | }); | 30 | }); |
| 31 | } | 31 | } |
| 32 | }, | 32 | }, |
| 33 | guardarCisterna: function(cisterna, idx) { | 33 | guardarCisterna: function(cisterna, idx) { |
| 34 | if(idx != -1) { | 34 | if(idx != -1) { |
| 35 | //update | 35 | //update |
| 36 | cisternas[idx] = cisterna; | 36 | cisternas[idx] = cisterna; |
| 37 | }else { | 37 | }else { |
| 38 | //insert | 38 | //insert |
| 39 | cisternas.push(cisterna); | 39 | cisternas.push(cisterna); |
| 40 | } | 40 | } |
| 41 | }, | 41 | }, |
| 42 | guardarCisternas: function(cisternas) { | 42 | guardarCisternas: function(cisternas) { |
| 43 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); | 43 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); |
| 44 | }, | 44 | }, |
| 45 | deleteCisterna: function(idx) { | 45 | deleteCisterna: function(idx) { |
| 46 | cisternas[idx].desactivado = true; | 46 | cisternas[idx].desactivado = true; |
| 47 | }, | 47 | }, |
| 48 | cleanCisternas: function() { | ||
| 49 | cisternas = []; | ||
| 50 | }, | ||
| 48 | getVehiculosPorTransportista: function(id) { | 51 | getVehiculosPorTransportista: function(id) { |
| 49 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); | 52 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); |
| 50 | }, | 53 | }, |
| 51 | getTransportistaPorId: function(id) { | 54 | getTransportistaPorId: function(id) { |
| 52 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); | 55 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); |
| 53 | }, | 56 | }, |
| 54 | transportistaSeleccionado: {} | 57 | transportistaSeleccionado: {} |
| 55 | }; | 58 | }; |
| 56 | }]); | 59 | }]); |
| 57 | 60 |