Make further use of notification messages

This commit is contained in:
Oliver 2021-11-04 10:14:01 +11:00
parent df30a85c03
commit b6d48cab2a
6 changed files with 30 additions and 14 deletions

View File

@ -75,6 +75,12 @@ function showMessage(message, options={}) {
var timeout = options.timeout || 5000;
var details = '';
if (options.details) {
details = `<p><small>${options.details}</p></small>`;
}
// Hacky function to get the next available ID
var id = 1;
@ -85,14 +91,15 @@ function showMessage(message, options={}) {
var icon = '';
if (options.icon) {
icon = `<span class='${options.icon}></span>`;
icon = `<span class='${options.icon}'></span>`;
}
// Construct the alert
var html = `
<div id='alert-${id}' class='alert alert-${style} alert-dismissible fade show' role='alert'>
${icon}
${message}
<b>${message}</b>
${details}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
`;

View File

@ -163,7 +163,7 @@ function inventreeDelete(url, options={}) {
}
function showApiError(xhr) {
function showApiError(xhr, url) {
var title = null;
var message = null;
@ -208,7 +208,11 @@ function showApiError(xhr) {
}
message += '<hr>';
message += renderErrorMessage(xhr);
message += `URL: ${url}`;
showAlertDialog(title, message);
showMessage(title, {
style: 'danger',
icon: 'fas fa-server icon-red',
details: message,
});
}

View File

@ -339,7 +339,7 @@ function completeBuildOutputs(build_id, outputs, options={}) {
break;
default:
$(opts.modal).modal('hide');
showApiError(xhr);
showApiError(xhr, opts.url);
break;
}
}
@ -1527,7 +1527,7 @@ function allocateStockToBuild(build_id, part_id, bom_items, options={}) {
break;
default:
$(opts.modal).modal('hide');
showApiError(xhr);
showApiError(xhr, opts.url);
break;
}
}

View File

@ -123,9 +123,10 @@ function getApiEndpointOptions(url, callback) {
json: 'application/json',
},
success: callback,
error: function() {
error: function(xhr) {
// TODO: Handle error
console.log(`ERROR in getApiEndpointOptions at '${url}'`);
showApiError(xhr, url);
}
});
}
@ -202,9 +203,11 @@ function constructChangeForm(fields, options) {
constructFormBody(fields, options);
},
error: function() {
error: function(xhr) {
// TODO: Handle error here
console.log(`ERROR in constructChangeForm at '${options.url}'`);
showApiError(xhr, options.url);
}
});
}
@ -241,9 +244,11 @@ function constructDeleteForm(fields, options) {
constructFormBody(fields, options);
},
error: function() {
error: function(xhr) {
// TODO: Handle error here
console.log(`ERROR in constructDeleteForm at '${options.url}`);
showApiError(xhr, options.url);
}
});
}
@ -708,7 +713,7 @@ function submitFormData(fields, options) {
break;
default:
$(options.modal).modal('hide');
showApiError(xhr);
showApiError(xhr, options.url);
break;
}
}

View File

@ -555,7 +555,7 @@ function receivePurchaseOrderItems(order_id, line_items, options={}) {
break;
default:
$(opts.modal).modal('hide');
showApiError(xhr);
showApiError(xhr, opts.url);
break;
}
}

View File

@ -427,7 +427,7 @@ function adjustStock(action, items, options={}) {
break;
default:
$(opts.modal).modal('hide');
showApiError(xhr);
showApiError(xhr, opts.url);
break;
}
}