notification_edit_ctrl.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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) {
  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. console.log('updated notification', result);
  30. });
  31. } else {
  32. this.backendSrv.post(`/api/alerts/notification`, this.notification)
  33. .then(result => {
  34. this.notification = result;
  35. console.log('created new notification', result);
  36. });
  37. }
  38. }
  39. }
  40. coreModule.controller('AlertNotificationEditCtrl', AlertNotificationEditCtrl);