2016-06-26 16:52:06 +02:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
2018-08-12 14:26:26 +02:00
|
|
|
angular.module('ariaNg').factory('ariaNgNotificationService', ['$notification', 'Notification', 'ariaNgSettingService', function ($notification, Notification, ariaNgSettingService) {
|
2016-06-26 16:52:06 +02:00
|
|
|
var isSupportBrowserNotification = $notification.isSupported;
|
|
|
|
|
|
|
|
var isPermissionGranted = function (permission) {
|
2016-08-01 19:26:10 +02:00
|
|
|
return permission === 'granted';
|
2016-06-26 16:52:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
isSupportBrowserNotification: function () {
|
|
|
|
return isSupportBrowserNotification;
|
|
|
|
},
|
|
|
|
isPermissionGranted: function (permission) {
|
|
|
|
return isPermissionGranted(permission);
|
|
|
|
},
|
|
|
|
hasBrowserPermission: function () {
|
|
|
|
if (!isSupportBrowserNotification) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return isPermissionGranted($notification.getPermission());
|
|
|
|
},
|
|
|
|
requestBrowserPermission: function (callback) {
|
|
|
|
if (!isSupportBrowserNotification) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$notification.requestPermission().then(function (permission) {
|
|
|
|
if (!isPermissionGranted(permission)) {
|
|
|
|
ariaNgSettingService.setBrowserNotification(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callback) {
|
|
|
|
callback(permission);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2016-07-16 17:16:07 +02:00
|
|
|
notifyViaBrowser: function (title, content) {
|
2016-06-26 16:52:06 +02:00
|
|
|
if (isSupportBrowserNotification && ariaNgSettingService.getBrowserNotification()) {
|
2018-08-12 14:26:26 +02:00
|
|
|
$notification(title, {
|
|
|
|
body: content
|
2016-06-26 16:52:06 +02:00
|
|
|
});
|
|
|
|
}
|
2016-06-28 18:18:17 +02:00
|
|
|
},
|
2016-07-16 17:16:07 +02:00
|
|
|
notifyInPage: function (title, content, options) {
|
|
|
|
if (!options) {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!content) {
|
|
|
|
options.message = title;
|
|
|
|
} else {
|
|
|
|
options.title = title;
|
|
|
|
options.message = content;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!options.type || !Notification[options.type]) {
|
|
|
|
options.type = 'primary';
|
|
|
|
}
|
|
|
|
|
2017-03-29 03:06:43 +02:00
|
|
|
return Notification[options.type](options);
|
2016-07-16 17:16:07 +02:00
|
|
|
},
|
|
|
|
clearNotificationInPage: function () {
|
|
|
|
Notification.clearAll();
|
2016-06-26 16:52:06 +02:00
|
|
|
}
|
2016-12-10 18:50:25 +01:00
|
|
|
};
|
2016-06-26 16:52:06 +02:00
|
|
|
}]);
|
2016-08-01 16:49:16 +02:00
|
|
|
}());
|