fixed location

This commit is contained in:
vedatakd 2019-12-20 14:03:03 +03:00
parent 6c8c3314d8
commit 377e8da769
3 changed files with 71 additions and 70 deletions

View File

@ -1,7 +1,7 @@
let searchParams = new URLSearchParams(window.location.search); let searchParams = new URLSearchParams(window.location.search);
//Set Select2 Type for Location Fields //Set Select2 Type for Location Fields
$('#cities, #countries, #districts, #neighborhoods, #village').select2({ $('.cities, .countries, .districts, .neighborhoods, .village').select2({
placeholder: select_trans placeholder: select_trans
}); });
@ -29,7 +29,7 @@ FindLocations = (id, table, typeDb, divId, paramName = null) => {
setLocations = (response, id, table, typeDb, divId, paramName) => { setLocations = (response, id, table, typeDb, divId, paramName) => {
//Add Options //Add Options
if(divId != "#cities") if(divId != ".cities")
{ {
$(divId).append("<option value></option>") $(divId).append("<option value></option>")
} }
@ -39,10 +39,10 @@ setLocations = (response, id, table, typeDb, divId, paramName) => {
//Set Selected Option //Set Selected Option
if (paramName != null) { if (paramName != null) {
if (divId == "#cities") { if (divId == ".cities") {
$('#countries').val(searchParams.get('country')); $('.countries').val(searchParams.get('country'));
$('#countries').select2(); $('.countries').select2();
$('#cities').val(findParam("city[]")); $('.cities').val(findParam("city[]"));
} else { } else {
$(divId).val(searchParams.get(paramName)); $(divId).val(searchParams.get(paramName));
} }
@ -52,43 +52,43 @@ setLocations = (response, id, table, typeDb, divId, paramName) => {
}; };
//Category Change //Category Change
$('#countries').on('change', function () { $('.countries').on('change', function () {
$('#cities').empty(); $('.cities').empty();
var table = "cities"; var table = "cities";
var typeDb = 'parent_country_id'; var typeDb = 'parent_country_id';
var id = $('#countries').val(); var id = $(this).val();
var divId = "#cities"; var divId = ".cities";
FindLocations(id, table, typeDb, divId); FindLocations(id, table, typeDb, divId);
}); });
//City Change //City Change
$('#cities, .select2-selection__choice__remove').on('change', function () { $('.cities, .select2-selection__choice__remove').on('change', function () {
$('#districts').empty(); $('.districts').empty();
var table = "districts"; var table = "districts";
var typeDb = 'parent_city_id'; var typeDb = 'parent_city_id';
var id = $('#cities').val(); var id = $(this).val();
var divId = "#districts"; var divId = ".districts";
FindLocations(id, table, typeDb, divId); FindLocations(id, table, typeDb, divId);
}); });
//Districts Change //Districts Change
$('#districts').on('change', function () { $('.districts').on('change', function () {
var table = "neighborhoods"; var table = "neighborhoods";
var typeDb = 'parent_district_id'; var typeDb = 'parent_district_id';
var id = $('#districts').val(); var id = $(this).val();
var divId = "#neighborhoods"; var divId = ".neighborhoods";
FindLocations(id, table, typeDb, divId); FindLocations(id, table, typeDb, divId);
}); });
//Neighborhoods Change //Neighborhoods Change
$('#neighborhoods').on('change', function () { $('.neighborhoods').on('change', function () {
var table = "village"; var table = "village";
var typeDb = 'parent_neighborhood_id'; var typeDb = 'parent_neighborhood_id';
var id = $('#neighborhoods').val(); var id = $(this).val();
var divId = "#village"; var divId = ".village";
FindLocations(id, table, typeDb, divId); FindLocations(id, table, typeDb, divId);
}); });
@ -100,11 +100,11 @@ jQuery(document).ready(function ($) {
//Get City && Set Country //Get City && Set Country
if (searchParams.get('country') != '') { if (searchParams.get('country') != '') {
$('#cities').empty(); $('.cities').empty();
var table = "cities"; var table = "cities";
var typeDb = 'parent_country_id'; var typeDb = 'parent_country_id';
var id = searchParams.get('country'); var id = searchParams.get('country');
var divId = "#cities"; var divId = ".cities";
var paramName = 'city'; var paramName = 'city';
FindLocations(id, table, typeDb, divId, paramName); FindLocations(id, table, typeDb, divId, paramName);
@ -114,11 +114,11 @@ jQuery(document).ready(function ($) {
//get District && set city //get District && set city
if (findParam('city[]').length) { if (findParam('city[]').length) {
$('#districts').empty(); $('.districts').empty();
var table = "districts"; var table = "districts";
var typeDb = 'parent_city_id'; var typeDb = 'parent_city_id';
var id = findParam('city[]'); var id = findParam('city[]');
var divId = "#districts"; var divId = ".districts";
var paramName = 'district'; var paramName = 'district';
FindLocations(id, table, typeDb, divId, paramName); FindLocations(id, table, typeDb, divId, paramName);
@ -128,11 +128,11 @@ jQuery(document).ready(function ($) {
//get neighborhood && set districts //get neighborhood && set districts
if (searchParams.get('district') != '') { if (searchParams.get('district') != '') {
$('#neighborhoods').empty(); $('.neighborhoods').empty();
var table = "neighborhoods"; var table = "neighborhoods";
var typeDb = 'parent_district_id'; var typeDb = 'parent_district_id';
var id = searchParams.get('district'); var id = searchParams.get('district');
var divId = "#neighborhoods"; var divId = ".neighborhoods";
var paramName = 'neighborhood'; var paramName = 'neighborhood';
FindLocations(id, table, typeDb, divId, paramName); FindLocations(id, table, typeDb, divId, paramName);
@ -142,11 +142,11 @@ jQuery(document).ready(function ($) {
//get village && set neighborhoods //get village && set neighborhoods
if (searchParams.get('neighborhood') != '') { if (searchParams.get('neighborhood') != '') {
$('#village').empty(); $('.village').empty();
var table = "village"; var table = "village";
var typeDb = 'parent_neighborhood_id'; var typeDb = 'parent_neighborhood_id';
var id = searchParams.get('neighborhood'); var id = searchParams.get('neighborhood');
var divId = "#village"; var divId = ".village";
var paramName = 'village'; var paramName = 'village';
FindLocations(id, table, typeDb, divId, paramName); FindLocations(id, table, typeDb, divId, paramName);

View File

@ -11,48 +11,7 @@
</div> </div>
<div id="location" class="collapse show overflow-auto" aria-labelledby="locationHeading" <div id="location" class="collapse show overflow-auto" aria-labelledby="locationHeading"
data-parent="#filter"> data-parent="#filter">
<div class="row w-100 px-2 m-0"> {% include "visiosoft.module.location::ads-list/partials/location-fields" %}
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.country.name") }}</label>
<select class="form-control" name="country" id="countries">
{% for country in params.countries %}
<option value="{{ country.id }}">{{ country.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.city.name") }}</label>
<select class="form-control" name="city[]" id="cities" multiple>
{% for city in params.cities %}
<option value="{{ city.id }}">{{ city.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.district.name") }}</label>
<select class="form-control" name="district" id="districts">
{% for district in params.districts %}
<option value="{{ district.id }}">{{ district.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.neighborhood.name") }}</label>
<select class="form-control" name="neighborhood" id="neighborhoods">
{% for neighborhood in params.neighborhoods %}
<option value="{{ neighborhood.id }}">{{ neighborhood.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.village.name") }}</label>
<select class="form-control" name="village" id="village">
{% for village in params.villages %}
<option value="{{ village.id }}">{{ village.name }}</option>
{% endfor %}
</select>
</div>
</div>
</div> </div>
</div> </div>
<script> <script>

View File

@ -0,0 +1,42 @@
<div class="row w-100 px-2 m-0">
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.country.name") }}</label>
<select class="form-control countries" name="country" id="countries">
{% for country in params.countries %}
<option value="{{ country.id }}">{{ country.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.city.name") }}</label>
<select class="form-control cities" name="city[]" id="cities" multiple>
{% for city in params.cities %}
<option value="{{ city.id }}">{{ city.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.district.name") }}</label>
<select class="form-control districts" name="district" id="districts">
{% for district in params.districts %}
<option value="{{ district.id }}">{{ district.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.neighborhood.name") }}</label>
<select class="form-control neighborhoods" name="neighborhood" id="neighborhoods">
{% for neighborhood in params.neighborhoods %}
<option value="{{ neighborhood.id }}">{{ neighborhood.name }}</option>
{% endfor %}
</select>
</div>
<div class="col-12 px-0 py-1">
<label class="label-filter-location">{{ trans("visiosoft.module.location::field.village.name") }}</label>
<select class="form-control village" name="village" id="village">
{% for village in params.villages %}
<option value="{{ village.id }}">{{ village.name }}</option>
{% endfor %}
</select>
</div>
</div>