1/* global jQuery, App */ 2(function ($) { 3 4 "use strict"; 5 6 App.obladyFicheidentity = App.DOMController.extend({ 7 rootElement: 'body', 8 originalClass: '', 9 $modalElement: null, 10 11 ajax: false, 12 chambersDatasForMap: null, 13 map: null, 14 mapBounds: null, 15 markers: [], 16 defaultZoom: 3, 17 markerInfoContent: null, 18 markerIconSize: null, 19 markerIconOff: null, 20 markerIconOn: null, 21 infowindow: null, 22 clickedMarker: null, 23 init: function () { 24 if ($('.section-search-chamber').length) { 25 this.searchChamberByAutocomplete(); 26 this.searchChamberByServices(); 27 } 28 29 this.mapLoad(); 30 }, 31 32 searchChamberByAutocomplete: function () { 33 // Code récupéré dans le fichier test.js des statics 34 var $field = $('.form-autocomplete .form-select'); 35 36 if ($field.length === 0) { 37 return; 38 } 39 40 $field.select2({ 41 dropdownPosition: 'below', 42 data: chambersData, 43 theme: 'autocomplete' 44 }); 45 46 $field.on('select2:select', function (event) { 47 window.location.href = event.params.data.url; 48 }); 49 }, 50 51 searchChamberByServices: function () { 52 $('#tab2').on('submit', '.form-search-room', $.proxy(function (e) { 53 e.preventDefault(); 54 55 var servicesId = $('.form-search-room .checkbox input:checkbox:checked').map(function () { 56 return this.value; 57 }).get(); 58 59 // S'il y a déjà une requête ajax lancée, annulation de celle-ci 60 if (this.ajax) { 61 this.ajax.abort(); 62 this.ajax = false; 63 } 64 65 this.ajax = $.ajax({ 66 url: searchChamberUrl, 67 type: "POST", 68 dataType: "html", 69 data: { 70 'value': JSON.stringify(servicesId) 71 } 72 }).done(function (data) { 73 $('#tab2 .page-search-results').html(data); 74 $.scrollTo('#tab2 .page-search-results'); 75 }); 76 }, this)); 77 }, 78 79 mapLoad: function () { 80 var container = document.getElementById('map-container'); 81 82 if (container === null || container === undefined) { 83 return; 84 } 85 86 this.chambersDatasForMap = chambersDatasForMapJson; 87 this.markerInfoContent = $.trim($('#map-info-container').html()); 88 $('#map-info-container').remove(); 89 90 google.maps.event.addDomListener(window, 'load', this.mapInitialize(container)); 91 92 $('.map-filters').on('change', 'select', $.proxy(function (e) { 93 this.updateMarkers(); 94 }, this)); 95 }, 96 97 mapInitialize: function (container) { 98 // map center 99 var center = new google.maps.LatLng(46.237802, 2.409439); 100 101 // options Map 102 var mapOptions = { 103 center: center, 104 zoom: this.defaultZoom, 105 scrollwheel: false, 106 mapTypeId: google.maps.MapTypeId.ROADMAP 107 }; 108 109 this.map = new google.maps.Map(container, mapOptions); 110 111 this.markerIconSize = new google.maps.Size(32, 32); 112 this.markerIconOff = { 113 url: window.location.origin + '/ext_oblady_ficheidentity/images/marker-off.png', 114 size: this.markerIconSize 115 }; 116 this.markerIconOn = { 117 url: window.location.origin + '/ext_oblady_ficheidentity/images/marker-on.png', 118 size: this.markerIconSize 119 }; 120 121 // A new Info Window is created and set content 122 this.infowindow = new SnazzyInfoWindow({ 123 map: this.map, 124 closeOnMapClick: true, 125 closeWhenOthersOpen: true 126 }); 127 128 this.updateMarkers(); 129 }, 130 131 updateMarkers: function () { 132 var that = this; 133 134 this.mapBounds = new google.maps.LatLngBounds(); 135 that.removeMarkers(); 136 137 $.each(that.chambersDatasForMap, function (key, chamber) { 138 if (!that.checkMapFilters(chamber)) { 139 return 140 } 141 142 // InfoWindow content 143 var content = that.markerInfoContent 144 .replace('|CHAMBER_TITLE|', chamber["ccifeName"] + ' : ' + chamber["ccifeTitle"]) 145 .replace('|CHAMBER_CREATION|', chamber["creationDate"]) 146 .replace('|CHAMBER_MEMBER|', chamber["membersNb"]) 147 .replace('|CHAMBER_COLLABORATOR|', chamber["collaboratorNb"]); 148 149 if (chamber["link"] != '') { 150 content = content.replace('|CHAMBER_LINK|', chamber["link"]); 151 } else { 152 content = content.replace(/<a class="btn btn-outline btn-secondary"[^]*?<\/a>/, ''); 153 } 154 155 if (chamber["incubators"] > 0) { 156 content = content.replace('|CHAMBER_INCUBATOR|', chamber["incubators"]); 157 if (chamber["incubators"] > 1) { 158 content = content.replace('|CHAMBER_TRANSLATE_INCUBATOR|', $(content).find('.incubator').data('translate-plural')); 159 } else { 160 content = content.replace('|CHAMBER_TRANSLATE_INCUBATOR|', $(content).find('.incubator').data('translate-single')); 161 } 162 } else { 163 content = content.replace(/<span class="incubator"[^]*?<\/span><br>/, ''); 164 } 165 166 if (chamber["workplaces"] > 0) { 167 content = content.replace('|CHAMBER_WORKPLACE|', chamber["workplaces"]); 168 if (chamber["workplaces"] > 1) { 169 content = content.replace('|CHAMBER_TRANSLATE_WORKPLACE|', $(content).find('.workplace').data('translate-plural')); 170 } else { 171 content = content.replace('|CHAMBER_TRANSLATE_WORKPLACE|', $(content).find('.workplace').data('translate-single')); 172 } 173 } else { 174 content = content.replace(/<span class="workplace"[^]*?<\/span><br>/, ''); 175 } 176 177 // marker position 178 var latLng = new google.maps.LatLng(chamber['latitude'], chamber['longitude']); 179 180 // marker options 181 var marker = new google.maps.Marker({ 182 position: latLng, 183 map: that.map, 184 title: chamber['ccifeName'] + ' : ' + chamber['ccifeTitle'], 185 icon: that.markerIconOff, 186 infowindowContent: content 187 }); 188 that.markers.push(marker); 189 that.mapBounds.extend(latLng); 190 191 // This event expects a click on a marker 192 // When this event is fired the Info Window is opened. 193 marker.addListener('click', function () { 194 that.clickedMarker && that.clickedMarker.setIcon(that.markerIconOff); 195 that.clickedMarker = this; 196 that.infowindow.setContent(this.infowindowContent); 197 that.infowindow.setPosition(this.getPosition()); 198 this.setIcon(that.markerIconOn); 199 that.infowindow.open(); 200 }); 201 }); 202 203 if (that.markers.length) { 204 that.map.fitBounds(that.mapBounds, 0); 205 } else { 206 that.map.setZoom(that.defaultZoom); 207 } 208 }, 209 210 removeMarkers: function () { 211 for (var i = 0; i < this.markers.length; i++) { 212 google.maps.event.clearInstanceListeners(this.markers[i]); 213 this.markers[i].setMap(null); 214 } 215 this.markers.length = 0; 216 }, 217 218 checkMapFilters: function (chamber) { 219 var currentSelectedContinent = $('#continentSelectForMap').val(); 220 var currentSelectedService = $('#serviceSelectForMap').val(); 221 222 if (currentSelectedContinent && currentSelectedContinent != '' && parseInt(currentSelectedContinent) != chamber['continent']) 223 return false;
224 if (currentSelectedService && currentSelectedService != '' && $.inArray(parseInt(currentSelectedService), chamber['services']) === -1) 225 return false; 226 227 return true 228 } 229 }); 230 231 App.registerController('App.obladyFicheidentity'); 232 233})(jQuery);
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.