var mobirise_swift = angular.module('Mobirise'); // Controller mobirise_swift.controller('OfferGridCtrl', function($scope,$http,$attrs,$sce,$rootScope,$timeout) { $scope.init = function() { // console.info('Hello from OfferGridCtrl'); $scope.httpconfig = { headers:{ 'Authorization': 'Bearer ' + gJWT } }; $scope.pebcolors = { 'a++':{"background-color":"#1B9DD9"}, 'a+':{"background-color":"#058738"}, 'a':{"background-color":"#0BA546"}, 'b':{"background-color":"#72B743"}, 'c':{"background-color":"#CFD723"}, 'd':{"background-color":"#EAE21C"}, 'e':{"background-color":"#FEC708"}, 'f':{"background-color":"#F59C2D"}, 'g':{"background-color":"#E20D18"}, }; $scope.stickersStyles = { 'loue':{ text:'LOUE', style:{'color':'#FFFFFF','background-color':'#77c04e'}, }, 'mois':{ text:'BIEN DU MOIS', style:{'color':'#FFF','background-color':'#e005fa'}, }, 'nouveauprix':{ text:'NOUVEAU PRIX', style:{'color':'#0562fd','background-color':'#f0ad00'}, }, 'vendu':{ text:'VENDU', style:{'color':'#FFFFFF','background-color':'#fa0516'}, }, 'exclu':{ text:'EXCLUSIVITE', style:{'color':'#FFFFFF','background-color':'#0578fa'}, }, 'optionvignette':{ text:'OPTION', style:{'color':'#FFFFFF','background-color':'#77c04e'}, }, 'option':{ text:'OPTION', style:{'color':'#FFFFFF','background-color':'#f0ad00'}, }, 'nouveau':{ text:'NOUVEAU', style:{'color':'#FFF','background-color':'#77c04e'}, } }; $scope.showsticker = ('showsticker' in $attrs) ? ($attrs.showsticker == 'true') ? true : false : true; $scope.showstatus = ('showstatus' in $attrs) ? ($attrs.showstatus == 'true') ? true : false : false; $scope.boughtclick = ('boughtclick' in $attrs) ? ($attrs.boughtclick == 'true') ? true : false : true; // console.log($attrs); $scope.gridwidth = ('swiftGridWidth' in $attrs) ? parseInt($attrs.swiftGridWidth) : 1; $scope.gridheight = ('swiftGridHeight' in $attrs) ? parseInt($attrs.swiftGridHeight) : 1; $scope.gridcontentcount = $scope.gridwidth * $scope.gridheight; $scope.gridoffset = 0; $scope.endofgrid = false; $scope.gridrowindex = 0; $scope.type = ('swiftGridType' in $attrs) ? $attrs.swiftGridType : 'Vente'; $scope.publish = ('swiftGridActive' in $attrs) ? ($attrs.swiftGridActive == 'true') ? 'Yes' : 'No' : null; $scope.bought = ('swiftGridSold' in $attrs) ? ($attrs.swiftGridSold == 'true') ? 'Yes' : 'No' : null; $scope.displayhome = ('swiftGridDisplayHome' in $attrs) ? ($attrs.swiftGridDisplayHome == 'true') ? 'Yes' : 'No' : null; $scope.icons = ('swiftGridIcons' in $attrs) ? ($attrs.swiftGridIcons == 'true') ? true : false : false; $scope.upperprice = 10000000; $scope.lowerprice = 0; $scope.matchinggroup = 0; $scope.region = 0; $scope.initCountries(); $scope.initStatus(); $scope.orderby = ('swiftGridOrderby' in $attrs) ? $attrs.swiftGridOrderby : 'finance_price'; $scope.statuses = ('swiftStatus' in $attrs) ? $attrs.swiftStatus : null; // console.log($attrs); // console.log($scope.orderby); $scope.infinitescroll = ('swiftGridInfiniteScroll' in $attrs) ? ($attrs.swiftGridInfiniteScroll == 'false') ? false : true : true; $scope.autoload = ('swiftGridAutoload' in $attrs) ? ($attrs.swiftGridAutoload == 'true') ? true : false : false; $scope.displayyoutubevisvir = ('displayyoutubevisvir' in $attrs) ? ($attrs.displayyoutubevisvir == 'true') ? true : false : false; $scope.firstsearch = false; $scope.offersdata = []; // Register rootScope events $scope.searchEvtFct = $rootScope.$on('search',function(event,args){ // console.log('search event'); $scope.firstsearch = false; $scope.type = args.type; $scope.upperprice = args.pricerange.upper; $scope.lowerprice = args.pricerange.lower; $scope.matchinggroup = args.group; $scope.region = args.region; $scope.searchOffer(); }); $scope.$on('$destroy',function(){ $scope.searchEvtFct(); }); // Infinite scroll $scope.loadingbusy = false; // Autoload if ($scope.autoload === true) { $timeout(function(){ $scope.loadOffers(); },200); } }; $scope.initCountries = function() { $scope.countries = null; $scope.countriesloaded = false; $scope.countrycode = ('swiftGridCountry' in $attrs) ? $attrs.swiftGridCountry.toUpperCase() : ''; $scope.notcountry = false; if ($scope.countrycode.length > 0 && $scope.countrycode.charAt(0) == '!') { $scope.notcountry = true; $scope.countrycode = $scope.countrycode.substr(1); } $scope.countryid = 0; if ($scope.countrycode.length != 0) { $scope.loadCountries(); } else { $scope.countriesloaded = true; } } $scope.initStatus = function() { $scope.status = []; $scope.statusloaded = false; $scope.statusnamelist = ('swiftGridStatus' in $attrs) ? $attrs.swiftGridStatus.toUpperCase() : ''; if ($scope.statusnamelist.length != 0 || $scope.statuses !== null) { $scope.loadStatus(); } else { $scope.statusloaded = true; } } $scope.statusList = function() { if ($scope.statusnamelist.length == 0) { return ''; } var thelist = ''; var first = true; var statusnames = $scope.statusnamelist.split(','); for(var j=0;j#' + ($scope.lowerprice - 1); if ($scope.matchinggroup != 0) { query += '&cache_matchinggroup=' + $scope.matchinggroup; } if ($scope.region != 0) { query += '&cache_matchingregion~' + $scope.region; } if ($scope.countryid != 0) { // console.log('add country to search filter ' + $scope.countryid); if ($scope.notcountry) { query += '&country!' + $scope.countryid; } else { query += '&country=' + $scope.countryid; } } if ($scope.statuses !== null) { // Get status id $statusid = $scope.statusByName($scope.statuses); if ($statusid !== null) { query += '|status=' + $statusid; } } query += ')$SNItem.SNOffer('; var firstorderby = true; if ($scope.orderby.length != 0) { var orderbylist = $scope.orderby.split(','); for (var i=0;i' + limit + ')'; var url = 'https://keyrealestate.swiftimmo.eu/api/v1/fr/' + gDomainId + '/offer/search?oquery=' + encodeURIComponent(query) + '&dataset=website'; //console.log(url); $http.get(url,$scope.httpconfig).then(function (success){ // cut response by gridwidth //console.log(success); for (var i=0;i