mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-30 04:26:44 +00:00
Merge pull request #2687 from SchrodingersGat/create-and-continue
Create and continue
This commit is contained in:
commit
d25e3dba20
@ -37,7 +37,6 @@ function showAlertOrCache(message, cache, options={}) {
|
|||||||
if (cache) {
|
if (cache) {
|
||||||
addCachedAlert(message, options);
|
addCachedAlert(message, options);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
showMessage(message, options);
|
showMessage(message, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,6 +81,8 @@ function showMessage(message, options={}) {
|
|||||||
|
|
||||||
var timeout = options.timeout || 5000;
|
var timeout = options.timeout || 5000;
|
||||||
|
|
||||||
|
var target = options.target || $('#alerts');
|
||||||
|
|
||||||
var details = '';
|
var details = '';
|
||||||
|
|
||||||
if (options.details) {
|
if (options.details) {
|
||||||
@ -111,7 +112,7 @@ function showMessage(message, options={}) {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
$('#alerts').append(html);
|
target.append(html);
|
||||||
|
|
||||||
// Remove the alert automatically after a specified period of time
|
// Remove the alert automatically after a specified period of time
|
||||||
$(`#alert-${id}`).delay(timeout).slideUp(200, function() {
|
$(`#alert-${id}`).delay(timeout).slideUp(200, function() {
|
||||||
|
@ -313,6 +313,10 @@
|
|||||||
fields: fields,
|
fields: fields,
|
||||||
groups: partGroups(),
|
groups: partGroups(),
|
||||||
title: '{% trans "Create Part" %}',
|
title: '{% trans "Create Part" %}',
|
||||||
|
reloadFormAfterSuccess: true,
|
||||||
|
persist: true,
|
||||||
|
persistMessage: '{% trans "Create another part after this one" %}',
|
||||||
|
successMessage: '{% trans "Part created successfully" %}',
|
||||||
onSuccess: function(data) {
|
onSuccess: function(data) {
|
||||||
// Follow the new part
|
// Follow the new part
|
||||||
location.href = `/part/${data.pk}/`;
|
location.href = `/part/${data.pk}/`;
|
||||||
|
@ -542,6 +542,11 @@ function constructFormBody(fields, options) {
|
|||||||
insertConfirmButton(options);
|
insertConfirmButton(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Insert "persist" button (if required)
|
||||||
|
if (options.persist) {
|
||||||
|
insertPersistButton(options);
|
||||||
|
}
|
||||||
|
|
||||||
// Display the modal
|
// Display the modal
|
||||||
$(modal).modal('show');
|
$(modal).modal('show');
|
||||||
|
|
||||||
@ -616,6 +621,22 @@ function insertConfirmButton(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Add a checkbox to select if the modal will stay open after success */
|
||||||
|
function insertPersistButton(options) {
|
||||||
|
|
||||||
|
var message = options.persistMessage || '{% trans "Keep this form open" %}';
|
||||||
|
|
||||||
|
var html = `
|
||||||
|
<div class="form-check form-switch">
|
||||||
|
<input class="form-check-input" type="checkbox" id="modal-persist">
|
||||||
|
<label class="form-check-label" for="modal-persist">${message}</label>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
$(options.modal).find('#modal-footer-buttons').append(html);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extract all specified form values as a single object
|
* Extract all specified form values as a single object
|
||||||
*/
|
*/
|
||||||
@ -934,19 +955,40 @@ function getFormFieldValue(name, field={}, options={}) {
|
|||||||
*/
|
*/
|
||||||
function handleFormSuccess(response, options) {
|
function handleFormSuccess(response, options) {
|
||||||
|
|
||||||
// Close the modal
|
|
||||||
if (!options.preventClose) {
|
|
||||||
// Note: The modal will be deleted automatically after closing
|
|
||||||
$(options.modal).modal('hide');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display any required messages
|
// Display any required messages
|
||||||
// Should we show alerts immediately or cache them?
|
// Should we show alerts immediately or cache them?
|
||||||
var cache = (options.follow && response.url) || options.redirect || options.reload;
|
var cache = (options.follow && response.url) || options.redirect || options.reload;
|
||||||
|
|
||||||
|
// Should the form "persist"?
|
||||||
|
var persist = false;
|
||||||
|
|
||||||
|
if (options.persist && options.modal) {
|
||||||
|
// Determine if this form should "persist", or be dismissed?
|
||||||
|
var chk = $(options.modal).find('#modal-persist');
|
||||||
|
|
||||||
|
persist = chk.exists() && chk.prop('checked');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (persist) {
|
||||||
|
cache = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
var msg_target = null;
|
||||||
|
|
||||||
|
if (persist) {
|
||||||
|
// If the modal is persistant, the target for any messages should be the modal!
|
||||||
|
msg_target = $(options.modal).find('#pre-form-content');
|
||||||
|
}
|
||||||
|
|
||||||
// Display any messages
|
// Display any messages
|
||||||
if (response && (response.success || options.successMessage)) {
|
if (response && (response.success || options.successMessage)) {
|
||||||
showAlertOrCache(response.success || options.successMessage, cache, {style: 'success'});
|
showAlertOrCache(
|
||||||
|
response.success || options.successMessage,
|
||||||
|
cache,
|
||||||
|
{
|
||||||
|
style: 'success',
|
||||||
|
target: msg_target,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response && response.info) {
|
if (response && response.info) {
|
||||||
@ -961,6 +1003,26 @@ function handleFormSuccess(response, options) {
|
|||||||
showAlertOrCache(response.danger, cache, {style: 'danger'});
|
showAlertOrCache(response.danger, cache, {style: 'danger'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (persist) {
|
||||||
|
// Instead of closing the form and going somewhere else,
|
||||||
|
// reload (empty) the form so the user can input more data
|
||||||
|
|
||||||
|
// Reset the status of the "submit" button
|
||||||
|
if (options.modal) {
|
||||||
|
$(options.modal).find('#modal-form-submit').prop('disabled', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove any error flags from the form
|
||||||
|
clearFormErrors(options);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Close the modal
|
||||||
|
if (!options.preventClose) {
|
||||||
|
// Note: The modal will be deleted automatically after closing
|
||||||
|
$(options.modal).modal('hide');
|
||||||
|
}
|
||||||
|
|
||||||
if (options.onSuccess) {
|
if (options.onSuccess) {
|
||||||
// Callback function
|
// Callback function
|
||||||
options.onSuccess(response, options);
|
options.onSuccess(response, options);
|
||||||
@ -977,6 +1039,7 @@ function handleFormSuccess(response, options) {
|
|||||||
window.location.href = options.redirect;
|
window.location.href = options.redirect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -989,6 +1052,8 @@ function clearFormErrors(options={}) {
|
|||||||
// Remove the individual error messages
|
// Remove the individual error messages
|
||||||
$(options.modal).find('.form-error-message').remove();
|
$(options.modal).find('.form-error-message').remove();
|
||||||
|
|
||||||
|
$(options.modal).find('.modal-content').removeClass('modal-error');
|
||||||
|
|
||||||
// Remove the "has error" class
|
// Remove the "has error" class
|
||||||
$(options.modal).find('.form-field-error').removeClass('form-field-error');
|
$(options.modal).find('.form-field-error').removeClass('form-field-error');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user