lemur/lemur/static/app/angular/notifications/notification/notification.js

81 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-08-02 00:29:34 +02:00
'use strict';
angular.module('lemur')
2016-05-12 21:38:44 +02:00
.controller('NotificationsCreateController', function ($scope, $uibModalInstance, PluginService, NotificationService, CertificateService, LemurRestangular, toaster){
2015-08-02 00:29:34 +02:00
$scope.notification = LemurRestangular.restangularizeElement(null, {}, 'notifications');
PluginService.getByType('notification').then(function (plugins) {
$scope.plugins = plugins;
});
$scope.save = function (notification) {
NotificationService.create(notification).then(
function () {
2016-05-12 21:38:44 +02:00
toaster.pop({
type: 'success',
title: notification.label,
body: 'Successfully Created!'
});
$uibModalInstance.close();
2016-05-12 21:38:44 +02:00
}, function (response) {
toaster.pop({
type: 'error',
title: notification.label,
body: 'lemur-bad-request',
bodyOutputType: 'directive',
directiveData: response.data,
timeout: 100000
});
});
2015-08-02 00:29:34 +02:00
};
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
2015-08-02 00:29:34 +02:00
};
$scope.certificateService = CertificateService;
})
2016-05-12 21:38:44 +02:00
.controller('NotificationsEditController', function ($scope, $uibModalInstance, NotificationService, NotificationApi, PluginService, CertificateService, toaster, editId) {
2015-08-02 00:29:34 +02:00
NotificationApi.get(editId).then(function (notification) {
$scope.notification = notification;
2015-08-04 00:52:39 +02:00
PluginService.getByType('notification').then(function (plugins) {
$scope.plugins = plugins;
_.each($scope.plugins, function (plugin) {
2020-10-23 03:15:26 +02:00
if (plugin.slug === $scope.notification.plugin.slug) {
plugin.pluginOptions = $scope.notification.plugin.pluginOptions;
2015-08-04 00:52:39 +02:00
$scope.notification.plugin = plugin;
}
});
});
2015-08-02 00:29:34 +02:00
NotificationService.getCertificates(notification);
});
$scope.save = function (notification) {
2016-05-12 21:38:44 +02:00
NotificationService.update(notification).then(
function () {
toaster.pop({
type: 'success',
title: notification.label,
2016-05-13 23:35:38 +02:00
body: 'Successfully Updated!'
2016-05-12 21:38:44 +02:00
});
$uibModalInstance.close();
}, function (response) {
toaster.pop({
type: 'error',
title: notification.label,
body: 'lemur-bad-request',
bodyOutputType: 'directive',
directiveData: response.data,
timeout: 100000
});
});
2015-08-02 00:29:34 +02:00
};
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
2015-08-02 00:29:34 +02:00
};
$scope.certificateService = CertificateService;
});