Modal handlers in ReqEase allow you to adapt the library's actions, such as showing modals or displaying progress, to custom modal behaviors or packages. While the default modal handler is 'bootstrap,' you have the flexibility to use 'jquery-confirm' (by including the jQuery Confirm script) or create your custom modal handler for specific modal libraries. Modal handlers are used by both the loading indicator and response handlers in ReqEase.
Base Modal Handler
The foundation of all modal handlers in ReqEase is the ModalHandler class:
exportclassModalHandler {protected options:ModalOptions; requester:Requester;static label:string;privatereadonly _modalCallbacks:ModalCallbacks[];privatereadonly _internalCallbacks:ModalCallbacks; $modal:JQuery=null;retry: () =>void= () => {};constructor(requester:Requester, options:ModalOptions) {// Constructor details }// Methods to show and close the modalshow():void {}close():void {}modalIsShowed():boolean {returnfalse; }// Other protected methods for building modal typesprotectedbuild() {}// More protected methods for building specific modal typesprotectedbuildLoadingModal(_options:ModalLoadingOptions) {}protectedbuildProgressModal(_options:ModalProgressOptions) {}protectedbuildMessageModal(_options:ModalMessageOptions) {}protectedbuildConfirmationModal(_options:ModalConfirmationOptions) {}protectedbuildDataNeededModal(_options:ModalDataNeededOptions) {}// Additional protected methodsprotectedbuildIcon():string {}// Callbacks to customize modal behaviorgetmodalCallbacks():ModalCallbacks {returnthis._internalCallbacks; }setmodalCallbacks(value:ModalCallbacks) {this._modalCallbacks.push(value); }}
Modal Handlers in ReqEase
Modal handlers in ReqEase allow you to adapt the library's actions, such as showing modals or displaying progress, to custom modal behaviors or packages. While the default modal handler is 'bootstrap,' you have the flexibility to use 'jquery-confirm' (by including the jQuery Confirm script) or create your custom modal handler for specific modal libraries. Modal handlers are used by both the loading indicator and response handlers in ReqEase.
Base Modal Handler
The foundation of all modal handlers in ReqEase is the ModalHandler class:
exportclassModalHandler {protected options:ModalOptions; requester:Requester;static label:string;privatereadonly _modalCallbacks:ModalCallbacks[];privatereadonly _internalCallbacks:ModalCallbacks; $modal:JQuery=null;retry: () =>void= () => {};constructor(requester:Requester, options:ModalOptions) {// Constructor details }// Methods to show and close the modalshow():void {}close():void {}modalIsShowed():boolean {returnfalse; }// Other protected methods for building modal typesprotectedbuild() {}// More protected methods for building specific modal typesprotectedbuildLoadingModal(_options:ModalLoadingOptions) {}protectedbuildProgressModal(_options:ModalProgressOptions) {}protectedbuildMessageModal(_options:ModalMessageOptions) {}protectedbuildConfirmationModal(_options:ModalConfirmationOptions) {}protectedbuildDataNeededModal(_options:ModalDataNeededOptions) {}// Additional protected methodsprotectedbuildIcon():string {}// Callbacks to customize modal behaviorgetmodalCallbacks():ModalCallbacks {returnthis._internalCallbacks; }setmodalCallbacks(value:ModalCallbacks) {this._modalCallbacks.push(value); }}
protected options: ModalOptions: The modal's configuration options.
requester: Requester: A reference to the Requester instance.
static label: string: Each modal handler has a label to identify its type.
_modalCallbacks and _internalCallbacks: Callbacks to customize modal behavior.
show() and close(): Methods to show and close the modal.
modalIsShowed(): A method to check if the modal is currently displayed.
Various protected methods for building different modal types.
Custom Modal Handler Example
Suppose you want to create a custom modal handler for a specific modal library called 'my-modal-library.' Here's how you can do it:
Create your custom modal handler class, extending ModalHandler:
exportclassMyModalHandlerextendsModalHandler {static label ="my-modal-library";constructor(requester:Requester, options:ModalOptions) {super(requester, options); }show():void {// Custom logic to show 'my-modal-library' }close():void {// Custom logic to close 'my-modal-library' }// Additional custom methods and logic for 'my-modal-library'}
Register your custom modal handler in the Requester configuration using the modalHandlersToRegister option:
const myRequester = new Requester({
// Other options
modalHandlersToRegister: [MyModalHandler],
});
By creating and registering a custom modal handler, you can seamlessly integrate ReqEase with your chosen modal library, providing a consistent and user-friendly experience in your web application.