1angular.module('app.controllers') 2 3.controller('tabsController', ['$scope', '$stateParams', '$timeout', 'localStorageService', '$ionicPopup', 'FavoriCritereFactory', 'FavoriSelectionFactory', 'NotificationFactory', 'NotificationsFactory', '$ionicLoading', '$ionicModal', '$state', 'FavoriFactory', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller 4// You can include any angular dependencies as parameters for this function 5// TIP: Access Route Parameters for your page via $stateParams.parameterName 6function ($scope, $stateParams, $timeout, localStorageService, $ionicPopup, FavoriCritereFactory, FavoriSelectionFactory, NotificationFactory, NotificationsFactory, $ionicLoading, $ionicModal, $state, FavoriFactory) { 7 8 //Notifications 9 $scope.notifications = { 10 list: [], 11 goTo: function( id_aid ) { 12 this.modal.remove(); 13 $state.go('tabsController.singleAide', {id_aid: id_aid}); 14 }, 15 }; 16 17 $scope.notifications.openModal = function() { 18 //Get user af_id from local storage 19 var af_id = localStorageService.get('ae_af_id'); 20 21 //Load notification 22 var loadNotification = function( af_id ) { 23 $ionicLoading.show({ 24 template: '<ion-spinner icon="bubbles" class="spinner-light"></ion-spinner>' 25 }); 26 27 //Get list of notification 28 var params = {}; 29 params.af_id = af_id; 30 NotificationFactory.forshow( params ).then( 31 function(response) { 32 $ionicLoading.hide(); 33 //Open modal 34 $ionicModal.fromTemplateUrl('./templates/m/notifications.html', { 35 scope: $scope, 36 animation: 'slide-in-up', 37 }).then(function(modal) { 38 $scope.notifications.modal = modal; 39 $scope.notifications.modal.show(); 40 }); 41 cordova.plugins.notification.badge.set(0); 42 $scope.notifications.list = response.data.list; 43 }); 44 }; 45 46 if ( af_id ) { 47 loadNotification( af_id ); 48 } 49 }; 50 51 52 53 54 // 55 // AIDE FAVORIS 56 // 57 //Init Local Favorites Aide 58 var localFavoritesAidesInitiated = false; 59 var initLocalFavoritesAides = function() { 60 //Get user af_id from local storage 61 var userLogged = localStorageService.get('ae_af_id'); 62 63 64 //Get list of favorite from local 65 var favoritesAides = localStorageService.get('aeFavoritesAides'); 66 if ( !favoritesAides ) { 67 favoritesAides = []; 68 } else { 69 favoritesAides = favoritesAides.split('|'); 70 } 71 72 // 73 var favoritesAidesTer = localStorageService.get('aeFavoritesAidesTer'); 74 if ( !favoritesAidesTer ) { 75 favoritesAidesTer = '{}'; 76 } 77 favoritesAidesTer = JSON.parse(favoritesAidesTer); //unserialize 78 79 if ( userLogged ) { 80 FavoriSelectionFactory.read( userLogged ).then(function(response) { 81 var userAides = response.data.list; 82 userAides.forEach(function(el, i) { 83 if ( el[0] ) { 84 var position = favoritesAides.indexOf(el[0].id_aid); 85 if ( position < 0 ) { 86 favoritesAides.push(el[0].id_aid); 87 } 88 if ( el.id_ter != null ) { 89 favoritesAidesTer[el[0].id_aid] = el.id_ter; 90 } 91 } 92 }); 93 localStorageService.set('aeFavoritesAides', favoritesAides.join('|')); 94 localStorageService.set('aeFavoritesAidesTer', JSON.stringify(favoritesAidesTer)); 95 }); 96 } 97 }; 98 99 100 //-----Check if mobile or web mobile 101 var appID = "ZEDGHEX457"; //Smatphone ID 102 var isApp = false; //If on smartphone 103 104 if ( !localFavoritesAidesInitiated ) { 105 if ( isApp ) { 106 localStorageService.set('aeFavoritesAides', ''); 107 localStorageService.set('aeFavoritesAidesTer', JSON.stringify({})); 108 //Check af_id 109 FavoriFactory.where('email', appID).getAll().then(function(response) { 110 if ( response.data.list.length ) { //If user exists 111 var af_id = response.data.list[0].uuid; 112 if ( !af_id ) { 113 af_id = response.data.list[0].af_id; 114 } 115 localStorageService.set('ae_af_id', af_id); 116 initLocalFavoritesAides(); 117 localFavoritesAidesInitiated = true; 118 } else { //User doesn't exists 119 FavoriFactory.create({ 120 email: appID, 121 choix: 'all', 122 }).then(function(response) { //Create new user 123 var af_id = response.data.list.af_id; 124 localStorageService.set('ae_af_id', af_id); 125 initLocalFavoritesAides(); 126 localFavoritesAidesInitiated = true; 127 }); 128 } 129 }); 130 } else { 131 initLocalFavoritesAides(); 132 localFavoritesAidesInitiated = true; 133 } 134 } 135 136 137 138 //Toogle aide to favorite 139 var toggleAideToFavorite = function(id_aid, id_ter) { 140 if ( !id_aid ) { 141 return; 142 } 143 144 if ( id_ter == undefined ) { 145 id_ter = null; 146 } 147 148 //Get user af_id from local storage 149 var userLogged = localStorageService.get('ae_af_id'); 150 151 152 //Get list of favorite from local 153 var favoritesAides = localStorageService.get('aeFavoritesAides'); 154 if ( !favoritesAides ) { 155 favoritesAides = []; 156 } else { 157 favoritesAides = favoritesAides.split('|'); 158 } 159 160 // 161 var favoritesAidesTer = localStorageService.get('aeFavoritesAidesTer'); 162 if ( !favoritesAidesTer ) { 163 favoritesAidesTer = '{}'; 164 } 165 favoritesAidesTer = JSON.parse(favoritesAidesTer); //unserialize 166 167 168 //Check if aide is already set to favorite 169 var position = favoritesAides.indexOf(id_aid); 170 if ( position >= 0 ) { 171 favoritesAides.splice(position, 1); 172 if ( favoritesAidesTer[id_aid] != undefined ) { 173 delete favoritesAidesTer[id_aid]; 174 } 175 176 //If user logged 177 if ( userLogged ) { 178 //Get all favori from API Database 179 FavoriSelectionFactory.read( userLogged ).then(function(response) { 180 var userAides = response.data.list;
181 userAides.forEach(function(el, i) { 182 if ( el[0] && el[0].id_aid == id_aid ) { 183 //Remove from API Database 184 FavoriSelectionFactory.del({ 185 afsa_id: el.afsa_id, 186 }); 187 } 188 }); 189 }); 190 } 191 } else { 192 favoritesAides.push(id_aid); 193 if ( id_ter ) { 194 favoritesAidesTer[id_aid] = id_ter; 195 } 196 197 //if logged add new item to API Database 198 if ( userLogged ) { 199 FavoriSelectionFactory.create({ 200 af_id: userLogged, 201 id_aid: id_aid, 202 id_ter: id_ter, 203 }); 204 } 205 } 206 207 localStorageService.set('aeFavoritesAides', favoritesAides.join('|')); 208 localStorageService.set('aeFavoritesAidesTer', JSON.stringify(favoritesAidesTer)); //serialize 209 210 }; 211 212 $scope.toggleAideToFavorite = toggleAideToFavorite; 213 214 //Check if aide is favorite or not 215 $scope.isFavoriteAide = function(id_aid) { 216 var favoritesAides = localStorageService.get('aeFavoritesAides'); 217 if ( !favoritesAides ) { 218 return false; 219 } 220 favoritesAides = favoritesAides.split('|'); 221 if ( favoritesAides.indexOf(id_aid) >= 0 ) { 222 return true; 223 } 224 return false; 225 }; 226 227 228 //Slow connection 229 $scope.slowConnection = { 230 popup: false, 231 chrono: false, 232 loaded: false, 233 openPopup: function() { 234 var _this = this; 235 if ( _this.popup ) { 236 return; 237 } 238 _this.popup = $ionicPopup.alert({ 239 title: 'Connexion lente', 240 template: '<p>Votre connexion semble lente, les données peuvent mettre du temps à être chargées</p>', 241 okText: 'Fermer', 242 okType: 'button-positive', 243 }); 244 _this.popup.then(function() { 245 _this.popup = false; 246 }); 247 }, 248 hidePopup: function() { 249 if ( this.popup ) { 250 this.popup.close(); 251 } 252 }, 253 init: function() { 254 var _this = this; 255 if ( _this.chrono ) { 256 $timeout.cancel(_this.chrono); 257 } 258 _this.loaded = false; 259 _this.chrono = $timeout(function() { 260 if ( !_this.loaded ) { 261 $ionicLoading.hide(); 262 _this.openPopup(); 263 } 264 }, 3000); 265 }, 266 cancel: function() { 267 this.loaded = true; 268 } 269 }; 270 271}]) 272 273.controller('MobileRechercheCtrl', ['$scope', '$stateParams', '$state', '$ionicScrollDelegate', '$ionicLoading', '$location', 'AidesFactory', 'ProjetFactory', 'TypePretFactory', 'ProfilFactory', 'OrganismeFactory', 'ParentTerritoireFactory', 'FavoriCritereFactory', 'localStorageService', '$ionicPopup', 'FavoriFactory', '$ionicPlatform',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller 274// You can include any angular dependencies as parameters for this function 275// TIP: Access Route Parameters for your page via $stateParams.parameterName 276function ($scope, $stateParams, $state, $ionicScrollDelegate, $ionicLoading, $location, AidesFactory, ProjetFactory, TypePretFactory, ProfilFactory, OrganismeFactory, ParentTerritoireFactory, FavoriCritereFactory, localStorageService, $ionicPopup, FavoriFactory, $ionicPlatform) { 277 //$scope.saveFilter.init();
278 var currentFilters = $scope.saveFilter.currentFilters; 279 280 //Global variable 281 var posts_per_page = 20; 282 $scope.recherche = { 283 archivePage: true, 284 aides: [], 285 noResults: false, 286 mayLoading: false, 287 nowLoading: false, 288 noFilter: true, 289 loadingMore: false, 290 currentTer: '', 291 showFilter: true, 292 }; 293 294 295 296 var timeout; 297 //Filtres 298 $scope.filters = { 299 showFinanceurFilter: false, 300 showNatureFilter: false, 301 showNiveauFilter: false, 302 projet: [], 303 profil: [], 304 localisation: [], 305 nature: [], 306 niveau:[ 307 { 308 id: 1, 309 text: 'Aides territoriales', 310 }, 311 { 312 id: 2, 313 text: 'Aides nationales', 314 }, 315 { 316 id: 3, 317 text: 'Aides européennes', 318 }, 319 ], 320 locationKeywords: '', 321 removeTer: function() { 322 this.locationKeywords = ''; 323 currentFilters.locations = []; 324 $scope.recherche.currentTer = ''; 325 updateFilter(); 326 }, 327 hide: function() { 328 ae.dom.selectAll('.suggest-list', function(el) { 329 ae.dom.removeClass(el, 'active'); 330 }); 331 ae.dom.selectAll('label.item-input', function(el) { 332 ae.dom.removeClass(el, 'blur'); 333 }); 334 ae.dom.removeClass('#layered-filter-search-blur', 'active'); 335 }, 336 show: function(type) { 337 if (!ae.dom.hasClass('#' + type + '-suggest-list', 'active')) { 338 this.hide(); 339 ae.dom.addClass('#' + type + '-suggest-list', 'active'); 340 ae.dom.addClass('#layered-filter-search-blur', 'active'); 341 ae.dom.selectAll('label.item-input', function(el) { 342 ae.dom.addClass(el, 'blur'); 343 }); 344 } 345 else { 346 this.hide(); 347 } 348 }, 349 searchLocation: function() { 350 var keywords = this.locationKeywords; 351 try { 352 clearTimeout(timeout); 353 } 354 catch (err) {} 355 356 currentFilters.locations = []; 357 $scope.recherche.currentTer = ''; 358 359 var self = this; 360 361 if (!ae.dom.hasClass('#locations-layered-suggest-list', 'active')) { 362 self.show('locations-layered'); 363 } 364 365 timeout = setTimeout(function() { 366 367 if (self.locationKeywords == '') { 368 self.hide(); 369 } 370 else { 371 ParentTerritoireFactory.search(self.locationKeywords).then(function(response) { 372 if (response.data.list.length > 0) { 373 self.localisation = response.data.list; 374 } 375 }); 376 } 377 378 }, 300); 379 }, 380 selectedText: { 381 projet: '', 382 profil: '', 383 financeur: '', 384 nature: '', 385 niveau: '', 386 }, 387 }; 388 389 390 if ( $stateParams.id_aid ) { 391 $scope.recherche.archivePage = false; 392 } else { //Load 393 $scope.recherche.archivePage = true; 394 } 395 396 // -------------------------------------------------- 397 // Load filter content 398 // -------------------------------------------------- 399 function checkNiveau() { 400 if ( $scope.recherche.archivePage ) { 401 for (var i in $scope.filters.niveau) { 402 $scope.filters.niveau[i].activeClass = false; 403 for (var j in currentFilters.niveau) { 404 if (currentFilters.niveau[j].id == $scope.filters.niveau[i].id) 405 $scope.filters.niveau[i].activeClass = true; 406 } 407 } 408 } 409 } 410 411 //activeClass 412 function checkProjets() { 413 if ( $scope.recherche.archivePage ) { 414 for (var i in $scope.filters.projet) { 415 for (var k in $scope.filters.projet[i].values) { 416 $scope.filters.projet[i].values[k].activeClass = false;
417 for (var j in currentFilters.projets) { 418 if (currentFilters.projets[j].id_proj == $scope.filters.projet[i].values[k].id_proj) 419 $scope.filters.projet[i].values[k].activeClass = true; 420 } 421 } 422 } 423 } 424 } 425 426 console.log($stateParams); 427 if ( !$stateParams.id_aid && !dataLoaded) { 428 $ionicLoading.show(); 429 $scope.slowConnection.init(); 430 431 var loadedCount = 0; 432 function checkFinishedLoad() { 433 setTimeout(function() { 434 if(loadedCount >= 4) { 435 dataLoaded = true; 436 $ionicLoading.hide(); 437 $scope.slowConnection.cancel(); 438 } 439 else { 440 checkFinishedLoad(); 441 } 442 }, 2000); 443 } 444 checkFinishedLoad(); 445 446 } 447 448 //Load filter content 449 450 if (!filterList.projet) { 451 ProjetFactory.orderAsc('proj_parent').orderAsc('proj_ordre').getAll().then(function(response) { 452 filterList.projet = $scope.filters.projet = response.data.list; 453 checkProjets(); 454 loadedCount++; 455 }); 456 } 457 else { 458 $scope.filters.projet = filterList.projet; 459 checkProjets(); 460 } 461 462 463 function checkProfil() { 464 if ($scope.recherche.archivePage) { 465 for (var i in $scope.filters.profil) { 466 $scope.filters.profil[i].activeClass = false; 467 for (var j in currentFilters.profils) { 468 if (currentFilters.profils[j].id_tut == $scope.filters.profil[i].id_tut) 469 $scope.filters.profil[i].activeClass = true; 470 } 471 } 472 } 473 } 474 475 if (!filterList.profil) { 476 ProfilFactory.orderAsc('tut_ordre').getAll().then(function(response) { 477 filterList.profil = $scope.filters.profil = response.data.list; 478 checkProfil(); 479 loadedCount++; 480 }); 481 } 482 else { 483 $scope.filters.profil = filterList.profil; 484 checkProfil(); 485 } 486 487 488 function checkNature() { 489 if ($scope.recherche.archivePage) { 490 for (var i in $scope.filters.nature) { 491 $scope.filters.nature[i].activeClass = false; 492 for (var j in currentFilters.nature) { 493 if (currentFilters.nature[j].id_typ == $scope.filters.nature[i].id_typ) 494 $scope.filters.nature[i].activeClass = true; 495 } 496 } 497 } 498 } 499 500 if (!filterList.nature) { 501 TypePretFactory.orderAsc('typ_libelle').getAll().then(function(response) { 502 filterList.nature = $scope.filters.nature = response.data.list; 503 checkNature(); 504 loadedCount++; 505 }); 506 } 507 else { 508 $scope.filters.nature = filterList.nature; 509 checkNature(); 510 } 511 512 513 if (!filterList.financeur) { 514 OrganismeFactory.getAll().then(function(response) { 515 filterList.financeur = $scope.filters.financeur = response.data.list; 516 loadedCount++; 517 }); 518 } 519 else { 520 $scope.filters.financeur = filterList.financeur; 521 } 522 523 var updateFilter = function() { 524 $scope.recherche.noFilter = false; 525 526 //Close all filters 527 $scope.filters.showProjet = false; 528 $scope.filters.showProfil = false;
529 $scope.filters.showFinanceur = false; 530 $scope.filters.showNature = false; 531 $scope.filters.showNiveau = false; 532 $scope.filters.projet.forEach(function(categorie, i) { 533 categorie.open = false; 534 }); 535 536 setTimeout(function() { 537 $ionicScrollDelegate.resize(); 538 $ionicScrollDelegate.scrollTop(); 539 }, 100); 540 541 //Check if no filter selected 542 if ( !currentFilters.projets.length && 543 !currentFilters.profils.length && 544 !currentFilters.financeurs.length && 545 !currentFilters.nature.length && 546 !currentFilters.locations.length && 547 !currentFilters.niveau.length ) { 548 $scope.recherche.noFilter = true; 549 $scope.recherche.showFilter = true; 550 551 return; 552 } 553 }; 554 555 // ------------------------------------------------ 556 // Charge la liste des aides 557 // ------------------------------------------------ 558 var loadListeAides = function() { 559 560 $scope.filters.showFinanceurFilter = currentFilters.financeurs.length ? true : false; 561 $scope.filters.showNatureFilter = currentFilters.nature.length ? true : false; 562 $scope.filters.showNiveauFilter = currentFilters.niveau.length ? true : false; 563 564 //$scope.recherche.showFilter = false; 565 566 $state.go('tabsController.listeAides', currentFilters); 567 568 }; 569 570 $scope.recherche.loadListeAides = loadListeAides; 571 572 // ------------------------------------------------ 573 // Charge une fiche d'aide 574 // ------------------------------------------------ 575 var loadFicheAide = function(id_aid, id_ter) { 576 $ionicLoading.show(); 577 $scope.slowConnection.init(); 578 $scope.recherche.currentTer = id_ter; 579 AidesFactory.singleResult(id_aid, id_ter).then(function(response) { 580 if ( response.data.list.length ) { 581 $scope.recherche.noResults = false; 582 $scope.recherche.aides = response.data.list; 583 $scope.recherche.aides.forEach(function(aide, i) { 584 var elm = aide.aid_source2.split('|'); 585 if( elm.length == 1 ) 586 elm = aide.aid_source2.split(' '); 587 588 589 aide.image = { 590 src: '', 591 link: '', 592 }; 593 if ( aide.aid_source2 ) { 594 aide.image = { 595 src: 'http://www.aides-entreprises.fr/repertoiredesaides/images/logos/' + elm[0].trim(), 596 link: elm[1].trim(), 597 }; 598 } 599 600 $scope.recherche.contactSelected = []; 601 $scope.recherche.terSelected = '0'; 602 603 $scope.recherche.showContact = function(value) { 604 $scope.recherche.contactSelected = []; 605 aide.contact.forEach(function(el, i) { 606 if (el.region == value) { 607 $scope.recherche.contactSelected.push(el); 608 } 609 }); 610 }; 611 612 if (aide.contact.length <= 1) { 613 $scope.recherche.contactSelected = aide.contact; 614 } 615 616 //Remove url from aid_source name 617 aide.aid_source = aide.aid_source.replace(/\((http(s)?(:\/\/))?(www\.)?[a-zA-Z0-9-_\.]+(\.[a-zA-Z0-9]{2,})([-a-zA-Z0-9:%_\+.~#?&//=]*)\)/i, ''); 618 619 //If id_ter, we can get info about 620 aide.source_info = []; 621 aide.formulaire = []; 622 aide.info_compl = []; 623 if ( aide.info.length ) { 624 aide.info.forEach(function(el, i) { 625 if (el.cmp_flag == 'sourc') { 626 aide.source_info.push(el); 627 } 628 else if (el.cmp_flag == 'formu') { 629 aide.formulaire.push(el); 630 } 631 else if (el.cmp_flag == 'compl') { 632 aide.info_compl.push(el); 633 } 634 }); 635 } 636 }); 637 } else { 638 $scope.recherche.aides = []; 639 $scope.recherche.noResults = true; 640 } 641 $ionicLoading.hide(); 642 $scope.slowConnection.cancel(); 643 }); 644 }; 645 646 647 648 // ------------------------------------------------ 649 // filter update event 650 // ------------------------------------------------ 651 $scope.filters.updateProjet = function( projet ) { 652 var inArray = false;
653 currentFilters.projets.forEach(function(el, i) { 654 el.activeClass = false; 655 if ( el.id_proj == projet.id_proj ) { 656 inArray = true; 657 } 658 }); 659 if ( !inArray ) { 660 currentFilters.projets = [projet]; 661 projet.activeClass = true; 662 } else { 663 currentFilters.projets = []; 664 } 665 updateFilter(); 666 667 $scope.filters.selectedText.projet = ''; 668 if ( currentFilters.projets.length ) { 669 $scope.filters.selectedText.projet = currentFilters.projets[0].parent_libelle?currentFilters.projets[0].parent_libelle:currentFilters.projets[0].proj_libelle; 670 } 671 }; 672 673 $scope.filters.updateProfil = function( profil ) { 674 var inArray = false; 675 currentFilters.profils.forEach(function(el, i) { 676 el.activeClass = false; 677 if ( el.id_tut == profil.id_tut ) { 678 inArray = true; 679 } 680 }); 681 if ( !inArray ) { 682 currentFilters.profils = [profil]; 683 profil.activeClass = true; 684 } else { 685 currentFilters.profils = []; 686 } 687 updateFilter(); 688 689 $scope.filters.selectedText.profil = ''; 690 if ( currentFilters.profils.length ) { 691 $scope.filters.selectedText.profil = currentFilters.profils[0].tut_libelle; 692 } 693 }; 694 695 $scope.filters.updateNature = function( nature ) { 696 var inArray = false; 697 currentFilters.nature.forEach(function(el, i) { 698 el.activeClass = false; 699 if ( el.id_typ == nature.id_typ ) { 700 inArray = true; 701 } 702 }); 703 if ( !inArray ) { 704 currentFilters.nature = [nature]; 705 nature.activeClass = true; 706 } else { 707 currentFilters.nature = []; 708 } 709 710 updateFilter(); 711 712 $scope.filters.selectedText.nature = ''; 713 if ( currentFilters.nature.length ) { 714 $scope.filters.selectedText.nature = currentFilters.nature[0].typ_libelle; 715 } 716 }; 717 718 $scope.filters.updateFinanceur = function( financeur ) { 719 var inArray = false; 720 currentFilters.financeurs.forEach(function(el, i) { 721 el.activeClass = false; 722 if ( el.id_org == financeur.id_org ) { 723 inArray = true; 724 } 725 }); 726 if ( !inArray ) { 727 currentFilters.financeurs = [financeur]; 728 financeur.activeClass = true; 729 } else { 730 currentFilters.financeurs = []; 731 } 732 733 current_page = 0; 734 //loadListeAides(); 735 updateFilter(); 736 737 $scope.filters.selectedText.financeur = ''; 738 if ( currentFilters.financeurs.length ) { 739 $scope.filters.selectedText.financeur = currentFilters.financeurs[0].org_nom; 740 } 741 }; 742 743 $scope.filters.updateNiveau = function( niveau ) { 744 var inArray = false; 745 currentFilters.niveau.forEach(function(el, i) { 746 el.activeClass = false; 747 if ( el.id == niveau.id ) { 748 inArray = true; 749 } 750 }); 751 if ( !inArray ) { 752 currentFilters.niveau = [niveau]; 753 niveau.activeClass = true; 754 } else { 755 currentFilters.niveau = []; 756 } 757 current_page = 0; 758 //loadListeAides(); 759 updateFilter(); 760 761 $scope.filters.selectedText.niveau = ''; 762 if ( currentFilters.niveau.length ) { 763 $scope.filters.selectedText.niveau = currentFilters.niveau[0].text; 764 } 765 }; 766 767 $scope.filters.updateLocation = function(location) { 768 current_page = 0; 769 currentFilters.locations = [location]; 770 $scope.recherche.currentTer = location.id_ter; 771 $scope.filters.locationKeywords = location.ter_libelle; 772 //loadListeAides(); 773 updateFilter(); 774 $scope.filters.hide(); 775 }; 776 777 //If single page 778 if ( $stateParams.id_aid ) { 779 $scope.recherche.archivePage = false; 780 loadFicheAide( $stateParams.id_aid, $stateParams.id_ter ); 781 } else { //Load 782 $scope.recherche.archivePage = true; 783 } 784 $ionicPlatform.ready(function() { 785 if(maVille === false) 786 return; 787 elm = maVille.split(','); 788 ParentTerritoireFactory.searchbis(elm[0].trim(),monCode) 789 .then( 790 function(response) { 791 self.localisation = response.data.list; 792 currentFilters.locations = self.localisation; 793 $scope.recherche.currentTer = self.localisation[0].id_ter; 794 $scope.filters.locationKeywords = self.localisation[0].ter_libelle; 795 updateFilter(); 796 }).catch(function(response, status) { 797 alert('error', response.status, response.data); 798 }) 799 .finally(function() { 800 console.log("fin"); 801 }); 802 }); 803 804}]) 805 806.controller('MobileListeAidesCtrl', ['$scope', '$stateParams', '$ionicScrollDelegate', '$ionicLoading', '$location', 'AidesFactory', 'ProjetFactory', 'TypePretFactory', 'ProfilFactory', 'OrganismeFactory', 'ParentTerritoireFactory', 'FavoriCritereFactory', 'localStorageService', '$ionicPopup', 'FavoriFactory', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller 807// You can include any angular dependencies as parameters for this function 808// TIP: Access Route Parameters for your page via $stateParams.parameterName 809function ($scope, $stateParams, $ionicScrollDelegate, $ionicLoading, $location, AidesFactory, ProjetFactory, TypePretFactory, ProfilFactory, OrganismeFactory, ParentTerritoireFactory, FavoriCritereFactory, localStorageService, $ionicPopup, FavoriFactory) { 810 811 var posts_per_page = 10, 812 page = 0; 813 814 //$scope.saveFilter.currentFilters = angular.merge( $scope.s
814aveFilter.currentFilters, $stateParams ); 815 816 //$scope.saveFilters.currentFilters = angular.merge($scope.saveFilters.currentFilters, $stateParams); 817 818 $scope.liste = { 819 aides: [], 820 noAides: true, 821 noFilter: false, 822 mayLoadMore: false, 823 currentTer: null, 824 }; 825 826 $scope.liste.nowLoading = false; 827 828 var loadAides = function() { 829 830 $scope.liste.nowLoading = true; 831 832 833 $ionicScrollDelegate.resize(); 834 835 $scope.liste.currentTer = null; 836 $scope.liste.mayLoadMore = false; 837 838 if ( !$scope.saveFilter.currentFilters.projets.length && 839 !$scope.saveFilter.currentFilters.locations.length && 840 !$scope.saveFilter.currentFilters.profils.length && 841 !$scope.saveFilter.currentFilters.nature.length && 842 !$scope.saveFilter.currentFilters.financeurs.length && 843 !$scope.saveFilter.currentFilters.niveau.length ) { 844 $scope.liste.aides = []; 845 $scope.liste.noAides = true; 846 $scope.liste.noFilter = false; 847 return; 848 } 849 850 851 //Define Service params 852 AidesFactory.params.page = page; 853 AidesFactory.limit( posts_per_page ); 854 855 var where = '';
856 if ( $scope.saveFilter.currentFilters.projets.length ) { 857 where = ''; 858 $scope.saveFilter.currentFilters.projets.forEach(function(el, i) { 859 where += '-' + el.id_proj; 860 }); 861 where = where.substring(1); 862 AidesFactory.where('id_proj', where); 863 } 864 865 866 if ( $scope.saveFilter.currentFilters.profils.length ) { 867 where = ''; 868 $scope.saveFilter.currentFilters.profils.forEach(function(el, i) { 869 where += '-' + el.id_tut; 870 }); 871 where = where.substring(1); 872 AidesFactory.where('id_tut', where); 873 874 } 875 876 if ( $scope.saveFilter.currentFilters.nature.length ) { 877 where = ''; 878 $scope.saveFilter.currentFilters.nature.forEach(function(el, i) { 879 where += '-' + el.id_typ; 880 }); 881 where = where.substring(1); 882 AidesFactory.where('id_typ', where); 883 } 884 885 if ( $scope.s
885aveFilter.currentFilters.financeurs.length ) { 886 where = ''; 887 $scope.saveFilter.currentFilters.financeurs.forEach(function(el, i) { 888 where += '-' + el.id_org; 889 }); 890 where = where.substring(1); 891 AidesFactory.where('id_org', where); 892 893 } 894 895 if ( $scope.saveFilter.currentFilters.niveau.length ) { 896 where = ''; 897 $scope.saveFilter.currentFilters.niveau.forEach(function(el, i) { 898 where += '-' + el.id; 899 }); 900 where = where.substring(1); 901 AidesFactory.where('couverture_geo', where); 902 } 903 904 if ( $scope.saveFilter.currentFilters.locations.length ) { 905 where = ''; 906 $scope.saveFilter.currentFilters.locations.forEach(function(el, i) { 907 where += '-' + el.id_ter; 908 }); 909 $scope.liste.currentTer = $scope.saveFilter.currentFilters.locations[0].id_ter; 910 where = where.substring(1); 911 AidesFactory.where('id_ter', where); 912 } 913 914 //Show loading 915 $ionicLoading.show(); 916 $scope.slowConnection.init(); 917 918 AidesFactory.getAll().then(function(response) { 919 920 //Hide loading 921 $ionicLoading.hide(); 922 $scope.slowConnection.cancel(); 923 924 //Show or hide load more button 925 if ( response.data.list.length >= posts_per_page ) { 926 $scope.liste.mayLoadMore = true; 927 } 928 929 if ( response.data.list.length ) { 930 if ( page == 0 ) { 931 $scope.liste.noAides = false; 932 } 933 934 var aides = response.data.list; 935 aides.forEach(function(el, i) { 936 aides[i].image = { 937 src: '', 938 link: '', 939 }; 940 if ( el.aid_source2 ) { 941 aides[i].image = { 942 src: 'http://www.aides-entreprises.fr/repertoiredesaides/images/logos/' + el.aid_source2.split('|')[0].trim(), 943 link: ( el.aid_source2.split('|')[1] + '' ).trim(), 944 }; 945 } 946 }); 947 948 //Concat if 949 if ( page > 0 ) { 950 $scope.liste.aides = $scope.liste.aides.concat( aides ); 951 } else { 952 $scope.liste.aides = aides; 953 } 954 } else { 955 if ( page == 0 ) { 956 $scope.liste.noAides = true; 957 } 958 } 959 960 $ionicScrollDelegate.resize(); 961 962 $scope.liste.nowLoading = false; 963 }); 964 }; 965 966 967 $scope.liste.loadMore = function() { 968 if ( $scope.liste.nowLoading ) { 969 return; 970 } 971 setTimeout(function() { 972 page++; 973 loadAides(); 974 }, 400); 975 }; 976 977 978 loadAides(); 979 980}]) 981 982.controller('MobileBrevesCtrl', ['$scope', '$stateParams', 'ActualitesFactory', '$ionicLoading', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller 983// You can include any angular dependencies as parameters for this function 984// TIP: Access Route Parameters for your page via $stateParams.parameterName 985function ($scope, $stateParams, ActualitesFactory, $ionicLoading) { 986 987 var months = { 988 'janvier' : '01', 989 'février' : '02', 990 'mars' : '03', 991 'avril' : '04', 992 'mai' : '05', 993 'juin' : '06', 994 'juillet' : '07', 995 'août' : '08', 996 'septembre' : '09', 997 'octobre' : '10', 998 'novembre' : '11', 999 'décembre' : '12', 1000 }; 1001 $scope.months = months; 1002 1003 var monthsById = { 1004 '01': 'janvier', 1005 '02': 'février', 1006 '03': 'mars', 1007 '04': 'avril', 1008 '05': 'mai', 1009 '06': 'juin', 1010 '07': 'juillet', 1011 '08': 'août', 1012 '09': 'septembre', 1013 '10': 'octobre', 1014 '11': 'novembre', 1015 '12': 'décembre' 1016 }; 1017 $scope.monthsById = monthsById; 1018 1019 var current_page = 0; 1020 1021 $scope.actualites = { 1022 items: [], 1023 archivePage: true, 1024 noResults: false, 1025 filters: {}, 1026 openedFilterList: false, 1027 toggleFilterList: function() { 1028 this.openedFilterList = !this.openedFilterList; 1029 }, 1030 toggleMonthFilter: function(annee) { 1031 annee.activeClass = !annee.activeClass; 1032 }, 1033 filteredByDate: false, 1034 currentFilter: { 1035 month: $stateParams.month, 1036 year: $stateParams.year, 1037 }, 1038 mayLoading: false,
1039 loadMore: function() { 1040 current_page++; 1041 $ionicLoading.show({ 1042 template: '<ion-spinner icon="bubbles" class="spinner-light"></ion-spinner>', 1043 }); 1044 $scope.slowConnection.init(); 1045 ActualitesFactory.p('page', current_page).limit(20).orderAsc('date').getAll().then(function(response) { 1046 $ionicLoading.hide(); 1047 $scope.slowConnection.cancel(); 1048 if (response.data.list.length) { 1049 $scope.actualites.mayLoading = true; 1050 if ( response.data.list.length < 20 ) { 1051 $scope.actualites.mayLoading = false; 1052 } 1053 var newActus = response.data.list; 1054 $scope.actualites.items = $scope.actualites.items.concat(newActus); 1055 } else { 1056 $scope.actualites.mayLoading = false; 1057 } 1058 }); 1059 }, 1060 }; 1061 1062 if ( $stateParams.id_breve ) { //If single 1063 $scope.actualites.archivePage = false; 1064 $ionicLoading.show(); 1065 $scope.slowConnection.init(); 1066 ActualitesFactory.limit(1).where('id', $stateParams.id_breve).getAll().then(function(response) { 1067 if ( response.data.count ) { 1068 $scope.actualites.items = response.data.list; 1069 $scope.actualites.noResults = false; 1070 } else { 1071 $scope.actualites.items = [], 1072 $scope.actualites.noResults = true; 1073 } 1074 $ionicLoading.hide(); 1075 $scope.slowConnection.cancel(); 1076 }); 1077 } else { //If archive page 1078 $ionicLoading.show(); 1079 $scope.slowConnection.init(); 1080 //Date filter 1081 ActualitesFactory.getDateFilter().then(function(response) { 1082 if ( response.data.list ) { 1083 var dateList = response.data.list; 1084 var oldYear = ''; 1085 dateList.forEach(function(el, i) { 1086 if ( oldYear != el.annee ) { 1087 oldYear = el.annee; 1088 $scope.actualites.filters[oldYear] = []; 1089 $scope.actualites.filters[oldYear].key = el.annee; 1090 } 1091 1092 el.value = el.annee + '-' + months[el.mois] + '-' + '01'; 1093 el.valueLast = el.annee + '-' + months[el.mois] + '-' + '31'; 1094 1095 el.label = el.mois + ' ' + el.annee; 1096 1097 $scope.actualites.filters[oldYear].push( el ); 1098 }); 1099 1100 } 1101 }); 1102 1103 //Load list 1104 ActualitesFactory.params = {}; 1105 if ( $stateParams.year && $stateParams.month ) { 1106 ActualitesFactory.params = { 1107 'between' : 'date,' + $stateParams.year + '-' + $stateParams.month + '-01' + '|date,' + $stateParams.year + '-' + $stateParams.month + '-31', 1108 }; 1109 $scope.actualites.filteredByDate = true; 1110 $scope.actualites.mayLoading = false; 1111 } else { 1112 ActualitesFactory.p('page', 0).limit(20).orderAsc('date'); 1113 $scope.actualites.filteredByDate = false; 1114 $scope.actualites.mayLoading = true; 1115 } 1116 ActualitesFactory.getAll().then(function(response) { 1117 if ( response.data.list.length < 20 ) { 1118 $scope.actualites.mayLoading = false; 1119 } 1120 if ( response.data.count ) { 1121 $scope.actualites.items = response.data.list; 1122 $scope.actualites.noResults = false; 1123 } else { 1124 $scope.actualites.items = [], 1125 $scope.actualites.noResults = true; 1126 } 1127 $ionicLoading.hide(); 1128 $scope.slowConnection.cancel(); 1129 }); 1130 } 1131 1132}]) 1133 1134.controller('MobileQuiSommesNousCtrl', ['$scope', '$stateParams', '$http', '$httpParamSerializer', 'EquipeFactory',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller 1135// You can include any angular dependencies as parameters for this function 1136// TIP: Access Route Parameters for your page via $stateParams.parameterName 1137function ($scope, $stateParams, $http, $httpParamSerializer, EquipeFactory) { 1138 1139 // -------------------------------------------- 1140 // Global 1141 // -------------------------------------------- 1142 var slugTitle = { 1143 contact: 'Contact', 1144 contactCordova: 'contactCordova', 1145 'l-equipe': 'L\'équipe', 1146 projet: 'Le projet', 1147 'mentions-legales': 'Mentions légales', 1148 }; 1149 1150 $scope.quiSommesNous = { 1151 slug: $stateParams.slug, 1152 getTitle: function() { 1153 if ( !this.slug ) { 1154 return 'Qui sommes-nous?'; 1155 } else { 1156 return slugTitle[this.slug]; 1157 } 1158 } 1159 }; 1160 1161 $scope.equipe = {}; 1162 $scope.equipe.membres = EquipeFactory.getTeam(); 1163 1164 if ( slugTitle[$scope.quiSommesNous.slug] ) { 1165 //console.log("toto"); 1166 $scope.quiSommesNous.template = $scope.quiSommesNous.slug + '.html'; 1167 } else { 1168 //console.log("dd"); 1169 $scope.quiSommesNous.template = false;
1170 } 1171 1172 // ---------------------------------------------- 1173 // Contact 1174 // ---------------------------------------------- 1175 $scope.contactData = { 1176 name: '', 1177 email: '', 1178 receiver: '', 1179 subject: '', 1180 message: '', 1181 captcha: '', 1182 }; 1183 $scope.contact = { 1184 processForm: function() { 1185 1186 var processURL = '/php/processContact.php'; 1187 1188 //Reset variable 1189 this.errors = []; 1190 this.successMessage = false; 1191 1192 //Send request to server 1193 $http({ 1194 method : 'POST', 1195 url : processURL, 1196 data : $httpParamSerializer( $scope.contactData ) + '&submitContactForm=1', //Add one param to specified that is contact form 1197 headers : {'Content-Type': 'application/x-www-form-urlencoded'}, 1198 }).then( 1199 function(response) { //on success 1200 var data = response.data; 1201 if ( data.success ) { //If success 1202 $scope.contact.errors = []; //Disable server errors 1203 if ( data.successMessage ) { //if message success from server 1204 $scope.contact.successMessage = data.successMessage; 1205 } 1206 //$scope.contactData = {}; 1207 } else { //Else 1208 if ( data.errors ) { //Show error message 1209 $scope.contact.errors = data.errors; 1210 } 1211 $scope.contact.successMessage = false; //Disable success Message 1212 } 1213 } 1214 ); 1215 }, 1216 captchaSuccess: function(response) { 1217 $scope.contactData.captcha = null; 1218 }, 1219 captchaExpire: function() { 1220 1221 }, 1222 errors: [], 1223 successMessage: '', 1224 }; 1225 1226 $scope.contactCordova= function() { 1227 var email = { 1228 to: '[email protected]', 1229 subject: 'Depuis l\'application', 1230 body: '', 1231 isHtml: true 1232 }; 1233 cordova.plugins.email.open(email); 1234 }; 1235}]) 1236 1237.controller('MobileAbonnementCtrl', ['$scope', '$stateParams', '$state', '$ionicLoading', 'localStorageService', 'FavoriFactory', 'FavoriCritereFactory', 'ProjetFactory', 'OrganismeFactory', 'ParentTerritoireFactory', 'ProfilFactory', 'TypePretFactory', '$ionicPopup', 'FavoriSelectionFactory', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller 1238// You can include any angular dependencies as parameters for this function 1239// TIP: Access Route Parameters for your page via $stateParams.parameterName 1240function ($scope, $stateParams, $state, $ionicLoading, localStorageService, FavoriFactory, FavoriCritereFactory, ProjetFactory, OrganismeFactory, ParentTerritoireFactory, ProfilFactory, TypePretFactory, $ionicPopup, FavoriSelectionFactory) { 1241 1242 // -------------------------------------------------- 1243 // Global 1244 // -------------------------------------------------- 1245 var slugTitle = { 1246 'ma-selection': 'Ma sélection', 1247 'mes-filtres': 'Mes filtres', 1248 }; 1249 1250 $scope.abonnement = { 1251 slug: $stateParams.slug, 1252 getTitle: function() { 1253 if ( !this.slug ) { 1254 return 'Abonnement'; 1255 } else { 1256 return slugTitle[this.slug]; 1257 } 1258 } 1259 }; 1260 1261 if ( slugTitle[$scope.abonnement.slug] ) { 1262 $scope.abonnement.template = $scope.abonnement.slug + '.html'; 1263 } else { 1264 $scope.abonnement.template = false; 1265 } 1266 1267 1268 // -------------------------------------------------- 1269 // Ma Sélection 1270 // -------------------------------------------------- 1271 $scope.maSelection = { 1272 aides: [], 1273 noAides: false, 1274 }; 1275 1276 var loadMaSelection = function(af_id) { 1277 1278 1279 //Get list of favorite from local 1280 var favoritesAides = localStorageService.get('aeFavoritesAides'); 1281 if ( !favoritesAides ) { 1282 favoritesAides = []; 1283 } else { 1284 favoritesAides = favoritesAides.split('|'); 1285 } 1286 1287 // 1288 var favoritesAidesTer = localStorageService.get('aeFavoritesAidesTer'); 1289 if ( !favoritesAidesTer ) { 1290 favoritesAidesTer = '{}'; 1291 } 1292 favoritesAidesTer = JSON.parse(favoritesAidesTer); //unserialize 1293 1294 // Load 1295 var favoriteServerAides = []; 1296 var favoriteServerAidesTer = {}; 1297 FavoriSelectionFactory.read(af_id).then(function(response) { 1298 if ( response.data.list.length ) { 1299 var aides = []; 1300 var list = response.data.list; 1301 list.forEach(function(el, i) { 1302 var aide = el[0]; 1303 if(typeof(aide) == 'undefined') { 1304 aide = el; 1305 } 1306 if(typeof(aide.id_aid) == 'undefined') 1307 return; 1308 aide.id_ter = el.id_ter; 1309 if(typeof(aide.id_ter) == 'undefined') 1310 aide.id_ter = -1; 1311 aide.image = { 1312 src: '', 1313 link: '', 1314 }; 1315 if ( aide.aid_source2 ) { 1316 aide.image = { 1317 src: 'http://www.aides-entreprises.fr/repertoiredesaides/images/logos/' + aide.aid_source2.split('|')[0].trim(), 1318 link: (aide.aid_source2.split('|')[1]+'').trim(), 1319 }; 1320 } 1321 aides.push(aide); 1322 1323 //Stocke les id des aides dans la base 1324 favoriteServerAides.push(aide.id_aid); 1325 if ( aide.id_ter != null ) 1326 favoriteServerAidesTer[aide.id_aid] = aide.id_ter; 1327 }); 1328
1329 //Match aides 1330 var aideToUpload = []; 1331 favoritesAides.forEach(function(id_aid) { 1332 if ( favoriteServerAides.indexOf(id_aid) < 0 ) { 1333 aideToUpload.push({ 1334 id_aid: id_aid, 1335 id_ter: favoritesAidesTer[id_aid], 1336 }); 1337 } 1338 }); 1339 1340 favoriteServerAides.forEach(function(id_aid) { 1341 if ( favoritesAides.indexOf(id_aid) < 0 ) { 1342 favoritesAides.push(id_aid); 1343 if ( favoriteServerAidesTer[id_aid] ) { 1344 favoritesAidesTer[id_aid] = favoriteServerAidesTer[id_aid]; 1345 } 1346 } 1347 }); 1348 1349 if ( !aideToUpload.length ) { 1350 $scope.maSelection.aides = aides; 1351 } else { 1352 var compteur = 0; 1353 aideToUpload.forEach(function(el, i) { 1354 FavoriSelectionFactory.create({ 1355 af_id: af_id, 1356 id_aid: el.id_aid, 1357 id_ter: el.id_ter, 1358 }).then(function(response) { 1359 compteur = compteur + 1; 1360 if ( compteur == aideToUpload.length ) { 1361 FavoriSelectionFactory.read(af_id).then(function(response) { 1362 if ( response.data.list.length ) { 1363 var aides = []; 1364 var list = response.data.list; 1365 1366 list.forEach(function(el, i) { 1367 var aide = el[0]; 1368 if(typeof(aide) == 'undefined') { 1369 aide = el; 1370 } 1371 if(typeof(aide.id_aid) == 'undefined') 1372 return; 1373 aide.id_ter = el.id_ter; 1374 1375 aide.image = { 1376 src: '', 1377 link: '', 1378 }; 1379 if ( aide.aid_source2 ) { 1380 aide.image = { 1381 src: 'http://www.aides-entreprises.fr/repertoiredesaides/images/logos/' + aide.aid_source2.split('|')[0].trim(), 1382 link: (aide.aid_source2.split('|')[1] + '').trim(), 1383 }; 1384 } 1385 JSON.stringify(aide); 1386 aides.push(aide); 1387 }); 1388 } 1389 $scope.maSelection.aides = aides; 1390 }); 1391 } 1392 }); 1393 }); 1394 } 1395 1396 //$scope.maSelection.aides = aides; 1397 $scope.maSelection.noAides = false; 1398 1399 localStorageService.set('aeFavoritesAides', favoritesAides.join('|')); 1400 localStorageService.set('aeFavoritesAidesTer', JSON.stringify(favoritesAidesTer)); 1401 1402 } else { 1403 //If has aide in local 1404 if ( favoritesAides.length ) { 1405 compteur = 1; 1406 favoritesAides.forEach(function(id_aid) { 1407 FavoriSelectionFactory.create({ 1408 af_id: af_id, 1409 id_aid: id_aid, 1410 id_ter: favoritesAidesTer[id_aid], 1411 }).then(function(response) { 1412 compteur = compteur + 1; 1413 if ( compteur == favoritesAides.length ) { 1414 FavoriSelectionFactory.read(af_id).then(function(response) { 1415 if ( response.data.list.length ) { 1416 var aides = []; 1417 var list = response.data.list; 1418 1419 list.forEach(function(el, i) { 1420 var aide = el[0]; 1421 if(typeof(aide.id_aid) == 'undefined') 1422 return; 1423 aide.id_ter = el.id_ter; 1424 1425 aide.image = { 1426 src: '', 1427 link: '', 1428 }; 1429 if ( aide.aid_source2 ) { 1430 aide.image = { 1431 src: 'http://www.aides-entreprises.fr/repertoiredesaides/images/logos/' + aide.aid_source2.split('|')[0].trim(), 1432 link: (aide.aid_source2.split('|')[1]+'').trim(), 1433 }; 1434 } 1435 aides.push(aide); 1436 }); 1437 } 1438 $scope.maSelection.aides = aides; 1439 $scope.maSelection.noAides = false;
1440 }); 1441 } 1442 }); 1443 }); 1444 } else { 1445 $scope.maSelection.aides = []; 1446 $scope.maSelection.noAides = true; 1447 } 1448 } 1449 }).catch(function(response, status) { 1450 alert('error', response.status, response.data); 1451 }) 1452 .finally(function() { 1453 console.log("fin"); 1454 }); 1455 }; 1456 1457 // -------------------------------------------------- 1458 // Mes Filtres 1459 // -------------------------------------------------- 1460 $scope.mesFiltres = { 1461 hasFiltres: false, 1462 userLogged: false, 1463 goToSearch : function( filtre ) { 1464 $state.go('tabsController.listeAides', filtre); 1465 }, 1466 remove: function(id) { 1467 1468 var confirmPopup = $ionicPopup.confirm({ 1469 title: 'Confirmation', 1470 template: 'Etes vous sur de vouloir supprimer ce filtre ?', 1471 cancelType: 'button-stable button-outline', 1472 okType: 'button-custom-red', 1473 }); 1474 1475 confirmPopup.then(function(res) { 1476 if(res) { 1477 ae.dom.remove('#filtre-' + id); 1478 FavoriCritereFactory.del({ 1479 afc_id: id, 1480 }); 1481 } else { 1482 1483 } 1484 }); 1485 1486 } 1487 }; 1488 1489 //Hydrate the filter_obj by getting info from respective service 1490 var loadDataFilter = function( filter_ids, filter_obj ) { 1491 if ( !filter_ids ) { 1492 return; 1493 } 1494 1495 for( var prop in filter_ids ) { 1496 if ( filter_ids[prop] == null || filter_ids[prop] == undefined ) { 1497 filter_ids[prop] = ''; 1498 } 1499 } 1500 1501 //Name 1502 filter_obj.name = filter_ids.intitule; 1503 filter_obj.id = filter_ids.afc_id; 1504 1505 //Get all id_proj 1506 var id_proj = filter_ids.id_proj.split('-'); 1507 //Retrieve projet object 1508 id_proj.forEach(function(el, i) { 1509 ProjetFactory.params = {}; 1510 ProjetFactory.where('id_proj', el).getAll().then(function(response) { 1511 var projet = response.data.list[0]; 1512 if ( projet && projet.values ) { 1513 projet = projet.values[0]; 1514 //Si projet libelle == Toutes les aides 1515 if ( projet.proj_parent && projet.proj_libelle == "Toutes les aides" ) { 1516 //On récupere le nom du projet parent 1517 ProjetFactory.where('id_proj', projet.proj_parent).getAll().then(function(res) { 1518 if ( res.data ) { 1519 var projet_parent = res.data.list[0].categorie; 1520 projet.proj_libelle = projet_parent.proj_libelle; 1521 } 1522 filter_obj.projet = filter_obj.projet.concat( projet ); 1523 }); 1524 } else { 1525 filter_obj.projet = filter_obj.projet.concat( projet ); 1526 } 1527 } 1528 }); 1529 }); 1530 1531 //Get all id_org 1532 var id_org = filter_ids.id_org.split('-'); 1533 //Retrieve organisme object 1534 id_org.forEach(function(el, i) { 1535 OrganismeFactory.params = {}; 1536 OrganismeFactory.where('id_org', el).getAll().then(function(response) { 1537 if ( response.data.count ) { 1538 filter_obj.financeur = filter_obj.financeur.concat( response.data.list ); 1539 } 1540 }); 1541 }); 1542 1543 //Get all id_ter 1544 if ( filter_ids.id_ter ) { 1545 var id_ter = filter_ids.id_ter.split('-'); 1546 id_ter.forEach(function(el, i) { 1547 ParentTerritoireFactory.params = {}; 1548 ParentTerritoireFactory.where('id_ter', el).getAll().then(function(response) { 1549 if ( response.data.count ) { 1550 filter_obj.localisation = filter_obj.localisation.concat( response.data.list ); 1551 } 1552 }); 1553 }); 1554 } 1555 1556 //Get all id_tut 1557 var id_tut = filter_ids.id_tut.split('-'); 1558 id_tut.forEach(function(el, i) { 1559 ProfilFactory.params = {}; 1560 ProfilFactory.where('id_tut', el).getAll().then(function(response) { 1561 if ( response.data.count ) { 1562 filter_obj.profil = filter_obj.profil.concat( response.data.list ); 1563 } 1564 }); 1565 }); 1566 1567 //Get all id_typ 1568 var id_typ = filter_ids.id_typ.split('-');
1569 id_typ.forEach(function(el, i) { 1570 TypePretFactory.params = {}; 1571 TypePretFactory.where('id_typ', el).getAll().then(function(response) { 1572 if ( response.data.count ) { 1573 filter_obj.nature = filter_obj.nature.concat( response.data.list ); 1574 } 1575 }); 1576 }); 1577 1578 var couvertureList = { 1579 '1': { 1580 id: 1, 1581 libelle: 'Aides territoriales', 1582 }, 1583 '2': { 1584 id: 2, 1585 libelle: 'Aides nationales', 1586 }, 1587 '3': { 1588 id: 3, 1589 libelle: 'Aides européennes', 1590 }, 1591 }; 1592 var in_aid_critere = filter_ids.in_aid_critere.split('|'); 1593 in_aid_critere.forEach(function(el, i) { 1594 var field = el.split(','); 1595 if ( field[0] == 'couverture_geo' ) { 1596 field[1].split('-').forEach(function(el, i) { 1597 if ( couvertureList[el] ) { 1598 filter_obj.niveau.push( couvertureList[el] ); 1599 } 1600 }); 1601 } 1602 }); 1603 1604 }; 1605 1606 //Load list of filter from server 1607 var loadFilters = function( af_id ) { 1608 $scope.mesFiltres.filtres = []; 1609 // 1610 1611 FavoriCritereFactory.list(af_id).then(function(response) { 1612 if ( response.data.list.length ) { 1613 $scope.mesFiltres.hasFiltres = true; 1614 //Pour chaque filtre 1615 response.data.list.forEach(function(filtreIDs, i) { 1616 //Crée un nouvel objet filtre 1617 var filtreObj = { 1618 projet: [], 1619 localisation: [], 1620 profil: [], 1621 financeur: [], 1622 nature: [], 1623 niveau: [], 1624 }; 1625 $scope.mesFiltres.filtres.push( filtreObj ); 1626 1627 //hydrate new filters 1628 loadDataFilter( filtreIDs, filtreObj ); 1629 }); 1630 } 1631 }); 1632 }; 1633 1634 var afterLogin = function( user ) { 1635 if ( user ) { 1636 var af_id = user.af_id; 1637 localStorageService.set( 'ae_af_id', af_id ); 1638 $scope.mesFiltres.userLogged = true; 1639 switch ( $stateParams.slug ) { 1640 case 'mes-filtres': 1641 loadFilters(af_id); 1642 break; 1643 case 'ma-selection': 1644 loadMaSelection(af_id); 1645 break; 1646 } 1647 } 1648 }; 1649 1650 1651 $scope.loginForm.init(); 1652 var intro = '<p>« Ma sélection » permet :</p>' + 1653 '<p>- de <strong>sauvegarder</strong> vos critères de recherche en renseignant uniquement votre adresse e-mail;</p>' + 1654 '<p>- de <strong>conserver</strong> plusieurs filtres de recherche à la fois;</p>' + 1655 '<p>- de <strong>retrouver</strong> les résultats de votre recherche depuis n\'importe quel navigateur et à n\'importe quel moment en saisissant simplement l\'e-mail utilisé lors de la sauvegarde des critères ;</p>' + 1656 '<p>- de <strong>recevoir</strong> une notification par e-mail (push notification) à chaque nouveauté dâune recherche pré-enregistrée.</p>'; 1657 $scope.loginForm.intro = intro; 1658 $scope.loginForm.afterLogged = afterLogin; 1659 1660 1661 // -------------------------------------------------- 1662 // Initialisation 1663 // -------------------------------------------------- 1664 var af_id = localStorageService.get('ae_af_id'); 1665 if ( af_id ) { 1666 $scope.mesFiltres.userLogged = true; 1667 } 1668 switch ( $stateParams.slug ) { 1669 case 'mes-filtres': 1670 if ( $scope.mesFiltres.userLogged ) { 1671 loadFilters(af_id); 1672 } 1673 break; 1674 1675 case 'ma-selection': 1676 if ( $scope.mesFiltres.userLogged ) { 1677 loadMaSelection(af_id); 1678 } 1679 break; 1680 1681 default: 1682 // code 1683 } 1684 1685}]) 1686 1687 1688 1689.directive('target', function() { 1690 return { 1691 restrict: 'A', 1692 link: function($scope, element, attrs) { 1693 element.on('click', function(e) { 1694 var link = element.attr('href'); 1695 if ( link && $scope.targetModal ) { 1696 e.preventDefault(); 1697 $scope.targetModal.open(link,'_system','location=yes'); 1698 } 1699 }); 1700 } 1701 /*, 1702 controller: ['$scope', '$ionicModal', function($scope, $ionicModal) { 1703 $scope.targetModal = { 1704 modal: null, 1705 link: null, 1706 open: function(link) { 1707 var _this = this; 1708 _this.link = link; 1709 var template = '<ion-modal-view><ion-header-bar class="bar-positive" style="background-color: #0c3b65"><div class="buttons pull-right"><button class="button button-light button-clear" ng-click="targetModal.close()">Fermer</button></div></ion-header-bar>'; 1710 template += '<ion-content padding="false" style="padding: 0; top: 45px;" overflow-scroll="false" scroll="false"><iframe style="width: 100%;height: 100%" src="' + link + '"></iframe></ion-content>'; 1711 template += '</ion-modal-view>'; 1712 1713 _this.modal = $ionicModal.fromTemplate( template, { 1714 scope: $scope, 1715 animation: 'slide-in-up' 1716 }); 1717 _this.modal.show(); 1718 }, 1719 close: function() { 1720 if ( this.modal ) { 1721 this.modal.hide(); 1722 this.modal.remove(); 1723 this.modal = null; 1724 } 1725 }, 1726 }; 1727 $scope.$on('$destroy', function() { 1728 if ( $scope.targetModal.modal != null ) { 1729 $scope.targetModal.modal.remove(); 1730 $scope.targetModal.modal = null; 1731 } 1732 }); 1733 }] 1734 */ 1735 }; 1736}); 1737 1738
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.