[Advanced search] Edit of stored query description can now be done. Formatted code a bit.

这个提交包含在:
Andreas 2021-10-03 20:06:08 +02:00
父节点 7979431d95
当前提交 3baffed23e
共有 4 个文件被更改,包括 321 次插入291 次删除

查看文件

@ -120,15 +120,14 @@ class Search extends CI_Controller {
$this->search_filter->delete_query($id);
}
function edit_query() {
function save_edited_query() {
$data = array(
'cat' => xss_clean($this->input->post('category')),
'title' => xss_clean($this->input->post('title')),
'note' => xss_clean($this->input->post('content'))
'description' => xss_clean($this->input->post('description')),
);
$this->db->where('id', xss_clean($this->input->post('id')));
$this->db->update('notes', $data);
$this->db->where('userid', $this->session->userdata['user_id']);
$this->db->update('queries', $data);
}
function fetchQueryResult($json, $returnquery) {

查看文件

@ -4,7 +4,7 @@ class Migration_add_queries_table extends CI_Migration
{
public function up()
{
$this->db->query("create table queries (id integer not null auto_increment, query text, description text, userid integer not null, primary key (id)) ENGINE=myisam DEFAULT CHARSET=utf8;");
$this->db->query("create table if not exists queries (id integer not null auto_increment, query text, description text, userid integer not null, primary key (id)) ENGINE=myisam DEFAULT CHARSET=utf8;");
}
public function down()

查看文件

@ -55,15 +55,13 @@ function load_was_map() {
<script type="text/javascript" src="<?php echo base_url(); ?>assets/js/query-builder.standalone.min.js"></script>
<script type="text/javascript">
$(".search-results-box").hide();
$('#builder').queryBuilder({
filters: [
<?php foreach ($get_table_names->result() as $row) {
$value_name = str_replace("COL_", "", $row->Field);
if ($value_name != "PRIMARY_KEY" && strpos($value_name, 'MY_') === false && strpos($value_name, '_INTL') == false) { ?>
{
if ($value_name != "PRIMARY_KEY" && strpos($value_name, 'MY_') === false && strpos($value_name, '_INTL') == false) { ?> {
id: '<?php echo $row->Field; ?>',
label: '<?php echo $value_name; ?>',
<?php if (strpos($row->Type, 'int(') !== false) { ?>
@ -151,7 +149,10 @@ $('#btn-save').on('click', function() {
btnOKLabel: 'Save',
callback: function(result) {
if (result) {
$.post( "<?php echo site_url('search/save_query');?>", { search: JSON.stringify(resultquery, null, 2), description: $(".getqueryname").val() })
$.post("<?php echo site_url('search/save_query'); ?>", {
search: JSON.stringify(resultquery, null, 2),
description: $(".getqueryname").val()
})
.done(function(data) {
$(".alert").remove();
$(".card-body.main").append('<div class="alert alert-success"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>Your query has been saved!</div>');
@ -161,8 +162,7 @@ $('#btn-save').on('click', function() {
},
});
}
else{
} else {
BootstrapDialog.show({
title: 'Stored Queries',
type: BootstrapDialog.TYPE_WARNING,
@ -185,7 +185,9 @@ function run_query() {
$(".runbutton").addClass('running');
$(".runbutton").prop('disabled', true);
let id = $('#querydropdown').val();
$.post( "<?php echo site_url('search/run_query');?>", { id: id})
$.post("<?php echo site_url('search/run_query'); ?>", {
id: id
})
.done(function(data) {
$('.exportbutton').html('<button class="btn btn-sm btn-primary" onclick="export_stored_query(' + id + ')">Export to ADIF</button>');
@ -228,13 +230,17 @@ function delete_stored_query(id) {
$.ajax({
url: base_url + 'index.php/search/delete_query',
type: 'post',
data: {'id': id
data: {
'id': id
},
success: function(data) {
$(".bootstrap-dialog-message").prepend('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>The stored query has been deleted!</div>');
$("#query_" + id).remove(); // removes query from table in dialog
$("#querydropdown option[value='" + id + "']").remove(); // removes query from dropdown
}
},
error: function() {
$(".bootstrap-dialog-message").prepend('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>The stored query could not be deleted. Please try again!</div>');
},
});
}
}
@ -242,7 +248,30 @@ function delete_stored_query(id) {
}
function edit_stored_query(id) {
$('#description_' + id).attr('contenteditable', 'true');
$('#description_' + id).focus();
$('#edit_' + id).html('<a class="btn btn-primary btn-sm" href="javascript:save_edited_query(' + id + ');">Save</a>'); // Change to save button
}
function save_edited_query(id) {
$('#description_' + id).attr('contenteditable', 'false');
$('#edit_' + id).html('<a class="btn btn-outline-primary btn-sm" href="javascript:edit_stored_query(' + id + ');">Edit</a>');
$.ajax({
url: base_url + 'index.php/search/save_edited_query',
type: 'post',
data: {
id: id,
description: $('#description_' + id).html(),
},
success: function(html) {
$('#edit_' + id).html('<a class="btn btn-outline-primary btn-sm" href="javascript:edit_stored_query(' + id + ');">Edit</a>'); // Change to edit button
$(".bootstrap-dialog-message").prepend('<div class="alert alert-success"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>The query description has been updated!</div>');
$("#querydropdown option[value='" + id + "']").text($('#description_' + id).html()); // Change text in dropdown
},
error: function() {
$(".bootstrap-dialog-message").prepend('<div class="alert alert-danger"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>Something went wrong with the save. Please try again!</div>');
},
});
}
$('#btn-edit').on('click', function() {
@ -275,7 +304,10 @@ $('#btn-get').on('click', function() {
$(".searchbutton").addClass('running');
$(".searchbutton").prop('disabled', true);
$.post( "<?php echo site_url('search/search_result');?>", { search: JSON.stringify(result, null, 2), temp: "testvar" })
$.post("<?php echo site_url('search/search_result'); ?>", {
search: JSON.stringify(result, null, 2),
temp: "testvar"
})
.done(function(data) {
$('.exportbutton').html('<button class="btn btn-sm btn-primary" onclick="export_search_result();">Export to ADIF</button>');
@ -304,8 +336,7 @@ $('#btn-get').on('click', function() {
$(".searchbutton").prop('disabled', false);
$("#btn-save").show();
});
}
else{
} else {
BootstrapDialog.show({
title: 'Stored Queries',
type: BootstrapDialog.TYPE_WARNING,

查看文件

@ -16,9 +16,9 @@ $i = 1;
foreach ($result as $q) {
echo '<tr id="query_' . $q->id . '">';
echo '<td>' . $i++ . '</td>';
echo '<td>' . $q->description . '</td>';
echo '<td contenteditable="false" id="description_' . $q->id . '">' . $q->description . '</td>';
echo '<td>' . $q->query . '</td>';
echo '<td><a class="btn btn-outline-primary btn-sm" href="javascript:edit_stored_query(' . $q->id . ');">Edit</a></>';
echo '<td id="edit_' . $q->id . '"><a class="btn btn-outline-primary btn-sm" href="javascript:edit_stored_query(' . $q->id . ');">Edit</a></>';
echo '<td><a class="btn btn-danger btn-sm" href="javascript:delete_stored_query(' . $q->id . ');">Delete</a></td>';
echo '</tr>';
}