Add gettext strings to model data-message fields, error handling

This commit is contained in:
billz 2023-04-04 22:30:03 +02:00
parent 2499c7a712
commit 13a113f717
3 changed files with 19 additions and 15 deletions

View file

@ -25,8 +25,9 @@ if (isset($_POST['csrf_token'])) {
} catch (Exception $e) {
$return = $e->getCode();
}
}
echo json_encode($return);
}
$jsonData = ['return'=>$return];
echo json_encode($jsonData);
} else {
handleInvalidCSRFToken();

View file

@ -20,7 +20,6 @@ function createNetmaskAddr(bitCount) {
function loadSummary(strInterface) {
$.post('ajax/networking/get_ip_summary.php',{interface:strInterface},function(data){
jsonData = JSON.parse(data);
console.log(jsonData);
if(jsonData['return'] == 0) {
$('#'+strInterface+'-summary').html(jsonData['output'].join('<br />'));
} else if(jsonData['return'] == 2) {
@ -323,18 +322,23 @@ $('#ovpn-userpw,#ovpn-certs').on('click', function (e) {
});
$('#js-system-reset-confirm').on('click', function (e) {
var resetHtml = $('#js-system-reset-confirm').attr('data-message');
var successHtml = $('#js-system-reset-message').attr('data-message');
var progressHtml = $('#js-system-reset-confirm').attr('data-message');
var successHtml = $('#system-reset-message').attr('data-message');
var closeHtml = $('#js-system-reset-cancel').attr('data-message');
var csrfToken = $('meta[name=csrf_token]').attr('content');
resetHtml += '<i class="fas fa-cog fa-spin ml-2"></i>';
$('#system-reset-message').html(resetHtml);
progressHtml += '<i class="fas fa-cog fa-spin ml-2"></i>';
$('#system-reset-message').html(progressHtml);
$.post('ajax/networking/do_sys_reset.php?',{'csrf_token':csrfToken},function(data){
setTimeout(function(){
$('#system-reset-message').text('Reset complete. Restart the hotspot for the changes to take effect.');
var response = JSON.parse(data);
console.log(response);
//$('#system-reset-message').text(responseText);
},1000);
jsonData = JSON.parse(data);
if(jsonData['return'] == 0) {
$('#system-reset-message').text(successHtml);
} else {
$('#system-reset-message').text('Error occured: '+ jsonData['return']);
}
$("#js-system-reset-confirm").hide();
$("#js-system-reset-cancel").text(closeHtml);
},750);
});
});
@ -480,7 +484,6 @@ window.addEventListener('load', function() {
// Loop over them and prevent submission
var validation = Array.prototype.filter.call(forms, function(form) {
form.addEventListener('submit', function(event) {
//console.log(event.submitter);
if (form.checkValidity() === false) {
event.preventDefault();
event.stopPropagation();

View file

@ -42,10 +42,10 @@
<div class="modal-title" id="ModalLabel"><i class="fas fa-history mr-2"></i><?php echo _("System reset"); ?></div>
</div>
<div class="modal-body">
<div class="col-md-12 mb-3 mt-1" id="system-reset-message"><?php echo _("Reset RaspAP to its initial configuration? This action cannot be undone."); ?></div>
<div class="col-md-12 mb-3 mt-1" data-message="<?php echo _("Reset complete. Restart the hotspot for the changes to take effect."); ?>" id="system-reset-message"><?php echo _("Reset RaspAP to its initial configuration? This action cannot be undone."); ?></div>
</div>
<div class="modal-footer">
<button type="button" id="js-system-reset-cancel" class="btn btn-outline-secondary" data-dismiss="modal"><?php echo _("Cancel"); ?></button>
<button type="button" id="js-system-reset-cancel" data-message="<?php echo _("Close"); ?>" class="btn btn-outline-secondary" data-dismiss="modal"><?php echo _("Cancel"); ?></button>
<button type="button" id="js-system-reset-confirm" data-message="<?php echo _("System reset in progress..."); ?>" class="btn btn-outline-danger btn-delete"><?php echo _("Reset"); ?></button>
</div>
</div>