PageSourceSearch

https://acquedottolucano.it/static/js/filtri-controller.js

js acquedottolucano.it collected 2026-10-07 23:06:25 UTC 19,493 bytes, 585 lines download raw bytes

1	app.controller('FiltriController', [ '$scope', 'FiltriService', 'GeneralService', 'RicercaService', '$location', '$anchorScroll', '$sce', '$timeout', '$q',
2		function($scope, FiltriService, GeneralService, RicercaService, $location, $anchorScroll, $sce, $timeout, $q){
3		$scope.contents = [];
4		$scope.renderContent = [];
5		$scope.renderContentSecondModel = [];
6		$scope.calendar = [];
7		$scope.secondModelId = "";
8		$scope.filters = "";
9		$scope.events = [];
10		$scope.renderEventContent = [];
11		$scope.categoryContent = [];
12		$scope.dayName = [];
13		$scope.loader = [];
14		$scope.full = [];
15		$scope.empty = false;
16		$scope.argomenti = [];
17		$scope.ammins_chk = [];
18		$scope.servizi_chk = [];
19		$scope.novita_chk = [];
20		$scope.docs_chk = [];
21		$scope.ammins_selected = [];
22		$scope.servizi_selected = [];
23		$scope.novita_selected = [];
24		$scope.docs_selected = [];
25		$scope.args_selected = [];
26		$scope.categoriaTab = "active";
27		$scope.argomentoTab = "";
28		$scope.opzioniTab = "";
29		$scope.active_chk = null;
30		$scope.data_inizio = null;
31		$scope.data_fine = null;
32		$scope.categorie = [];
33		$scope.cercatxt = "";
34		
35		$scope.General = GeneralService;
36		
37		const monthNames = ["Gennaio", "Febbraio", "Marzo", "Aprile", "Maggio", "Giugno", "Luglio", "Agosto", "Settembre", "Ottobre", "Novembre", "Dicembre"];
38		
39		var searchList = [{contentName: "Pagamento della TARI", category: "Pagamenti"},
40            {contentName: "Pagamento tassa di circolazione", category: "Pagamenti"},
41            {contentName: "Modulo pagamento tasse universitarie", category: "Modulistica"},
42            {contentName: "Pagamento tributi a Pirri", category: "Pagamenti"},
43            {contentName: "Concorso ragioniere - Ufficio pagamenti", category: "Concorsi"},
44            {contentName: "Modulistica pagamento TARSU", category: "Modulistica"}];
45			
46		$scope.setParameters = function (pageSize, maxElem, contentType, modelId, categoryCode, elemId, secondModelId, filters, contents) {
47			$scope.pageSize = parseInt(pageSize);
48			if (categoryCode != "")
49				$scope.categorie = categoryCode;
50			if (maxElem != "")
51				$scope.maxElements =  parseInt(maxElem);
52			if (filters != "")
53				$scope.filters = filters;
54			if (secondModelId != undefined)
55				$scope.secondModelId = secondModelId;
56			if (contents) {
57				$scope.setContents(contents);
58			} else
59				$scope.getContents(contentType, modelId, categoryCode, elemId);
60		}
61		
62		$scope.setCalendarParameters = function (day, finemese, nextMonth) {
63			$scope.oneMonth = true;
64			$scope.day = day;
65			$scope.finemese = finemese;
66			$scope.days = finemese - day;
67			for (i = 0; i <= $scope.days; i++) { 
68				$scope.calendar[i] = i+parseInt($scope.day);
69				$scope.full[$scope.calendar[i]] = true;
70			}
71			if ($scope.days <= 9) {
72				$scope.oneMonth = false;
73				var d = new Date();
74				$scope.nextMonth = monthNames[d.getMonth()+1];
75				$scope.daysOld = angular.copy($scope.days)+1;
76				$scope.day = 1;
77				$scope.finemese = 10 - $scope.days;
78				$scope.days = $scope.finemese - $scope.day;
79				for (i = 0; i <= $scope.days; i++) { 
80					$scope.calendar[i+$scope.daysOld] = i+parseInt($scope.day);
81					$scope.full[$scope.calendar[i+$scope.daysOld]] = true;
82				}
83			}
84		}
85		
86		$scope.getContents = function (contentType, modelId, categoryCode, elemId, filters, date) {
87			$scope.countEmpty = 0;
88			if (filters != undefined)
89				$scope.filters = filters;
90			if ($scope.searchParameters) {
91				for(var i in $scope.searchParameters){
92					if ($scope.searchParameters[i] != null) {
93						if (i.indexOf("dat")>=0) {
94							if($scope.filters == "")
95								$scope.filters += '(attributeFilter=true;key=' + i +';value='+ $scope.searchParameters[i].start +';end=' + $scope.searchParameters[i].end + ';)';
96							else
97								$scope.filters += '+(attributeFilter=true;key=' + i +';start='+ $scope.searchParameters[i].start +';end=' + $scope.searchParameters[i].end + ';)';
98						} else {
99							if($scope.filters == "")
100								$scope.filters += '(attributeFilter=true;key=' + i +';value='+ $scope.searchParameters[i] +';likeOption=true;)';
101							else
102								$scope.filters += '+(attributeFilter=true;
102key=' + i +';value='+ $scope.searchParameters[i] +';likeOption=true;)';
103						}
104					}
105				}
106			}
107			$scope.currentPage = 0;
108			$scope.pages = [];
109			if (elemId) {
110				setActive(elemId, $scope.oldElem);
111				$scope.oldElem = elemId;
112			}
113			FiltriService.getContents(contentType, categoryCode, $scope.filters, date).then(
114				function(response) {
115					$scope.events[date]=[];
116					if(response == undefined){
117						$scope.full[date] = false;
118						$scope.countEmpty = $scope.countEmpty + 1;
119					}
120					if (response != undefined) {
121						$scope.loader[date]= true;
122						if (!Array.isArray(response)) {
123							if (response.$){
124								$scope.contents = [];
125								$scope.contents[0] = response;
126								$scope.events[date].push(response);
127							}
128						} else {
129							if ($scope.maxElements >= response.length){
130								$scope.contents = response;
131								$scope.events[date] = response;
132							} else {
133								for (i = 0; i < $scope.maxElements; i++) {
134									$scope.contents[i] = response[i];
135									$scope.events[date] = response[i];
136								}
137							}
138						}
139						$scope.numberOfPages = Math.ceil($scope.contents.length/$scope.pageSize);
140						for (i = 0; i < $scope.numberOfPages; i++) { 
141							$scope.pages[i] = i+1;
142						}
143						for(var i in $scope.contents){
144							FiltriService.getContent($scope.contents[i].$, modelId, i).then(
145								function(response) {
146									$scope.renderContent[response.item.id] = $sce.trustAsHtml(renderContent(response.html));
147								}, function(errResponse) {
148									console.error("Errore durante il caricamento del contenuto");
149							});
150						}
151						if ($scope.secondModelId != ""){
152							for(var i in $scope.contents){
153								FiltriService.getContent($scope.contents[i].$, $scope.secondModelId).then(
154									function(response) {
155										$scope.renderContentSecondModel[response.item.id] = $sce.trustAsHtml(renderContent(response.html));
156									}, function(errResponse) {
157										console.error("Errore durante il caricamento del contenuto");
158								});
159							}
160						}
161						if (date != undefined) {
162							$scope.renderEventContent[date] = [];
163							$scope.categoryContent[date] = [];
164							for(var i in $scope.events[date]){
165								FiltriService.getContent($scope.events[date][i].$, modelId).then(
166									function(response) {
167										$scope.renderEventContent[date][response.item.id] = $sce.trustAsHtml(response.html);
168										$scope.loader[date]= false;
169										$scope.categoryContent[date][response.item.id] = "";
170										for(var i in response.item.categories.category){
171											if(response.item.categories.category[i] != undefined)
172												$scope.categoryContent[date][response.item.id] += response.item.categories.category[i];
173										}
174									}, function(errResponse) {
175										$scope.loader[date]= false;
176										console.error("Errore durante il caricamento del contenuto");
177								});
178							}
179						}
180					} else {
181						$scope.contents = [];
182					}
183					if ($scope.countEmpty != $scope.calendar.length && contentType == 'EVN')
184						$timeout(owlInit, 1000);
185					else {
186						$scope.empty = true;
187					}
188				}, function(errResponse) {
189					$scope.contents = [];
190					$scope.loader[date]= false;
191				});
192		}
193		
194		$scope.getContent = function (i, modelId) {
195			FiltriService.getContent($scope.contents[i].$, modelId).then(
196				function(response) {
197					$scope.renderContentSecondModel[response.item.id] = $sce.trustAsHtml(renderContent(response.html));
198				}, function(errResponse) {
199					console.error("Errore durante il caricamento del contenuto");
200			});
201		}
202		
203		function renderContent(htmlElement){
204			var userAgent, ieReg, ie;
205			userAgent = window.navigator.userAgent;
206			ieReg = /msie|Trident.*rv[ :]*11\./gi;
207			ie = ieReg.test(userAgent);			
208			if (ie) {
209				var htmlObject = $(htmlElement);
210				var imgUrl = htmlObject.find('img').prop('src');
211				if (imgUrl)
212					htmlObject.find( ".img-fit-cover" ).css('backgroundImage', 'url(' + imgUrl + ')').addClass('img-fit-ie');
213				return htmlObject.prop('outerHTML');
214			} else
215				return htmlElement;
216		}
217		
218		function setActive(element, oldElement) {
219			if(oldElement) {
220				var oldElem = document.getElementById(oldElement);
221				$(oldElem).removeClass("active");
222			}
223			if (element != "") {
224				var elem = document.getElementById(element);
225				$(elem).addClass("active");
226			}
227		}
228		
229		$scope.goToPage = function (page) {
230			$scope.currentPage = page;
231		}
232		
233		$scope.goToFirstPage = function () {
234			$scope.currentPage = 0;
235		}
236		
237		$scope.refreshPage = function () {
238			$scope.currentPage = 1;
239			$timeout($scope.goToFirstPage, 1000);
240		}
241		
242		$scope.getFilterDay = function (day, month, year) {
243			var monthInt = parseInt(month)-1;
244			var date = new Date(year,monthInt,day);
245			$scope.dayName[day] = date.toLocaleString(undefined, {weekday: 'short'});
246			return "(attributeFilter=true;key=data_iniz;start="+ day +"/"+ month +"/"+ year+";end="+ day +"/"+ month +"/"+ year+")"
247		}
248		
249		$scope.setContents = function (contents) {
250			$scope.contents = contents.replace(/=/g, '":"');
251			$scope.contents = $scope.contents.replace(/}/g, '"}');
252			$scope.contents = $scope.contents.replace(/contentId/g, '"contentId').replace(/modelId/g, '"modelId');
253			$scope.contents = $scope.contents.replace(/, "/g, '", "');
254			$scope.contents = JSON.parse($scope.contents);
255			if ($scope.pageSize != 0)
256				$scope.numberOfPages = Math.ceil($scope.contents.length/$scope.pageSize);
257			else
258				$scope.numberOfPages = 1;
259			$scope.pages = [];
260			$scope.currentPage = 0;
261			for (i = 0; i < $scope.numberOfPages; i++) { 
262				$scope.pages[i] = i+1;
263			}
264			for(var i in $scope.contents){
265				FiltriService.getContent($scope.contents[i].contentId, $scope.contents[i].modelId).then(
266					function(response) {
267						$scope.renderContent[response.item.id] = $sce.trustAsHtml(response.html);
268					}, function(errResponse) {
269						console.error("Errore durante il caricamento del contenuto");
270				});
271			}
272		}
273		
274		function owlInit(){
275			var owl = $('#owl-calendario');
276			owl.owlCarousel({
277				nav:false,
278				startPosition: 0,
279				autoPlay:false,
280				responsiveClass:true,
281				responsive:{
282						0:{
283							items:1,
284						},
285						576: {
286							items:2,
287						},
288						768: {
289							items:3,
290						},
291						991: {
292							items:4,
293						},
294					}
295			});
296		}
297		
298		$scope.setArgomenti = function (argomento, codice) {
299			if (argomento != 'Argomenti')
300				$scope.argomenti.push({name:argomento.replace("%", "'"),code:codice});
301		}
302
303        $scope.setCategorie = function (categoria, padre) {
304            switch (padre) {
305                case 'Amministrazione':
306                    ammins_chk.push(categoria);
307                    break;
308                case 'Novità':
309                    novita_chk.push(categoria);
310                    break;
311                case 'Servizi':
312                    servizi_chk.push(categoria);
313                    break;
314                case 'Documenti e dati':
315                    docs_chk.push(categoria);
316                    break;
317            }
318        }
319		
320		$scope.getArgomentiList = function () {
321			var argomenti = "";
322			if ($scope.categorie)
323				argomenti = $scope.categorie;
324			for(var i in $scope.args_selected){
325				if (argomenti == '')
326					argomenti += $scope.args_selected[i].code + "";
327				else
328					argomenti += ',' + $scope.args_selected[i].code;
329			}
330			for(var i in $scope.ammins_selected){
331				if (argomenti == '')
332					argomenti += $scope.ammins_selected[i].code + "";
333				else
334					argomenti += ',' + $scope.ammins_selected[i].code;
335			}
336			for(var i in $scope.servizi_selected){
337				if (argomenti == '')
338					argomenti += $scope.servizi_selected[i].code + "";
339				else
340					argomenti += ',' + $scope.servizi_selected[i].code;
341			}
342			for(var i in $scope.novita_selected){
343				if (argomenti == '')
344					argomenti += $scope.novita_selected[i].code + "";
345				else
346					argomenti += ',' + $scope.novita_selected[i].code;
347			}
348			for(var i in $scope.docs_selected){
349				if (argomenti == '')
350					argomenti += $scope.docs_selected[i].code + "";
351				else
352					argomenti += ',' + $scope.docs_selected[i].code;
353			}
354			return argomenti;
355		}
356		
357		$scope.cleanSearchParameter = function(key) {
358			if (key == 'all')
359				$scope.searchParameters = {};
360			else
361				delete $scope.searchParameters[key];
362		}
363		
364		$scope.toggle = function(item, list) {
365			var idx = list.indexOf(item);
366			if (idx > -1) {
367				list.splice(idx, 1);
368				setActive('', item.code);
369			}
370			else {
371				list.push(item);
372				setActive(item.code);
373			}
374		};
375
376		$scope.exists = function(item, list) {
377			return list.indexOf(item) > -1;
378		};
379
380		$scope.ammins_isIndeterminate = function() {
381			return ($scope.ammins_selected.length !== 0 && $scope.ammins_selected.length !== $scope.ammins_chk.length);
382		};
383
384		$scope.ammins_isChecked = function() {
385			return $scope.ammins_selected.length === $scope.ammins_chk.length;
386		};
387
388		$scope.ammins_toggleAll = function() {
389			if ($scope.ammins_selected.length === $scope.ammins_chk.length) {
390				$scope.ammins_selected = [];
391			} else if ($scope.ammins_selected.length === 0 || $scope.ammins_selected.length > 0) {
392				$scope.ammins_selected = $scope.ammins_chk.slice(0);
393			}
394		};
395
396		$scope.servizi_isIndeterminate = function() {
397			return ($scope.servizi_selected.length !== 0 && $scope.servizi_selected.length !== $scope.servizi_chk.length);
398		};
399
400		$scope.servizi_isChecked = function() {
401			return $scope.servizi_selected.length === $scope.servizi_chk.length;
402		};
403
404		$scope.servizi_toggleAll = function() {
405			if ($scope.servizi_selected.length === $scope.servizi_chk.length) {
406				$scope.servizi_selected = [];
407			} else if ($scope.servizi_selected.length === 0 || $scope.servizi_selected.length > 0) {
408				$scope.servizi_selected = $scope.servizi_chk.slice(0);
409			}
410		};
411
412		$scope.novita_isIndeterminate = function() {
413			return ($scope.novita_selected.length !== 0 && $scope.novita_selected.length !== $scope.novita_chk.length);
414		};
415
416		$scope.novita_isChecked = function() {
417			return $scope.novita_selected.length === $scope.novita_chk.length;
418		};
419
420		$scope.novita_toggleAll = function() {
421			if ($scope.novita_selected.length === $scope.novita_chk.length) {
422				$scope.novita_selected = [];
423			} else if ($scope.novita_selected.length === 0 || $scope.novita_selected.length > 0) {
424				$scope.novita_selected = $scope.novita_chk.slice(0);
425			}
426		};
427
428		$scope.docs_isIndeterminate = function() {
429			return ($scope.docs_selected.length !== 0 && $scope.docs_selected.length !== $scope.docs_chk.length);
430		};
431
432		$scope.docs_isChecked = function() {
433			return $scope.docs_selected.length === $scope.docs_chk.length;
434		};
435
436		$scope.docs_toggleAll = function() {
437			if ($scope.docs_selected.length === $scope.docs_chk.length) {
438				$scope.docs_selected = [];
439			} else if ($scope.docs_selected.length === 0 || $scope.docs_selected.length > 0) {
440				$scope.docs_selected = $scope.docs_chk.slice(0);
441			}
442		};
443
444		$scope.toggleAll = function(filterType) {
445			if(filterType == 'categorie') {
446				$scope.ammins_selected = [];
447				$scope.servizi_selected = [];
448				$scope.novita_selected = [];
449				$scope.docs_selected = [];
450			}
451			if(filterType =='argomenti') {
452				$scope.args_selected = [];
453			}
454			switch(filterType) {
455			  case 'categorie':
456				$scope.ammins_selected = [];
457				$scope.servizi_selected = [];
458				$scope.novita_selected = [];
459				$scope.docs_selected = [];
460				break;
461			  case 'argomenti':
462				$scope.args_selected = [];
463				break;
464			  default:
465				$scope.ammins_selected = [];
466				$scope.servizi_selected = [];
467				$scope.novita_selected = [];
468				$scope.docs_selected = [];
469				$scope.args_selected = [];
470				$scope.active_chk = null;
471				$scope.clean_date();
472			}
473		}
474
475		$scope.class_tutti = function(mode){
476			$scope.searchParametersLength = 0;
477			if ($scope.searchParameters)
478				$scope.searchParametersLength = Object.keys($scope.searchParameters).length;
479			switch(mode) {
480			  case 'categorie':
481				if($scope.ammins_selected.length !== 0 || $scope.servizi_selected.length !== 0 || $scope.novita_selected.length !== 0 || $scope.docs_selected.length !== 0 || $scope.searchParametersLength !== 0 || $scope.searchParameters !== undefined )
482					return ""
483				else 
484					return "active";
485				break;
486			  default:
487				if($scope.ammins_selected.length !== 0 || $scope.servizi_selected.length !== 0 || $scope.novita_selected.length !== 0 || $scope.docs_selected.length !== 0 || 
488					$scope.args_selected.length !== 0 || $scope.active_chk != null || $scope.data_inizio != null || $scope.data_fine != null || $scope.searchParametersLength !== 0)
489					return ""
490				else 
491					return "active";
492				break;
493			}
494		}
495
496		$scope.class_categorie = function(selected, checked){
497			if(selected.length !== 0 &&	selected.length !== checked.length)
498				return "active"
499			else if(selected.length === checked.length)
500				return "active";
501			else
502				return "";
503		}
504
505		$scope.unchk = function(item, list) {
506			var idx = list.indexOf(item);
507			if (idx > -1) {
508				list.splice(idx, 1);
509			}
510		}
511
512		$scope.clean_date = function() {
513			$scope.data_inizio = null;
514			$scope.data_fine = null;
515		}
516		
517		$scope.setActive = function(tab) {
518			switch(tab) {
519				case 'argomenti':
520					$scope.categoriaTab = "";
521					$scope.argomentoTab = "active";
522					$scope.opzioniTab = "";
523					break;
524				case 'opzioni':
525					$scope.categoriaTab = "";
526					$scope.argomentoTab = "";
527					$scope.opzioniTab = "active";
528					break;
529				default:
530					$scope.categoriaTab = "active";
531					$scope.argomentoTab = "";
532					$scope.opzioniTab = "";
533			}
534		}
535		
536		$scope.setArgsSelected = function(argomenti) {
537			if(argomenti != "")
538				$scope.args_selected = argomenti.split(",");
539		}
540		
541		$scope.setCatSelected = function(type, categorie) {
542			if(categorie != "") {
543				switch(type) {
544					case 'amministrazione':
545						$scope.ammins_selected = categorie.split(",");
546					break;
547					case 'servizi':
548						$scope.servizi_selected = categorie.split(",");
549					break;
550					case 'novita':
551						$scope.novita_selected = categorie.split(",");
552					break;
553					case 'documenti':
554						$scope.docs_selected = categorie.split(",");
555					break;
556					default:
557				}
558			}
559				
560		}
561		
562		$scope.getRisultatiRicerca =  function(search) {
563            var deferred = $q.defer();
564            deferred.resolve(searchList);
565            return deferred.promise;
566        };
567
568        $scope.selectedRicercaTxtItemChanged = function(item) {
569            if (item !== undefined && item.contentName !== undefined) {
570                cercatxt = item.contentName;
571            }
572            // Clear fields
573            if (item === undefined) {
574                cercatxt = "";
575            }
576        }
577		
578	}]);
579
580	app.filter('startFrom', function() {
581		return function(input, start) {
582			start = +start; //parse to int
583			return input.slice(start);
584		}
585	});

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.