Skip to content

Commit

Permalink
[QSO Dialog] County has been added.
Browse files Browse the repository at this point in the history
Adds USA County
  • Loading branch information
magicbug committed Jan 31, 2021
2 parents d2aec5d + 44a1dd5 commit 89d5794
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 1 deletion.
35 changes: 35 additions & 0 deletions application/controllers/Qso.php
Expand Up @@ -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);
}
}
1 change: 1 addition & 0 deletions application/language/english/general_words_lang.php
Expand Up @@ -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';
Expand Down
4 changes: 3 additions & 1 deletion application/models/Logbook_model.php
Expand Up @@ -150,6 +150,7 @@ function create_qso() {
'COL_DXCC' => $dxcc_id,
'COL_CQZ' => $cqz,
'COL_STATE' => trim($this->input->post('usa_state')),
'COL_USACA_COUNTIES' => trim($this->input->post('county')),
'COL_SOTA_REF' => trim($this->input->post('sota_ref')),
'COL_SIG' => trim($this->input->post('sig')),
'COL_SIG_INFO' => trim($this->input->post('sig_info')),
Expand Down Expand Up @@ -529,7 +530,8 @@ function edit() {
'COL_QSL_VIA' => $this->input->post('qsl_via_callsign'),
'station_id' => $this->input->post('station_profile'),
'COL_OPERATOR' => $this->input->post('operator_callsign'),
'COL_STATE' =>$this->input->post('usa_state')
'COL_STATE' =>$this->input->post('usa_state'),
'COL_USACA_COUNTIES' =>$this->input->post('usa_county'),
);

if ($this->exists_qrz_api_key($data['station_id'])) {
Expand Down
97 changes: 97 additions & 0 deletions application/views/interface_assets/footer.php
Expand Up @@ -323,6 +323,49 @@ function searchButtonPress(){
$( document ).ready(function() {
var baseURL= "<?php echo base_url();?>";

$('#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,
Expand Down Expand Up @@ -1991,6 +2034,26 @@ function qso_edit(id) {
nl2br: false,
message: html,
onshown: function(dialog) {
var state = $("#input_usa_state option:selected").text();
if (state != "") {
$("#stationCntyInput").prop('disabled', false);
selectize_usa_county();
}

$('#input_usa_state').change(function(){
var state = $("#input_usa_state option:selected").text();
if (state != "") {
$("#stationCntyInput").prop('disabled', false);

selectize_usa_county();

} else {
$("#stationCntyInput").prop('disabled', true);
$('#stationCntyInput')[0].selectize.destroy();
$("#stationCntyInput").val("");
}
});

$('#sota_ref').selectize({
maxItems: 1,
closeAfterSelect: true,
Expand Down Expand Up @@ -2052,6 +2115,40 @@ function qso_edit(id) {
});
}

function selectize_usa_county() {
var baseURL= "<?php echo base_url();?>";
$('#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);
}
});
}
});
}

function qso_save() {
var baseURL= "<?php echo base_url();?>";
var myform = document.getElementById("qsoform");
Expand Down
5 changes: 5 additions & 0 deletions application/views/qso/edit_ajax.php
Expand Up @@ -371,6 +371,11 @@
</select>
</div>

<div class="form-group">
<label for="stationCntyInput">USA County</label>
<input disabled="disabled" class="form-control" id="stationCntyInput" type="text" name="usa_county" value="<?php echo $qso->COL_USACA_COUNTIES; ?>" />
</div>

<div class="form-group">
<label for="iota_ref">IOTA</label>
<select class="custom-select" id="iota_ref" name="iota_ref">
Expand Down
5 changes: 5 additions & 0 deletions application/views/qso/index.php
Expand Up @@ -347,6 +347,11 @@
</select>
</div>

<div class="form-group">
<label for="stationCntyInput"><?php echo $this->lang->line('gen_hamradio_county_reference'); ?></label>
<input disabled="disabled" class="form-control" id="stationCntyInput" type="text" name="county" value="" />
</div>

<div class="form-group">
<label for="iota_ref"><?php echo $this->lang->line('gen_hamradio_iota_reference'); ?></label>
<select class="custom-select" id="iota_ref" name="iota_ref">
Expand Down
6 changes: 6 additions & 0 deletions application/views/view_log/qso.php
Expand Up @@ -144,6 +144,12 @@
</tr>
<?php } ?>

<?php if($row->COL_USACA_COUNTIES != null) { ?>
<tr>
<td>USA County:</td>
<td><?php echo $row->COL_USACA_COUNTIES; ?></td>
</tr>
<?php } ?>

<?php if($row->COL_NAME != null) { ?>
<tr>
Expand Down

0 comments on commit 89d5794

Please sign in to comment.