mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-19 05:25:42 +00:00
More refactoring for notifications
- Adds default behaviour for successful stock item creation
This commit is contained in:
@ -111,7 +111,13 @@ $(document).ready(function () {
|
||||
// notifications
|
||||
{% if messages %}
|
||||
{% for message in messages %}
|
||||
showAlertOrCache('{{ message }}', 'info', true);
|
||||
showAlertOrCache(
|
||||
'{{ message }}',
|
||||
true,
|
||||
{
|
||||
style: 'info',
|
||||
}
|
||||
);
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
|
@ -480,10 +480,13 @@ function barcodeCheckIn(location_id) {
|
||||
$(modal).modal('hide');
|
||||
if (status == 'success' && 'success' in response) {
|
||||
|
||||
showAlertOrCache(response.success, 'success', true);
|
||||
addCachedAlert(response.success);
|
||||
location.reload();
|
||||
} else {
|
||||
showAlertOrCache('{% trans "Error transferring stock" %}', 'danger', false);
|
||||
showMessage('{% trans "Error transferring stock" %}', {
|
||||
style: 'danger',
|
||||
icon: 'fas fa-times-circle',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -604,10 +607,12 @@ function scanItemsIntoLocation(item_id_list, options={}) {
|
||||
$(modal).modal('hide');
|
||||
|
||||
if (status == 'success' && 'success' in response) {
|
||||
showAlertOrCache(response.success, 'success', true);
|
||||
addCachedAlert(response.success);
|
||||
location.reload();
|
||||
} else {
|
||||
showAlertOrCache('{% trans "Error transferring stock" %}', 'danger', false);
|
||||
showMessage('{% trans "Error transferring stock" %}', {
|
||||
style: 'danger',
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -904,19 +904,19 @@ function handleFormSuccess(response, options) {
|
||||
|
||||
// Display any messages
|
||||
if (response && response.success) {
|
||||
showAlertOrCache(response.success, 'success', cache);
|
||||
showAlertOrCache(response.success, cache, {style: 'success'});
|
||||
}
|
||||
|
||||
if (response && response.info) {
|
||||
showAlertOrCache(response.info, 'info', cache);
|
||||
showAlertOrCache(response.info, cache, {style: 'info'});
|
||||
}
|
||||
|
||||
if (response && response.warning) {
|
||||
showAlertOrCache(response.warning, 'warning', cache);
|
||||
showAlertOrCache(response.warning, cache, {style: 'warning'});
|
||||
}
|
||||
|
||||
if (response && response.danger) {
|
||||
showAlertOrCache(response.danger, 'dagner', cache);
|
||||
showAlertOrCache(response.danger, cache, {style: 'danger'});
|
||||
}
|
||||
|
||||
if (options.onSuccess) {
|
||||
|
@ -399,19 +399,19 @@ function afterForm(response, options) {
|
||||
|
||||
// Display any messages
|
||||
if (response.success) {
|
||||
showAlertOrCache(response.success, 'success', cache);
|
||||
showAlertOrCache(response.success, cache, {style: 'success'});
|
||||
}
|
||||
|
||||
if (response.info) {
|
||||
showAlertOrCache(response.info, 'info', cache);
|
||||
showAlertOrCache(response.info, cache, {style: 'info'});
|
||||
}
|
||||
|
||||
if (response.warning) {
|
||||
showAlertOrCache(response.warning, 'warning', cache);
|
||||
showAlertOrCache(response.warning, cache, {style: 'warning'});
|
||||
}
|
||||
|
||||
if (response.danger) {
|
||||
showAlertOrCache(response.danger, 'danger', cache);
|
||||
showAlertOrCache(response.danger, cache, {style: 'danger'});
|
||||
}
|
||||
|
||||
// Was a callback provided?
|
||||
|
@ -317,6 +317,33 @@ function createNewStockItem(options={}) {
|
||||
options.fields = stockItemFields(options);
|
||||
options.groups = stockItemGroups(options);
|
||||
|
||||
if (!options.onSuccess) {
|
||||
options.onSuccess = function(response) {
|
||||
// If a single stock item has been created, follow it!
|
||||
if (response.pk) {
|
||||
var url = `/stock/item/${pk}/`;
|
||||
|
||||
addCachedAlert('{% trans "Created stock item" %}', {
|
||||
icon: 'fas fa-boxes',
|
||||
});
|
||||
|
||||
location.href = url;
|
||||
} else {
|
||||
|
||||
var q = response.quantity;
|
||||
|
||||
showMessage('{% trans "Created stock items" %}', {
|
||||
icon: 'fas fa-boxes',
|
||||
});
|
||||
|
||||
if (options.table) {
|
||||
// Reload the table
|
||||
$(options.table).bootstrapTable('refresh');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
constructForm(url, options);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user