From 7892846e8a969c2446e54b9bbf5f1165b966a2cf Mon Sep 17 00:00:00 2001 From: Andreas Date: Sun, 31 Jan 2021 15:02:23 +0100 Subject: [PATCH 1/2] [QSO Entry] Added county with autocomplete to the form. --- application/controllers/Qso.php | 35 +++++++++++++++ .../language/english/general_words_lang.php | 1 + application/views/interface_assets/footer.php | 43 +++++++++++++++++++ application/views/qso/index.php | 5 +++ 4 files changed, 84 insertions(+) diff --git a/application/controllers/Qso.php b/application/controllers/Qso.php index b8376d4ef..f1e7b1b0d 100755 --- a/application/controllers/Qso.php +++ b/application/controllers/Qso.php @@ -317,4 +317,39 @@ public function get_dok() { header('Content-Type: application/json'); echo json_encode($json); } + + /* + * 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"); + $cleanedcounty = explode('(', $county); + $cleanedcounty = trim($cleanedcounty[0]); + + $file = 'assets/json/US_counties.csv'; + + if (is_readable($file)) { + $lines = file($file, FILE_IGNORE_NEW_LINES); + $input = preg_quote($cleanedcounty, '~'); + $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); + } } diff --git a/application/language/english/general_words_lang.php b/application/language/english/general_words_lang.php index dc0c1406c..7f12badd3 100644 --- a/application/language/english/general_words_lang.php +++ b/application/language/english/general_words_lang.php @@ -83,6 +83,7 @@ $lang['gen_hamradio_cq_zone'] = 'CQ Zone'; $lang['gen_hamradio_dxcc'] = 'DXCC'; $lang['gen_hamradio_usa_state'] = 'USA State'; +$lang['gen_hamradio_county_reference'] = 'USA County'; $lang['gen_hamradio_iota_reference'] = 'IOTA Reference'; $lang['gen_hamradio_sota_reference'] = 'SOTA Reference'; $lang['gen_hamradio_dok'] = 'DOK'; diff --git a/application/views/interface_assets/footer.php b/application/views/interface_assets/footer.php index 390a2228f..f6727945f 100644 --- a/application/views/interface_assets/footer.php +++ b/application/views/interface_assets/footer.php @@ -323,6 +323,49 @@ function searchButtonPress(){ $( document ).ready(function() { var baseURL= ""; + $('#input_usa_state').change(function(){ + var state = $("#input_usa_state 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 = $("#input_usa_state option:selected").text(); + + if (!query || state == "") return callback(); + $.ajax({ + url: baseURL+'index.php/qso/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(""); + } + }); + $('#sota_ref').selectize({ maxItems: 1, closeAfterSelect: true, diff --git a/application/views/qso/index.php b/application/views/qso/index.php index 5ab674755..ca3b2b37b 100755 --- a/application/views/qso/index.php +++ b/application/views/qso/index.php @@ -347,6 +347,11 @@ +
+ + +
+
+
+ + +
+