blob: 0718e4ddb4e4538c679682745b11469c164f4873 [file] [log] [blame]
beccabroek27ce84d2019-02-05 15:43:17 -06001/**
2 * data service
3 *
4 * @module app/common/services/toastService
5 * @exports toastService
6 * @name toastService
7
8 */
9
10window.angular && (function(angular) {
11 'use strict';
12
13 angular.module('app.common.services').service('toastService', [
14 'ngToast', '$sce',
15 function(ngToast, $sce) {
Yoshie Muranaka5e930c02019-10-16 08:13:53 -070016 function initToast(
17 type = 'create', title = '', message = '', dismissOnTimeout = false) {
18 const iconStatus = type === 'success' ?
19 'on' :
20 type === 'danger' ? 'error' : type === 'warning' ? 'warn' : null;
21 const content = $sce.trustAsHtml(`
22 <div role="alert" class="alert-content-container">
23 <status-icon ng-if="${iconStatus !== null}"
24 status="${iconStatus}"
25 class="status-icon">
26 </status-icon>
27 <div class="alert-content">
28 <h2 class="alert-content__header">${title}</h2>
29 <p class="alert-content__body">${message}</p>
30 </div>
31 </div>`);
32 ngToast[type]({content, dismissOnTimeout, compileContent: true});
beccabroek27ce84d2019-02-05 15:43:17 -060033 };
Yoshie Muranaka5e930c02019-10-16 08:13:53 -070034
35 this.error = function(message) {
36 initToast('danger', 'Error', message);
37 };
38
beccabroek27ce84d2019-02-05 15:43:17 -060039 this.success = function(message) {
Yoshie Muranaka5e930c02019-10-16 08:13:53 -070040 initToast('success', 'Success!', message, true);
41 };
42
43 this.warn = function(message) {
44 initToast('warning', 'Warning', message);
45 };
46
47 this.info = function(title, message) {
48 initToast('info', title, message);
beccabroek27ce84d2019-02-05 15:43:17 -060049 };
50 }
51 ]);
52})(window.angular);