Commit 5046fde412e583f7c4658e045a0b4ecf7a487f17

Authored by Jose Pinto
1 parent 2f621a2c3d
Exists in master and in 1 other branch develop

texto boton salir

Showing 1 changed file with 4 additions and 4 deletions   Show diff stats
src/js/controllerCisterna.js
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .controller('focaAbmVehiculoCisternaController', [ 2 .controller('focaAbmVehiculoCisternaController', [
3 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 3 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window',
5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
6 focaModalService, focaBotoneraLateralService, $timeout, $window) { 6 focaModalService, focaBotoneraLateralService, $timeout, $window) {
7 $scope.nuevo = ($routeParams.idx > -1) ? false : true; 7 $scope.nuevo = ($routeParams.idx > -1) ? false : true;
8 $scope.editar = false; 8 $scope.editar = false;
9 $scope.now = new Date(); 9 $scope.now = new Date();
10 $scope.cisterna = { 10 $scope.cisterna = {
11 codigo: '', 11 codigo: '',
12 capacidad: '', 12 capacidad: '',
13 unidadMedida: {} 13 unidadMedida: {}
14 }; 14 };
15 15
16 $scope.focused = $scope.nuevo ? 1 : 2; 16 $scope.focused = $scope.nuevo ? 1 : 2;
17 $scope.next = function(key) { 17 $scope.next = function(key) {
18 if (key === 13) $scope.focused++; 18 if (key === 13) $scope.focused++;
19 }; 19 };
20 $scope.capacidadVechiulo = 0; 20 $scope.capacidadVechiulo = 0;
21 $scope.transportista = ''; 21 $scope.transportista = '';
22 22
23 //SETEO BOTONERA LATERAL 23 //SETEO BOTONERA LATERAL
24 $timeout(function() { 24 $timeout(function() {
25 focaBotoneraLateralService.showSalir(false); 25 focaBotoneraLateralService.showSalir(false);
26 focaBotoneraLateralService.showPausar(true); 26 focaBotoneraLateralService.showPausar(true);
27 focaBotoneraLateralService.showCancelar(false); 27 focaBotoneraLateralService.showCancelar(false);
28 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 28 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
29 focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); 29 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
30 }); 30 });
31 31
32 if ($routeParams.idx !== -1) { 32 if ($routeParams.idx !== -1) {
33 $scope.cisterna = [$routeParams.idx]; 33 $scope.cisterna = [$routeParams.idx];
34 focaAbmVehiculoService 34 focaAbmVehiculoService
35 .getCisternas($routeParams.idVehiculo) 35 .getCisternas($routeParams.idVehiculo)
36 .then(function(res) { 36 .then(function(res) {
37 $scope.cisterna = res[$routeParams.idx]; 37 $scope.cisterna = res[$routeParams.idx];
38 }); 38 });
39 } 39 }
40 40
41 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 41 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
42 var codigo = ('00000' + res.data.transportista.COD).slice(-5); 42 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
43 $scope.transportista = res.data.transportista.COD; 43 $scope.transportista = res.data.transportista.COD;
44 $scope.capacidadVechiulo = res.data.capacidad; 44 $scope.capacidadVechiulo = res.data.capacidad;
45 $scope.$broadcast('addCabecera', { 45 $scope.$broadcast('addCabecera', {
46 label: 'Transportista:', 46 label: 'Transportista:',
47 valor: codigo + ' - ' + res.data.transportista.NOM 47 valor: codigo + ' - ' + res.data.transportista.NOM
48 }); 48 });
49 $scope.$broadcast('addCabecera', { 49 $scope.$broadcast('addCabecera', {
50 label: 'Unidad:', 50 label: 'Unidad:',
51 valor: res.data.codigo 51 valor: res.data.codigo
52 }); 52 });
53 $scope.$broadcast('addCabecera', { 53 $scope.$broadcast('addCabecera', {
54 label: 'Capacidad total vehículo:', 54 label: 'Capacidad total vehículo:',
55 valor: res.data.capacidad 55 valor: res.data.capacidad
56 }); 56 });
57 }); 57 });
58 58
59 $scope.cancelar = function() { 59 $scope.salir = function() {
60 60
61 if (!$scope.formCisterna.$pristine) { 61 if (!$scope.formCisterna.$pristine) {
62 focaModalService.confirm( 62 focaModalService.confirm(
63 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 63 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
64 ).then(function(data) { 64 ).then(function(data) {
65 if (data) { 65 if (data) {
66 $location.path('/vehiculo'); 66 $window.history.back();
67 } 67 }
68 }); 68 });
69 } else { 69 } else {
70 $window.history.back(); 70 $window.history.back();
71 } 71 }
72 }; 72 };
73 73
74 $scope.guardar = function() { 74 $scope.guardar = function() {
75 75
76 if ($scope.formCisterna.$pristine) { 76 if ($scope.formCisterna.$pristine) {
77 $scope.cancelar(); 77 $scope.salir();
78 return; 78 return;
79 } else if (!$scope.cisterna.codigo) { 79 } else if (!$scope.cisterna.codigo) {
80 focaModalService.alert('Ingrese codigo de cisterna'); 80 focaModalService.alert('Ingrese codigo de cisterna');
81 return; 81 return;
82 } else if (!$scope.cisterna.capacidad) { 82 } else if (!$scope.cisterna.capacidad) {
83 focaModalService.alert('Ingrese capacidad'); 83 focaModalService.alert('Ingrese capacidad');
84 return; 84 return;
85 } else if (!$scope.cisterna.idUnidadMedida) { 85 } else if (!$scope.cisterna.idUnidadMedida) {
86 focaModalService.alert('Ingrese unidad de medida'); 86 focaModalService.alert('Ingrese unidad de medida');
87 return; 87 return;
88 } 88 }
89 89
90 validaCodigo() 90 validaCodigo()
91 .then(function() { 91 .then(function() {
92 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); 92 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo);
93 delete $scope.cisterna.vehiculo; 93 delete $scope.cisterna.vehiculo;
94 94
95 focaAbmVehiculoService 95 focaAbmVehiculoService
96 .guardarCisterna($scope.cisterna, $routeParams.idx); 96 .guardarCisterna($scope.cisterna, $routeParams.idx);
97 97
98 $timeout(function() { 98 $timeout(function() {
99 $location.path('/vehiculo/' + $routeParams.idVehiculo + 99 $location.path('/vehiculo/' + $routeParams.idVehiculo +
100 '/' + $scope.transportista); 100 '/' + $scope.transportista);
101 }, 0); 101 }, 0);
102 }, function(err) { 102 }, function(err) {
103 focaModalService.alert(err); 103 focaModalService.alert(err);
104 }); 104 });
105 105
106 }; 106 };
107 107
108 $scope.seleccionarUnidadMedida = function() { 108 $scope.seleccionarUnidadMedida = function() {
109 var modalInstance = $uibModal.open( 109 var modalInstance = $uibModal.open(
110 { 110 {
111 ariaLabelledBy: 'Busqueda de Unidades de medida', 111 ariaLabelledBy: 'Busqueda de Unidades de medida',
112 templateUrl: 'modal-unidad-medida.html', 112 templateUrl: 'modal-unidad-medida.html',
113 controller: 'focaModalUnidadMedidaCtrl', 113 controller: 'focaModalUnidadMedidaCtrl',
114 size: 'lg' 114 size: 'lg'
115 } 115 }
116 ); 116 );
117 modalInstance.result.then(function(unidaMedida) { 117 modalInstance.result.then(function(unidaMedida) {
118 $scope.cisterna.idUnidadMedida = unidaMedida.ID; 118 $scope.cisterna.idUnidadMedida = unidaMedida.ID;
119 $scope.cisterna.unidadMedida = unidaMedida; 119 $scope.cisterna.unidadMedida = unidaMedida;
120 }); 120 });
121 }; 121 };
122 122
123 function validaCodigo() { 123 function validaCodigo() {
124 return new Promise(function(resolve, reject) { 124 return new Promise(function(resolve, reject) {
125 focaAbmVehiculoService 125 focaAbmVehiculoService
126 .getCisternas($routeParams.idVehiculo) 126 .getCisternas($routeParams.idVehiculo)
127 .then(function(res) { 127 .then(function(res) {
128 var cisternas = res; 128 var cisternas = res;
129 var totalCargado = 0; 129 var totalCargado = 0;
130 cisternas.forEach(function(cisterna, idx) { 130 cisternas.forEach(function(cisterna, idx) {
131 //SI EL CODIGO YA EXISTE 131 //SI EL CODIGO YA EXISTE
132 if (cisterna.codigo === $scope.cisterna.codigo && 132 if (cisterna.codigo === $scope.cisterna.codigo &&
133 idx != $routeParams.idx && 133 idx != $routeParams.idx &&
134 !cisterna.desactivado) { 134 !cisterna.desactivado) {
135 reject('Código de cisterna existente'); 135 reject('Código de cisterna existente');
136 } 136 }
137 if (idx !== $routeParams.idx && 137 if (idx !== $routeParams.idx &&
138 !cisterna.desactivado) { 138 !cisterna.desactivado) {
139 totalCargado += cisterna.capacidad; 139 totalCargado += cisterna.capacidad;
140 } 140 }
141 }); 141 });
142 resolve(); 142 resolve();
143 }); 143 });
144 }); 144 });
145 } 145 }
146 } 146 }
147 ]); 147 ]);
148 148