123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- /**
- * 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.
- */
- App.MainAlertDefinitionDetailsController = Em.Controller.extend({
- name: 'mainAlertDefinitionDetailsController',
- alerts: function () {
- return App.AlertInstance.find().toArray()
- .filterProperty('definitionId', this.get('content.id'));
- }.property('App.router.mainAlertInstancesController.isLoaded'),
- // stores object with editing form data (label, description, thresholds)
- editing: Em.Object.create({
- label: Em.Object.create({
- name: 'label',
- isEditing: false,
- value: '',
- originalValue: '',
- isError: false,
- bindingValue: 'content.label'
- }),
- description: Em.Object.create({
- name: 'description',
- isEditing: false,
- value: '',
- originalValue: '',
- isError: false,
- bindingValue: 'content.description'
- })
- }),
- /**
- * Validation function to define if label field populated correctly
- */
- labelValidation: function () {
- this.set('editing.label.isError', !this.get('editing.label.value').trim());
- }.observes('editing.label.value'),
- /**
- * Validation function to define if description field populated correctly
- */
- descriptionValidation: function () {
- this.set('editing.description.isError', !this.get('editing.description.value').trim());
- }.observes('editing.description.value'),
- /**
- * Load alert instances for current alertDefinition
- * Start updating loaded data
- * @method loadAlertInstances
- */
- loadAlertInstances: function() {
- App.router.get('mainAlertInstancesController').loadAlertInstancesByAlertDefinition(this.get('content.id'));
- App.router.set('mainAlertInstancesController.isUpdating', true);
- },
- /**
- * Edit button handler
- * @param event
- */
- edit: function (event) {
- var element = event.context;
- var value = this.get(element.get('bindingValue'));
- element.set('originalValue', value);
- element.set('value', value);
- element.set('isEditing', true);
- },
- /**
- * Cancel button handler
- * @param event
- */
- cancelEdit: function (event) {
- var element = event.context;
- element.set('value', element.get('originalValue'));
- element.set('isEditing', false);
- },
- /**
- * Save button handler, could save label/description/thresholds of alert definition
- * @param event
- * @returns {$.ajax}
- * @method saveEdit
- */
- saveEdit: function (event) {
- var element = event.context;
- this.set(element.get('bindingValue'), element.get('value'));
- element.set('isEditing', false);
- var data = Em.Object.create({});
- var property_name = "AlertDefinition/" + element.get('name');
- data.set(property_name, element.get('value'));
- var alertDefinition_id = this.get('content.id');
- return App.ajax.send({
- name: 'alerts.update_alert_definition',
- sender: this,
- data: {
- id: alertDefinition_id,
- data: data
- }
- });
- },
- /**
- * "Delete" button handler
- * @param event
- */
- deleteAlertDefinition : function(event) {
- var alertDefinition = this.get('content');
- var self = this;
- App.showConfirmationPopup(function() {
- App.ajax.send({
- name : 'alerts.delete_alert_definition',
- sender : self,
- success : 'deleteAlertDefinitionSuccess',
- error : 'deleteAlertDefinitionError',
- data : {
- id : alertDefinition.get('id')
- }
- });
- }, null, function() {
- });
- },
- deleteAlertDefinitionSuccess : function() {
- App.router.transitionTo('main.alerts.index');
- },
- deleteAlertDefinitionError : function(xhr, textStatus, errorThrown, opt) {
- console.log(textStatus);
- console.log(errorThrown);
- xhr.responseText = "{\"message\": \"" + xhr.statusText + "\"}";
- App.ajax.defaultErrorHandler(xhr, opt.url, 'DELETE', xhr.status);
- },
- /**
- * "Disable / Enable" button handler
- * @returns {$.ajax}
- * @method toggleState
- */
- toggleState: function() {
- var alertDefinition = this.get('content');
- return App.ajax.send({
- name: 'alerts.update_alert_definition',
- sender: this,
- data: {
- id: alertDefinition.get('id'),
- data: {
- "AlertDefinition/enabled": !alertDefinition.get('enabled')
- }
- }
- });
- },
- /**
- * Router transition to host level alerts page
- * @param event
- */
- goToHostAlerts: function (event) {
- if (event && event.context) {
- App.router.transitionTo('main.hosts.hostDetails.alerts', event.context);
- }
- }
- });
|