PageSourceSearch

https://borm.es/scripts/suscripcion/controllers/suscripcionController.js

js borm.es collected 2026-10-02 05:24:16 UTC 10,288 bytes, 296 lines download raw bytes

1'use strict';
2
3angular.module("BormApp.SuscripcionModule", [
4	'oc.lazyLoad',
5	'ui.router',
6	'ui.bootstrap'
7	])
8	.controller('suscripcionController', ['$rootScope', '$scope', '$location', '$anchorScroll', 'AlertsService', 'SuscripcionService', 
9		'SuscripcionFactory', 'BuscadorFactory','PasswordService',
10		function($rootScope, $scope, $location, $anchorScroll, AlertsService, SuscripcionService, SuscripcionFactory, BuscadorFactory, PasswordService) {
11
12		$scope.suscripcionA = {
13			cadena: '',
14			apartado: [],
15			categoria: '',
16			subcategoria: [],
17			anunciante: []
18		}
19		
20		$scope.suscripciones = {};
21		$scope.modificar = true;
22		var idSuscModficada = 0;
23		
24		if(!$rootScope.authenticated){
25			$location.path("/home/suscripcion");
26		}
27		else{
28			// Carga inicial
29			SuscripcionFactory.findApartados()
30				.then(function(response){
31					$scope.apartados = response.data;
32				}, function myError(response) {
33					AlertsService.addDangerAlert(response.data);
34			    });
35			
36			SuscripcionFactory.findCategoriasPadre()
37				.then(function(response){
38					$scope.categorias = response.data;
39				}, function myError(response) {
40					AlertsService.addDangerAlert(response.data);
41			    });
42			
43			SuscripcionFactory.findAnunciantesSuscripcion()
44				.then(function(response){
45					$scope.anunciantes = response.data;
46				}, function myError(response) {
47					AlertsService.addDangerAlert(response.data);
48			    });
49			
50			cargarSuscripciones();
51			
52			if($rootScope.suscripcionAyuntamientoPendiente != undefined){
53				suscribirAyuntamientoPendiente($rootScope.suscripcionAyuntamientoPendiente);
54				$rootScope.suscripcionAyuntamientoPendiente = undefined;
55			}
56			if($rootScope.suscripcionBusquedaPendiente != undefined){
57				guardarBusquedaPendiente($rootScope.suscripcionBusquedaPendiente);
58				$rootScope.suscripcionBusquedaPendiente = undefined;
59			}
60		}
61		
62		$scope.logout = function(){
63			SuscripcionService.logout()
64				.finally(function(){
65					$rootScope.authenticated = false;
66					$rootScope.usuarioAutenticado = undefined;
67					$location.path("/");
68				});
69		}
70		
71		$scope.eliminarCuenta = function(){
72			SuscripcionFactory.eliminarCuenta()
73				.then(function(response){
74					AlertsService.addSuccessAlert('suscripcion.alerts.success.cuentaEliminada');
75					$("#modalCuenta").modal('hide');
76					$('body').removeClass('modal-open');
77					$('.modal-backdrop').remove();
78
79					$scope.logout();
80				}, function myError(response) {
81					AlertsService.addDangerAlert(response.data);
82		    });
83		}
84		
85		$scope.suscribirseBoletin = function(){
86			SuscripcionFactory.suscribirseBoletin()
87				.then(function(response){
88					AlertsService.addSuccessAlert('suscripcion.alerts.success.suscripcionBoletin');
89					$scope.suscripciones.suscripcionBoletin = true;
90				}, function myError(response) {
91					AlertsService.addDangerAlert(response.data);
92		    });
93		}
94		
95		$scope.bajaSuscripcionBoletin = function(){
96			SuscripcionFactory.bajaSuscripcionBoletin()
97				.then(function(response){
98					AlertsService.addSuccessAlert('suscripcion.alerts.success.bajaBoletin');
99					$scope.suscripciones.suscripcionBoletin = false;
100					$("#modalElimSuscB").modal('hide');
101				}, function myError(response) {
102					AlertsService.addDangerAlert(response.data);
103		    });
104		}
105		
106		$scope.suscribirseAnuncio = function(parametrosSuscripcion){
107			SuscripcionFactory.suscribirseAnuncio(parametrosSuscripcion)
108				.then(function(response){
109					limpiar();
110					cargarSuscripciones();
111					AlertsService.addSuccessAlert('suscripcion.alerts.success.suscripcionAnuncio');
112				}, function myError(response) {
113					AlertsService.addDangerAlert(response.data);
114		    });
115		}
116		
117		function cargarSuscripciones(){
118			SuscripcionFactory.cargarSuscripciones()
119				.then(function(response){
120					$scope.suscripciones = response.data;
121				}, function myError(response) {
122					AlertsService.addDangerAlert(response.data);
123		    });
124		}
125		
126		$scope.seleccionarSuscripcion = function(idSuscripcion, index){
127			$scope.suscripcion = {id: idSuscripcion, i: index};
128		}
129		
130		$scope.eliminarSuscripcion = function(){
131			SuscripcionFactory.eliminarSuscripcionAnuncio($scope.suscripcion.id)
132				.then(function(response){
133					$scope.suscripciones.suscripcionesAnuncios.splice($scope.suscripcion.i, 1);
134					$("#modalElimSusc").modal('hide');
135					AlertsService.addSuccessAlert('suscripcion.alerts.success.elminarSuscripcionAnuncio');
136				}, function myError(response) {
137					AlertsService.addDangerAlert(response.data);
138		    });
139		}
140		
141		$scope.modificarSuscripcion = function(id){
142			idSuscModficada = id;
143			$scope.modificar = false;
144			SuscripcionFactory.recuperarSuscripcionAnuncio(id)
145				.then(function(response){
146					$scope.suscripcionA = response.data;
147					$scope.cargarSubcategorias();
148					
149					window.setTimeout(aplicarValores, 1000);
150					
151				}, function myError(response) {
152					AlertsService.addDangerAlert(response.data);
153		    });
154		}
155		
156		$scope.actualizarSuscripcion = function(){
157			$scope.modificar = true;
158			SuscripcionFactory.actualizarSuscripcionAnuncio(idSuscModficada, $scope.suscripcionA)
159				.then(function(response){
160					limpiar();
161					cargarSuscripciones();
162					$scope.refrescarSelect();
163					AlertsService.addSuccessAlert('suscripcion.alerts.success.modificarSuscripcion');
164				}, function myError(response) {
165					AlertsService.addDangerAlert(response.data);
166		    });
167		}
168		
169		function aplicarValores(){
170			$('#apartado').val($scope.suscripcionA.apartado);
171			$('#subcategoria').val($scope.suscripcionA.subcategoria);
172			$('#anunciante').val($scope.suscripcionA.anunciante);
173			
174			$scope.refrescarSelect();
175			
176			$location.hash('menu2');
177		    $anchorScroll();
178		}
179		
180		
181		// Según categoría seleccionada
182		$scope.cargarSubcategorias = function(){
183			var idCategoriaPadre = $scope.suscripcionA.categoria;
184			SuscripcionFactory.findCategoriasHijasByPadre(idCategoriaPadre)
185				.then(function(response){
186					$scope.subcategorias = response.data;
187					if($scope.subcategorias.length == 0) $scope.suscripcionA.subcategoria = [];
188					window.setTimeout($scope.refrescarSelect, 200);
189				}, function myError(response) {
190					AlertsService.addDangerAlert(response.data);
191		    });
192		}
193		
194		// Modificar datos del usuario
195		$scope.modificarPerfil = function(datosModificados){
196			let correoTratar = datosModificados.email || $rootScope.usuarioAutenticado.username;
197			let errores = PasswordService.validarClave(datosModificados.clave, correoTratar);
198			if(datosModificados.claveActual == ''){
199				AlertsService.addWarningAlert('suscripcion.alerts.warning.faltaClave');
200			} else if(datosModificados.clave !== datosModificados.clave2){
201				AlertsService.addDangerAlert('suscripcion.alerts.danger.confirmarClave');
202			} else if(errores){
203				AlertsService.addDangerAlert(errores);
204			}
205			else{
206				SuscripcionFactory.modificarDatos(datosModificados)
207					.then(function(response){
208						AlertsService.addSuccessAlert('suscripcion.alerts.success.modificacionPerfilCorrecta');
209						if(datosModificados.email != '') $rootScope.usuarioAutenticado.username = datosModificados.email;
210						$("#modficarPerfilForm")[0].reset();
211					}, function myError(response) {
212						AlertsService.addDangerAlert('suscripcion.alerts.danger.modificacionPerfilIncorrecta');
213			    });
214			}
215		}
216		
217		function suscribirAyuntamientoPendiente(idAyuntamiento){
218			SuscripcionFactory.suscribirseAnunciante(idAyuntamiento)
219				.then(function(response){
220					cargarSuscripciones();
221					AlertsService.addSuccessAlert('suscripcion.alerts.success.suscripcionAnuncio');
222				}, function myError(response) {
223					AlertsService.addDangerAlert(response.data);
224				});
225		}
226		
227		function guardarBusquedaPendiente(parametrosBusqueda){
228			BuscadorFactory.guardarBusqueda(parametrosBusqueda)
229				.then(function(response){
230					cargarSuscripciones();
231					AlertsService.addSuccessAlert('suscripcion.alerts.success.suscripcionAnuncio');
232				}, function myError(response) {
233					AlertsService.addDangerAlert(response.data);
234				});
235		}
236		
237		$scope.seleccionarBusqueda = function(idBusqueda, index){
238			$scope.busqueda = {id: idBusqueda, i: index};
239		}
240		
241		// Elminar búsqueda
242		$scope.eliminarBusqueda = function(){
243			BuscadorFactory.eliminarBusqueda($scope.busqueda.id)
244				.then(function(response){
245					$scope.suscripciones.misBusquedas.splice($scope.busqueda.i, 1);
246					AlertsService.addSuccessAlert('suscripcion.alerts.success.elminarSuscripcionAnuncio');
247					$("#modalElimBus").modal('hide');
248				}, function myError(response) {
249					AlertsService.addDangerAlert(response.data);
250		    });
251		}
252		
253		// Lanzar búsqueda
254		$scope.lanzarBusqueda = function(busqueda){
255			$rootScope.busquedaLanzada = busqueda;
256			$location.path("/home/buscador");
257		}
258		
259		// Limpiar formulario
260		function limpiar(){
261			$scope.suscripcionA = {cadena: '', apartado: [], categoria: '',subcategoria: [], anunciante: []}
262			$("#suscripcionForm")[0].reset();
263		}
264		
265		$scope.refrescarSelect = function(){
266			$('#apartado').selectpicker({tickIcon: 'glyphicon-asterisk'});
267			$('#apartado').selectpicker('render');
268			$('#apartado').selectpicker('refresh');
269			
270			$('#anunciante').selectpicker({tickIcon: 'glyphicon-asterisk'});
271			$('#anunciante').selectpicker('render');
272			$('#anunciante').selectpicker('refresh');
273			
274			$('#subcategoria').selectpicker({tickIcon: 'glyphicon-asterisk'});
275			$('#subcategoria').selectpicker('render');
276			$('#subcategoria').selectpicker('refresh');
277		}
278		
279		function refrescarSelect2(){
280			$('#apartado').selectpicker('refresh');
281			$('#anunciante').selectpicker('refresh');
282			$('#subcategoria').selectpicker('refresh');
283		}
284
285			$scope.isPasswordVisi = {};
286			//Visibilidad de las contraseñas
287			$scope.passwordVisibilidad = function (campo){
288				if(!$scope.isPasswordVisi[campo]){
289					$scope.isPasswordVisi[campo] = false;
290				}
291				$scope.isPasswordVisi[campo] = !$scope.isPasswordVisi[campo];
292				let input= document.getElementById(campo);
293				input.type = $scope.isPasswordVisi[campo] ? 'text' : 'password';
294			}
295		
296	} ]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.