var mobirise_swift = angular.module('Mobirise'); // Controller mobirise_swift.controller('OfferGroupsCtrl', function($scope,$http,$attrs,$sce,$rootScope,$timeout) { $scope.init = function() { console.info('Hello from OfferGroupsCtrl'); $scope.httpconfig = { headers:{ 'Authorization': 'Bearer ' + gJWT } }; $scope.displayyoutubevisvir = ('displayyoutubevisvir' in $attrs) ? ($attrs.displayyoutubevisvir == 'true') ? true : false : false; $scope.displayoffers = ('displayoffers' in $attrs) ? ($attrs.displayoffers == 'true') ? true : false : false; $scope.offergroups = []; $scope.swipers = {}; $scope.loadGroups(800,600); }; $scope.loadGroups = function(photowidth,photoheight) { $scope.loadingbusy = true; var url = 'https://keyrealestate.swiftimmo.eu/api/v1/fr/' + gDomainId + '/offergroup?photowidth=' + photowidth + '&photoheight=' + photoheight; //console.log(url); $http.get(url,$scope.httpconfig).then(function (response){ //console.log(success); $scope.loadingbusy = false; if (typeof(response.data.errors) == 'undefined') { $scope.offergroups = response.data; } $timeout(function(){ $scope.offergroups.forEach(function(group){ $scope.buildSwipers(group.ID); $scope.checkVisvir(group); }); $scope.setPhotos(); },100); }); }; $scope.buildSwipers = function(swiperid) { var mySwiper = new Swiper ('#swiper-container-' + swiperid, { // Optional parameters pagination: '#swiper-pagination-' + swiperid, paginationClickable: true, nextButton: '#swiper-button-next-' + swiperid, prevButton: '#swiper-button-prev-' + swiperid, spaceBetween: 30 }); mySwiper.appendSlide('
'); $scope.swipers[swiperid] = mySwiper; }; $scope.setPhotos = function() { $timeout(function() { $scope.offergroups.forEach(function(group){ var swiper = $scope.swipers[group.ID]; for (var i=0;i'); swiper.removeSlide(1); } else { swiper.appendSlide('
'); } } $scope.loadGroupOffers(group); }); }, 100); }; $scope.loadGroupOffers = function(group) { $scope.loadingbusy = true; var url = 'https://keyrealestate.swiftimmo.eu/api/v1/fr/' + gDomainId + '/offergroup/' + group.ID + '/offer'; console.log(url); $http.get(url,$scope.httpconfig).then(function (response){ //console.log(success); $scope.loadingbusy = false; if (typeof(response.data.errors) == 'undefined') { group.offers = response.data; } }); }; $scope.checkVisvir = function(offer) { offer.properties.is_externallink = false; offer.properties.is_youtubelink = false; offer.properties.youtubelink = $sce.getTrustedResourceUrl(''); // Check display youtube visvir if (typeof(offer.properties.visvir) !== 'undefined' && offer.properties.visvir !== null && offer.properties.visvir.length !== 0) { if (offer.properties.visvir.indexOf('www.youtube.com') !== -1) { // Extract youtube video id var urlparts = offer.properties.visvir.split('?'); // console.log(urlparts); if (urlparts.length == 2) { var params = urlparts[1].split('&'); // console.log(params); for (var i=0;i