Commit 6b95661cdd8578b31192b255b8240209c07fb890

Authored by Jose Pinto
1 parent ccf0901ea0
Exists in master

ok modal-prompt

Showing 1 changed file with 5 additions and 1 deletions   Show diff stats
src/js/controller.js
1 angular.module('focaAgendarVisita') 1 angular.module('focaAgendarVisita')
2 .controller('focaAgendarVisitaController', [ 2 .controller('focaAgendarVisitaController', [
3 '$scope', 'focaAgendarVisitaService', '$location','$localStorage', '$timeout', 3 '$scope', 'focaAgendarVisitaService', '$location','$localStorage', '$timeout',
4 '$uibModal', 'focaBotoneraLateralService', '$filter', 4 '$uibModal', 'focaBotoneraLateralService', '$filter',
5 'focaModalService', 'focaSeguimientoService', 5 'focaModalService', 'focaSeguimientoService',
6 function($scope, focaAgendarVisitaService, $location, $localStorage, $timeout, 6 function($scope, focaAgendarVisitaService, $location, $localStorage, $timeout,
7 $uibModal, focaBotoneraLateralService, $filter, 7 $uibModal, focaBotoneraLateralService, $filter,
8 focaModalService, focaSeguimientoService 8 focaModalService, focaSeguimientoService
9 ) { 9 ) {
10 10
11 config(); 11 config();
12 init(); 12 init();
13 13
14 function config() { 14 function config() {
15 $scope.focused = 0; 15 $scope.focused = 0;
16 $scope.rol = 1; 16 $scope.rol = 1;
17 $scope.visita = {}; 17 $scope.visita = {};
18 $scope.now = new Date(); 18 $scope.now = new Date();
19 } 19 }
20 20
21 function init() { 21 function init() {
22 $scope.botonera = focaAgendarVisitaService.getBotonera(); 22 $scope.botonera = focaAgendarVisitaService.getBotonera();
23 $timeout(function() { 23 $timeout(function() {
24 focaBotoneraLateralService.showSalir(false); 24 focaBotoneraLateralService.showSalir(false);
25 focaBotoneraLateralService.showPausar(true); 25 focaBotoneraLateralService.showPausar(true);
26 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 26 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
27 focaBotoneraLateralService.addCustomButton('Salir', salir); 27 focaBotoneraLateralService.addCustomButton('Salir', salir);
28 }); 28 });
29 29
30 $timeout(function() {getLSVisita();}); 30 $timeout(function() {getLSVisita();});
31 } 31 }
32 32
33 $scope.seleccionarCliente = function() { 33 $scope.seleccionarCliente = function() {
34 var modalInstance = $uibModal.open( 34 var modalInstance = $uibModal.open(
35 { 35 {
36 ariaLabelledBy: 'Busqueda de Cliente', 36 ariaLabelledBy: 'Busqueda de Cliente',
37 templateUrl: 'foca-busqueda-cliente-modal.html', 37 templateUrl: 'foca-busqueda-cliente-modal.html',
38 controller: 'focaBusquedaClienteModalController', 38 controller: 'focaBusquedaClienteModalController',
39 resolve: { 39 resolve: {
40 vendedor: function() { return null; } 40 vendedor: function() { return null; }
41 }, 41 },
42 size: 'lg' 42 size: 'lg'
43 } 43 }
44 ); 44 );
45 modalInstance.result.then( 45 modalInstance.result.then(
46 function(cliente) { 46 function(cliente) {
47 $scope.visita.cliente = cliente; 47 $scope.visita.cliente = cliente;
48 $scope.$broadcast('addCabecera', { 48 $scope.$broadcast('addCabecera', {
49 label: 'Cliente:', 49 label: 'Cliente:',
50 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' + 50 valor: $filter('rellenarDigitos')(cliente.cod, 3) + ' - ' +
51 cliente.nom 51 cliente.nom
52 }); 52 });
53 } 53 }
54 ); 54 );
55 }; 55 };
56 function setearVisita(visita){ 56 function setearVisita(visita){
57 $scope.visita = visita; 57 $scope.visita = visita;
58 $scope.$broadcast('addCabecera', { 58 $scope.$broadcast('addCabecera', {
59 label: 'Cliente:', 59 label: 'Cliente:',
60 valor: $filter('rellenarDigitos')(visita.cliente.cod, 3) + ' - ' + 60 valor: $filter('rellenarDigitos')(visita.cliente.cod, 3) + ' - ' +
61 visita.cliente.nom 61 visita.cliente.nom
62 }); 62 });
63 } 63 }
64 function getLSVisita(){ 64 function getLSVisita(){
65 var visita = JSON.parse($localStorage.visita || null); 65 var visita = JSON.parse($localStorage.visita || null);
66 if (visita) { 66 if (visita) {
67 setearVisita(visita); 67 setearVisita(visita);
68 delete $localStorage.visita; 68 delete $localStorage.visita;
69 } 69 }
70 } 70 }
71 71
72 $scope.seleccionarVisitante = function() { 72 $scope.seleccionarVisitante = function() {
73 var parametrosModal = { 73 var parametrosModal = {
74 query: '/vendedor-cobrador', 74 query: '/vendedor-cobrador',
75 columnas: [ 75 columnas: [
76 { 76 {
77 propiedad: 'NUM', 77 propiedad: 'NUM',
78 nombre: 'Codigo', 78 nombre: 'Codigo',
79 filtro: { 79 filtro: {
80 nombre: 'rellenarDigitos', 80 nombre: 'rellenarDigitos',
81 parametro: 3 81 parametro: 3
82 } 82 }
83 }, 83 },
84 { 84 {
85 propiedad: 'NOM', 85 propiedad: 'NOM',
86 nombre: 'Nombre' 86 nombre: 'Nombre'
87 } 87 }
88 ], 88 ],
89 titulo:'Búsqueda de vendedores y cobradores', 89 titulo:'Búsqueda de vendedores y cobradores',
90 size: 'md' 90 size: 'md'
91 }; 91 };
92 focaModalService.modal(parametrosModal).then(function(vendedorCobrador) { 92 focaModalService.modal(parametrosModal).then(function(vendedorCobrador) {
93 if (vendedorCobrador.rol === 3) { 93 if (vendedorCobrador.rol === 3) {
94 $uibModal.open( 94 $uibModal.open(
95 { 95 {
96 ariaLabelledBy: 'Seleccionar tipo de visita', 96 ariaLabelledBy: 'Seleccionar tipo de visita',
97 templateUrl: 'modal-tipo-visita.html', 97 templateUrl: 'modal-tipo-visita.html',
98 controller: 'focaModalTipoVisita', 98 controller: 'focaModalTipoVisita',
99 resolve: {}, 99 resolve: {},
100 size: 'md' 100 size: 'md'
101 } 101 }
102 ) 102 )
103 .result 103 .result
104 .then(function(res) { 104 .then(function(res) {
105 $scope.rol = res; 105 $scope.rol = res;
106 $scope.visita.visitante = vendedorCobrador; 106 $scope.visita.visitante = vendedorCobrador;
107 $scope.$broadcast('addCabecera', { 107 $scope.$broadcast('addCabecera', {
108 label: 'Vendedor:', 108 label: 'Vendedor:',
109 valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' + 109 valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' +
110 vendedorCobrador.NOM 110 vendedorCobrador.NOM
111 }); 111 });
112 }); 112 });
113 113
114 } else { 114 } else {
115 $scope.visita.visitante = vendedorCobrador; 115 $scope.visita.visitante = vendedorCobrador;
116 $scope.$broadcast('addCabecera', { 116 $scope.$broadcast('addCabecera', {
117 label: 'Vendedor:', 117 label: 'Vendedor:',
118 valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' + 118 valor: $filter('rellenarDigitos')(vendedorCobrador.NUM, 3) + ' - ' +
119 vendedorCobrador.NOM 119 vendedorCobrador.NOM
120 }); 120 });
121 } 121 }
122 122
123 }); 123 });
124 }; 124 };
125 $scope.seleccionarObservaciones = function() { 125 $scope.seleccionarObservaciones = function() {
126 focaModalService 126 focaModalService
127 .prompt('Ingrese observaciones', $scope.visita.observacion, true) 127 .prompt({
128 titulo: 'Ingrese observaciones',
129 value: $scope.visita.observacion,
130 textarea: true
131 })
128 .then(function(observacion) { 132 .then(function(observacion) {
129 $scope.visita.observacion = observacion; 133 $scope.visita.observacion = observacion;
130 }); 134 });
131 }; 135 };
132 136
133 $scope.next = function(key) { 137 $scope.next = function(key) {
134 if (key === 13) $scope.focused ++; 138 if (key === 13) $scope.focused ++;
135 }; 139 };
136 140
137 $scope.$watch('visita', function(newValue, oldValue){ 141 $scope.$watch('visita', function(newValue, oldValue){
138 focaBotoneraLateralService.setPausarData({ 142 focaBotoneraLateralService.setPausarData({
139 label: 'visita', 143 label: 'visita',
140 val: newValue 144 val: newValue
141 }); 145 });
142 }); 146 });
143 147
144 $scope.guardar = function() { 148 $scope.guardar = function() {
145 var rol; 149 var rol;
146 if ($scope.visita.visitante.rol === 1) { 150 if ($scope.visita.visitante.rol === 1) {
147 rol = 'Nota de pedido'; 151 rol = 'Nota de pedido';
148 } else if ($scope.visita.visitante.rol === 2) { 152 } else if ($scope.visita.visitante.rol === 2) {
149 rol = 'Cobranza'; 153 rol = 'Cobranza';
150 } else { 154 } else {
151 rol = ($scope.rol === 1) ? 'Nota de pedido' : 'Cobranza'; 155 rol = ($scope.rol === 1) ? 'Nota de pedido' : 'Cobranza';
152 } 156 }
153 157
154 focaAgendarVisitaService 158 focaAgendarVisitaService
155 .guardarVisita({ 159 .guardarVisita({
156 idVisitante: $scope.visita.visitante.NUM, 160 idVisitante: $scope.visita.visitante.NUM,
157 idCliente: $scope.visita.cliente.cod 161 idCliente: $scope.visita.cliente.cod
158 }) 162 })
159 .then(function(data) { 163 .then(function(data) {
160 focaSeguimientoService.guardarPosicion( 164 focaSeguimientoService.guardarPosicion(
161 rol, 165 rol,
162 data.data.id, 166 data.data.id,
163 $scope.visita.observacion, 167 $scope.visita.observacion,
164 data.data.id 168 data.data.id
165 ); 169 );
166 }) 170 })
167 .then(function() { 171 .then(function() {
168 $location.path('/'); 172 $location.path('/');
169 }); 173 });
170 }; 174 };
171 function salir() { 175 function salir() {
172 var confirmar = angular.equals($scope.visita, {}); 176 var confirmar = angular.equals($scope.visita, {});
173 177
174 if (!confirmar) { 178 if (!confirmar) {
175 focaModalService.confirm( 179 focaModalService.confirm(
176 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 180 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
177 ).then(function(data) { 181 ).then(function(data) {
178 if (data) $location.path('/'); 182 if (data) $location.path('/');
179 }); 183 });
180 } else { 184 } else {
181 $location.path('/'); 185 $location.path('/');
182 } 186 }
183 } 187 }
184 } 188 }
185 ]) 189 ])
186 .controller('focaModalTipoVisita', ['$uibModalInstance', '$scope', 190 .controller('focaModalTipoVisita', ['$uibModalInstance', '$scope',
187 function($uibModalInstance, $scope) { 191 function($uibModalInstance, $scope) {
188 $scope.cancel = function() { 192 $scope.cancel = function() {
189 $uibModalInstance.dismiss(); 193 $uibModalInstance.dismiss();
190 }; 194 };
191 195
192 $scope.select = function(val) { 196 $scope.select = function(val) {
193 $uibModalInstance.close(val); 197 $uibModalInstance.close(val);
194 }; 198 };
195 } 199 }
196 ]); 200 ]);
197 201