notification_edit_ctrl.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. model: any;
  8. /** @ngInject */
  9. constructor(private $routeParams, private backendSrv, private $scope, private $location) {
  10. if ($routeParams.id) {
  11. this.loadNotification($routeParams.id);
  12. } else {
  13. this.model = {
  14. type: 'email',
  15. settings: {}
  16. };
  17. }
  18. }
  19. loadNotification(id) {
  20. this.backendSrv.get(`/api/alert-notifications/${id}`).then(result => {
  21. this.model = result;
  22. });
  23. }
  24. isNew() {
  25. return this.model.id === undefined;
  26. }
  27. save() {
  28. if (this.model.id) {
  29. this.backendSrv.put(`/api/alert-notifications/${this.model.id}`, this.model).then(res => {
  30. this.model = res;
  31. });
  32. } else {
  33. this.backendSrv.post(`/api/alert-notifications`, this.model).then(res => {
  34. this.$location.path('alerting/notification/' + res.id + '/edit');
  35. });
  36. }
  37. }
  38. typeChanged() {
  39. this.model.settings = {};
  40. }
  41. }
  42. coreModule.controller('AlertNotificationEditCtrl', AlertNotificationEditCtrl);