notification_edit_ctrl.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. ///<reference path="../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. import coreModule from '../../core/core_module';
  5. import config from 'app/core/config';
  6. export class AlertNotificationEditCtrl {
  7. notification: any;
  8. /** @ngInject */
  9. constructor(private $routeParams, private backendSrv, private $scope) {
  10. if ($routeParams.notificationId) {
  11. this.loadNotification($routeParams.notificationId);
  12. }
  13. }
  14. loadNotification(notificationId) {
  15. this.backendSrv.get(`/api/alerts/notification/${notificationId}`).then(result => {
  16. console.log(result);
  17. this.notification = result;
  18. });
  19. }
  20. isNew() {
  21. return this.notification === undefined || this.notification.id === undefined;
  22. }
  23. save() {
  24. if (this.notification.id) {
  25. console.log('this.notification: ', this.notification);
  26. this.backendSrv.put(`/api/alerts/notification/${this.notification.id}`, this.notification)
  27. .then(result => {
  28. this.notification = result;
  29. this.$scope.appEvent('alert-success', ['Notification created!', '']);
  30. }, () => {
  31. this.$scope.appEvent('alert-error', ['Unable to create notification.', '']);
  32. });
  33. } else {
  34. this.backendSrv.post(`/api/alerts/notification`, this.notification)
  35. .then(result => {
  36. this.notification = result;
  37. this.$scope.appEvent('alert-success', ['Notification updated!', '']);
  38. }, () => {
  39. this.$scope.appEvent('alert-error', ['Unable to update notification.', '']);
  40. });
  41. }
  42. }
  43. }
  44. coreModule.controller('AlertNotificationEditCtrl', AlertNotificationEditCtrl);