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

63 lines
2.0 KiB
JavaScript
Raw Normal View History

2015-08-02 00:29:34 +02:00
'use strict';
angular.module('lemur')
.service('NotificationApi', function (LemurRestangular) {
LemurRestangular.extendModel('notifications', function (obj) {
return angular.extend(obj, {
attachCertificate: function (certificate) {
this.selectedCertificate = null;
if (this.certificates === undefined) {
this.certificates = [];
}
this.certificates.push(certificate);
},
removeCertificate: function (index) {
2016-05-10 02:35:18 +02:00
this.certificates.splice(index, 1);
2015-08-02 00:29:34 +02:00
}
});
});
return LemurRestangular.all('notifications');
})
2016-05-12 21:38:44 +02:00
.service('NotificationService', function ($location, NotificationApi, PluginService) {
2015-08-02 00:29:34 +02:00
var NotificationService = this;
NotificationService.findNotificationsByName = function (filterValue) {
return NotificationApi.getList({'filter[label]': filterValue})
.then(function (notifications) {
return notifications;
});
};
NotificationService.getCertificates = function (notification) {
notification.getList('certificates').then(function (certificates) {
notification.certificates = certificates;
});
};
NotificationService.getPlugin = function (notification) {
return PluginService.getByName(notification.pluginName).then(function (plugin) {
notification.plugin = plugin;
});
};
NotificationService.loadMoreCertificates = function (notification, page) {
notification.getList('certificates', {page: page}).then(function (certificates) {
_.each(certificates, function (certificate) {
notification.roles.push(certificate);
});
});
};
NotificationService.create = function (notification) {
2016-05-12 21:38:44 +02:00
return NotificationApi.post(notification);
2015-08-02 00:29:34 +02:00
};
NotificationService.update = function (notification) {
2016-05-12 21:38:44 +02:00
return notification.put();
2015-08-02 00:29:34 +02:00
};
NotificationService.updateActive = function (notification) {
2016-05-12 21:38:44 +02:00
notification.put();
2015-08-02 00:29:34 +02:00
};
return NotificationService;
});