display operation status

This commit is contained in:
root
2020-10-09 14:59:06 +00:00
parent 59bafe9f9a
commit 2ef451b63f
2 changed files with 24 additions and 5 deletions

View File

@@ -135,3 +135,22 @@ function getUserStartPage() {
return userMenu[0].file;
}
function showSuccess(msg) {
const st = document.getElementById("status-message");
if (st) {
st.innerHTML = `<div class="alert alert-primary" id="success-alert">`+
`<button type="button" class="close" data-dismiss="alert">x</button>`+
`<strong>Success! </strong> `+msg+`</div>`;
$("#success-alert").fadeTo(2000, 500).fadeOut(500);
}
}
function showError(msg) {
const st = document.getElementById("status-message");
if (st) {
st.innerHTML = `<div class="alert alert-warning" id="error-alert">`+
`<button type="button" class="close" data-dismiss="alert">x</button>`+
`<strong>Error! </strong> `+msg+`</div>`;
$("#success-alert").fadeTo(2000, 500).fadeOut(500);
}
}

View File

@@ -61,7 +61,7 @@ if (conf["custom_css_link"]) {
</div>
</div>
<p id="msg">Click on a field to edit, when finished click Save.</p>
<div id="errordiv" class="alert alert-warning" role="alert" style="display:none;"></div>
<div id='status-message'></div>
<div id="jsoneditor" style="width:100%;height:300px;overflow:auto;"></div>
<pre id="data"></pre>
@@ -153,21 +153,21 @@ if (conf["custom_css_link"]) {
xhr0.setRequestHeader("X-Bunker-Token", xtoken)
xhr0.setRequestHeader('Content-type', 'application/json');
xhr0.onload = function () {
$('#errordiv').hide();
if (xhr0.status === 200) {
var data = JSON.parse(xhr0.responseText);
if (data.status == "ok" && data.result && data.result == "request-created") {
showAlert("Admin request created to approve changes in your profile.");
} else if (data.status == "ok" && data.result && data.result == "request-exists") {
showAlert("Similar request already exists for Admin approval.");
}
} else {
showSuccess('Record saved');
}
} else if (xhr0.status === 403) {
document.location = "/";
} else {
var data = JSON.parse(xhr0.responseText);
if (data.status == "error") {
$('#errordiv').text(data.message);
$('#errordiv').show();
showError("Failed to save. "+data.message);
}
}
}