Update toast notification
Added new toast notification types, warn and info,
and updated visual styling. All toasts will need
to be manually closed by clicking the 'X' close icon,
except a success toast which will be dismissed
automatically after 10 secs.
- Small updates to critical and success/on icon
- Added new colors for toast status background colors
Signed-off-by: Yoshie Muranaka <yoshiemuranaka@gmail.com>
Change-Id: I9077109042621b2d3346b4121d6344da502b6b26
diff --git a/app/common/services/toastService.js b/app/common/services/toastService.js
index c199e96..0718e4d 100644
--- a/app/common/services/toastService.js
+++ b/app/common/services/toastService.js
@@ -13,15 +13,39 @@
angular.module('app.common.services').service('toastService', [
'ngToast', '$sce',
function(ngToast, $sce) {
- this.error = function(message) {
- var errorMessage = $sce.trustAsHtml(
- '<div role="alert"><b>Error</b><br>' + message + '</div>');
- ngToast.create({className: 'danger', content: errorMessage});
+ function initToast(
+ type = 'create', title = '', message = '', dismissOnTimeout = false) {
+ const iconStatus = type === 'success' ?
+ 'on' :
+ type === 'danger' ? 'error' : type === 'warning' ? 'warn' : null;
+ const content = $sce.trustAsHtml(`
+ <div role="alert" class="alert-content-container">
+ <status-icon ng-if="${iconStatus !== null}"
+ status="${iconStatus}"
+ class="status-icon">
+ </status-icon>
+ <div class="alert-content">
+ <h2 class="alert-content__header">${title}</h2>
+ <p class="alert-content__body">${message}</p>
+ </div>
+ </div>`);
+ ngToast[type]({content, dismissOnTimeout, compileContent: true});
};
+
+ this.error = function(message) {
+ initToast('danger', 'Error', message);
+ };
+
this.success = function(message) {
- var successMessage = $sce.trustAsHtml(
- '<div role="alert"><b>Success!</b><br>' + message + '</div>');
- ngToast.create({className: 'success', content: successMessage});
+ initToast('success', 'Success!', message, true);
+ };
+
+ this.warn = function(message) {
+ initToast('warning', 'Warning', message);
+ };
+
+ this.info = function(title, message) {
+ initToast('info', title, message);
};
}
]);