Refactorin'

This commit is contained in:
Oliver 2021-07-02 11:06:52 +10:00
parent 2f1dea1123
commit 3ff19f8c75
2 changed files with 12 additions and 14 deletions

View File

@ -237,11 +237,6 @@ function constructForm(url, options) {
// Default HTTP method
options.method = options.method || 'PATCH';
// Create a new modal if one does not exists
if (!options.modal) {
options.modal = createNewModal();
}
// Request OPTIONS endpoint from the API
getApiEndpointOptions(url, function(OPTIONS) {
@ -396,17 +391,15 @@ function constructFormBody(fields, options) {
// TODO: Dynamically create the modals,
// so that we can have an infinite number of stacks!
options.modal = options.modal || '#modal-form';
// Create a new modal if one does not exists
if (!options.modal) {
options.modal = createNewModal(options);
}
var modal = options.modal;
modalEnable(modal, true);
// Set the form title and button labels
modalSetTitle(modal, options.title || '{% trans "Form Title" %}');
modalSetSubmitText(modal, options.submitText || '{% trans "Submit" %}');
modalSetCloseText(modal, options.cancelText || '{% trans "Cancel" %}');
// Insert generated form content
$(modal).find('.modal-form-content').html(html);

View File

@ -31,7 +31,7 @@ function createNewModal(options={}) {
</div>
<div class='modal-footer'>
<div id='modal-footer-buttons'></div>
<button type='button' class='btn btn-default' id='modal-form-cancel' data-dismiss='modal'>{% trans "Cancel" %}</button>
<button type='button' class='btn btn-default' id='modal-form-close' data-dismiss='modal'>{% trans "Cancel" %}</button>
<button type='button' class='btn btn-primary' id='modal-form-submit'>{% trans "Submit" %}</button>
</div>
</div>
@ -48,6 +48,11 @@ function createNewModal(options={}) {
$(modal_name).remove();
});
// Set labels based on supplied options
modalSetTitle(modal_name, options.title || '{% trans "Form Title" %}');
modalSetSubmitText(modal_name, options.submitText || '{% trans "Submit" %}');
modalSetCloseText(modal_name, options.cancelText || '{% trans "Cancel" %}');
// Return the "name" of the modal
return modal_name;
}