[Station profile] US Counties dropdown added

pull/847/head
Andreas 2021-01-24 15:29:29 +01:00
rodzic 7fb35a0947
commit 43a78f499c
4 zmienionych plików z 92 dodań i 6 usunięć

Wyświetl plik

@ -135,4 +135,37 @@ class Station extends CI_Controller {
redirect('station');
}
/*
* Function is used for autocompletion of Counties in the station profile form
*/
public function get_county() {
$json = [];
if(!empty($this->input->get("query"))) {
$query = isset($_GET['query']) ? $_GET['query'] : FALSE;
$county = $this->input->get("state");
$file = 'assets/json/US_counties.csv';
if (is_readable($file)) {
$lines = file($file, FILE_IGNORE_NEW_LINES);
$input = preg_quote($county, '~');
$reg = '~^'. $input .'(.*)$~';
$result = preg_grep($reg, $lines);
$json = [];
$i = 0;
foreach ($result as &$value) {
$county = explode(',', $value);
// Limit to 100 as to not slowdown browser too much
if (count($json) <= 100) {
$json[] = ["name"=>$county[1]];
}
}
}
}
header('Content-Type: application/json');
echo json_encode($json);
}
}

Wyświetl plik

@ -2785,6 +2785,55 @@ function deleteQsl(id) {
}
</script>
<?php } ?>
<?php if ($this->uri->segment(1) == "station") { ?>
<script>
var baseURL= "<?php echo base_url();?>";
$('#StateHelp').change(function(){
var state = $("#StateHelp option:selected").text();
if (state != "") {
$("#stationCntyInput").prop('disabled', false);
$('#stationCntyInput').selectize({
maxItems: 1,
closeAfterSelect: true,
loadThrottle: 250,
valueField: 'name',
labelField: 'name',
searchField: 'name',
options: [],
create: false,
load: function(query, callback) {
var state = $("#StateHelp option:selected").text();
if (!query || state == "") return callback();
$.ajax({
url: baseURL+'index.php/station/get_county',
type: 'GET',
dataType: 'json',
data: {
query: query,
state: state,
},
error: function() {
callback();
},
success: function(res) {
callback(res);
}
});
}
});
} else {
$("#stationCntyInput").prop('disabled', true);
$('#stationCntyInput')[0].selectize.destroy();
$("#stationCntyInput").val("");
}
});
</script>
<?php } ?>
</body>
</html>

Wyświetl plik

@ -59,7 +59,8 @@
<small id="stationCityInputHelp" class="form-text text-muted">Station city. For example: Inverness</small>
</div>
<div class="form-group">
<div class="form-row">
<div class="form-group col-sm-6">
<label for="stateInput">Station State</label>
<select class="form-control custom-select" name="station_state" id="StateHelp" aria-describedby="stationCntyInputHelp">
<option value="" selected></option>
@ -117,11 +118,12 @@
<small id="StateHelp" class="form-text text-muted">Station state. Applies to certain countries only. Leave blank if not applicable.</small>
</div>
<div style="display: none" class="form-group">
<div class="form-group col-sm-6">
<label for="stationCntyInput">Station County</label>
<input type="text" class="form-control" name="station_cnty" id="stationCntyInput" aria-describedby="stationCntyInputHelp">
<input disabled="disabled" type="text" class="form-control" name="station_cnty" id="stationCntyInput" aria-describedby="stationCntyInputHelp">
<small id="stationCntyInputHelp" class="form-text text-muted">Station County (Only used for USA/Alaska/Hawaii)</small>
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-6">

Wyświetl plik

@ -60,7 +60,8 @@
<small id="stationCityInputHelp" class="form-text text-muted">Station city. For example: Inverness</small>
</div>
<div class="form-group">
<div class="form-row">
<div class="form-group col-sm-6">
<label for="stateInput">Station State</label>
<select class="form-control custom-select" name="station_state" id="StateHelp" aria-describedby="stationCntyInputHelp">
<option value=""></option>
@ -131,11 +132,12 @@
<small id="StateHelp" class="form-text text-muted">Station state. Applies to certain countries only. Leave blank if not applicable.</small>
</div>
<div style="display: none" class="form-group">
<div class="form-group col-sm-6">
<label for="stationCntyInput">Station County</label>
<input type="text" class="form-control" name="station_cnty" id="stationCntyInput" aria-describedby="stationCntyInputHelp" value="<?php if(set_value('station_cnty') != "") { echo set_value('station_cnty'); } else { echo $my_station_profile->station_cnty; } ?>">
<input disabled="disabled" type="text" class="form-control" name="station_cnty" id="stationCntyInput" aria-describedby="stationCntyInputHelp" value="<?php if(set_value('station_cnty') != "") { echo set_value('station_cnty'); } else { echo $my_station_profile->station_cnty; } ?>">
<small id="stationCntyInputHelp" class="form-text text-muted">Station County (Only used for USA/Alaska/Hawaii)</small>
</div>
</div>
<div class="form-row">
<div class="form-group col-sm-6">