notification_edit_ctrl.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. }
  39. coreModule.controller('AlertNotificationEditCtrl', AlertNotificationEditCtrl);