var PublicPluginNeedsMap=(function(){var _this=this;_this.FRONT_FILE_SIZE_ERROR='Przesłane zdjęcie przekracza dopuszczalny rozmiar, maksymalny rozmiar to '+Math.floor(($('input[name="MAX_FILE_SIZE"]').val()/(1024*1024)))+'MB';_this.params={config:null};_this.vars={map:null,list:null};_this.photo=null;_this.setConfig=function(config){_this.params.config=config;};_this.getConfig=function(name){return _this.params.config[name];};_this.getConfigAll=function(){return _this.params.config;};_this.setMap=function(map){_this.vars.map=map;};_this.getMap=function(){return _this.vars.map;};_this.setRequestUrl=function(url){_this.vars.requestUrl=url;};_this.getRequestUrl=function(){return _this.vars.requestUrl;};_this.unbindEvents=function(){$('body').off('plugin-needs-map-open-form');$('body').off('#needs-map-new-need');$('body').off('click','#need-map-geolocate');$('body').off('submit','#needs_map_add_form');$('.input-disabled').off('keydown paste');$('#needs_map_photo').off('change');$('#photo_show_preview').off('click');$('#photo_remove').off('click');};_this.init=function(config){_this.setRequestUrl(window.location.protocol+'//'+window.location.host+'/public/request.php');_this.setConfig(config);_this.bindEvents();_this.initMap();_this.initList();_this.getNeeds();if(_this.getConfig('recaptcha_sitekey')&&_this.getConfig('recaptcha_secretkey')) {_this.loadRecaptchaLib();} _this.checkGeolocation();};_this.bindEvents=function(){_this.unbindEvents();_this.bindOpenForm();_this.bindGeolocate();_this.bindSubmitForm();};_this.bindOpenForm=function(){$('body').on('plugin-needs-map-open-form',function(event,lat,lng){_this.clearForm();_this.openForm(lat,lng);});$('body').on('click','#needs-map-new-need',function(event){_this.clearForm();_this.openForm(null,null);});$('body').on('plugin-needs-map-form-on-map-click',function(event,lat,lng){if($('div#need-map-form').is(':visible')) {_this.openForm(lat,lng);}});};_this.bindGeolocate=function(){$('body').on('click','#need-map-geolocate',function(){var isIE=!!document.documentMode;var geolocationOptions={enableHighAccuracy:!isIE,timeout:5000,maximumAge:0};_this.getMap().geolocate(_this.setFormLatLng,_this.formSetAddress,_this.errorGeolocate,geolocationOptions);});};_this.bindSubmitForm=function(){$('body').on('submit','#needs_map_add_form',function(e){e.preventDefault();e.stopPropagation();_this.submitForm();});$('.input-disabled').on('keydown paste',function(e){e.preventDefault();e.stopPropagation();});$('#needs_map_photo').on('change',function(e){var previewContainer=$('#needs_map_photo_preview');if(this.files&&this.files[0]) {if(this.files[0].size>$('input[name="MAX_FILE_SIZE"]').val()) {e.preventDefault();e.stopPropagation();_this.removePhoto();$('.need_map_error_container').show().find('.error_content').html('
'+_this.FRONT_FILE_SIZE_ERROR+'
');$('div#need-map-form').scrollTop('0px');} else {var reader=new FileReader();reader.onload=function(e){previewContainer.find('#photo_preview_container').html(''+response.info+'
');_this.clearForm();if(typeof grecaptcha!='undefined') {grecaptcha.reset();} $('.need_map_error_container').fadeOut(3000,function(){_this.addNeed(response.need);_this.vars.list.sort('id',{order:'desc'});_this.hideForm();_this.showList();})}else{$('.need_map_error_container').show().find('.error_content').html(''+response.info+'
');if(typeof grecaptcha!='undefined') {grecaptcha.reset();}} $('div#need-map-form').scrollTop('0px');};_this.formSetAddress=function(address){$('#needs_map_street').val('');if(address.Address) {$('#needs_map_street').val(address.Address);} if(address.City&&!address.Neighborhood) {$('#needs_map_city').val(address.City);} if(address.Neighborhood) {$('#needs_map_city').val(address.Neighborhood);} if(address.Postal) {$('#needs_map_post').val(address.Postal);}};_this.clearForm=function(){$('#need-map-form input.clearable').val('');$('#need-map-form textarea.clearable').val('');$('#need-map-form .form-check-input').attr('checked',false);$("#need-map-form select").val($("#need-map-form select option:first").val());$('#needs_map_city').val(_this.getConfig('city'));_this.removePhoto();if(_this.getMap()) {_this.getMap().removeNewNeedMarker();}};_this.hideList=function(){$('#need-map-needs').hide();};_this.showList=function(){$('#need-map-needs').show();};_this.hideForm=function(){$('#need-map-form').hide();};_this.showForm=function(){$('#need-map-form').show();};_this.getFormAdress=function(){var address=$('#needs_map_street').val();if($('#needs_map_post').val()){address+=', '+$('#needs_map_post').val();} return address;};_this.setFormLatLng=function(lat,lng){$('#needs_map_lat').val(lat);$('#needs_map_lng').val(lng);$('#needs_map_lat_text').html(magellan(lat).latitude().toDMS());$('#needs_map_lng_text').html(magellan(lng).latitude().toDMS());};_this.errorGeolocate=function(message){alert(message);};_this.initList=function(){var options={valueNames:['id','date','category','address'],pagination:true,page:6,item:'