chg: [js:bootstrap-helper] new functionalities and refacto
parent
1a08670671
commit
0bd90916f7
|
@ -94,6 +94,21 @@ class UIFactory {
|
|||
return $container
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Place an overlay onto a node and remove it whenever the promise resolves
|
||||
* @param {(jQuery|string)} node - The node on which the overlay should be placed
|
||||
* @param {Promise} promise - A promise to be fulfilled
|
||||
* @param {Object} [overlayOptions={} - The options to be passed to the overlay class
|
||||
*/
|
||||
overlayUntilResolve(node, promise, overlayOptions={}) {
|
||||
const $node = $(node)
|
||||
const loadingOverlay = new OverlayFactory($node[0], overlayOptions);
|
||||
loadingOverlay.show()
|
||||
promise.finally(() => {
|
||||
loadingOverlay.hide()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/** Class representing a Toast */
|
||||
|
@ -235,6 +250,9 @@ class ModalFactory {
|
|||
if (this.options.rawHTML) {
|
||||
this.attachSubmitButtonListener = true
|
||||
}
|
||||
if (options.type === undefined && options.cancel !== undefined) {
|
||||
this.options.type = 'confirm'
|
||||
}
|
||||
this.bsModalOptions = {
|
||||
show: true
|
||||
}
|
||||
|
@ -304,7 +322,7 @@ class ModalFactory {
|
|||
* @property {boolean} closeOnSuccess - If true, the modal will be closed if the $FILL_ME operation is successful
|
||||
* @property {ModalFactory~confirm} confirm - The callback that should be called if the user confirm the modal
|
||||
* @property {ModalFactory~cancel} cancel - The callback that should be called if the user cancel the modal
|
||||
* @property {ModalFactory~APIConfirm} APIConfirm - The callback that should be called if the user confirm the modal. Behave like the confirm option but provide an AJAXApi object that can be used to issue requests
|
||||
* @property {ModalFactory~APIConfirm} APIConfirm - The callback that should be called if the user confirm the modal. Behaves like the confirm option but provides an AJAXApi object that can be used to issue requests
|
||||
* @property {ModalFactory~APIError} APIError - The callback called if the APIConfirm callback fails.
|
||||
* @property {ModalFactory~shownCallback} shownCallback - The callback that should be called whenever the modal is shown
|
||||
* @property {ModalFactory~hiddenCallback} hiddenCallback - The callback that should be called whenever the modal is hiddenAPIConfirm
|
||||
|
@ -702,11 +720,11 @@ class OverlayFactory {
|
|||
}
|
||||
}
|
||||
|
||||
/** Class representing a FormHelper */
|
||||
class FormHelper {
|
||||
/** Class representing a FormValidationHelper */
|
||||
class FormValidationHelper {
|
||||
/**
|
||||
* Create a FormHelper.
|
||||
* @param {Object} options - The options supported by Toaster#defaultOptions
|
||||
* Create a FormValidationHelper.
|
||||
* @param {Object} options - The options supported by FormValidationHelper#defaultOptions
|
||||
*/
|
||||
constructor(form, options={}) {
|
||||
this.form = form
|
||||
|
@ -721,7 +739,7 @@ class FormHelper {
|
|||
|
||||
/**
|
||||
* Create node containing validation information from validationError. If no field can be associated to the error, it will be placed on top
|
||||
* @param {Object} validationErrors - The validation errors to be displayed
|
||||
* @param {Object} validationErrors - The validation errors to be displayed. Keys are the fieldName that had errors, values are the error text
|
||||
*/
|
||||
injectValidationErrors(validationErrors) {
|
||||
this.cleanValidationErrors()
|
||||
|
@ -751,9 +769,9 @@ class FormHelper {
|
|||
} else {
|
||||
$messageNode.addClass('invalid-feedback')
|
||||
}
|
||||
const isList = Object.keys(errors).length > 1
|
||||
const hasMultipleErrors = Object.keys(errors).length > 1
|
||||
for (const [ruleName, error] of Object.entries(errors)) {
|
||||
if (isList) {
|
||||
if (hasMultipleErrors) {
|
||||
$messageNode.append($('<li></li>').text(error))
|
||||
} else {
|
||||
$messageNode.text(error)
|
||||
|
|
Loading…
Reference in New Issue