var mobirise_swift = angular.module('Mobirise'); // Controller mobirise_swift.controller('OfferDetailsCtrl', function($scope,$http,$attrs,$window,$rootScope,$timeout,$sce,$mdDialog,$filter) { $scope.init = function() { console.info('Hello from OfferDetailsCtrl'); $scope.offer = null; $scope.offerloaded = false; $scope.documents = []; $scope.mySwiper = new Swiper ('.swiper-container', { // Optional parameters pagination: '.swiper-pagination', paginationClickable: true, nextButton: '.swiper-button-next', prevButton: '.swiper-button-prev', spaceBetween: 30 }); if ($scope.mySwiper) { $scope.mySwiper.appendSlide('
'); } $scope.detailsproperties = [ {"key":"reference","name":"Référence","type":"string"}, {"key":"finance_price","name":"Prix","type":"price"}, {"key":"finance_cadastre","name":"Cadastre","type":"price"}, {"key":"finance_propertytax","name":"Taxe propriété","type":"price"}, {"key":"house_suphabi","name":"Surface habitable","type":"area"}, {"key":"house_supjardin","name":"Surface jardin","type":"area"}, {"key":"house_supterrace","name":"Superficie terrasse","type":"area"}, {"key":"house_supsol","name":"Surface au sol","type":"area"}, {"key":"building_groundarea","name":"Superficie du terrain","type":"area"}, {"key":"house_bednumber","name":"Chambre(s)","type":"number"}, {"key":"house_douchenumber","name":"Douche(s)","type":"number"}, {"key":"house_sdbnumber","name":"Salle(s) de bain","type":"number"}, {"key":"house_caves","name":"Cave(s)","type":"number"}, {"key":"house_category","name":"Catégories","type":"string"}, {"key":"house_internalstate","name":"Etat","type":"string"}, {"key":"house_kitchentype","name":"Cuisine","type":"string"}, {"key":"house_heatnature","name":"Chauffage","type":"string"}, {"key":"building_buildingyear","name":"Année de construction","type":"string"}, {"key":"building_levels","name":"Nbr de niveaux","type":"number"}, {"key":"building_faces","name":"Nbr de façades","type":"number"}, {"key":"building_renovationyear","name":"Année de rénovation","type":"string"}, {"key":"details_office","name":"Bureau","type":"boolean"}, {"key":"details_lift","name":"Ascenseur","type":"boolean"}, {"key":"details_teledis","name":"Télédistribution","type":"boolean"}, {"key":"details_terrace","name":"Terrasse","type":"boolean"}, {"key":"details_alarm","name":"Alarme","type":"boolean"}, {"key":"details_laundry","name":"Buanderie","type":"boolean"}, {"key":"details_interphone","name":"Interphone","type":"boolean"}, {"key":"details_pool","name":"Piscine","type":"boolean"}, {"key":"details_internet","name":"Connexion internet","type":"boolean"}, {"key":"field_sewer","name":"Egout","type":"boolean"}, {"key":"field_water","name":"Eau","type":"boolean"}, {"key":"field_electricity","name":"Electricité","type":"boolean"}, {"key":"field_gaz","name":"Gaz","type":"boolean"}, {"key":"field_cabletv","name":"Cable TV","type":"boolean"}, {"key":"field_phone","name":"Ligne téléphonique","type":"boolean"} ]; $scope.nearproperties = [ {"key":"details_nearschool","name":"Proximité école","distance":"details_nearschool_distance","type":"boolean"}, {"key":"details_nearshop","name":"Proximité commerce","distance":"details_nearshop_distance","type":"boolean"}, {"key":"details_neartrain","name":"Proximité train","distance":"details_neartrain_distance","type":"boolean"}, {"key":"details_nearmetro","name":"Proximité métro","distance":"details_nearmetro_distance","type":"boolean"}, {"key":"details_neartram","name":"Proximité tram","distance":"details_neartram_distance","type":"boolean"}, {"key":"details_nearbus","name":"Proximité bus","distance":"details_nearbus_distance","type":"boolean"}, {"key":"details_nearrer","name":"Proximité RER","distance":"details_nearrer_distance","type":"boolean"} ]; $scope.energyproperties = [ {"key":"details_energyperf","name":"Consommation spécifique","type":"number","suffix":"kWh/m²/an"}, {"key":"details_energycertnumber","name":"Certificat énergétique","type":"string"}, {"key":"details_energyperftotal","name":"Consommation totale","type":"number","suffix":"kWh/an"} ]; $scope.pebpositions = { 'wal':{ 'a++':{"top":"1px"}, 'a+':{"top":"33px"}, 'a':{"top":"64px"}, 'b':{"top":"96px"}, 'c':{"top":"127px"}, 'd':{"top":"158px"}, 'e':{"top":"189px"}, 'f':{"top":"221px"}, 'g':{"top":"251px"} }, 'bxl':{ 'a++':{"top":"33px"}, 'a+':{"top":"33px"}, 'a':{"top":"33px"}, 'a-':{"top":"33px"}, 'b+':{"top":"64px"}, 'b':{"top":"64px"}, 'b-':{"top":"64px"}, 'c+':{"top":"96px"}, 'c':{"top":"96px"}, 'c-':{"top":"96px"}, 'd+':{"top":"127px"}, 'd':{"top":"127px"}, 'd-':{"top":"127px"}, 'e+':{"top":"158px"}, 'e':{"top":"158px"}, 'e-':{"top":"158px"}, 'f':{"top":"188px"}, 'g':{"top":"219px"} }, 'fla':{ leftmin:226.0, leftmax:-44.0, 'a+':{"left":"210px"}, 'a':{"left":"173px"}, 'b':{"left":"135px"}, 'c':{"left":"97px"}, 'd':{"left":"59px"}, 'e':{"left":"21px"}, 'f':{"left":"-16px"} } }; $scope.pebcolors = { 'wal':{ '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"} }, 'bxl':{ 'a++':{"fill":"#249e3b"}, 'a+':{"fill":"#249e3b"}, 'a':{"fill":"#249e3b"}, 'a-':{"fill":"#249e3b"}, 'b+':{"fill":"#5ab43b"}, 'b':{"fill":"#5ab43b"}, 'b-':{"fill":"#5ab43b"}, 'c+':{"fill":"#83bf2d"}, 'c':{"fill":"#83bf2d"}, 'c-':{"fill":"#83bf2d"}, 'd+':{"fill":"#fbdc2c"}, 'd':{"fill":"#fbdc2c"}, 'd-':{"fill":"#fbdc2c"}, 'e+':{"fill":"#ed9a29"}, 'e':{"fill":"#ed9a29"}, 'e-':{"fill":"#ed9a29"}, 'f':{"fill":"#e66628"}, 'g':{"fill":"#df132a"} }, 'fla':{ 'a+':{"fill":"#278235"}, 'a':{"fill":"#529f34"}, 'b':{"fill":"#d0d100"}, 'c':{"fill":"#f6d700"}, 'd':{"fill":"#fbba3d"}, 'e':{"fill":"#ef7921"}, 'f':{"fill":"#dd3231"} } }; console.log('init pebcolors : ',$scope.pebcolors['wal']['b']); $scope.pebtables = { 'wal':{ '0|0':'a++', '1|45':'a+', '46|85':'a', '86|170':'b', '171|255':'c', '256|340':'d', '341|425':'e', '426|510':'f', '511|9999':'g' }, 'fla':{ '-100|0':'a+', '1|100':'a', '101|200':'b', '201|300':'c', '301|400':'d', '401|500':'e', '501|9999':'f' }, 'bxl':{ '-9999|-1':'a++', '0|15':'a+', '16|30':'a', '31|45':'a-', '46|62':'b+', '63|78':'b', '79|95':'b-', '96|113':'c+', '114|132':'c', '133|150':'c-', '151|170':'d+', '171|190':'d', '191|210':'d-', '211|232':'e+', '233|253':'e', '254|275':'e-', '276|345':'f', '346|9999':'g' } }; $scope.details = []; $scope.energydetails = []; $scope.displayenergy = false; $scope.showextdescription = false; $scope.pebscore = ''; $scope.peblabel = ''; $scope.pebgraphtype = ''; $scope.displayprintbutton = ('printButton' in $attrs) ? ($attrs.printButton == 'true') ? true : false : false; $scope.displaysendtofriendbutton = ('sendtofriendButton' in $attrs) ? ($attrs.sendtofriendButton == 'true') ? true : false : false; $scope.displaysendmessagebutton = ('sendmessageButton' in $attrs) ? ($attrs.sendmessageButton == 'false') ? false : true : true; $scope.displayyoutubevisvir = ('displayyoutubevisvir' in $attrs) ? ($attrs.displayyoutubevisvir == 'true') ? true : false : false; $scope.displayyoutube = false; $scope.displaydocument = ('displaydocument' in $attrs) ? ($attrs.displaydocument == 'true') ? true : false : false; $scope.youtubevideoid = ''; if ($scope.hidemap) { $scope.hideGoogleMap(); } $scope.delegates = { 'AFE':{ photo:'assets/images/anthony-ferronato-500x500.jpg', email:'anthony@logissim.be', phone:'065/61.05.65' }, 'BBE':{ photo:'assets/images/berengere-beriot-500x500.jpg', email:'berengere@logissim.be', phone:'065/61.05.65' }, 'JMH':{ photo:'assets/images/jean-marie-haubourdin-500x500.jpg', email:'jean-marie@logissim.be', phone:'065/61.05.65' }, 'GH':{ photo:'assets/images/guillaume-haubourdin-500x500.jpg', email:'guillaume@logissim.be', phone:'065/61.05.65' }, 'FTO':{ photo:'assets/images/frederic-tonneau-500x500.jpg', email:'frederic@logissim.be', phone:'065/61.05.65' }, 'VCO':{ photo:'assets/images/vincent-coulon-500x500.jpg', email:'vincent@logissim.be', phone:'065/61.05.65' }, 'AGE':{ photo:'assets/images/logo-logissim.jpg', email:'contact@logissim.be', phone:'065/61.05.65' }, 'JOM':{ photo:'assets/images/jose-mafrici-500x500.jpg', email:'jose@logissim.be', phone:'065/61.05.65' } }; $scope.willdisplaydelegate = ('displayDelegate' in $attrs) ? ($attrs.displayDelegate == 'true') ? true : false : false; $scope.delegatephoto = ''; $scope.delegateemail = ''; $scope.delegatephone = ''; $scope.delegate = undefined; $scope.displaydelegate = false; $scope.loadOffer('{offer::id}',800,600); }; $scope.hideGoogleMap = function() { var iframecontainer = 'google-map'; $('.' + iframecontainer).prepend('
'); $('.google-map-hide').load('assets-mobirise/app/views/mapaccess.tmpl.html',function(){ console.log($('.offer_mapaccess').find('button')); $('.offer_mapaccess').find('button').click(function(){ console.log('unlock'); var config = { headers:{ 'Authorization': 'Bearer ' + gJWT } }; // Send contact var contact = { type:'contact', firstname:$('.offer_mapaccess').find('#firstname').val(), lastname:$('.offer_mapaccess').find('#lastname').val(), phone:$('.offer_mapaccess').find('#phone').val(), email:$('.offer_mapaccess').find('#email').val(), note:'map unlock' }; $http.post('https://www.lorge.be/api/v1/notification', { type:'contact', contact:contact, offer:$scope.offer },config).then(function (success){ // Remove contact form $('.google-map-hide').hide(); $scope.setGoogleMap(); }); }); }); } $scope.loadOffer = function(offerid,photowidth,photoheight) { console.log('load offer id ' + offerid); var config = { headers:{ 'Authorization': 'Bearer ' + gJWT } }; var url = 'https://www.lorge.be/api/v1/fr/' + gDomainId + '/offer/' + offerid + '?photowidth=' + photowidth + '&photoheight=' + photoheight + '&dataset=website'; $http.get(url,config).then(function (success){ $scope.offer = success.data; if (typeof($scope.offer.properties.desc_extended) != 'undefined' && $scope.offer.properties.desc_extended !== null) { var desc = $scope.offer.properties.desc_extended; $scope.offer.properties.desc_extended = $sce.trustAsHtml(desc.replace(/\n/g,"
")); } if (typeof($scope.offer.properties.desc_simple) != 'undefined' && $scope.offer.properties.desc_simple !== null) { var desc = $scope.offer.properties.desc_simple; $scope.offer.properties.desc_simple = $sce.trustAsHtml(desc.replace(/\n/g,"
")); } if (typeof($scope.offer.properties.desc_note) != 'undefined' && $scope.offer.properties.desc_note !== null) { var desc = $scope.offer.properties.desc_note; $scope.offer.properties.desc_note = $sce.trustAsHtml(desc.replace(/\n/g,"
")); } if (typeof($scope.offer.properties.desc_window) != 'undefined' && $scope.offer.properties.desc_window !== null) { var desc = $scope.offer.properties.desc_window; $scope.offer.properties.desc_window = $sce.trustAsHtml(desc.replace(/\n/g,"
")); } // Order properties to display in details $scope.details = []; for (var i=0;i<$scope.detailsproperties.length;i++) { var prop = $scope.detailsproperties[i]; var propname = prop.name; var propkey = prop.key; var propsuffix = (typeof(prop.suffix) != 'undefined') ? prop.suffix : ''; var propvalue = $scope.getPropValue(prop); if (propvalue !== null) { $scope.details.push({ name:propname, value:propvalue }); } } // Distance details for (var i=0;i<$scope.nearproperties.length;i++) { var prop = $scope.nearproperties[i]; var propname = prop.name; var propkey = prop.key; var propdistance = prop.distance; var propsuffix = (typeof(prop.suffix) != 'undefined') ? prop.suffix : ''; var propvalue = $scope.getPropValue(prop); if (propvalue !== null) { if (typeof($scope.offer.properties[propdistance]) != 'undefined' && $scope.offer.properties[propdistance] !== null && $scope.offer.properties[propdistance].length != 0) { propvalue = $scope.offer.properties[propdistance] + ' m'; } $scope.details.push({ name:propname, value:propvalue }); } } // Energy details $scope.energydetails = []; for (var i=0;i<$scope.energyproperties.length;i++) { var prop = $scope.energyproperties[i]; var propname = prop.name; var propkey = prop.key; var propsuffix = (typeof(prop.suffix) != 'undefined') ? prop.suffix : ''; var propvalue = $scope.getPropValue(prop); if (propvalue !== null) { $scope.displayenergy = true; $scope.energydetails.push({ name:propname, value:propvalue }); } } $scope.pebgraphtype = $scope.getPEBGraphType(); $scope.pebscore = $scope.offer.properties.details_energyperf; if ($scope.pebgraphtype == 'fla' || $scope.pebgraphtype == 'bxl') { // Calculate peb label $scope.peblabel = $scope.getPEBLabel($scope.pebgraphtype,parseInt($scope.pebscore)); } else { $scope.peblabel = $scope.offer.properties.cache_epclabel.toLowerCase(); } $scope.offerloaded = true; $scope.setPhotos(); // Check delegate if ($scope.willdisplaydelegate && typeof($scope.offer.delegates) != 'undefined' && $scope.offer.delegates.length != 0) { var delegatetodisplay = $scope.delegates[$scope.offer.properties.cache_delegateinitials]; $scope.delegatephoto = delegatetodisplay.photo; $scope.delegateemail = delegatetodisplay.email; $scope.delegatephone = delegatetodisplay.phone; $scope.delegate = $scope.offer.delegates[0].delegate; $scope.displaydelegate = true; } // Check display youtube visvir if ($scope.displayyoutubevisvir == true && typeof($scope.offer.properties.visvir) !== 'undefined' && $scope.offer.properties.visvir.length !== 0) { if ($scope.offer.properties.visvir.indexOf('www.youtube.com') !== -1) { // Extract youtube video id var urlparts = $scope.offer.properties.visvir.split('?'); // console.log(urlparts); if (urlparts.length == 2) { var params = urlparts[1].split('&'); // console.log(params); for (var i=0;i= min && pebvalue <= max) { return peblabel; } } return ''; } $scope.getPropValue = function(prop) { var propkey = prop.key; var propsuffix = (typeof(prop.suffix) != 'undefined') ? prop.suffix : ''; var propvalue = $scope.offer.properties[propkey]; if (typeof(propvalue) != 'undefined' && propvalue != null && propvalue.length != 0 && propvalue != '0') { switch(prop.type) { case 'price': propvalue = $filter('price')(propvalue); break; case 'area': propvalue = $filter('area')(propvalue); break; case 'boolean': { if (propvalue.toLowerCase() == 'yes') { propvalue = 'Oui'; } else { propvalue = null; } } break; } if (propvalue !== null) { if (propsuffix.length != 0) { propvalue = propvalue + ' ' + propsuffix; } } } else { propvalue = null; } return propvalue; } $scope.setPhotos = function() { $timeout(function() { for (var i=0;i<$scope.offer.photos.length;i++) { var photo = $scope.offer.photos[i]; if (i == 0) { $scope.mySwiper.prependSlide('
'); $scope.mySwiper.removeSlide(1); } else { $scope.mySwiper.appendSlide('
'); } } }, 100); } $scope.contactCtrl = function($scope, $mdDialog, offer) { $scope.offer = offer; $scope.contact = { type:'contact' }; $scope.cancel = function() { $mdDialog.cancel(); }; $scope.send = function() { console.log($scope.contact); $mdDialog.hide( { offer:$scope.offer, contact:$scope.contact }); } }; $scope.showContact = function(ev) { if ($scope.offer == null) { return; } var confirm = $mdDialog.show({ controller: $scope.contactCtrl, templateUrl: 'https://www.lorge.be/assets-mobirise/app/views/contactdialog.tmpl.html', parent: angular.element(document.body), targetEvent: ev, locals:{ offer:$scope.offer } }) .then(function(result) { console.log(result.offer); console.log(result.contact); var config = { headers:{ 'Authorization': 'Bearer ' + gJWT } }; // Send contact $http.post('https://www.lorge.be/api/v1/notification', { type:'contact', contact:result.contact, offer:result.offer },config).then(function (success){ console.log(success); }); }, function() { console.info('canceled'); }); } $scope.showVisVir = function() { window.open($scope.offer.properties.visvir,'_blank'); } $scope.printOffer = function() { window.open('offer_print.html?context=offerid;' + $scope.offer.ID,'_blank',"width=880"); } $scope.pebcolor = function() { if ($scope.offer === null || $scope.offer.properties.cache_epclabel.length == 0) { return null; } var regioncolors = $scope.pebcolors[$scope.pebgraphtype]; var thepebcolor = regioncolors[$scope.peblabel]; console.log(regioncolors); console.log('pebcolor : ',thepebcolor); return thepebcolor; } $scope.pebcursorposition = function() { if ($scope.offer === null || $scope.offer.properties.cache_epclabel.length == 0 || $scope.pebgraphtype.length == 0) { return null; } switch($scope.pebgraphtype) { case 'wal': case 'bxl': return $scope.pebpositions[$scope.pebgraphtype][$scope.peblabel]; break; case 'fla': { var score = parseFloat($scope.pebscore); if (score > 600) { score = 600; } var min = $scope.pebpositions['fla']['leftmin']; var max = $scope.pebpositions['fla']['leftmax']; var leftstep = (max - min) / 600; var leftoffset = min + parseInt(leftstep * score); return {"left":leftoffset + "px"}; } break; } return ''; } $scope.pebelementstyle = function() { if ($scope.offer === null || $scope.offer.properties.cache_epclabel.length == 0 || $scope.pebgraphtype.length == 0) { return null; } var color = $scope.pebcolors[$scope.pebgraphtype][$scope.peblabel.toLowerCase()]; var position = $scope.pebpositions[$scope.pebgraphtype][$scope.peblabel.toLowerCase()]; console.log('pebelementstyle',color,position); return Object.assign({},color,position); } $scope.setGoogleMap = function() { var iframecontainer = 'google-map'; var mapapikey = 'AIzaSyA0Dx_boXQiwvdz8sJHoYeZNVTdoWONYkU'; var offeraddress = ''; if ($scope.offer.properties.address_publish.toLowerCase() == 'yes') { offeraddress = $scope.offer.properties.addresse_number + ' ' + $scope.offer.properties.address + ', ' + $scope.offer.properties.city + ', ' + $scope.offer.properties.country; } else { offeraddress = $scope.offer.properties.city + ', ' + $scope.offer.properties.country; } if (offeraddress.length != 0) { var mapurl = 'https://www.google.com/maps/embed/v1/search?key=' + mapapikey + '&q=' + encodeURIComponent(offeraddress); var iframeel = $('.' + iframecontainer + ' > iframe'); if (iframeel) { iframeel.attr('src',mapurl); } } } });