Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 49 additions & 6 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function boot(): void

Carbon::setLocale('app.locale');
\View::composer(
['event.add', 'event.search', 'profile', 'event.edit'],
['event.add', 'event.search', 'event.edit'],
function ($view) {
$audiences = \App\Audience::all()->map(function ($audience) {
$audience->name = __('event.audience.' . $audience->name);
Expand All @@ -57,17 +57,60 @@ function ($view) {
$view->with('languages', Arr::sort(Lang::get('base.languages')));
$view->with('active_countries', $activeCountries);
$view->with('themes', $themes);
}
);

$cities = \App\City::query()
->whereIn('country_iso', $activeCountries->pluck('iso'))
\View::composer(['community', 'profile'], function ($view) {
$supportedCountries = [
'GR',
'CY',
'MT',
'IT',
'BG',
'TR',
'UA',
'PL',
'IE',
'FR',
'LU',
'NL',
'BE',
'SK',
'CZ',
'NO',
'IS',
'FI',
'SE',
'PT',
'ES',
'LV',
'LT',
'HR',
'SI',
'DE',
'AT',
'CH',
'RO',
'MD',
'DK',
];

$activeCountries = \App\Country::query()
->whereIn('iso', $supportedCountries)
->orderBy('name')
->get();

$cities = \App\City::query()
->whereIn('country_iso', $supportedCountries)
->select(['id', 'city', 'country_iso'])
->orderBy('country_iso')
->orderBy('city')
->get();

$view->with('cities', $cities);
}
);
$view->with('cities', $cities);
$view->with('active_countries', $activeCountries);
$view->with('supportedCountries', $supportedCountries);
});

\View::composer(['stats'], function ($view) {
$view->with('active_countries', \App\Country::withEvents());
Expand Down
71 changes: 46 additions & 25 deletions public/js/ext/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2135,38 +2135,59 @@ var SEMICOLON = SEMICOLON || {};
var $country = $('#id_country');
var $city = $('#id_city');
if (!$country.length || !$city.length) return;

if (!$city.data('originalHtml')) {
$city.data('originalHtml', $city.html());
}

// cache once per current DOM
if (!$city.data('originalOptions')) {
$city.data('originalOptions', $city.find('option').clone());
$city.data('emptyOption', $city.find('option').first().clone());
function getAllOptions() {
var html = $city.data('originalHtml') || '';
var $tmp = $('<select>' + html + '</select>');
return $tmp.find('option');
}

function applyCityFilter() {
var iso = $country.val() || '';
var prev = $city.val();
var $original = $city.data('originalOptions');
var $empty = $city.data('emptyOption').clone();

var $next = [$empty.get(0)];
if (iso) {
$original.each(function (i, opt) {
if (i === 0) return; // keep first for empty
var $opt = $(opt);
if ($opt.attr('data-country') === iso) $next.push(opt);
var iso = ($country.val() || '').toUpperCase();
var prev = $city.val();
var $all = getAllOptions();

if (!iso) {
$city.html($all.clone());
if ($city.find('option[value="'+ prev +'"]').length) $city.val(prev);
return;
}

var $empty = $all.first().clone();
var $filtered = $all.filter(function (i, opt) {
if (i === 0) return false;
var dc = (opt.getAttribute('data-country') || '').toUpperCase();
return dc === iso;
});
}
$city.empty().append($next);

// restore previous if still valid
if ($next.some(function(o){ return o.value === prev; })) {
$city.val(prev);
} else {
$city.val('');
}

$city.empty().append($empty).append($filtered.clone());

if ($city.find('option[value="'+ prev +'"]').length) {
$city.val(prev);
} else {
$city.val(''); // reset
}
}

(function autoSelectCountryFromCity() {
if ($country.val()) return;
var $sel = getAllOptions().filter(function(i, opt){
return opt.value && opt.selected;
}).first();
if ($sel.length) {
var dc = ($sel.attr('data-country') || '').toUpperCase();
if (dc) {
var $opt = $country.find('option[value="'+ dc +'"]');
if ($opt.length) $country.val(dc);
}
}
})();

// bind once per render
// bind & run
$country.off('change.cityfilter').on('change.cityfilter', applyCityFilter);
applyCityFilter();
},
Expand Down
33 changes: 0 additions & 33 deletions resources/views/community.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,39 +444,6 @@ class="absolute left-0 z-50 hidden md:block">
{{-- Display this section only if a country is selected and has specific content --}}
@php
$country = app('request')->input('country_iso');
$supportedCountries = [
'GR',
'CY',
'MT',
'IT',
'BG',
'TR',
'UA',
'PL',
'IE',
'FR',
'LU',
'NL',
'BE',
'SK',
'CZ',
'NO',
'IS',
'FI',
'SE',
'PT',
'ES',
'LV',
'LT',
'HR',
'SI',
'DE',
'AT',
'CH',
'RO',
'MD',
'DK',
];
@endphp
@if (in_array($country, $supportedCountries))
<svg xmlns="http://www.w3.org/2000/svg" width="94" height="131" viewBox="0 0 94 131" fill="none"
Expand Down