diff --git a/static/js/normalizeToast.js b/static/js/normalizeToast.js deleted file mode 100644 index 17fd9b5..0000000 --- a/static/js/normalizeToast.js +++ /dev/null @@ -1,8 +0,0 @@ -function normalizeToast(){ - console.warn("Something is using the deprecated function normalizeToast(). Please use createNewToast() instead.") - $('#generalToast').removeClass('text-bg-primary'); - $('#generalToast').removeClass('text-bg-success'); - $('#generalToast').removeClass('text-bg-danger'); - $('#generalToast').removeClass('text-bg-warning'); - $('#generalToast').removeClass('text-bg-info'); -} diff --git a/static/js/toastHandler.js b/static/js/toastHandler.js index 9f8571f..856ff03 100644 --- a/static/js/toastHandler.js +++ b/static/js/toastHandler.js @@ -1,5 +1,13 @@ const currentToasts = []; +/** + * Generic function to create a new toast + * @param {String} message The message to be displayed + * @param {String} colorSelector The bootstrap color selector class, can be one of the following: text-bg-primary, text-bg-success, text-bg-danger, text-bg-warning, text-bg-info + * @param {Number} autoHideTime The time in milliseconds to auto hide the toast, default is 3000 + * @param {Boolean} autoReload Should the page reload after the toast is hidden, default is true (for compatibility with old code) + * @returns {String} The id of the created toast, format: toast- + */ function createNewToast(message, colorSelector, autoHideTime = 3000, autoReload = true){ const targetContainer = document.getElementById('toastMainController'); const masterToast = document.getElementById('masterToast'); @@ -17,11 +25,26 @@ function createNewToast(message, colorSelector, autoHideTime = 3000, autoReload location.reload(); } }, autoHideTime); + return newToast.id; } +/** + * Generic function to destroy a toast + * @param {String} id The id of the toast to destroy + */ function destroyToast(id){ const targetContainer = document.getElementById('toastMainController'); const targetToast = document.getElementById(id); targetContainer.removeChild(targetToast); currentToasts.splice(currentToasts.indexOf(targetToast), 1); -} \ No newline at end of file +} + +// Moved here +function normalizeToast(){ + console.warn("Something is using the deprecated function normalizeToast(). Please use createNewToast() instead.") + $('#generalToast').removeClass('text-bg-primary'); + $('#generalToast').removeClass('text-bg-success'); + $('#generalToast').removeClass('text-bg-danger'); + $('#generalToast').removeClass('text-bg-warning'); + $('#generalToast').removeClass('text-bg-info'); +}