manage_alert_notifications_view.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.ManageAlertNotificationsView = Em.View.extend({
  20. templateName: require('templates/main/alerts/manage_alert_notifications_popup'),
  21. /**
  22. * @type {App.AlertNotification}
  23. */
  24. selectedAlertNotification: null,
  25. selectedAlertNotificationGroups: function () {
  26. return this.get('controller.selectedAlertNotification.groups').toArray().mapProperty('name').join(', ');
  27. }.property('controller.selectedAlertNotification'),
  28. isEditButtonDisabled: true,
  29. isRemoveButtonDisabled: true,
  30. isDuplicateButtonDisabled: true,
  31. /**
  32. * Show EMAIL information if selected alert notification has type EMAIL
  33. * @type {boolean}
  34. */
  35. showEmailDetails: function () {
  36. return this.get('controller.selectedAlertNotification.type') === 'EMAIL';
  37. }.property('controller.selectedAlertNotification.type'),
  38. /**
  39. * Show SNMP information if selected alert notification has type SNMP
  40. * @type {boolean}
  41. */
  42. showSNMPDetails: function () {
  43. return this.get('controller.selectedAlertNotification.type') === 'SNMP';
  44. }.property('controller.selectedAlertNotification.type'),
  45. /**
  46. * Enable/disable "edit"/"remove"/"duplicate" buttons basing on <code>controller.selectedAlertNotification</code>
  47. * @method buttonObserver
  48. */
  49. buttonObserver: function () {
  50. var selectedAlertNotification = this.get('controller.selectedAlertNotification');
  51. this.set('isEditButtonDisabled', !selectedAlertNotification);
  52. this.set('isRemoveButtonDisabled', !selectedAlertNotification);
  53. this.set('isDuplicateButtonDisabled', !selectedAlertNotification);
  54. }.observes('controller.selectedAlertNotification'),
  55. /**
  56. * Prevent user select more than 1 alert notification
  57. * @method onAlertNotificationSelect
  58. */
  59. onAlertNotificationSelect: function () {
  60. var selectedAlertNotification = this.get('selectedAlertNotification');
  61. if (selectedAlertNotification && selectedAlertNotification.length) {
  62. this.set('controller.selectedAlertNotification', selectedAlertNotification[selectedAlertNotification.length - 1]);
  63. }
  64. if (selectedAlertNotification && selectedAlertNotification.length > 1) {
  65. this.set('selectedAlertNotification', selectedAlertNotification[selectedAlertNotification.length - 1]);
  66. }
  67. }.observes('selectedAlertNotification'),
  68. /**
  69. * Set first alert notification as selected (if they are already loaded)
  70. * Add some tooltips on manage buttons
  71. * @method onLoad
  72. */
  73. onLoad: function () {
  74. if (this.get('controller.isLoaded')) {
  75. var notifications = this.get('controller.alertNotifications');
  76. if (notifications && notifications.length) {
  77. this.set('selectedAlertNotification', notifications[0]);
  78. this.buttonObserver();
  79. } else {
  80. this.set('selectedAlertNotification', null);
  81. }
  82. Em.run.later(this, function () {
  83. App.tooltip(this.$("[rel='button-info']"));
  84. App.tooltip(this.$("[rel='button-info-dropdown']"), {placement: 'left'});
  85. }, 50) ;
  86. }
  87. }.observes('controller.isLoaded'),
  88. willInsertElement: function () {
  89. this.get('controller').loadAlertNotifications();
  90. },
  91. didInsertElement: function () {
  92. this.onLoad();
  93. }
  94. });