Commit b9d2b80bbcfcd091bfa7aabb55448235030328d6
Exists in
master
Merge branch 'master' into 'develop'
Master See merge request !43
Showing
6 changed files
Show diff stats
spec/controllerSpec.js
| 1 | describe('Controladores abm vehículo', function() { | 1 | describe('Controladores abm vehículo', function() { |
| 2 | 2 | ||
| 3 | var $controller; | 3 | var $controller; |
| 4 | 4 | ||
| 5 | beforeEach(function() { | 5 | beforeEach(function() { |
| 6 | module('focaAbmVehiculo'); | 6 | module('focaAbmVehiculo'); |
| 7 | inject(function(_$controller_) { | 7 | inject(function(_$controller_) { |
| 8 | $controller = _$controller_; | 8 | $controller = _$controller_; |
| 9 | }); | 9 | }); |
| 10 | }); | 10 | }); |
| 11 | 11 | ||
| 12 | describe('Controlador focaAbmVehiculosController', function() { | 12 | describe('Controlador focaAbmVehiculosController', function() { |
| 13 | 13 | ||
| 14 | it('Existe el controller focaAbmVehiculosController', function() { | 14 | it('Existe el controller focaAbmVehiculosController', function() { |
| 15 | //arrange | 15 | //arrange |
| 16 | var controller = $controller('focaAbmVehiculosController', { | 16 | var controller = $controller('focaAbmVehiculosController', { |
| 17 | $scope: {}, | 17 | $scope: {}, |
| 18 | focaAbmVehiculoService: { | 18 | focaAbmVehiculoService: { |
| 19 | cleanCisternas: function() { return;}, | 19 | cleanCisternas: function() { return;}, |
| 20 | transportistaSeleccionado: {} | 20 | transportistaSeleccionado: {} |
| 21 | }, | 21 | }, |
| 22 | $location: {}, | 22 | $location: {}, |
| 23 | focaModalService: {}, | 23 | focaModalService: {}, |
| 24 | $uibModal: {}, | 24 | $uibModal: {}, |
| 25 | focaBotoneraLateralService: { | 25 | focaBotoneraLateralService: { |
| 26 | showSalir: function() { return; }, | 26 | showSalir: function() { return; }, |
| 27 | showPausar: function() { return; }, | 27 | showPausar: function() { return; }, |
| 28 | showCancelar: function() { return; }, | 28 | showCancelar: function() { return; }, |
| 29 | showGuardar: function() { return; }, | 29 | showGuardar: function() { return; }, |
| 30 | addCustomButton: function() { return; } | 30 | addCustomButton: function() { return; } |
| 31 | }, | 31 | }, |
| 32 | $localStorage: {}, | 32 | $localStorage: {}, |
| 33 | $timeout: {} | 33 | $timeout: {} |
| 34 | }); | 34 | }); |
| 35 | 35 | ||
| 36 | //assert | 36 | //assert |
| 37 | expect(typeof controller).toEqual('object'); | 37 | expect(typeof controller).toEqual('object'); |
| 38 | }); | 38 | }); |
| 39 | 39 | ||
| 40 | it('Crea fecha nueva', function() { | 40 | it('Crea fecha nueva', function() { |
| 41 | //arrange | 41 | //arrange |
| 42 | var scope = { | 42 | var scope = { |
| 43 | $watch: function() {} | 43 | $watch: function() {} |
| 44 | }; | 44 | }; |
| 45 | var controller = $controller('focaAbmVehiculosController', { | 45 | var controller = $controller('focaAbmVehiculosController', { |
| 46 | $scope: scope, | 46 | $scope: scope, |
| 47 | focaAbmVehiculoService: { | 47 | focaAbmVehiculoService: { |
| 48 | cleanCisternas: function() { return;}, | 48 | cleanCisternas: function() { return;}, |
| 49 | transportistaSeleccionado: {} | 49 | transportistaSeleccionado: {} |
| 50 | }, | 50 | }, |
| 51 | $location: {}, | 51 | $location: {}, |
| 52 | focaModalService: {}, | 52 | focaModalService: {}, |
| 53 | $uibModal: {}, | 53 | $uibModal: {}, |
| 54 | focaBotoneraLateralService: { | 54 | focaBotoneraLateralService: { |
| 55 | showSalir: function() { return; }, | 55 | showSalir: function() { return; }, |
| 56 | showPausar: function() { return; }, | 56 | showPausar: function() { return; }, |
| 57 | showCancelar: function() { return; }, | 57 | showCancelar: function() { return; }, |
| 58 | showGuardar: function() { return; }, | 58 | showGuardar: function() { return; }, |
| 59 | addCustomButton: function() { return; } | 59 | addCustomButton: function() { return; } |
| 60 | }, | 60 | }, |
| 61 | $localStorage: {}, | 61 | $localStorage: {}, |
| 62 | $timeout: {} | 62 | $timeout: {} |
| 63 | }); | 63 | }); |
| 64 | 64 | ||
| 65 | //act | 65 | //act |
| 66 | var date = scope.now; | 66 | var date = scope.now; |
| 67 | 67 | ||
| 68 | //assert | 68 | //assert |
| 69 | expect(angular.isDate(date)).toBe(true); | 69 | expect(angular.isDate(date)).toBe(true); |
| 70 | }); | 70 | }); |
| 71 | 71 | ||
| 72 | it('$scope setea botonera lateral', function() { | 72 | it('$scope setea botonera lateral', function() { |
| 73 | //arrange | 73 | //arrange |
| 74 | var scope = { | 74 | var scope = { |
| 75 | $watch: function() {} | 75 | $watch: function() {} |
| 76 | }; | 76 | }; |
| 77 | var controller = $controller('focaAbmVehiculosController', { | 77 | var controller = $controller('focaAbmVehiculosController', { |
| 78 | $scope: scope, | 78 | $scope: scope, |
| 79 | focaAbmVehiculoService: { | 79 | focaAbmVehiculoService: { |
| 80 | cleanCisternas: function() { return;}, | 80 | cleanCisternas: function() { return;}, |
| 81 | transportistaSeleccionado: {} | 81 | transportistaSeleccionado: {} |
| 82 | }, | 82 | }, |
| 83 | $location: {}, | 83 | $location: {}, |
| 84 | focaModalService: {}, | 84 | focaModalService: {}, |
| 85 | $uibModal: {}, | 85 | $uibModal: {}, |
| 86 | focaBotoneraLateralService: { | 86 | focaBotoneraLateralService: { |
| 87 | showSalir: function() { return; }, | 87 | showSalir: function() { return; }, |
| 88 | showPausar: function() { return; }, | 88 | showPausar: function() { return; }, |
| 89 | showCancelar: function() { return; }, | 89 | showCancelar: function() { return; }, |
| 90 | showGuardar: function() { return; }, | 90 | showGuardar: function() { return; }, |
| 91 | addCustomButton: function() { return; } | 91 | addCustomButton: function() { return; } |
| 92 | }, | 92 | }, |
| 93 | $timeout: {}, | 93 | $timeout: {}, |
| 94 | $localStorage: {} | 94 | $localStorage: {} |
| 95 | }); | 95 | }); |
| 96 | 96 | ||
| 97 | //act | 97 | //act |
| 98 | var botonera = scope.botonera; | 98 | var botonera = scope.botonera; |
| 99 | 99 | ||
| 100 | //assert | 100 | //assert |
| 101 | expect(angular.isArray(botonera)).toBe(true); | 101 | expect(angular.isArray(botonera)).toBe(true); |
| 102 | }); | 102 | }); |
| 103 | 103 | ||
| 104 | it('$scope.editar lleva a la ruta correcta', function() { | 104 | it('$scope.editar lleva a la ruta correcta', function() { |
| 105 | inject(function($location) { | 105 | inject(function($location) { |
| 106 | //arrange | 106 | //arrange |
| 107 | var scope = { | 107 | var scope = { |
| 108 | $watch: function() {} | 108 | $watch: function() {} |
| 109 | }; | 109 | }; |
| 110 | var controller = $controller('focaAbmVehiculosController', { | 110 | var controller = $controller('focaAbmVehiculosController', { |
| 111 | $scope: scope, | 111 | $scope: scope, |
| 112 | focaAbmVehiculoService: { | 112 | focaAbmVehiculoService: { |
| 113 | cleanCisternas: function() { return;}, | 113 | cleanCisternas: function() { return;}, |
| 114 | transportistaSeleccionado: {} | 114 | transportistaSeleccionado: {} |
| 115 | }, | 115 | }, |
| 116 | $location: $location, | 116 | $location: $location, |
| 117 | focaModalService: {}, | 117 | focaModalService: {}, |
| 118 | $uibModal: {}, | 118 | $uibModal: {}, |
| 119 | focaBotoneraLateralService: { | 119 | focaBotoneraLateralService: { |
| 120 | showSalir: function() { return; }, | 120 | showSalir: function() { return; }, |
| 121 | showPausar: function() { return; }, | 121 | showPausar: function() { return; }, |
| 122 | showCancelar: function() { return; }, | 122 | showCancelar: function() { return; }, |
| 123 | showGuardar: function() { return; }, | 123 | showGuardar: function() { return; }, |
| 124 | addCustomButton: function() { return; } | 124 | addCustomButton: function() { return; } |
| 125 | }, | 125 | }, |
| 126 | $timeout: {}, | 126 | $timeout: {}, |
| 127 | $localStorage: {} | 127 | $localStorage: {} |
| 128 | }); | 128 | }); |
| 129 | 129 | ||
| 130 | //act | 130 | //act |
| 131 | scope.editar(1); | 131 | scope.editar(1); |
| 132 | var esperado = '/vehiculo/' + 1 + '/' + scope.idTransportista; | 132 | var esperado = '/vehiculo/' + 1 + '/' + scope.idTransportista; |
| 133 | 133 | ||
| 134 | //assert | 134 | //assert |
| 135 | expect($location.url()).toEqual(esperado); | 135 | expect($location.url()).toEqual(esperado); |
| 136 | }); | 136 | }); |
| 137 | }); | 137 | }); |
| 138 | 138 | ||
| 139 | it('Solicita confirmacion', function() { | 139 | it('Solicita confirmacion', function() { |
| 140 | //arrange | 140 | //arrange |
| 141 | var scope = { | 141 | var scope = { |
| 142 | $watch: function() {} | 142 | $watch: function() {} |
| 143 | }; | 143 | }; |
| 144 | var focaModalService = { | 144 | var focaModalService = { |
| 145 | confirm: function() {} | 145 | confirm: function() {} |
| 146 | }; | 146 | }; |
| 147 | var controller = $controller('focaAbmVehiculosController', { | 147 | var controller = $controller('focaAbmVehiculosController', { |
| 148 | $scope: scope, | 148 | $scope: scope, |
| 149 | focaAbmVehiculoService: { | 149 | focaAbmVehiculoService: { |
| 150 | cleanCisternas: function() { return;}, | 150 | cleanCisternas: function() { return;}, |
| 151 | transportistaSeleccionado: {} | 151 | transportistaSeleccionado: {} |
| 152 | }, | 152 | }, |
| 153 | $location: {}, | 153 | $location: {}, |
| 154 | focaModalService: focaModalService, | 154 | focaModalService: focaModalService, |
| 155 | $uibModal: {}, | 155 | $uibModal: {}, |
| 156 | focaBotoneraLateralService: { | 156 | focaBotoneraLateralService: { |
| 157 | showSalir: function() { return; }, | 157 | showSalir: function() { return; }, |
| 158 | showPausar: function() { return; }, | 158 | showPausar: function() { return; }, |
| 159 | showCancelar: function() { return; }, | 159 | showCancelar: function() { return; }, |
| 160 | showGuardar: function() { return; }, | 160 | showGuardar: function() { return; }, |
| 161 | addCustomButton: function() { return; } | 161 | addCustomButton: function() { return; } |
| 162 | }, | 162 | }, |
| 163 | $timeout: {}, | 163 | $timeout: {}, |
| 164 | $localStorage: {} | 164 | $localStorage: {} |
| 165 | }); | 165 | }); |
| 166 | 166 | ||
| 167 | //act | 167 | //act |
| 168 | spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); | 168 | spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); |
| 169 | scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); | 169 | scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); |
| 170 | 170 | ||
| 171 | //assert | 171 | //assert |
| 172 | expect(focaModalService.confirm).toHaveBeenCalled(); | 172 | expect(focaModalService.confirm).toHaveBeenCalled(); |
| 173 | }); | 173 | }); |
| 174 | 174 | ||
| 175 | it('Elimina vehículo al confirmar', function(done) { | 175 | it('Elimina vehículo al confirmar', function(done) { |
| 176 | 176 | ||
| 177 | //arrange | 177 | //arrange |
| 178 | var scope = { | 178 | var scope = { |
| 179 | vehiculos: [] | 179 | vehiculos: [] |
| 180 | }; | 180 | }; |
| 181 | var focaModalService = { | 181 | var focaModalService = { |
| 182 | confirm: function() { return; } | 182 | confirm: function() { return; } |
| 183 | }; | 183 | }; |
| 184 | var focaAbmVehiculoService = { | 184 | var focaAbmVehiculoService = { |
| 185 | cleanCisternas: function() { return;}, | 185 | cleanCisternas: function() { return;}, |
| 186 | transportistaSeleccionado: {}, | 186 | transportistaSeleccionado: {}, |
| 187 | deleteVehiculo: function() { return; } | 187 | deleteVehiculo: function() { return; } |
| 188 | }; | 188 | }; |
| 189 | var controller = $controller('focaAbmVehiculosController', { | 189 | var controller = $controller('focaAbmVehiculosController', { |
| 190 | $scope: scope, | 190 | $scope: scope, |
| 191 | focaAbmVehiculoService: focaAbmVehiculoService, | 191 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 192 | $location: {}, | 192 | $location: {}, |
| 193 | focaModalService: focaModalService, | 193 | focaModalService: focaModalService, |
| 194 | $uibModal: {}, | 194 | $uibModal: {}, |
| 195 | focaBotoneraLateralService: { | 195 | focaBotoneraLateralService: { |
| 196 | showSalir: function() { return; }, | 196 | showSalir: function() { return; }, |
| 197 | showPausar: function() { return; }, | 197 | showPausar: function() { return; }, |
| 198 | showCancelar: function() { return; }, | 198 | showCancelar: function() { return; }, |
| 199 | showGuardar: function() { return; }, | 199 | showGuardar: function() { return; }, |
| 200 | addCustomButton: function() { return; } | 200 | addCustomButton: function() { return; } |
| 201 | }, | 201 | }, |
| 202 | $timeout: {}, | 202 | $timeout: {}, |
| 203 | $localStorage: {} | 203 | $localStorage: {} |
| 204 | }); | 204 | }); |
| 205 | var promesa = Promise.resolve(true); | 205 | var promesa = Promise.resolve(true); |
| 206 | 206 | ||
| 207 | //act | 207 | //act |
| 208 | spyOn(focaModalService, 'confirm').and.returnValue(promesa); | 208 | spyOn(focaModalService, 'confirm').and.returnValue(promesa); |
| 209 | spyOn(focaAbmVehiculoService, 'deleteVehiculo'); | 209 | spyOn(focaAbmVehiculoService, 'deleteVehiculo'); |
| 210 | scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); | 210 | scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); |
| 211 | 211 | ||
| 212 | //assert | 212 | //assert |
| 213 | promesa.then( | 213 | promesa.then( |
| 214 | function() { | 214 | function() { |
| 215 | expect(focaAbmVehiculoService.deleteVehiculo).toHaveBeenCalled(); | 215 | expect(focaAbmVehiculoService.deleteVehiculo).toHaveBeenCalled(); |
| 216 | done(); | 216 | done(); |
| 217 | } | 217 | } |
| 218 | ); | 218 | ); |
| 219 | }); | 219 | }); |
| 220 | 220 | ||
| 221 | it('Se selecciona transportista', function() { | 221 | it('Se selecciona transportista', function() { |
| 222 | //arrange | 222 | //arrange |
| 223 | var scope = { | 223 | var scope = { |
| 224 | $watch: function() {} | 224 | $watch: function() {} |
| 225 | }; | 225 | }; |
| 226 | var focaModalService = { | 226 | var focaModalService = { |
| 227 | modal: function() {} | 227 | modal: function() {} |
| 228 | }; | 228 | }; |
| 229 | var controller = $controller('focaAbmVehiculosController', { | 229 | var controller = $controller('focaAbmVehiculosController', { |
| 230 | $scope: scope, | 230 | $scope: scope, |
| 231 | focaAbmVehiculoService: { | 231 | focaAbmVehiculoService: { |
| 232 | cleanCisternas: function() { return;}, | 232 | cleanCisternas: function() { return;}, |
| 233 | transportistaSeleccionado: {} | 233 | transportistaSeleccionado: {} |
| 234 | }, | 234 | }, |
| 235 | $location: {}, | 235 | $location: {}, |
| 236 | focaModalService: focaModalService, | 236 | focaModalService: focaModalService, |
| 237 | $uibModal: {}, | 237 | $uibModal: {}, |
| 238 | focaBotoneraLateralService: { | 238 | focaBotoneraLateralService: { |
| 239 | showSalir: function() { return; }, | 239 | showSalir: function() { return; }, |
| 240 | showPausar: function() { return; }, | 240 | showPausar: function() { return; }, |
| 241 | showCancelar: function() { return; }, | 241 | showCancelar: function() { return; }, |
| 242 | showGuardar: function() { return; }, | 242 | showGuardar: function() { return; }, |
| 243 | addCustomButton: function() { return; } | 243 | addCustomButton: function() { return; } |
| 244 | }, | 244 | }, |
| 245 | $timeout: {}, | 245 | $timeout: {}, |
| 246 | $localStorage: {} | 246 | $localStorage: {} |
| 247 | }); | 247 | }); |
| 248 | 248 | ||
| 249 | //act | 249 | //act |
| 250 | spyOn(focaModalService, 'modal').and.returnValue({then: function() {}}); | 250 | spyOn(focaModalService, 'modal').and.returnValue({then: function() {}}); |
| 251 | scope.seleccionarTransportista(); | 251 | scope.seleccionarTransportista(); |
| 252 | 252 | ||
| 253 | //assert | 253 | //assert |
| 254 | expect(focaModalService.modal).toHaveBeenCalled(); | 254 | expect(focaModalService.modal).toHaveBeenCalled(); |
| 255 | }); | 255 | }); |
| 256 | 256 | ||
| 257 | it('Se setea el transportista seleccionado al service', function(done) { | 257 | it('Se setea el transportista seleccionado al service', function(done) { |
| 258 | inject(function($timeout) { | 258 | inject(function($timeout) { |
| 259 | 259 | ||
| 260 | //arrange | 260 | //arrange |
| 261 | var scope = { | 261 | var scope = { |
| 262 | $watch: function() {} | 262 | $watch: function() {} |
| 263 | }; | 263 | }; |
| 264 | var focaModalService = { | 264 | var focaModalService = { |
| 265 | modal: function() { return; } | 265 | modal: function() { return; } |
| 266 | }; | 266 | }; |
| 267 | var focaAbmVehiculoService = { | 267 | var focaAbmVehiculoService = { |
| 268 | cleanCisternas: function() { return;}, | 268 | cleanCisternas: function() { return;}, |
| 269 | transportistaSeleccionado: {}, | 269 | transportistaSeleccionado: {}, |
| 270 | deleteVehiculo: function() { return; }, | 270 | deleteVehiculo: function() { return; }, |
| 271 | getVehiculosPorTransportista: function() { | 271 | getVehiculosPorTransportista: function() { |
| 272 | return { | 272 | return { |
| 273 | then: function() { return; } | 273 | then: function() { return; } |
| 274 | }; | 274 | }; |
| 275 | } | 275 | } |
| 276 | }; | 276 | }; |
| 277 | var controller = $controller('focaAbmVehiculosController', { | 277 | var controller = $controller('focaAbmVehiculosController', { |
| 278 | $scope: scope, | 278 | $scope: scope, |
| 279 | focaAbmVehiculoService: focaAbmVehiculoService, | 279 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 280 | $location: {}, | 280 | $location: {}, |
| 281 | focaModalService: focaModalService, | 281 | focaModalService: focaModalService, |
| 282 | $uibModal: {}, | 282 | $uibModal: {}, |
| 283 | focaBotoneraLateralService: { | 283 | focaBotoneraLateralService: { |
| 284 | showSalir: function() { return; }, | 284 | showSalir: function() { return; }, |
| 285 | showPausar: function() { return; }, | 285 | showPausar: function() { return; }, |
| 286 | showCancelar: function() { return; }, | 286 | showCancelar: function() { return; }, |
| 287 | showGuardar: function() { return; }, | 287 | showGuardar: function() { return; }, |
| 288 | addCustomButton: function() { return; } | 288 | addCustomButton: function() { return; } |
| 289 | }, | 289 | }, |
| 290 | $localStorage: {}, | 290 | $localStorage: {}, |
| 291 | $timeout: $timeout | 291 | $timeout: $timeout |
| 292 | }); | 292 | }); |
| 293 | var promesa = Promise.resolve({COD: '', NOM: ''}); | 293 | var promesa = Promise.resolve({COD: '', NOM: ''}); |
| 294 | 294 | ||
| 295 | //act | 295 | //act |
| 296 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | 296 | spyOn(focaModalService, 'modal').and.returnValue(promesa); |
| 297 | scope.seleccionarTransportista(); | 297 | scope.seleccionarTransportista(); |
| 298 | 298 | ||
| 299 | //assert | 299 | //assert |
| 300 | promesa.then( | 300 | promesa.then( |
| 301 | function() { | 301 | function() { |
| 302 | expect(focaAbmVehiculoService.transportistaSeleccionado) | 302 | expect(focaAbmVehiculoService.transportistaSeleccionado) |
| 303 | .toEqual(jasmine.objectContaining({ | 303 | .toEqual(jasmine.objectContaining({ |
| 304 | COD: '', NOM: '' | 304 | COD: '', NOM: '' |
| 305 | })); | 305 | })); |
| 306 | done(); | 306 | done(); |
| 307 | } | 307 | } |
| 308 | ); | 308 | ); |
| 309 | }); | 309 | }); |
| 310 | }); | 310 | }); |
| 311 | }); | 311 | }); |
| 312 | 312 | ||
| 313 | describe('Controlador focaAbmVehiculoController', function() { | 313 | describe('Controlador focaAbmVehiculoController', function() { |
| 314 | 314 | ||
| 315 | var $timeout; | 315 | var $timeout; |
| 316 | beforeEach(inject(function(_$timeout_) { | 316 | beforeEach(inject(function(_$timeout_) { |
| 317 | $timeout = _$timeout_; | 317 | $timeout = _$timeout_; |
| 318 | })); | 318 | })); |
| 319 | 319 | ||
| 320 | it('Existe el controller focaAbmVehiculoController', function() { | 320 | it('Existe el controller focaAbmVehiculoController', function() { |
| 321 | 321 | ||
| 322 | //arrange | 322 | //arrange |
| 323 | var controller = $controller('focaAbmVehiculoController', { | 323 | var controller = $controller('focaAbmVehiculoController', { |
| 324 | $scope: { | 324 | $scope: { |
| 325 | $watch: function() {} | 325 | $watch: function() {} |
| 326 | }, | 326 | }, |
| 327 | focaAbmVehiculoService: { | 327 | focaAbmVehiculoService: { |
| 328 | getCisternas: function() { | ||
| 329 | return { | ||
| 330 | then: function() { return; } | ||
| 331 | }; | ||
| 332 | }, | ||
| 328 | getVehiculo: function() { | 333 | getVehiculo: function() { |
| 329 | return { | 334 | return { |
| 330 | then: function() { return; } | 335 | then: function() { return; } |
| 331 | }; | 336 | }; |
| 332 | } | 337 | } |
| 333 | }, | 338 | }, |
| 334 | $routeParams: {}, | 339 | $routeParams: {}, |
| 335 | $location: {}, | 340 | $location: {}, |
| 336 | $uibModal: {}, | 341 | $uibModal: {}, |
| 337 | focaModalService: {}, | 342 | focaModalService: {}, |
| 338 | $timeout: $timeout, | 343 | $timeout: $timeout, |
| 339 | focaBotoneraLateralService: { | 344 | focaBotoneraLateralService: { |
| 340 | showSalir: function() { return; }, | 345 | showSalir: function() { return; }, |
| 341 | showPausar: function() { return; }, | 346 | showPausar: function() { return; }, |
| 342 | showCancelar: function() { return; }, | 347 | showCancelar: function() { return; }, |
| 343 | showGuardar: function() { return; }, | 348 | showGuardar: function() { return; }, |
| 344 | addCustomButton: function() { return; } | 349 | addCustomButton: function() { return; } |
| 345 | }, | 350 | }, |
| 346 | $localStorage: {}, | 351 | $localStorage: {}, |
| 347 | $window: {} | 352 | $window: {} |
| 348 | }); | 353 | }); |
| 349 | 354 | ||
| 350 | //assert | 355 | //assert |
| 351 | expect(typeof controller).toEqual('object'); | 356 | expect(typeof controller).toEqual('object'); |
| 352 | 357 | ||
| 353 | }); | 358 | }); |
| 354 | 359 | ||
| 355 | it('Se busca el transportista cuando es nuevo', function() { | 360 | it('Se busca el transportista cuando es nuevo', function() { |
| 356 | 361 | ||
| 357 | //arrange | 362 | //arrange |
| 358 | var scope = { | 363 | var scope = { |
| 359 | $watch: function() {} | 364 | $watch: function() {} |
| 360 | }; | 365 | }; |
| 361 | var focaAbmVehiculoService = { | 366 | var focaAbmVehiculoService = { |
| 367 | |||
| 368 | getCisternas: function() { | ||
| 369 | return { | ||
| 370 | then: function() { return; } | ||
| 371 | }; | ||
| 372 | }, | ||
| 362 | getVehiculo: function() { | 373 | getVehiculo: function() { |
| 363 | return { | 374 | return { |
| 364 | then: function() { return; } | 375 | then: function() { return; } |
| 365 | }; | 376 | }; |
| 366 | }, | 377 | }, |
| 367 | getTransportistaPorId: function() { return; } | 378 | getTransportistaPorId: function() { return; } |
| 368 | }; | 379 | }; |
| 369 | 380 | ||
| 370 | spyOn(focaAbmVehiculoService, 'getTransportistaPorId') | 381 | spyOn(focaAbmVehiculoService, 'getTransportistaPorId') |
| 371 | .and.returnValue({then: function() { return; }}); | 382 | .and.returnValue({then: function() { return; }}); |
| 372 | 383 | ||
| 373 | //act | 384 | //act |
| 374 | var controller = $controller('focaAbmVehiculoController', { | 385 | var controller = $controller('focaAbmVehiculoController', { |
| 375 | $scope: scope, | 386 | $scope: scope, |
| 376 | focaAbmVehiculoService: focaAbmVehiculoService, | 387 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 377 | $routeParams: { | 388 | $routeParams: { |
| 378 | idVehiculo: '0' | 389 | idVehiculo: '0' |
| 379 | }, | 390 | }, |
| 380 | $location: {}, | 391 | $location: {}, |
| 381 | $uibModal: {}, | 392 | $uibModal: {}, |
| 382 | focaModalService: {}, | 393 | focaModalService: {}, |
| 383 | $timeout: $timeout, | 394 | $timeout: $timeout, |
| 384 | focaBotoneraLateralService: { | 395 | focaBotoneraLateralService: { |
| 385 | showSalir: function() { return; }, | 396 | showSalir: function() { return; }, |
| 386 | showPausar: function() { return; }, | 397 | showPausar: function() { return; }, |
| 387 | showCancelar: function() { return; }, | 398 | showCancelar: function() { return; }, |
| 388 | showGuardar: function() { return; }, | 399 | showGuardar: function() { return; }, |
| 389 | addCustomButton: function() { return; } | 400 | addCustomButton: function() { return; } |
| 390 | }, | 401 | }, |
| 391 | $localStorage: {}, | 402 | $localStorage: {}, |
| 392 | $window: {} | 403 | $window: {} |
| 393 | }); | 404 | }); |
| 394 | 405 | ||
| 395 | //assert | 406 | //assert |
| 396 | expect(focaAbmVehiculoService.getTransportistaPorId).toHaveBeenCalled(); | 407 | expect(focaAbmVehiculoService.getTransportistaPorId).toHaveBeenCalled(); |
| 397 | }); | 408 | }); |
| 398 | 409 | ||
| 399 | it('No se busca el transportista cuando es nuevo', function() { | 410 | it('No se busca el transportista cuando es nuevo', function() { |
| 400 | 411 | ||
| 401 | //arrange | 412 | //arrange |
| 402 | var scope = { | 413 | var scope = { |
| 403 | $watch: function() {} | 414 | $watch: function() {} |
| 404 | }; | 415 | }; |
| 405 | var focaAbmVehiculoService = { | 416 | var focaAbmVehiculoService = { |
| 417 | |||
| 418 | getCisternas: function() { | ||
| 419 | return { | ||
| 420 | then: function() { return; } | ||
| 421 | }; | ||
| 422 | }, | ||
| 423 | |||
| 406 | getVehiculo: function() { | 424 | getVehiculo: function() { |
| 407 | return { | 425 | return { |
| 408 | then: function() { return; } | 426 | then: function() { return; } |
| 409 | }; | 427 | }; |
| 410 | }, | 428 | }, |
| 411 | getTransportistaPorId: function() { return; } | 429 | getTransportistaPorId: function() { return; } |
| 412 | }; | 430 | }; |
| 413 | 431 | ||
| 414 | spyOn(focaAbmVehiculoService, 'getTransportistaPorId') | 432 | spyOn(focaAbmVehiculoService, 'getTransportistaPorId') |
| 415 | .and.returnValue({then: function() { return; }}); | 433 | .and.returnValue({then: function() { return; }}); |
| 416 | 434 | ||
| 417 | //act | 435 | //act |
| 418 | var controller = $controller('focaAbmVehiculoController', { | 436 | var controller = $controller('focaAbmVehiculoController', { |
| 419 | $scope: scope, | 437 | $scope: scope, |
| 420 | focaAbmVehiculoService: focaAbmVehiculoService, | 438 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 421 | $routeParams: {}, | 439 | $routeParams: {}, |
| 422 | $location: {}, | 440 | $location: {}, |
| 423 | $uibModal: {}, | 441 | $uibModal: {}, |
| 424 | focaModalService: {}, | 442 | focaModalService: {}, |
| 425 | $timeout: $timeout, | 443 | $timeout: $timeout, |
| 426 | focaBotoneraLateralService: { | 444 | focaBotoneraLateralService: { |
| 427 | showSalir: function() { return; }, | 445 | showSalir: function() { return; }, |
| 428 | showPausar: function() { return; }, | 446 | showPausar: function() { return; }, |
| 429 | showCancelar: function() { return; }, | 447 | showCancelar: function() { return; }, |
| 430 | showGuardar: function() { return; }, | 448 | showGuardar: function() { return; }, |
| 431 | addCustomButton: function() { return; } | 449 | addCustomButton: function() { return; } |
| 432 | }, | 450 | }, |
| 433 | $localStorage: {}, | 451 | $localStorage: {}, |
| 434 | $window: {} | 452 | $window: {} |
| 435 | }); | 453 | }); |
| 436 | 454 | ||
| 437 | //assert | 455 | //assert |
| 438 | expect(focaAbmVehiculoService.getTransportistaPorId).not.toHaveBeenCalled(); | 456 | expect(focaAbmVehiculoService.getTransportistaPorId).not.toHaveBeenCalled(); |
| 439 | }); | 457 | }); |
| 440 | 458 | ||
| 441 | it('Cancelar lleva a la ruta /vehiculo', function() { | 459 | it('Cancelar lleva a la ruta /vehiculo', function() { |
| 442 | 460 | ||
| 443 | inject(function($location) { | 461 | inject(function($location) { |
| 444 | //arrange | 462 | //arrange |
| 445 | var scope = { | 463 | var scope = { |
| 446 | $watch: function() {}, | 464 | $watch: function() {}, |
| 447 | cancelar: function() {}, | 465 | cancelar: function() {}, |
| 448 | formVehiculo: { | 466 | formVehiculo: { |
| 449 | $pristine: true | 467 | $pristine: true |
| 450 | } | 468 | } |
| 451 | }; | 469 | }; |
| 452 | var controller = $controller('focaAbmVehiculoController', { | 470 | var controller = $controller('focaAbmVehiculoController', { |
| 453 | $scope: scope, | 471 | $scope: scope, |
| 454 | focaAbmVehiculoService: { | 472 | focaAbmVehiculoService: { |
| 473 | getCisternas: function() { | ||
| 474 | return { | ||
| 475 | then: function() { return; } | ||
| 476 | }; | ||
| 477 | }, | ||
| 455 | getVehiculo: function() { | 478 | getVehiculo: function() { |
| 456 | return { | 479 | return { |
| 457 | then: function() { return; } | 480 | then: function() { return; } |
| 458 | }; | 481 | }; |
| 459 | } | 482 | } |
| 460 | }, | 483 | }, |
| 461 | $routeParams: {}, | 484 | $routeParams: {}, |
| 462 | $location: $location, | 485 | $location: $location, |
| 463 | $uibModal: {}, | 486 | $uibModal: {}, |
| 464 | focaModalService: {}, | 487 | focaModalService: {}, |
| 465 | $timeout: $timeout, | 488 | $timeout: $timeout, |
| 466 | focaBotoneraLateralService: { | 489 | focaBotoneraLateralService: { |
| 467 | showSalir: function() { return; }, | 490 | showSalir: function() { return; }, |
| 468 | showPausar: function() { return; }, | 491 | showPausar: function() { return; }, |
| 469 | showCancelar: function() { return; }, | 492 | showCancelar: function() { return; }, |
| 470 | showGuardar: function() { return; }, | 493 | showGuardar: function() { return; }, |
| 471 | addCustomButton: function() { return; } | 494 | addCustomButton: function() { return; } |
| 472 | }, | 495 | }, |
| 473 | $localStorage: {}, | 496 | $localStorage: {}, |
| 474 | $window: {}, | 497 | $window: {}, |
| 475 | 498 | ||
| 476 | }); | 499 | }); |
| 477 | 500 | ||
| 478 | //act | 501 | //act |
| 479 | scope.salir(); | 502 | scope.salir(); |
| 480 | 503 | ||
| 481 | //assert | 504 | //assert |
| 482 | expect($location.url()).toEqual('/vehiculo'); | 505 | expect($location.url()).toEqual('/vehiculo'); |
| 483 | }); | 506 | }); |
| 484 | }); | 507 | }); |
| 485 | 508 | ||
| 486 | it('Editar lleva a la ruta correcta cuando recibe variable key', function() { | 509 | it('Editar lleva a la ruta correcta cuando recibe variable key', function() { |
| 487 | 510 | ||
| 488 | inject(function($location) { | 511 | inject(function($location) { |
| 489 | //arrange | 512 | //arrange |
| 490 | var scope = { | 513 | var scope = { |
| 491 | $watch: function() {} | 514 | $watch: function() {} |
| 492 | }; | 515 | }; |
| 493 | var controller = $controller('focaAbmVehiculoController', { | 516 | var controller = $controller('focaAbmVehiculoController', { |
| 494 | $scope: scope, | 517 | $scope: scope, |
| 495 | focaAbmVehiculoService: { | 518 | focaAbmVehiculoService: { |
| 519 | getCisternas: function() { | ||
| 520 | return { | ||
| 521 | then: function() { return; } | ||
| 522 | }; | ||
| 523 | }, | ||
| 496 | getVehiculo: function() { | 524 | getVehiculo: function() { |
| 497 | return { | 525 | return { |
| 498 | then: function() { return; } | 526 | then: function() { return; } |
| 499 | }; | 527 | }; |
| 500 | } | 528 | } |
| 501 | }, | 529 | }, |
| 502 | $routeParams: { | 530 | $routeParams: { |
| 503 | idVehiculo: 1 | 531 | idVehiculo: 1 |
| 504 | }, | 532 | }, |
| 505 | $location: $location, | 533 | $location: $location, |
| 506 | $uibModal: {}, | 534 | $uibModal: {}, |
| 507 | focaModalService: {}, | 535 | focaModalService: {}, |
| 508 | $timeout: $timeout, | 536 | $timeout: $timeout, |
| 509 | focaBotoneraLateralService: { | 537 | focaBotoneraLateralService: { |
| 510 | showSalir: function() { return; }, | 538 | showSalir: function() { return; }, |
| 511 | showPausar: function() { return; }, | 539 | showPausar: function() { return; }, |
| 512 | showCancelar: function() { return; }, | 540 | showCancelar: function() { return; }, |
| 513 | showGuardar: function() { return; }, | 541 | showGuardar: function() { return; }, |
| 514 | addCustomButton: function() { return; } | 542 | addCustomButton: function() { return; } |
| 515 | }, | 543 | }, |
| 516 | $localStorage: {}, | 544 | $localStorage: {}, |
| 517 | $window: {} | 545 | $window: {} |
| 518 | }); | 546 | }); |
| 519 | 547 | ||
| 520 | //act | 548 | //act |
| 521 | scope.editar('testing'); | 549 | scope.editar('testing'); |
| 522 | var esperado = '/vehiculo/1/cisterna/testing'; | 550 | var esperado = '/vehiculo/1/cisterna/testing'; |
| 523 | 551 | ||
| 524 | //assert | 552 | //assert |
| 525 | expect($location.url()).toEqual(esperado); | 553 | expect($location.url()).toEqual(esperado); |
| 526 | }); | 554 | }); |
| 527 | }); | 555 | }); |
| 528 | 556 | ||
| 529 | it('Editar lleva a la ruta correcta cuando no recibe variable key', function() { | 557 | it('Editar lleva a la ruta correcta cuando no recibe variable key', function() { |
| 530 | 558 | ||
| 531 | inject(function($location) { | 559 | inject(function($location) { |
| 532 | //arrange | 560 | //arrange |
| 533 | var scope = { | 561 | var scope = { |
| 534 | $watch: function() {} | 562 | $watch: function() {} |
| 535 | }; | 563 | }; |
| 536 | var controller = $controller('focaAbmVehiculoController', { | 564 | var controller = $controller('focaAbmVehiculoController', { |
| 537 | $scope: scope, | 565 | $scope: scope, |
| 538 | focaAbmVehiculoService: { | 566 | focaAbmVehiculoService: { |
| 567 | getCisternas: function() { | ||
| 568 | return { | ||
| 569 | then: function() { return; } | ||
| 570 | }; | ||
| 571 | }, | ||
| 539 | getVehiculo: function() { | 572 | getVehiculo: function() { |
| 540 | return { | 573 | return { |
| 541 | then: function() { return; } | 574 | then: function() { return; } |
| 542 | }; | 575 | }; |
| 543 | } | 576 | } |
| 544 | }, | 577 | }, |
| 545 | $routeParams: { | 578 | $routeParams: { |
| 546 | idVehiculo: 1 | 579 | idVehiculo: 1 |
| 547 | }, | 580 | }, |
| 548 | $location: $location, | 581 | $location: $location, |
| 549 | $uibModal: {}, | 582 | $uibModal: {}, |
| 550 | focaModalService: {}, | 583 | focaModalService: {}, |
| 551 | $timeout: $timeout, | 584 | $timeout: $timeout, |
| 552 | focaBotoneraLateralService: { | 585 | focaBotoneraLateralService: { |
| 553 | showSalir: function() { return; }, | 586 | showSalir: function() { return; }, |
| 554 | showPausar: function() { return; }, | 587 | showPausar: function() { return; }, |
| 555 | showCancelar: function() { return; }, | 588 | showCancelar: function() { return; }, |
| 556 | showGuardar: function() { return; }, | 589 | showGuardar: function() { return; }, |
| 557 | addCustomButton: function() { return; } | 590 | addCustomButton: function() { return; } |
| 558 | }, | 591 | }, |
| 559 | $localStorage: {}, | 592 | $localStorage: {}, |
| 560 | $window: {} | 593 | $window: {} |
| 561 | }); | 594 | }); |
| 562 | 595 | ||
| 563 | //act | 596 | //act |
| 564 | scope.editar(); | 597 | scope.editar(); |
| 565 | var esperado = '/vehiculo/1/cisterna/0/'; | 598 | var esperado = '/vehiculo/1/cisterna/0/'; |
| 566 | 599 | ||
| 567 | //assert | 600 | //assert |
| 568 | expect($location.url()).toEqual(esperado); | 601 | expect($location.url()).toEqual(esperado); |
| 569 | }); | 602 | }); |
| 570 | }); | 603 | }); |
| 571 | 604 | ||
| 572 | it('$scope.solicitarConfirmacionCisterna ejecuta modal de confirmación', function() { | 605 | it('$scope.solicitarConfirmacionCisterna ejecuta modal de confirmación', function() { |
| 573 | 606 | ||
| 574 | //arrange | 607 | //arrange |
| 575 | var focaModalService = { | 608 | var focaModalService = { |
| 576 | confirm: function() {} | 609 | confirm: function() {} |
| 577 | }; | 610 | }; |
| 578 | var scope = { | 611 | var scope = { |
| 579 | $watch: function() {} | 612 | $watch: function() {} |
| 580 | }; | 613 | }; |
| 581 | var controller = $controller('focaAbmVehiculoController', { | 614 | var controller = $controller('focaAbmVehiculoController', { |
| 582 | $scope: scope, | 615 | $scope: scope, |
| 583 | focaAbmVehiculoService: { | 616 | focaAbmVehiculoService: { |
| 617 | getCisternas: function() { | ||
| 618 | return { | ||
| 619 | then: function() { return; } | ||
| 620 | }; | ||
| 621 | }, | ||
| 584 | getVehiculo: function() { | 622 | getVehiculo: function() { |
| 585 | return { | 623 | return { |
| 586 | then: function() { return; } | 624 | then: function() { return; } |
| 587 | }; | 625 | }; |
| 588 | } | 626 | } |
| 589 | }, | 627 | }, |
| 590 | $routeParams: { | 628 | $routeParams: { |
| 591 | idVehiculo: 1 | 629 | idVehiculo: 1 |
| 592 | }, | 630 | }, |
| 593 | $location: {}, | 631 | $location: {}, |
| 594 | $uibModal: {}, | 632 | $uibModal: {}, |
| 595 | focaModalService: focaModalService, | 633 | focaModalService: focaModalService, |
| 596 | $timeout: $timeout, | 634 | $timeout: $timeout, |
| 597 | focaBotoneraLateralService: { | 635 | focaBotoneraLateralService: { |
| 598 | showSalir: function() { return; }, | 636 | showSalir: function() { return; }, |
| 599 | showPausar: function() { return; }, | 637 | showPausar: function() { return; }, |
| 600 | showCancelar: function() { return; }, | 638 | showCancelar: function() { return; }, |
| 601 | showGuardar: function() { return; }, | 639 | showGuardar: function() { return; }, |
| 602 | addCustomButton: function() { return; } | 640 | addCustomButton: function() { return; } |
| 603 | }, | 641 | }, |
| 604 | $localStorage: {}, | 642 | $localStorage: {}, |
| 605 | $window: {} | 643 | $window: {}, |
| 606 | }); | 644 | }); |
| 607 | 645 | ||
| 608 | //act | 646 | //act |
| 609 | spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); | 647 | spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); |
| 610 | scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); | 648 | scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); |
| 611 | 649 | ||
| 612 | //assert | 650 | //assert |
| 613 | expect(focaModalService.confirm).toHaveBeenCalled(); | 651 | expect(focaModalService.confirm).toHaveBeenCalled(); |
| 614 | }); | 652 | }); |
| 615 | 653 | ||
| 616 | it('Elimina y obtiene cisternas al dar confirmar', function(done) { | 654 | it('Elimina y obtiene cisternas al dar confirmar', function(done) { |
| 617 | 655 | ||
| 618 | //arrange | 656 | //arrange |
| 619 | var scope = { | 657 | var scope = { |
| 620 | $watch: function() {} | 658 | $watch: function() {} |
| 621 | }; | 659 | }; |
| 622 | var focaModalService = { | 660 | var focaModalService = { |
| 623 | confirm: function() {} | 661 | confirm: function() {} |
| 624 | }; | 662 | }; |
| 625 | var focaAbmVehiculoService = { | 663 | var focaAbmVehiculoService = { |
| 626 | getVehiculo: function() { | 664 | getVehiculo: function() { |
| 627 | return { | 665 | return { |
| 628 | then: function() { return; } | 666 | then: function() { return; } |
| 629 | }; | 667 | }; |
| 630 | }, | 668 | }, |
| 631 | getCisternas: function() { return; }, | 669 | getCisternas: function() { |
| 670 | return { | ||
| 671 | then: function() { return; } | ||
| 672 | }; | ||
| 673 | }, | ||
| 632 | deleteCisterna: function() { return; } | 674 | deleteCisterna: function() { return; } |
| 633 | }; | 675 | }; |
| 634 | var controller = $controller('focaAbmVehiculoController', { | 676 | var controller = $controller('focaAbmVehiculoController', { |
| 635 | $scope: scope, | 677 | $scope: scope, |
| 636 | focaAbmVehiculoService: focaAbmVehiculoService, | 678 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 637 | $routeParams: {}, | 679 | $routeParams: {}, |
| 638 | $location: {}, | 680 | $location: {}, |
| 639 | $uibModal: {}, | 681 | $uibModal: {}, |
| 640 | focaModalService: focaModalService, | 682 | focaModalService: focaModalService, |
| 641 | $timeout: $timeout, | 683 | $timeout: $timeout, |
| 642 | focaBotoneraLateralService: { | 684 | focaBotoneraLateralService: { |
| 643 | showSalir: function() { return; }, | 685 | showSalir: function() { return; }, |
| 644 | showPausar: function() { return; }, | 686 | showPausar: function() { return; }, |
| 645 | showCancelar: function() { return; }, | 687 | showCancelar: function() { return; }, |
| 646 | showGuardar: function() { return; }, | 688 | showGuardar: function() { return; }, |
| 647 | addCustomButton: function() { return; } | 689 | addCustomButton: function() { return; } |
| 648 | }, | 690 | }, |
| 649 | $localStorage: {}, | 691 | $localStorage: {}, |
| 650 | $window: {} | 692 | $window: {} |
| 651 | }); | 693 | }); |
| 652 | var promesa = Promise.resolve(true); | 694 | var promesa = Promise.resolve(true); |
| 653 | 695 | ||
| 654 | //act | 696 | //act |
| 655 | spyOn(focaModalService, 'confirm').and.returnValue(promesa); | 697 | spyOn(focaModalService, 'confirm').and.returnValue(promesa); |
| 656 | spyOn(focaAbmVehiculoService, 'deleteCisterna'); | 698 | spyOn(focaAbmVehiculoService, 'deleteCisterna'); |
| 657 | spyOn(focaAbmVehiculoService, 'getCisternas').and.returnValue({ then: function() {} }); | 699 | spyOn(focaAbmVehiculoService, 'getCisternas').and.returnValue({ then: function() {} }); |
| 658 | scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); | 700 | scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); |
| 659 | 701 | ||
| 660 | //assert | 702 | //assert |
| 661 | promesa.then( | 703 | promesa.then( |
| 662 | function() { | 704 | function() { |
| 663 | expect(focaAbmVehiculoService.deleteCisterna).toHaveBeenCalled(); | 705 | expect(focaAbmVehiculoService.deleteCisterna).toHaveBeenCalled(); |
| 664 | expect(focaAbmVehiculoService.getCisternas).toHaveBeenCalled(); | 706 | expect(focaAbmVehiculoService.getCisternas).toHaveBeenCalled(); |
| 665 | done(); | 707 | done(); |
| 666 | } | 708 | } |
| 667 | ); | 709 | ); |
| 668 | }); | 710 | }); |
| 669 | }); | 711 | }); |
| 670 | }); | 712 | }); |
| 671 | 713 |
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', '$localStorage', | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', |
| 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, |
| 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { | 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { |
| 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(); | 14 | focaAbmVehiculoService.cleanCisternas(); |
| 15 | 15 | ||
| 16 | //SETEO BOTONERA LATERAL | 16 | //SETEO BOTONERA LATERAL |
| 17 | focaBotoneraLateralService.showSalir(false); | 17 | focaBotoneraLateralService.showSalir(false); |
| 18 | focaBotoneraLateralService.showPausar(false); | 18 | focaBotoneraLateralService.showPausar(false); |
| 19 | focaBotoneraLateralService.showCancelar(false); | 19 | focaBotoneraLateralService.showCancelar(false); |
| 20 | focaBotoneraLateralService.showGuardar(false); | 20 | focaBotoneraLateralService.showGuardar(false); |
| 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 22 | 22 | ||
| 23 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | 23 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { |
| 24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
| 25 | } | 25 | } |
| 26 | $scope.editar = function(id) { | 26 | $scope.editar = function(id) { |
| 27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
| 28 | }; | 28 | }; |
| 29 | $scope.solicitarConfirmacion = function(vehiculo) { | 29 | $scope.solicitarConfirmacion = function(vehiculo) { |
| 30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
| 31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
| 32 | function(data) { | 32 | function(data) { |
| 33 | if (data) { | 33 | if (data) { |
| 34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); |
| 35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | ); | 38 | ); |
| 39 | }; | 39 | }; |
| 40 | $scope.seleccionarTransportista = function() { | 40 | $scope.seleccionarTransportista = function() { |
| 41 | var parametrosModal = { | 41 | var parametrosModal = { |
| 42 | titulo: 'Búsqueda de Transportista', | 42 | titulo: 'Búsqueda de Transportista', |
| 43 | query: '/transportista', | 43 | query: '/transportista', |
| 44 | columnas: [ | 44 | columnas: [ |
| 45 | { | 45 | { |
| 46 | nombre: 'Código', | 46 | nombre: 'Código', |
| 47 | propiedad: 'COD' | 47 | propiedad: 'COD' |
| 48 | }, | 48 | }, |
| 49 | { | 49 | { |
| 50 | nombre: 'Nombre', | 50 | nombre: 'Nombre', |
| 51 | propiedad: 'NOM' | 51 | propiedad: 'NOM' |
| 52 | }, | 52 | }, |
| 53 | { | 53 | { |
| 54 | nombre: 'CUIT', | 54 | nombre: 'CUIT', |
| 55 | propiedad: 'CUIT' | 55 | propiedad: 'CUIT' |
| 56 | } | 56 | } |
| 57 | ] | 57 | ] |
| 58 | }; | 58 | }; |
| 59 | focaModalService.modal(parametrosModal).then( | 59 | focaModalService.modal(parametrosModal).then( |
| 60 | function(transportista) { | 60 | function(transportista) { |
| 61 | elegirTransportista(transportista); | 61 | elegirTransportista(transportista); |
| 62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; |
| 63 | }, function() { | 63 | }, function() { |
| 64 | 64 | ||
| 65 | } | 65 | } |
| 66 | ); | 66 | ); |
| 67 | }; | 67 | }; |
| 68 | function elegirTransportista(transportista) { | 68 | function elegirTransportista(transportista) { |
| 69 | var codigo = ('00000' + transportista.COD).slice(-5); | 69 | var codigo = ('00000' + transportista.COD).slice(-5); |
| 70 | $scope.idTransportista = transportista.COD; | 70 | $scope.idTransportista = transportista.COD; |
| 71 | $scope.filtros = transportista.NOM.trim(); | 71 | $scope.filtros = transportista.NOM.trim(); |
| 72 | $timeout(function() { | 72 | $timeout(function() { |
| 73 | $scope.$broadcast('addCabecera', { | 73 | $scope.$broadcast('addCabecera', { |
| 74 | label: 'Transportista:', | 74 | label: 'Transportista:', |
| 75 | valor: codigo + ' - ' + transportista.NOM | 75 | valor: codigo + ' - ' + transportista.NOM |
| 76 | }); | 76 | }); |
| 77 | }); | 77 | }); |
| 78 | buscar(transportista.COD); | 78 | buscar(transportista.COD); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | function buscar(idTransportista) { | 81 | function buscar(idTransportista) { |
| 82 | focaAbmVehiculoService | 82 | focaAbmVehiculoService |
| 83 | .getVehiculosPorTransportista(idTransportista) | 83 | .getVehiculosPorTransportista(idTransportista) |
| 84 | .then(function(datos) { | 84 | .then(function(datos) { |
| 85 | $scope.vehiculos = datos.data; | 85 | $scope.vehiculos = datos.data; |
| 86 | }); | 86 | }); |
| 87 | } | 87 | } |
| 88 | function salir() { | 88 | function salir() { |
| 89 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 89 | focaAbmVehiculoService.transportistaSeleccionado = {}; |
| 90 | $location.path('/'); | 90 | $location.path('/'); |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | ]) | 93 | ]) |
| 94 | .controller('focaAbmVehiculoController', [ | 94 | .controller('focaAbmVehiculoController', [ |
| 95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', | 96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', |
| 97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | 98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { |
| 99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
| 100 | $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; | ||
| 100 | $scope.now = new Date(); | 101 | $scope.now = new Date(); |
| 101 | $scope.focused = 1; | 102 | $scope.focused = 1; |
| 103 | $scope.creando = false; | ||
| 104 | $scope.crear = false; | ||
| 102 | $scope.transportistaStamp = ''; | 105 | $scope.transportistaStamp = ''; |
| 103 | $scope.cisternas = []; | 106 | $scope.cisternas = []; |
| 104 | 107 | ||
| 105 | $timeout(function() { | 108 | $timeout(function() { |
| 106 | focaBotoneraLateralService.showSalir(false); | 109 | focaBotoneraLateralService.showSalir(false); |
| 107 | focaBotoneraLateralService.showPausar(true); | 110 | focaBotoneraLateralService.showPausar(true); |
| 108 | focaBotoneraLateralService.showCancelar(false); | 111 | focaBotoneraLateralService.showCancelar(false); |
| 109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 112 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 110 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | 113 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); |
| 111 | }); | 114 | }); |
| 112 | |||
| 113 | $timeout(function() {getLSVehiculo();}); | ||
| 114 | 115 | ||
| 115 | if ($scope.nuevo) { | 116 | if ($scope.nuevo) { |
| 116 | focaAbmVehiculoService | 117 | focaAbmVehiculoService |
| 117 | .getTransportistaPorId($routeParams.idTransportista) | 118 | .getTransportistaPorId($routeParams.idTransportista) |
| 118 | .then(function(res) { | 119 | .then(function(res) { |
| 119 | var codigo = ('00000' + res.data.COD).slice(-5); | 120 | var codigo = ('00000' + res.data.COD).slice(-5); |
| 120 | $scope.vehiculo.idTransportista = res.data.COD; | 121 | $scope.vehiculo.idTransportista = res.data.COD; |
| 121 | $scope.vehiculo.transportista = res.data; | 122 | $scope.vehiculo.transportista = res.data; |
| 122 | $scope.$broadcast('addCabecera', { | 123 | $scope.$broadcast('addCabecera', { |
| 123 | label: 'Transportista:', | 124 | label: 'Transportista:', |
| 124 | valor: codigo + ' - ' + res.data.NOM | 125 | valor: codigo + ' - ' + res.data.NOM |
| 125 | }); | 126 | }); |
| 126 | }); | 127 | }); |
| 127 | } | 128 | } |
| 128 | $scope.vehiculo = {}; | 129 | $scope.vehiculo = {}; |
| 130 | |||
| 129 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 131 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 132 | |||
| 130 | if (res.data) { | 133 | if (res.data) { |
| 131 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 134 | var vehiculoSeteado = getLSVehiculo(); |
| 132 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 135 | if (vehiculoSeteado === false) { |
| 136 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | ||
| 137 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | ||
| 133 | 138 | ||
| 134 | $scope.vehiculo = res.data; | 139 | $scope.vehiculo = res.data; |
| 135 | $scope.$broadcast('addCabecera', { | 140 | $scope.$broadcast('addCabecera', { |
| 136 | label: 'Transportista:', | 141 | label: 'Transportista:', |
| 137 | valor: $scope.transportistaStamp | 142 | valor: $scope.transportistaStamp |
| 138 | }); | 143 | }); |
| 139 | $scope.$broadcast('addCabecera', { | 144 | $scope.$broadcast('addCabecera', { |
| 140 | label: 'Unidad:', | 145 | label: 'Unidad:', |
| 141 | valor: res.data.codigo | 146 | valor: res.data.codigo |
| 142 | }); | 147 | }); |
| 148 | } | ||
| 149 | |||
| 143 | focaAbmVehiculoService | 150 | focaAbmVehiculoService |
| 144 | .getCisternas($routeParams.idVehiculo) | 151 | .getCisternas($routeParams.idVehiculo) |
| 145 | .then(function(res) { | 152 | .then(function(res) { |
| 146 | $scope.cisternas = res; | 153 | $scope.cisternas = res; |
| 147 | $scope.$apply(); | 154 | $scope.$apply(); |
| 148 | }); | 155 | }); |
| 149 | } | 156 | } |
| 150 | }); | 157 | }); |
| 151 | 158 | ||
| 152 | $scope.next = function(key) { | 159 | $scope.next = function(key) { |
| 153 | if (key === 13) $scope.focused++; | 160 | if (key === 13) $scope.focused++; |
| 154 | }; | 161 | }; |
| 155 | 162 | ||
| 156 | $scope.salir = function() { | 163 | $scope.salir = function() { |
| 157 | if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | 164 | if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { |
| 158 | focaModalService.confirm( | 165 | focaModalService.confirm( |
| 159 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 166 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 160 | ).then(function(data) { | 167 | ).then(function(data) { |
| 161 | if (data) { | 168 | if (data) { |
| 162 | $location.path('/vehiculo'); | 169 | $location.path('/vehiculo'); |
| 163 | } | 170 | } |
| 164 | }); | 171 | }); |
| 165 | } else { | 172 | } else { |
| 166 | $location.path('/vehiculo'); | 173 | $location.path('/vehiculo'); |
| 167 | } | 174 | } |
| 168 | } | 175 | }; |
| 169 | 176 | ||
| 170 | $scope.editar = function(key) { | 177 | $scope.editar = function(cisterna) { |
| 171 | if (key) { | 178 | $scope.cisternas.forEach(function(cisterna) { |
| 172 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 179 | cisterna.editando = false; |
| 173 | '/cisterna/' + key); | 180 | $scope.crear = true; |
| 174 | } else { | 181 | }); |
| 175 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 182 | cisterna.editando = true; |
| 183 | $scope.inicial = angular.copy(cisterna); | ||
| 184 | }; | ||
| 185 | |||
| 186 | $scope.volver = function(cisterna, key) { | ||
| 187 | if (cisterna.id === undefined || !$scope.crear) { | ||
| 188 | $scope.cisternas.shift(cisterna); | ||
| 189 | $scope.crear = false; | ||
| 190 | return; | ||
| 176 | } | 191 | } |
| 192 | if (cisterna.id !== undefined) { | ||
| 193 | $scope.cisternas[key] = $scope.inicial; | ||
| 194 | $scope.cisternas[key].editando = false; | ||
| 195 | } | ||
| 196 | $scope.crear = false; | ||
| 197 | }; | ||
| 198 | |||
| 199 | $scope.crearCisterna = function() { | ||
| 200 | var cisterna = { | ||
| 201 | codigo: '', | ||
| 202 | capacidad: '', | ||
| 203 | idUnidadMedida: 0, | ||
| 204 | unidadMedida: {}, | ||
| 205 | editando: true, | ||
| 206 | }; | ||
| 207 | $scope.cisternas.unshift(cisterna); | ||
| 208 | $scope.crear = true; | ||
| 209 | }; | ||
| 210 | |||
| 211 | $scope.seleccionarUnidadMedida = function(cisterna) { | ||
| 212 | var modalInstance = $uibModal.open( | ||
| 213 | { | ||
| 214 | ariaLabelledBy: 'Busqueda de Unidades de medida', | ||
| 215 | templateUrl: 'modal-unidad-medida.html', | ||
| 216 | controller: 'focaModalUnidadMedidaCtrl', | ||
| 217 | size: 'lg' | ||
| 218 | } | ||
| 219 | ); | ||
| 220 | modalInstance.result.then(function(unidaMedida) { | ||
| 221 | cisterna.idUnidadMedida = unidaMedida.ID; | ||
| 222 | cisterna.unidadMedida = unidaMedida; | ||
| 223 | }); | ||
| 177 | }; | 224 | }; |
| 178 | $scope.guardar = function(key) { | ||
| 179 | 225 | ||
| 226 | $scope.guardar = function(key) { | ||
| 180 | key = (typeof key === 'undefined') ? 13 : key; | 227 | key = (typeof key === 'undefined') ? 13 : key; |
| 181 | 228 | ||
| 182 | if (key === 13) { | 229 | if (key === 13) { |
| 183 | 230 | ||
| 184 | if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | 231 | if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { |
| 185 | $scope.salir(); | 232 | $scope.salir(); |
| 186 | return; | 233 | return; |
| 187 | } | 234 | } |
| 235 | $scope.cisternas.forEach( function(cisterna) { | ||
| 236 | if (cisterna.id === 0) cisterna.id = undefined; | ||
| 237 | }); | ||
| 188 | 238 | ||
| 189 | if (!$scope.vehiculo.codigo) { | 239 | if (!$scope.vehiculo.codigo) { |
| 190 | focaModalService.alert('Ingrese unidad'); | 240 | focaModalService.alert('Ingrese unidad'); |
| 191 | return; | 241 | return; |
| 192 | } else if (!$scope.vehiculo.tractor) { | 242 | } else if (!$scope.vehiculo.tractor) { |
| 193 | focaModalService.alert('Ingrese dominio tractor'); | 243 | focaModalService.alert('Ingrese dominio tractor'); |
| 194 | return; | 244 | return; |
| 195 | } else if (!$scope.vehiculo.semi) { | 245 | } else if (!$scope.vehiculo.semi) { |
| 196 | focaModalService.alert('Ingrese dominio semi'); | 246 | focaModalService.alert('Ingrese dominio semi'); |
| 197 | return; | 247 | return; |
| 198 | } else if (!$scope.vehiculo.capacidad) { | 248 | } else if (!$scope.vehiculo.capacidad) { |
| 199 | focaModalService.alert('Ingrese capacidad total'); | 249 | focaModalService.alert('Ingrese capacidad total'); |
| 200 | return; | 250 | return; |
| 201 | } | 251 | } |
| 202 | //Valida si existe numero de unidad | 252 | //Valida si existe numero de unidad |
| 203 | if (!validaTotalCargas() && !$scope.nuevo) { | 253 | if (!validaTotalCargas() && !$scope.nuevo) { |
| 204 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 254 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
| 205 | ' debe ser igual a la capacidad total del vehículo'); | 255 | ' debe ser igual a la capacidad total del vehículo'); |
| 206 | return; | 256 | return; |
| 207 | } | 257 | } |
| 258 | |||
| 208 | validaCodigoUnidad().then(function() { | 259 | validaCodigoUnidad().then(function() { |
| 209 | delete $scope.vehiculo.transportista; | 260 | delete $scope.vehiculo.transportista; |
| 210 | delete $scope.vehiculo.cisternas; | 261 | delete $scope.vehiculo.cisternas; |
| 211 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 262 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) |
| 212 | .then(function(res) { | 263 | .then(function(res) { |
| 213 | if ($scope.nuevo) { | 264 | if ($scope.nuevo) { |
| 214 | $location.path('/vehiculo/' + res.data.id + | 265 | $location.path('/vehiculo/' + res.data.id + |
| 215 | '/' + res.data.idTransportista); | 266 | '/' + res.data.idTransportista); |
| 216 | } else { | 267 | } else { |
| 217 | guardarCisternas().then(function() { | 268 | guardarCisternas($scope.cisternas).then(function() { |
| 218 | $location.path('/vehiculo'); | 269 | $location.path('/vehiculo'); |
| 219 | }); | 270 | }); |
| 220 | } | 271 | } |
| 221 | }); | 272 | }); |
| 222 | }, function() { | 273 | }, function() { |
| 223 | focaModalService.alert('Código de unidad existente'); | 274 | focaModalService.alert('Código de unidad existente'); |
| 224 | }); | 275 | }); |
| 225 | } | 276 | } |
| 226 | |||
| 227 | }; | 277 | }; |
| 228 | 278 | //Agregar propiedades de cisterna | |
| 229 | $scope.$watch('vehiculo', function(newValue) { | 279 | $scope.$watch('vehiculo', function(newValue) { |
| 230 | focaBotoneraLateralService.setPausarData({ | 280 | focaBotoneraLateralService.setPausarData({ |
| 231 | label:'vehiculo', | 281 | label:'vehiculo', |
| 232 | val: { | 282 | val: { |
| 233 | codigo: newValue.codigo, | 283 | codigo: newValue.codigo, |
| 234 | tractor: newValue.tractor, | 284 | tractor: newValue.tractor, |
| 235 | semi: newValue.semi, | 285 | semi: newValue.semi, |
| 236 | capacidad: newValue.capacidad, | 286 | capacidad: newValue.capacidad, |
| 237 | idVehiculo: newValue.idVehiculo, | 287 | idVehiculo: newValue.idVehiculo, |
| 238 | idTransportista: newValue.idTransportista | 288 | idTransportista: newValue.idTransportista |
| 239 | } | 289 | } |
| 240 | }); | 290 | }); |
| 241 | }, true); | 291 | }, true); |
| 242 | 292 | ||
| 243 | function getLSVehiculo() { | 293 | function getLSVehiculo() { |
| 244 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); | 294 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); |
| 245 | if (vehiculo) { | 295 | if (vehiculo) { |
| 246 | setearVehiculo(vehiculo); | 296 | setearVehiculo(vehiculo); |
| 247 | delete $localStorage.vehiculo; | 297 | delete $localStorage.vehiculo; |
| 298 | return true; | ||
| 248 | } | 299 | } |
| 300 | return false; | ||
| 249 | } | 301 | } |
| 250 | 302 | ||
| 251 | function setearVehiculo(vehiculo) { | 303 | function setearVehiculo(vehiculo) { |
| 252 | $scope.vehiculo = vehiculo; | 304 | $scope.vehiculo = vehiculo; |
| 253 | $scope.$broadcast('addCabecera', { | 305 | $scope.$broadcast('addCabecera', { |
| 254 | label: 'Vehiculo:', | 306 | label: 'Vehiculo:', |
| 255 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | 307 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' |
| 256 | }); | 308 | }); |
| 257 | } | 309 | } |
| 258 | 310 | ||
| 259 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 311 | $scope.solicitarConfirmacionTabla = function(cisterna) { |
| 260 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 312 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?') |
| 261 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 313 | .then( function(data) { |
| 262 | function(data) { | 314 | if (data) { |
| 263 | if (data) { | 315 | cisterna.desactivado = true; |
| 264 | focaAbmVehiculoService.deleteCisterna(idx); | ||
| 265 | focaAbmVehiculoService | ||
| 266 | .getCisternas($routeParams.idVehiculo) | ||
| 267 | .then(function(res) { | ||
| 268 | $scope.cisternas = res; | ||
| 269 | }); | ||
| 270 | } | ||
| 271 | } | 316 | } |
| 272 | ); | 317 | }); |
| 318 | return; | ||
| 273 | }; | 319 | }; |
| 274 | 320 | ||
| 275 | function validaCodigoUnidad() { | 321 | function validaCodigoUnidad() { |
| 276 | return new Promise(function(resolve, reject) { | 322 | return new Promise(function(resolve, reject) { |
| 277 | focaAbmVehiculoService | 323 | focaAbmVehiculoService |
| 278 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 324 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) |
| 279 | .then(function(res) { | 325 | .then(function(res) { |
| 280 | //Valida si existe numero de unidad | 326 | //Valida si existe numero de unidad |
| 281 | var existe = res.data.filter(function(vehiculo) { | 327 | var existe = res.data.filter(function(vehiculo) { |
| 282 | return vehiculo.codigo === $scope.vehiculo.codigo && | 328 | return vehiculo.codigo === $scope.vehiculo.codigo && |
| 283 | vehiculo.id !== $scope.vehiculo.id; | 329 | vehiculo.id !== $scope.vehiculo.id; |
| 284 | }); | 330 | }); |
| 285 | 331 | ||
| 286 | if (existe.length) { | 332 | if (existe.length) { |
| 287 | reject(existe); | 333 | reject(existe); |
| 288 | } else { | 334 | } else { |
| 289 | resolve(); | 335 | resolve(); |
| 290 | } | 336 | } |
| 291 | }); | 337 | }); |
| 292 | }); | 338 | }); |
| 293 | } | 339 | } |
| 294 | 340 | ||
| 295 | function validaTotalCargas() { | 341 | function validaTotalCargas() { |
| 296 | var total = 0; | 342 | var total = 0; |
| 297 | $scope.cisternas.forEach(function(cisterna) { | 343 | $scope.cisternas.forEach(function(cisterna) { |
| 298 | if (!cisterna.desactivado) { | 344 | if (!cisterna.desactivado) { |
| 299 | total += parseInt(cisterna.capacidad); | 345 | total += parseInt(cisterna.capacidad); |
| 300 | } | 346 | } |
| 301 | }); | 347 | }); |
| 302 | return $scope.vehiculo.capacidad == total; | 348 | return $scope.vehiculo.capacidad >= total; |
| 303 | } | 349 | } |
| 304 | |||
| 305 | function guardarCisternas() { | 350 | function guardarCisternas() { |
| 306 | var cisternas = $scope.cisternas.map(function(cisterna) { | 351 | var cisternas = $scope.cisternas.map(function(cisterna) { |
| 307 | return { | 352 | return { |
| 308 | id: cisterna.id, | 353 | id: cisterna.id, |
| 309 | capacidad: parseFloat(cisterna.capacidad), | 354 | capacidad: parseFloat(cisterna.capacidad), |
| 310 | codigo: cisterna.codigo, | 355 | codigo: cisterna.codigo, |
| 311 | idUnidadMedida: cisterna.idUnidadMedida, | 356 | idUnidadMedida: cisterna.idUnidadMedida, |
| 312 | idVehiculo: $routeParams.idVehiculo, | 357 | idVehiculo: $routeParams.idVehiculo, |
| 313 | desactivado: cisterna.desactivado | 358 | desactivado: cisterna.desactivado |
| 314 | }; | 359 | }; |
| 315 | }); | 360 | }); |
| 316 | 361 | ||
| 317 | return focaAbmVehiculoService.guardarCisternas(cisternas); | 362 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
| 318 | } | 363 | } |
| 319 | 364 | ||
| 365 | $scope.agregarCisterna = function(cisterna) { | ||
| 366 | if (!cisterna) { | ||
| 367 | focaModalService.alert('Ingrese valores'); | ||
| 368 | return; | ||
| 369 | } else if (!cisterna.codigo) { | ||
| 370 | focaModalService.alert('Ingrese codigo de cisterna'); | ||
| 371 | return; | ||
| 372 | } else if (!cisterna.capacidad) { | ||
| 373 | focaModalService.alert('Ingrese capacidad'); | ||
| 374 | return; | ||
| 375 | } else if (!cisterna.idUnidadMedida) { | ||
| 376 | focaModalService.alert('Ingrese unidad de medida'); | ||
| 377 | return; | ||
| 378 | } | ||
| 379 | |||
| 380 | validaCodigo(cisterna); | ||
| 381 | cisterna.id = 0; | ||
| 382 | }; | ||
| 383 | |||
| 384 | if ($routeParams.idx !== -1) { | ||
| 385 | $scope.cisterna = [$routeParams.idx]; | ||
| 386 | focaAbmVehiculoService | ||
| 387 | .getCisternas($routeParams.idVehiculo) | ||
| 388 | .then(function(res) { | ||
| 389 | $scope.cisterna = res[$routeParams.idx]; | ||
| 390 | }); | ||
| 391 | } | ||
| 392 | |||
| 393 | function validaCodigo(cisterna) { | ||
| 394 | focaAbmVehiculoService | ||
| 395 | .getCisternas($routeParams.idVehiculo) | ||
| 396 | .then(function(res) { | ||
| 397 | var cisternas = res; | ||
| 398 | var totalCargado = 0; | ||
| 399 | cisternas.forEach(function(cisternaBase, idx) { | ||
| 400 | //SI EL CODIGO YA EXISTE | ||
| 401 | if (cisternaBase.codigo === cisterna.codigo && | ||
| 402 | idx !== $routeParams.idx && | ||
| 403 | cisternaBase.desactivado === false && | ||
| 404 | cisternaBase.id !== cisterna.id | ||
| 405 | ) | ||
| 406 | { | ||
| 407 | focaModalService.alert('Código de cisterna existente'); | ||
| 408 | } | ||
| 409 | if (idx !== $routeParams.idx && | ||
| 410 | !cisternaBase.desactivado) { |
src/js/controllerCisterna.js
| 1 | angular.module('focaAbmVehiculo') | File was deleted | |
| 2 | .controller('focaAbmVehiculoCisternaController', [ | ||
| 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | ||
| 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', | ||
| 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | ||
| 6 | focaModalService, focaBotoneraLateralService, $timeout, $window) { | ||
| 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; | ||
| 8 | $scope.editar = false; | ||
| 9 | $scope.now = new Date(); | ||
| 10 | $scope.cisterna = { | ||
| 11 | codigo: '', | ||
| 12 | capacidad: '', | ||
| 13 | unidadMedida: {} | ||
| 14 | }; | ||
| 15 | |||
| 16 | $scope.focused = $scope.nuevo ? 1 : 2; | ||
| 17 | $scope.next = function(key) { | ||
| 18 | if (key === 13) $scope.focused++; | ||
| 19 | }; | ||
| 20 | $scope.capacidadVechiulo = 0; | ||
| 21 | $scope.transportista = ''; | ||
| 22 | |||
| 23 | //SETEO BOTONERA LATERAL | ||
| 24 | $timeout(function() { | ||
| 25 | focaBotoneraLateralService.showSalir(false); | ||
| 26 | focaBotoneraLateralService.showPausar(true); | ||
| 27 | focaBotoneraLateralService.showCancelar(false); | ||
| 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | ||
| 29 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | ||
| 30 | }); | ||
| 31 | |||
| 32 | if ($routeParams.idx !== -1) { | ||
| 33 | $scope.cisterna = [$routeParams.idx]; | ||
| 34 | focaAbmVehiculoService | ||
| 35 | .getCisternas($routeParams.idVehiculo) | ||
| 36 | .then(function(res) { | ||
| 37 | $scope.cisterna = res[$routeParams.idx]; | ||
| 38 | }); | ||
| 39 | } | ||
| 40 | |||
| 41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | ||
| 42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | ||
| 43 | $scope.transportista = res.data.transportista.COD; | ||
| 44 | $scope.capacidadVechiulo = res.data.capacidad; | ||
| 45 | $scope.$broadcast('addCabecera', { | ||
| 46 | label: 'Transportista:', | ||
| 47 | valor: codigo + ' - ' + res.data.transportista.NOM | ||
| 48 | }); | ||
| 49 | $scope.$broadcast('addCabecera', { | ||
| 50 | label: 'Unidad:', | ||
| 51 | valor: res.data.codigo | ||
| 52 | }); | ||
| 53 | $scope.$broadcast('addCabecera', { | ||
| 54 | label: 'Capacidad total vehículo:', | ||
| 55 | valor: res.data.capacidad | ||
| 56 | }); | ||
| 57 | }); | ||
| 58 | |||
| 59 | $scope.salir = function() { | ||
| 60 | |||
| 61 | if (!$scope.formCisterna.$pristine) { | ||
| 62 | focaModalService.confirm( | ||
| 63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | ||
| 64 | ).then(function(data) { | ||
| 65 | if (data) { | ||
| 66 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | ||
| 67 | $scope.transportista); | ||
| 68 | } | ||
| 69 | }); | ||
| 70 | } else { | ||
| 71 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | ||
| 72 | $scope.transportista); | ||
| 73 | } | ||
| 74 | }; | ||
| 75 | |||
| 76 | $scope.guardar = function() { | ||
| 77 | |||
| 78 | if ($scope.formCisterna.$pristine) { | ||
| 79 | $scope.salir(); | ||
| 80 | return; | ||
| 81 | } else if (!$scope.cisterna.codigo) { | ||
| 82 | focaModalService.alert('Ingrese codigo de cisterna'); | ||
| 83 | return; | ||
| 84 | } else if (!$scope.cisterna.capacidad) { | ||
| 85 | focaModalService.alert('Ingrese capacidad'); | ||
| 86 | return; | ||
| 87 | } else if (!$scope.cisterna.idUnidadMedida) { | ||
| 88 | focaModalService.alert('Ingrese unidad de medida'); | ||
| 89 | return; | ||
| 90 | } | ||
| 91 | |||
| 92 | validaCodigo() | ||
| 93 | .then(function() { | ||
| 94 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | ||
| 95 | delete $scope.cisterna.vehiculo; | ||
| 96 | |||
| 97 | focaAbmVehiculoService | ||
| 98 | .guardarCisterna($scope.cisterna, $routeParams.idx); | ||
| 99 | |||
| 100 | $timeout(function() { | ||
| 101 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | ||
| 102 | '/' + $scope.transportista); | ||
| 103 | }, 0); | ||
| 104 | }, function(err) { | ||
| 105 | focaModalService.alert(err); | ||
| 106 | }); | ||
| 107 | |||
| 108 | }; | ||
| 109 | |||
| 110 | $scope.seleccionarUnidadMedida = function() { | ||
| 111 | var modalInstance = $uibModal.open( | ||
| 112 | { | ||
| 113 | ariaLabelledBy: 'Busqueda de Unidades de medida', | ||
| 114 | templateUrl: 'modal-unidad-medida.html', | ||
| 115 | controller: 'focaModalUnidadMedidaCtrl', | ||
| 116 | size: 'lg' | ||
| 117 | } | ||
| 118 | ); | ||
| 119 | modalInstance.result.then(function(unidaMedida) { | ||
| 120 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | ||
| 121 | $scope.cisterna.unidadMedida = unidaMedida; | ||
| 122 | }); | ||
| 123 | }; | ||
| 124 | |||
| 125 | function validaCodigo() { | ||
| 126 | return new Promise(function(resolve, reject) { | ||
| 127 | focaAbmVehiculoService | ||
| 128 | .getCisternas($routeParams.idVehiculo) | ||
| 129 | .then(function(res) { | ||
| 130 | var cisternas = res; | ||
| 131 | var totalCargado = 0; | ||
| 132 | cisternas.forEach(function(cisterna, idx) { | ||
| 133 | //SI EL CODIGO YA EXISTE | ||
| 134 | if (cisterna.codigo === $scope.cisterna.codigo && | ||
| 135 | idx != $routeParams.idx && | ||
| 136 | !cisterna.desactivado) { | ||
| 137 | reject('Código de cisterna existente'); | ||
| 138 | } | ||
| 139 | if (idx !== $routeParams.idx && | ||
| 140 | !cisterna.desactivado) { | ||
| 141 | totalCargado += cisterna.capacidad; | ||
| 142 | } | ||
| 143 | }); | ||
| 144 | resolve(); | ||
| 145 | }); | ||
| 146 | }); | ||
| 147 | } | ||
| 148 | } | ||
| 149 | ]); | ||
| 150 | 1 | angular.module('focaAbmVehiculo') |
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 | var cisternasPristine = true; | 4 | var cisternasPristine = true; |
| 5 | return { | 5 | return { |
| 6 | getVehiculos: function() { | 6 | getVehiculos: function() { |
| 7 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); | 7 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); |
| 8 | }, | 8 | }, |
| 9 | getVehiculo: function(id) { | 9 | getVehiculo: function(id) { |
| 10 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); | 10 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); |
| 11 | }, | 11 | }, |
| 12 | getTransportistas: function() { | 12 | getTransportistas: function() { |
| 13 | return $http.get(API_ENDPOINT.URL + '/transportista'); | 13 | return $http.get(API_ENDPOINT.URL + '/transportista'); |
| 14 | }, | 14 | }, |
| 15 | guardarVehiculo: function(vehiculo) { | 15 | guardarVehiculo: function(vehiculo) { |
| 16 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); | 16 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); |
| 17 | }, | 17 | }, |
| 18 | deleteVehiculo: function(id) { | 18 | deleteVehiculo: function(id) { |
| 19 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); | 19 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); |
| 20 | }, | 20 | }, |
| 21 | getCisternas: function(idVehiculo) { | 21 | getCisternas: function(idVehiculo) { |
| 22 | if (cisternas.length) { | ||
| 23 | cisternasPristine = true; | ||
| 24 | return Promise.resolve(angular.copy(cisternas)); | ||
| 25 | } else { | ||
| 26 | cisternasPristine = true; | 22 | cisternasPristine = true; |
| 27 | return new Promise(function(resolve) { | 23 | return new Promise(function(resolve) { |
| 28 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) | 24 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) |
| 29 | .then(function(res) { | 25 | .then(function(res) { |
| 30 | cisternas = res.data; | 26 | cisternas = res.data; |
| 31 | resolve(res.data); | 27 | resolve(res.data); |
| 32 | }); | 28 | }); |
| 33 | }); | 29 | }); |
| 34 | } | ||
| 35 | }, | 30 | }, |
| 36 | guardarCisterna: function(cisterna, idx) { | 31 | guardarCisterna: function(cisterna, idx) { |
| 37 | if (idx !== '-1') { | 32 | if (idx !== '-1') { |
| 38 | //update | 33 | //update |
| 39 | cisternas[idx] = cisterna; | 34 | cisternas[idx] = cisterna; |
| 40 | cisternasPristine = false; | 35 | cisternasPristine = false; |
| 41 | } else { | 36 | } else { |
| 42 | //insert | 37 | //insert |
| 43 | cisternas.push(cisterna); | 38 | cisternas.push(cisterna); |
| 44 | cisternasPristine = false; | 39 | cisternasPristine = false; |
| 45 | } | 40 | } |
| 46 | }, | 41 | }, |
| 47 | guardarCisternas: function(cisternas) { | 42 | guardarCisternas: function(cisternas) { |
| 48 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); | 43 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); |
| 49 | }, | 44 | }, |
| 50 | deleteCisterna: function(idx) { | 45 | deleteCisterna: function(cisterna) { |
| 51 | cisternas[idx].desactivado = true; | 46 | cisterna.desactivado = true; |
| 52 | cisternasPristine = false; | 47 | cisternasPristine = false; |
| 48 | return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisterna.id); | ||
| 53 | }, | 49 | }, |
| 54 | cleanCisternas: function() { | 50 | cleanCisternas: function() { |
| 55 | cisternas = []; | 51 | cisternas = []; |
| 56 | }, | 52 | }, |
| 57 | getVehiculosPorTransportista: function(id) { | 53 | getVehiculosPorTransportista: function(id) { |
| 58 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); | 54 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); |
| 59 | }, | 55 | }, |
| 60 | getTransportistaPorId: function(id) { | 56 | getTransportistaPorId: function(id) { |
| 61 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); | 57 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); |
| 62 | }, | 58 | }, |
| 63 | transportistaSeleccionado: {} | 59 | transportistaSeleccionado: {} |
| 64 | }; | 60 | }; |
| 65 | }]); | 61 | }]); |
src/views/foca-abm-cisterna-item.html
| 1 | <div class="row"> | File was deleted | |
| 2 | <foca-cabecera-facturador | ||
| 3 | titulo="'Vehículo cisterna'" | ||
| 4 | fecha="now" | ||
| 5 | class="mb-0 col-lg-12" | ||
| 6 | ></foca-cabecera-facturador> | ||
| 7 | </div> | ||
| 8 | <div class="row"></div> | ||
| 9 | <form name="formCisterna"> | ||
| 10 | <div class="form-group row"> | ||
| 11 | <label class="offset-sm-1 col-sm-2 col-form-label">Código de cisterna</label> | ||
| 12 | <div class="col-sm-4"> | ||
| 13 | <input | ||
| 14 | class="form-control" | ||
| 15 | type="text" | ||
| 16 | ng-required="true" | ||
| 17 | ng-model="cisterna.codigo" | ||
| 18 | ng-keypress="next($event.keyCode)" | ||
| 19 | foca-focus="focused == 1" | ||
| 20 | ng-focus="focused = 1" | ||
| 21 | ng-disabled="!nuevo" | ||
| 22 | teclado-virtual | ||
| 23 | /> | ||
| 24 | </div> | ||
| 25 | </div> | ||
| 26 | <div class="form-group row"> | ||
| 27 | <label class="offset-sm-1 col-sm-2 col-form-label">Capacidad</label> | ||
| 28 | <div class="col-sm-4"> | ||
| 29 | <input | ||
| 30 | class="form-control" | ||
| 31 | type="text" | ||
| 32 | teclado-virtual | ||
| 33 | foca-tipo-input | ||
| 34 | ng-model="cisterna.capacidad" | ||
| 35 | ng-required="true" | ||
| 36 | ng-keypress="next($event.keyCode)" | ||
| 37 | foca-focus="focused == 2" | ||
| 38 | ng-focus="focused = 2" | ||
| 39 | /> | ||
| 40 | </div> | ||
| 41 | </div> | ||
| 42 | <div class="form-group row"> | ||
| 43 | <label class="offset-sm-1 col-sm-2 col-form-label">Unidad de medida</label> | ||
| 44 | <div class="col-sm-4 input-group"> | ||
| 45 | <input | ||
| 46 | ng-model="cisterna.unidadMedida.NOM" | ||
| 47 | class="form-control" | ||
| 48 | readonly | ||
| 49 | /> | ||
| 50 | <div class="input-group-append"> | ||
| 51 | <button | ||
| 52 | ladda="searchLoading" | ||
| 53 | class="btn btn-outline-secondary form-control" | ||
| 54 | type="button" | ||
| 55 | ng-click="seleccionarUnidadMedida()" | ||
| 56 | foca-focus="focused == 3" | ||
| 57 | > | ||
| 58 | <i class="fa fa-search" aria-hidden="true"></i> | ||
| 59 | </button> | ||
| 60 | </div> | ||
| 61 | </div> | ||
| 62 | </div> | ||
| 63 | </form> | ||
| 64 | 1 | <div class="row"> |
src/views/foca-abm-vehiculos-item.html
| 1 | <div class="row"> | 1 | <div class="row"> |
| 2 | <foca-cabecera-facturador | 2 | <foca-cabecera-facturador |
| 3 | titulo="'Vehículo'" | 3 | titulo="'Vehículo'" |
| 4 | fecha="now" | 4 | fecha="now" |
| 5 | class="mb-0 col-lg-12" | 5 | class="mb-0 col-lg-12" |
| 6 | ></foca-cabecera-facturador> | 6 | ></foca-cabecera-facturador> |
| 7 | </div> | 7 | </div> |
| 8 | <div class="row"> | 8 | <div class="row"> |
| 9 | <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> | 9 | <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> |
| 10 | <form name="formVehiculo" class="px-3"> | 10 | <form name="formVehiculo" class="px-3"> |
| 11 | <input type="hidden" name="id" ng-model="sector.id" /> | 11 | <input type="hidden" name="id" ng-model="sector.id" /> |
| 12 | <div class="row mt-3"> | 12 | <div class="row mt-3"> |
| 13 | <div class="form-group d-flex mb-2 col-md-6"> | 13 | <div class="form-group d-flex mb-2 col-md-6"> |
| 14 | <label class="col-form-label col-md-4">Unidad</label> | 14 | <label class="col-form-label col-md-4">Unidad</label> |
| 15 | <div class="input-group col-md-8 pl-0"> | 15 | <div class="input-group col-md-8 pl-0"> |
| 16 | <input | 16 | <input |
| 17 | class="form-control" | 17 | class="form-control" |
| 18 | type="text" | 18 | type="text" |
| 19 | teclado-virtual | 19 | teclado-virtual |
| 20 | ng-model="vehiculo.codigo" | 20 | ng-model="vehiculo.codigo" |
| 21 | foca-focus="focused == 1" | 21 | foca-focus="focused == 1" |
| 22 | ng-focus="focused = 1" | 22 | ng-focus="focused = 1" |
| 23 | ng-keypress="next($event.keyCode)" | 23 | ng-keypress="next($event.keyCode)" |
| 24 | ng-disabled="!nuevo" | 24 | ng-disabled="!nuevo" |
| 25 | /> | 25 | /> |
| 26 | </div> | 26 | </div> |
| 27 | </div> | 27 | </div> |
| 28 | <div class="form-group d-flex mb-2 col-md-6"> | 28 | <div class="form-group d-flex mb-2 col-md-6"> |
| 29 | <label class="col-form-label col-md-4">Dominio tractor</label> | 29 | <label class="col-form-label col-md-4">Dominio tractor</label> |
| 30 | <div class="input-group col-md-8 pl-0"> | 30 | <div class="input-group col-md-8 pl-0"> |
| 31 | <input | 31 | <input |
| 32 | class="form-control" | 32 | class="form-control" |
| 33 | type="text" | 33 | type="text" |
| 34 | teclado-virtual | 34 | teclado-virtual |
| 35 | ng-model="vehiculo.tractor" | 35 | ng-model="vehiculo.tractor" |
| 36 | ng-required="true" | 36 | ng-required="true" |
| 37 | foca-focus="focused == 2" | 37 | foca-focus="focused == 2" |
| 38 | ng-focus="focused = 2" | 38 | ng-focus="focused = 2" |
| 39 | ng-keypress="next($event.keyCode)" | 39 | ng-keypress="next($event.keyCode)" |
| 40 | /> | 40 | /> |
| 41 | </div> | 41 | </div> |
| 42 | </div> | 42 | </div> |
| 43 | <div class="form-group d-flex mb-2 col-md-6"> | 43 | <div class="form-group d-flex mb-2 col-md-6"> |
| 44 | <label class="col-form-label col-md-4">Dominio semi</label> | 44 | <label class="col-form-label col-md-4">Dominio semi</label> |
| 45 | <div class="input-group col-md-8 pl-0"> | 45 | <div class="input-group col-md-8 pl-0"> |
| 46 | <input | 46 | <input |
| 47 | class="form-control" | 47 | class="form-control" |
| 48 | type="text" | 48 | type="text" |
| 49 | teclado-virtual | 49 | teclado-virtual |
| 50 | ng-model="vehiculo.semi" | 50 | ng-model="vehiculo.semi" |
| 51 | ng-required="true" | 51 | ng-required="true" |
| 52 | foca-focus="focused == 3" | 52 | foca-focus="focused == 3" |
| 53 | ng-focus="focused = 3" | 53 | ng-focus="focused = 3" |
| 54 | ng-keypress="next($event.keyCode)" | 54 | ng-keypress="next($event.keyCode)" |
| 55 | /> | 55 | /> |
| 56 | </div> | 56 | </div> |
| 57 | </div> | 57 | </div> |
| 58 | <div class="form-group d-flex mb-2 col-md-6"> | 58 | <div class="form-group d-flex mb-2 col-md-6"> |
| 59 | <label class="col-form-label col-md-4">Capacidad total</label> | 59 | <label class="col-form-label col-md-4">Capacidad total</label> |
| 60 | <div class="input-group col-md-8 pl-0"> | 60 | <div class="input-group col-md-8 pl-0"> |
| 61 | <input | 61 | <input |
| 62 | class="form-control" | 62 | class="form-control" |
| 63 | type="text" | 63 | type="text" |
| 64 | teclado-virtual | 64 | teclado-virtual |
| 65 | ng-model="vehiculo.capacidad" | 65 | ng-model="vehiculo.capacidad" |
| 66 | ng-required="true" | 66 | ng-required="true" |
| 67 | foca-focus="focused == 4" | 67 | foca-focus="focused == 4" |
| 68 | ng-focus="focused = 4" | 68 | ng-focus="focused = 4" |
| 69 | ng-keypress="guardar($event.keyCode)" | 69 | ng-keypress="guardar($event.keyCode)" |
| 70 | /> | 70 | /> |
| 71 | </div> | 71 | </div> |
| 72 | </div> | 72 | </div> |
| 73 | </div> | 73 | </div> |
| 74 | </form> | 74 | </form> |
| 75 | <div ng-show="!nuevo"> | 75 | <div ng-show="!nuevo"> |
| 76 | <h5 class="pl-4 table-title">Cisternas</h5> | 76 | <h5 class="pl-4 table-title">Cisternas</h5> |
| 77 | <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> | 77 | <table class="table table-default table-hover table-sm table-abm table-striped mb-0" > |
| 78 | <thead> | 78 | <thead> |
| 79 | <tr> | 79 | <tr> |
| 80 | <th class="px-5">Código</th> | 80 | <th class="text-center px-4">Código</th> |
| 81 | <th class="text-right px-5">Capacidad</th> | 81 | <th class="text-center">Capacidad</th> |
| 82 | <th class="text-center px-4"> | 82 | <th class="text-center">Unidad de Medida</th> |
| 83 | <th class="text-center"> | ||
| 83 | <button | 84 | <button |
| 84 | class="btn btn-outline-debo boton-accion" | 85 | class="btn btn-outline-debo boton-accion" |
| 85 | title="Agregar" | 86 | title="Agregar" |
| 86 | ng-click="editar(-1)"> | 87 | ng-click="crearCisterna()" |
| 88 | ng-disabled="crear"> | ||
| 87 | <i class="fa fa-plus"></i> | 89 | <i class="fa fa-plus"></i> |
| 88 | </button> | 90 | </button> |
| 89 | </th> | 91 | </th> |
| 90 | </tr> | 92 | </tr> |
| 91 | </thead> | 93 | </thead> |
| 92 | <tbody> | 94 | <tbody> |
| 93 | <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" | 95 | <tr ng-show="creando"> |
| 94 | ng-show="!cisterna.desactivado"> | 96 | <td align="center"> |
| 95 | <td ng-bind="cisterna.codigo" class="px-5"></td> | 97 | <input |
| 96 | <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td> | 98 | class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" |
| 97 | <td class="text-center px-4"> | 99 | ng-model="cisterna.codigo" |
| 100 | ng-keypress="next($event.keyCode)" | ||
| 101 | foca-focus="focused == 1" | ||
| 102 | ng-focus="focused = 1" | ||
| 103 | ng-disabled="!nuevoCisterna" | ||
| 104 | teclado-virtual | ||
| 105 | > | ||
| 106 | </td> | ||
| 107 | <td align="center"> | ||
| 108 | <input | ||
| 109 | class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | ||
| 110 | teclado-virtual | ||
| 111 | foca-tipo-input | ||
| 112 | ng-model="cisterna.capacidad" | ||
| 113 | ng-required="true" | ||
| 114 | ng-keypress="next($event.keyCode)" | ||
| 115 | foca-focus="focused == 2" | ||
| 116 | ng-focus="focused = 2" | ||
| 117 | > | ||
| 118 | </td> | ||
| 119 | <td align="center"> | ||
| 120 | <div class="input-group"> | ||
| 121 | <input | ||
| 122 | ng-model="cisterna.unidadMedida.NOM" | ||
| 123 | class="form-control" | ||
| 124 | readonly | ||
| 125 | /> | ||
| 126 | <div class="input-group-append"> | ||
| 127 | <button | ||
| 128 | ladda="searchLoading" | ||
| 129 | class="btn btn-outline-secondary form-control" | ||
| 130 | type="button" | ||
| 131 | ng-click="seleccionarUnidadMedida()" | ||
| 132 | foca-focus="focused == 3" | ||
| 133 | > | ||
| 134 | <i class="fa fa-search" aria-hidden="true"></i> | ||
| 135 | </button> | ||
| 136 | </div> | ||
| 137 | </div> | ||
| 138 | </td> | ||
| 139 | <td align="center"> | ||
| 140 | <button | ||
| 141 | class="btn btn-outline-dark boton-accion" | ||
| 142 | ng-click="agregarCisterna()" | ||
| 143 | > | ||
| 144 | <i class="fa fa-save"></i> | ||
| 145 | </button> | ||
| 146 | </td> | ||
| 147 | </tr> | ||
| 148 | |||
| 149 | <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" ng-hide="cisterna.desactivado"> | ||
| 150 | <td ng-bind="cisterna.codigo" class="text-center" ng-hide="cisterna.editando"></td> | ||
| 151 | <td align="center" ng-show="cisterna.editando"> | ||
| 152 | <input | ||
| 153 | class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | ||
| 154 | ng-model="cisterna.codigo" | ||
| 155 | ng-keypress="next($event.keyCode)" | ||
| 156 | foca-focus="focused == 1" | ||
| 157 | ng-focus="focused = 1" | ||
| 158 | teclado-virtual | ||
| 159 | esc-key="volver(cisterna, key)" | ||
| 160 | > | ||
| 161 | </td> | ||
| 162 | <td ng-bind="cisterna.capacidad" class="text-center" ng-hide="cisterna.editando"></td> | ||
| 163 | <td align="center" ng-show="cisterna.editando" > | ||
| 164 | <input | ||
| 165 | class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | ||
| 166 | teclado-virtual | ||
| 167 | foca-tipo-input | ||
| 168 | ng-model="cisterna.capacidad" | ||
| 169 | ng-required="true" | ||
| 170 | ng-keypress="next($event.keyCode)" | ||
| 171 | foca-focus="focused == 2" | ||
| 172 | ng-focus="focused = 2" | ||
| 173 | esc-key="volver(cisterna, key)" | ||
| 174 | > | ||
| 175 | </td> | ||
| 176 | <td ng-bind="cisterna.unidadMedida.NOM" class="text-center" ng-hide="cisterna.editando"></td> | ||
| 177 | <td align="center" ng-show="cisterna.editando"> | ||
| 178 | <div class="input-group"> | ||
| 179 | <input | ||
| 180 | ng-model="cisterna.unidadMedida.NOM" | ||
| 181 | class="form-control" | ||
| 182 | readonly | ||
| 183 | esc-key="volver(cisterna, key)" | ||
| 184 | /> | ||
| 185 | <div class="input-group-append"> | ||
| 186 | <button | ||
| 187 | ladda="searchLoading" | ||
| 188 | class="btn btn-outline-secondary form-control" | ||
| 189 | type="button" | ||
| 190 | ng-click="seleccionarUnidadMedida(cisterna)" | ||
| 191 | foca-focus="focused == 3" | ||
| 192 | > | ||
| 193 | <i class="fa fa-search" aria-hidden="true"></i> | ||
| 194 | </button> | ||
| 195 | </div> | ||
| 196 | </div> | ||
| 197 | </td> | ||
| 198 | <td class="text-center" ng-hide="cisterna.editando"> | ||
| 98 | <button | 199 | <button |
| 99 | class="btn btn-outline-dark boton-accion" | 200 | class="btn btn-outline-dark boton-accion" |
| 100 | title="Editar" | 201 | title="Editar" |
| 101 | ng-click="editar(key)" | 202 | ng-click="editar(cisterna)" |
| 102 | > | 203 | > |
| 103 | <i class="fa fa-pencil"></i> | 204 | <i class="fa fa-pencil"></i> |
| 104 | </button> | 205 | </button> |
| 105 | <button | 206 | <button |
| 106 | class="btn btn-outline-dark boton-accion" | 207 | class="btn btn-outline-dark boton-accion" |
| 107 | title="Eliminar" | 208 | title="Eliminar" |
| 108 | ng-click="solicitarConfirmacionCisterna(cisterna, key)" | 209 | ng-click="solicitarConfirmacionTabla(cisterna, $index)" |
| 109 | > | 210 | > |
| 110 | <i class="fa fa-trash"></i> | 211 | <i class="fa fa-trash"></i> |
| 111 | </button> | 212 | </button> |
| 112 | </td> | 213 | </td> |
| 214 | <td align="center" ng-show="cisterna.editando" > | ||
| 215 | <button | ||
| 216 | class="btn btn-outline-dark boton-accion" | ||
| 217 | ng-click="agregarCisterna(cisterna)" | ||
| 218 | > | ||
| 219 | <i class="fa fa-save"></i> | ||
| 220 | </button> | ||
| 221 | <button | ||
| 222 | class="btn btn-outline-dark boton-accion" | ||
| 223 | ng-click="volver(cisterna, key)" | ||
| 224 | > | ||
| 225 | <i class="fa fa-undo" aria-hidden="true"></i> | ||
| 226 | </button> | ||
| 227 | </td> | ||
| 228 | </tr> | ||
| 229 | |||
| 230 | <tr ng-repeat="(key, cisterna) in cisternas" ng-show="false"> | ||
| 113 | </tr> | 231 | </tr> |
| 232 | |||
| 114 | </body> | 233 | </body> |
| 115 | </table> | 234 | </table> |
| 116 | </div> | 235 | </div> |
| 117 | </div> | 236 | </div> |
| 118 | </div> | 237 | </div> |
| 119 | 238 |