Made download a JS call

This commit is contained in:
Andreas Kristiansen
2025-01-30 21:07:58 +01:00
parent 8da0dc38e3
commit a25132d5cb
3 changed files with 29 additions and 5 deletions

View File

@@ -144,7 +144,7 @@ class Clublog extends CI_Controller
$this->load->model('clublog_model');
$customDate = $this->input->post('from');
$customDate = $this->input->post('date');
if ($customDate != NULL) {
$clublog_last_date = date($customDate);
} else {
@@ -161,7 +161,8 @@ class Clublog extends CI_Controller
$r = __("No user has configured Clublog.");
}
echo $r;
header('Content-type: application/json');
echo json_encode($r);
}
}

View File

@@ -71,11 +71,11 @@
<div class="row">
<div class="col-md-2">
<label for="from"><?= __("From date") . ": " ?></label>
<input name="from" id="from" type="date" class="form-control w-auto">
<input name="from" id="from" type="date" class="importdate form-control w-auto">
</div>
</div>
<br>
<button type="submit" class="btn btn-sm btn-primary" value="Export"><?= __("Download from Clublog"); ?></button>
<button type="button" class="btn btn-sm btn-primary ld-ext-right ld-ext-right-import" onclick="importlog();"><i class="fas fa-cloud-download-alt"></i> <?= __("Download from Clublog"); ?><div class="ld ld-ring ld-spin"></div></button>
</form>
</div>
<?php } ?>

View File

@@ -28,7 +28,7 @@ function ExportClublog(station_id) {
}
if (data.errormessages.length > 0) {
$("#clublog_export").append(
$("#export").append(
'<div class="errormessages">\n' +
' <div class="card mt-2">\n' +
' <div class="card-header bg-danger">\n' +
@@ -47,3 +47,26 @@ function ExportClublog(station_id) {
}
});
}
function importlog() {
if ($(".alert").length > 0) {
$(".alert").remove();
}
if ($(".errormessages").length > 0) {
$(".errormessages").remove();
}
$(".ld-ext-right-import").addClass('running');
$(".ld-ext-right-import").prop('disabled', true);
$.ajax({
url: base_url + 'index.php/clublog/importlog',
type: 'post',
data: {'date': $(".importdate").val()},
success: function (data) {
$(".ld-ext-right-import").removeClass('running');
$(".ld-ext-right-import").prop('disabled', false);
$("#import").append('<div class="alert alert-success" role="alert">' + data + '</div>');
}
});
}