diff --git a/index.html b/index.html index eb4dd2d..fe87cf8 100644 --- a/index.html +++ b/index.html @@ -14,6 +14,8 @@ + + diff --git a/package.json b/package.json index 53e4ec1..e9584b6 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "angular": "^1.7.5", "angular-route": "^1.7.5", "bootstrap": "^4.1.3", + "foca-directivas": "git+http://git.focasoftware.com/npm/foca-directivas.git", "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", "font-awesome": "^4.7.0", "gulp": "^3.9.1", diff --git a/src/js/controller.js b/src/js/controller.js index c8236de..d9380b9 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -1,18 +1,15 @@ angular.module('focaAbmChofer') .controller('focaAbmChoferesController', [ - '$scope', 'focaAbmChoferService', '$location', + '$scope', 'focaAbmChoferService', '$location', '$uibModal', 'focaModalService', 'focaBotoneraLateralService', '$timeout', - function($scope, focaAbmChoferService, $location, focaModalService, + function($scope, focaAbmChoferService, $location, $uibModal, focaModalService, focaBotoneraLateralService, $timeout) { + $scope.now = new Date(); $scope.filters = ''; $scope.choferes = []; - $scope.choferesFiltrados = []; - - focaAbmChoferService.getChoferes().then(function(datos) { - $scope.choferes = datos.data; - $scope.choferesFiltrados = $scope.choferes; - }); + $scope.botonera = ['Transportista']; + $scope.focused = 1; //SETEO BOTONERA LATERAL $timeout(function() { @@ -22,8 +19,12 @@ angular.module('focaAbmChofer') focaBotoneraLateralService.showGuardar(false); }); + if(focaAbmChoferService.transportistaSeleccionado.COD) { + elegirTransportista(focaAbmChoferService.transportistaSeleccionado); + } + $scope.editar = function(id) { - $location.path('/chofer/' + id); + $location.path('/chofer/' + id + '/' + $scope.idTransportista); }; $scope.solicitarConfirmacion = function(chofer) { @@ -35,8 +36,46 @@ angular.module('focaAbmChofer') } }); }; - + $scope.seleccionarTransportista = function() { + var modalInstance = $uibModal.open( + { + ariaLabelledBy: 'Busqueda de Transportista', + templateUrl: 'modal-proveedor.html', + controller: 'focaModalProveedorCtrl', + size: 'lg', + resolve: { + transportista: function() { + return true; + } + } + } + ); + modalInstance.result.then( + function(transportista) { + elegirTransportista(transportista); + focaAbmChoferService.transportistaSeleccionado = transportista; + }, function() {} + ); + }; + + function elegirTransportista(transportista) { + buscar(transportista.COD); + var codigo = ('00000' + transportista.COD).slice(-5); + $scope.idTransportista = transportista.COD; + $timeout(function() { + $scope.$broadcast('addCabecera', { + label: 'Transportista:', + valor: codigo + ' - ' + transportista.NOM + }); + }); + } + + function buscar(id) { + focaAbmChoferService.getChoferPorTransportista(id).then(function(res) { + $scope.choferes = res.data; + }); + } } ]) .controller('focaAbmChoferController', [ @@ -44,9 +83,13 @@ angular.module('focaAbmChofer') '$location', 'focaBotoneraLateralService', '$timeout', function($scope, focaAbmChoferService, $routeParams, $location, focaBotoneraLateralService, $timeout) { - + $scope.nuevo = $routeParams.id === '0'; $scope.chofer = {}; $scope.transportistas = []; + $scope.now = new Date(); + $scope.next = function(key) { + if (key === 13) $scope.focused++; + }; //SETEO BOTONERA LATERAL $timeout(function() { @@ -56,8 +99,29 @@ angular.module('focaAbmChofer') focaBotoneraLateralService.showGuardar(true, $scope.guardar); }); + if($scope.nuevo) { + focaAbmChoferService + .getTransportistaPorId($routeParams.idTransportista) + .then(function(res) { + var codigo = ('00000' + res.data.COD).slice(-5); + $scope.chofer.idTransportista = res.data.COD; + $scope.chofer.transportista = res.data; + $scope.$broadcast('addCabecera', { + label: 'Transportista:', + valor: codigo + ' - ' + res.data.NOM + }); + }); + } + focaAbmChoferService.getChofer($routeParams.id).then(function(res) { - if(res.data) $scope.chofer = res.data; + if(res.data) { + var codigo = ('00000' + res.data.transportista.COD).slice(-5); + $scope.chofer = res.data; + $scope.$broadcast('addCabecera', { + label: 'Transportista:', + valor: codigo + ' - ' + res.data.transportista.NOM + }); + } }); focaAbmChoferService.getTransportistas().then(function(res) { @@ -69,12 +133,11 @@ angular.module('focaAbmChofer') }; $scope.guardar = function() { - $scope.chofer.idTransportista = $scope.chofer.transportista.COD; + $scope.chofer.idTransportista = $routeParams.idTransportista; delete $scope.chofer.transportista; focaAbmChoferService.guardarChofer($scope.chofer).then(function() { $location.path('/chofer'); }); }; - } ]); diff --git a/src/js/route.js b/src/js/route.js index 244143a..526f243 100644 --- a/src/js/route.js +++ b/src/js/route.js @@ -11,7 +11,7 @@ angular.module('focaAbmChofer') .config([ '$routeProvider', function($routeProvider) { - $routeProvider.when('/chofer/:id', { + $routeProvider.when('/chofer/:id/:idTransportista', { controller: 'focaAbmChoferController', templateUrl: 'src/views/foca-abm-choferes-item.html' }); diff --git a/src/js/service.js b/src/js/service.js index 655c3d1..0affb73 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -7,14 +7,21 @@ angular.module('focaAbmChofer') getChofer: function(id) { return $http.get(API_ENDPOINT.URL + '/chofer/' + id); }, + getChoferPorTransportista: function(id) { + return $http.get(API_ENDPOINT.URL + '/chofer/transportista/' + id); + }, guardarChofer: function(chofer) { return $http.post(API_ENDPOINT.URL + '/chofer', {chofer: chofer}); }, getTransportistas: function() { return $http.get(API_ENDPOINT.URL + '/transportista'); }, + getTransportistaPorId: function(id) { + return $http.get(API_ENDPOINT.URL + '/transportista/' + id); + }, deleteChofer: function(id) { return $http.delete(API_ENDPOINT.URL + '/chofer/' + id); - } + }, + transportistaSeleccionado: {} }; }]); diff --git a/src/views/foca-abm-choferes-item.html b/src/views/foca-abm-choferes-item.html index 779489b..5dd7f03 100644 --- a/src/views/foca-abm-choferes-item.html +++ b/src/views/foca-abm-choferes-item.html @@ -1,49 +1,69 @@ -

Chofer

-
- -
- -
- -
-
-
- -
- +
+ +
+
+ + +
+ +
+ +
-
-
- +
+
-
- -
- +
+ +
+ +
+
+
+ +
+ +
-
- + +
diff --git a/src/views/foca-abm-choferes-listado.html b/src/views/foca-abm-choferes-listado.html index 6179c83..9a2e5b7 100644 --- a/src/views/foca-abm-choferes-listado.html +++ b/src/views/foca-abm-choferes-listado.html @@ -1,37 +1,30 @@
-
-

Choferes

-
- -
- + +
+
+
+
+
+
- +
- @@ -43,16 +36,17 @@ -
Código Nombre DNI TeléfonoTransportista -
-
-