var mobirise_swift = angular.module('Mobirise'); // Controller mobirise_swift.controller('MailAlertCtrl', function($scope,$http,$attrs,$window,$rootScope,$sce,vcRecaptchaService) { $scope.init = function() { console.info('Hello from MailAlertCtrl'); $scope.httpconfig = { headers:{ 'Authorization': 'Bearer ' + gJWT } }; $scope.recaptcha = { key: '6Ldt9zgUAAAAAGCDq_e98Ltxx_gk4Y-SwNs-34di', response:'' }; $scope.notificationsended = false; $scope.sending = false; $scope.btniconclass = 'fa-envelope'; $scope.btnclass = 'btn-primary'; $scope.btnmessage = 'Envoyer votre demande'; $scope.countrycode = ('swiftMailalertCountry' in $attrs) ? $attrs.swiftMailalertCountry.toUpperCase() : 'BE'; $scope.displaycountry = ('swiftMailalertDisplaycountry' in $attrs) ? ($attrs.swiftMailalertDisplaycountry == 'true') ? true : false : false; $scope.countries = null; $scope.countriesloaded = false; if ($scope.displaycountry) { $scope.loadCountries(); } $scope.contact = {}; $scope.request = {}; $scope.matchinggroups = [ { ID:0, properties:{ name:'Toutes', categories:'' } } ]; $scope.regions = [ { ID:0, properties:{ name:'Toutes', regions:'' } } ]; $scope.bednumbers = [ { number:1, name:'1' }, { number:2, name:'2' }, { number:3, name:'3' }, { number:4, name:'4' }, { number:5, name:'5' }, { number:10, name:'10' } ]; } $scope.loadMatchingGroups = function() { $scope.scrollYOffset = $window.pageYOffset; var url = 'https://keyrealestate.swiftimmo.eu/api/v1/fr/' + gDomainId + '/offer/categories'; // console.log(url); $http.get(url,$scope.httpconfig).then(function (success){ $scope.matchinggroups = $scope.matchinggroups.concat(success.data); }); }; $scope.loadRegions = function() { $scope.scrollYOffset = $window.pageYOffset; var url = 'https://keyrealestate.swiftimmo.eu/api/v1/fr/' + gDomainId + '/offer/regions'; // console.log(url); $http.get(url,$scope.httpconfig).then(function (success){ $scope.regions = $scope.regions.concat(success.data); }); }; $scope.loadCountries = function() { $http.get('https://keyrealestate.swiftimmo.eu/api/v1/fr/' + gDomainId + '/offer/countries',$scope.httpconfig) .then(function (response) { if (typeof(response.data.errors) == 'undefined') { $scope.countries = response.data; } $scope.countriesloaded = true; }); }; $scope.send = function($event) { console.log($scope.contact); console.log($scope.request); var config = { headers:{ 'Authorization': 'Bearer ' + gJWT } }; $scope.sending = true; $scope.btniconclass = 'fa-spinner fa-pulse'; // Send contact $http.post('https://keyrealestate.swiftimmo.eu/api/v1/notification', { type:'request', captcha:$scope.recaptcha.response, contact:$scope.contact, request:$scope.request },config).then(function (success){ if (typeof(success.data.success) == 'undefined' || success.data.success == false) { $scope.sending = false; $scope.btnclass = 'btn-danger'; $scope.btniconclass = 'fa-times'; $scope.btnmessage = "Erreur lors de l'envoi"; return; } $scope.notificationsended = true; $scope.sending = false; $scope.btnclass = 'btn-success'; $scope.btniconclass = 'fa-check'; $scope.btnmessage = $sce.trustAsHtml('Demande envoyée'); }); $event.preventDefault(); }; });