Code coverage report for app/views/main/alerts/manage_alert_groups_view.js

Statements: 93.75% (30 / 32)      Branches: 100% (20 / 20)      Functions: 90.91% (10 / 11)      Lines: 93.55% (29 / 31)      Ignored: none     

All files » app/views/main/alerts/ » manage_alert_groups_view.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153    1                                     1   1                           6   6 4   6 1   6             19 2               17 2 2                   1               1             3 3 3                                                                           3 1   2 1   1               3 1   2 1   1        
'use strict';
 
;require.register("views/main/alerts/manage_alert_groups_view", function (exports, require, module) {
  /**
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
 
  var App = require('app');
 
  App.MainAlertsManageAlertGroupView = Em.View.extend({
 
    templateName: require('templates/main/alerts/manage_alert_groups_popup'),
 
    /**
     * @type {object}
     */
    selectedAlertGroup: null,
 
    /**
     * Observer to prevent user select more than 1 alert group
     * @method onGroupSelect
     */
    onGroupSelect: function () {
      var selectedAlertGroup = this.get('selectedAlertGroup');
      // to unable user select more than one alert group at a time
      if (selectedAlertGroup && selectedAlertGroup.length) {
        this.set('controller.selectedAlertGroup', selectedAlertGroup[selectedAlertGroup.length - 1]);
      }
      if (selectedAlertGroup && selectedAlertGroup.length > 1) {
        this.set('selectedAlertGroup', selectedAlertGroup[selectedAlertGroup.length - 1]);
      }
      this.set('controller.selectedDefinitions', []);
    }.observes('selectedAlertGroup'),
 
    /**
     * Observer to provide two-way binding for group selection
     */
    setGroupInController: function () {
      if (!this.get('controller.isLoaded')) return;
      this.set('selectedAlertGroup', [this.get('controller.selectedAlertGroup')]);
    }.observes('controller.selectedAlertGroup'),
 
    /**
     * Select first alert group when all groups are loaded
     * @method onLoad
     */
    onLoad: function () {
      if (this.get('controller.isLoaded')) {
        this.set('selectedAlertGroup', [this.get('controller.alertGroups.firstObject')]);
        this.setTooltips();
      }
    }.observes('controller.isLoaded'),
 
    /**
     * Load alert groups, definitions and notification to have all new data
     * Useful if user delete some definition and immediately open "Manage Alert Groups" popup
     * @method willInsertElement
     */
    willInsertElement: function willInsertElement() {
      this.get('controller').loadAlertNotifications();
    },
 
    /**
     * Add tooltips and try to select first alert group
     * @method didInsertElement
     */
    didInsertElement: function didInsertElement() {
      this.onLoad();
    },
 
    /**
     * Setup tooltips for view elements
     */
    setTooltips: function setTooltips() {
      Em.run.next(function () {
        App.tooltip($("[rel='button-info']"));
        App.tooltip($("[rel='button-info-dropdown']"), { placement: 'left' });
      });
    },
 
    willDestroyElement: function willDestroyElement() {
      $("[rel='button-info']").tooltip('destroy');
      $("[rel='button-info-dropdown']").tooltip('destroy');
    },
 
    /**
     * Tooltip for "Add group"-button
     * @type {string}
     */
    addButtonTooltip: Em.I18n.t('alerts.actions.manage_alert_groups_popup.addButton'),
 
    /**
     * Tooltip for "Remove group"-button
     * @type {string}
     */
    removeButtonTooltip: Em.computed.ifThenElse('controller.isRemoveButtonDisabled', Em.I18n.t('alerts.actions.manage_alert_groups_popup.removeButtonDisabled'), Em.I18n.t('alerts.actions.manage_alert_groups_popup.removeButton')),
 
    /**
     * Tooltip for "Rename"-button
     * @type {string}
     */
    renameButtonTooltip: Em.I18n.t('alerts.actions.manage_alert_groups_popup.renameButton'),
 
    /**
     * Tooltip for "Duplicate group"-button
     * @type {string}
     */
    duplicateButtonTooltip: Em.I18n.t('alerts.actions.manage_alert_groups_popup.duplicateButton'),
 
    /**
     * Tooltip for "Add definition to group"-button
     * @type {string}
     */
    addDefinitionTooltip: function () {
      if (this.get('controller.selectedAlertGroup.default')) {
        return Em.I18n.t('alerts.actions.manage_alert_groups_popup.addDefinitionToDefault');
      }
      if (this.get('controller.selectedAlertGroup.isAddDefinitionsDisabled')) {
        return Em.I18n.t('alerts.actions.manage_alert_groups_popup.addDefinitionDisabled');
      }
      return Em.I18n.t('alerts.actions.manage_alert_groups_popup.addDefinition');
    }.property('controller.selectedAlertGroup.default', 'controller.selectedAlertGroup.isAddDefinitionsDisabled'),
 
    /**
     * Tooltip for "Remove definition from group"-button
     * @type {string}
     */
    removeDefinitionTooltip: function () {
      if (this.get('controller.selectedAlertGroup.default')) {
        return Em.I18n.t('alerts.actions.manage_alert_groups_popup.removeDefinitionDisabled');
      }
      if (this.get('controller.isDeleteDefinitionsDisabled')) {
        return Em.I18n.t('common.nothingToDelete');
      }
      return Em.I18n.t('alerts.actions.manage_alert_groups_popup.removeDefinition');
    }.property('controller.selectedAlertGroup.default', 'controller.isDeleteDefinitionsDisabled')
 
  });
});