ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akovale...@apache.org
Subject ambari git commit: AMBARI-10470. Alert Notifications : save button is disabled when creating alert notification (akovalenko)
Date Wed, 24 Jun 2015 15:36:10 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.0.maint 000bdbbfb -> 21ae5c1f1


AMBARI-10470. Alert Notifications : save button is disabled when creating alert notification
(akovalenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/21ae5c1f
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/21ae5c1f
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/21ae5c1f

Branch: refs/heads/branch-2.0.maint
Commit: 21ae5c1f1518f3d1e3750a8d502de854777e5e2b
Parents: 000bdbb
Author: Aleksandr Kovalenko <akovalenko@hortonworks.com>
Authored: Wed Jun 24 18:06:52 2015 +0300
Committer: Aleksandr Kovalenko <akovalenko@hortonworks.com>
Committed: Wed Jun 24 18:07:08 2015 +0300

----------------------------------------------------------------------
 .../manage_alert_notifications_controller.js    | 48 +++++++++++++++++
 ...anage_alert_notifications_controller_test.js | 54 +++++++++++++++++++-
 2 files changed, 101 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/21ae5c1f/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
index 6d0fad2..741f139 100644
--- a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
+++ b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
@@ -223,6 +223,37 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     'mail.smtp.starttls.enable'
   ],
 
+  validationMap: {
+    EMAIL: [
+      {
+        errorKey: 'emailToError',
+        validator: 'emailToValidation'
+      },
+      {
+        errorKey: 'emailFromError',
+        validator: 'emailFromValidation'
+      },
+      {
+        errorKey: 'smtpPortError',
+        validator: 'smtpPortValidation'
+      },
+      {
+        errorKey: 'passwordError',
+        validator: 'retypePasswordValidation'
+      }
+    ],
+    SNMP: [
+      {
+        errorKey: 'portError',
+        validator: 'portValidation'
+      },
+      {
+        errorKey: 'hostError',
+        validator: 'hostsValidation'
+      }
+    ]
+  },
+
   /**
    * Load all Alert Notifications from server
    * @method loadAlertNotifications
@@ -360,6 +391,23 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
           return this.get('controller.inputFields.method.value') === 'EMAIL';
         }.property('controller.inputFields.method.value'),
 
+        methodObserver: function () {
+          var currentMethod = this.get('controller.inputFields.method.value'),
+              validationMap = self.get('validationMap');
+          self.get('methods').forEach(function (method) {
+            var validations = validationMap[method];
+            if (method == currentMethod) {
+              validations.mapProperty('validator').forEach(function (key) {
+                this.get(key).call(this);
+              }, this);
+            } else {
+              validations.mapProperty('errorKey').forEach(function (key) {
+                this.set(key, false);
+              }, this);
+            }
+          }, this);
+        }.observes('controller.inputFields.method.value'),
+
         nameValidation: function () {
           var newName = this.get('controller.inputFields.name.value').trim();
           var errorMessage = '';

http://git-wip-us.apache.org/repos/asf/ambari/blob/21ae5c1f/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
index 92fb0a7..0e8a6e7 100644
--- a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
+++ b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js
@@ -516,7 +516,8 @@ describe('App.ManageAlertNotificationsController', function () {
               global: {},
               allGroups: {},
               SMTPPassword: {},
-              retypeSMTPPassword: {}
+              retypeSMTPPassword: {},
+              method: {}
             }
           }),
           groupSelect: Em.Object.create({
@@ -622,6 +623,57 @@ describe('App.ManageAlertNotificationsController', function () {
 
       });
 
+      describe('#methodObserver', function () {
+
+        var cases = [
+              {
+                method: 'EMAIL',
+                errors: ['portError', 'hostError'],
+                validators: ['emailToValidation', 'emailFromValidation', 'smtpPortValidation',
'retypePasswordValidation']
+              },
+              {
+                method: 'SNMP',
+                errors: ['emailToError', 'emailFromError', 'smtpPortError', 'passwordError'],
+                validators: ['portValidation', 'hostsValidation']
+              }
+            ],
+            validators = [];
+
+        before(function () {
+          cases.forEach(function (item) {
+            validators.pushObjects(item.validators);
+          });
+        });
+
+        beforeEach(function () {
+          validators.forEach(function (item) {
+            sinon.stub(view, item, Em.K);
+          });
+        });
+
+        afterEach(function () {
+          validators.forEach(function (item) {
+            view.get(item).restore();
+          });
+        });
+
+        cases.forEach(function (item) {
+          it(item.method, function () {
+            item.errors.forEach(function (errorName) {
+              view.set(errorName, true);
+            });
+            view.set('controller.inputFields.method.value', item.method);
+            item.errors.forEach(function (errorName) {
+              expect(view.get(errorName)).to.be.false;
+            });
+            validators.forEach(function (validatorName) {
+              expect(view.get(validatorName).calledOnce).to.equal(item.validators.contains(validatorName));
+            });
+          });
+        });
+
+      });
+
     });
 
   });


Mime
View raw message