Repository: qpid-dispatch
Updated Branches:
  refs/heads/master c4029df1e -> 5c9e8d7e7


DISPATCH-428 Add form error checking on port


Project: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/commit/5c9e8d7e
Tree: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/tree/5c9e8d7e
Diff: http://git-wip-us.apache.org/repos/asf/qpid-dispatch/diff/5c9e8d7e

Branch: refs/heads/master
Commit: 5c9e8d7e739eef11525e44d52197c087a522b6aa
Parents: c4029df
Author: Ernest Allen <eal...@redhat.com>
Authored: Thu Jul 7 10:21:52 2016 -0400
Committer: Ernest Allen <eal...@redhat.com>
Committed: Thu Jul 7 10:21:52 2016 -0400

----------------------------------------------------------------------
 .../src/main/webapp/plugin/css/plugin.css       |  8 +++
 .../src/main/webapp/plugin/html/qdrConnect.html |  4 +-
 .../src/main/webapp/plugin/js/qdrSettings.js    | 76 +++++++++++++++++++-
 3 files changed, 84 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/5c9e8d7e/console/hawtio/src/main/webapp/plugin/css/plugin.css
----------------------------------------------------------------------
diff --git a/console/hawtio/src/main/webapp/plugin/css/plugin.css 
b/console/hawtio/src/main/webapp/plugin/css/plugin.css
index d02dc55..d6c9aa2 100644
--- a/console/hawtio/src/main/webapp/plugin/css/plugin.css
+++ b/console/hawtio/src/main/webapp/plugin/css/plugin.css
@@ -851,3 +851,11 @@ select:focus, input[type="file"]:focus, 
input[type="radio"]:focus, input[type="c
     outline: 5px auto -webkit-focus-ring-color;
     outline-offset: -2px;
 }
+
+btn.disabled, .btn[disabled] {
+    opacity: 0.35;
+}
+
+#dispatch-login-container .ng-invalid-posint {
+       border-color: #e9322d !important;
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/5c9e8d7e/console/hawtio/src/main/webapp/plugin/html/qdrConnect.html
----------------------------------------------------------------------
diff --git a/console/hawtio/src/main/webapp/plugin/html/qdrConnect.html 
b/console/hawtio/src/main/webapp/plugin/html/qdrConnect.html
index 3614db9..6a448d3 100644
--- a/console/hawtio/src/main/webapp/plugin/html/qdrConnect.html
+++ b/console/hawtio/src/main/webapp/plugin/html/qdrConnect.html
@@ -42,12 +42,12 @@ under the License.
                           <div class="control-group" ng-show="true">
                               <label class="strong control-label">Address: 
</label>
                               <div class="controls">
-                                  <input type="text" 
ng-model="formEntity.address" name="address" required="required" 
autofocus="autofocus" class="ng-pristine ng-valid ng-valid-required"><span 
class="help-block"></span></div>
+                                  <input type="text" 
ng-model="formEntity.address" placeholder="localhost" name="address" 
autofocus="autofocus" class="ng-pristine ng-valid ng-valid-required"><span 
class="help-block"></span></div>
                           </div>
                           <div class="control-group" ng-show="true">
                               <label class="control-label" title="Ports to 
connect to, by default 5673">Port: </label>
                               <div class="controls">
-                                  <input type="number" tooltip="Ports to 
connect to, by default 5673" ng-model="formEntity.port" name="port" 
title="Ports to connect to, by default 5673" class="ng-scope ng-pristine 
ng-valid ng-valid-number"><span class="help-block"></span></div>
+                                  <input type="number" ng-pattern="/^[0-9]+$/" 
placeholder="5673" tooltip="Ports to connect to, by default 5673" 
ng-model="formEntity.port" name="port" title="Ports to connect to, by default 
5673" class="ng-scope ng-pristine ng-valid ng-valid-number"><span 
class="help-block"></span></div>
                           </div>
                           <div class="control-group" ng-show="true">
                               <label class="control-label" title="Whether or 
not the connection should be started as soon as you log into hawtio">Autostart: 
</label>

http://git-wip-us.apache.org/repos/asf/qpid-dispatch/blob/5c9e8d7e/console/hawtio/src/main/webapp/plugin/js/qdrSettings.js
----------------------------------------------------------------------
diff --git a/console/hawtio/src/main/webapp/plugin/js/qdrSettings.js 
b/console/hawtio/src/main/webapp/plugin/js/qdrSettings.js
index 9d07ba5..518229d 100644
--- a/console/hawtio/src/main/webapp/plugin/js/qdrSettings.js
+++ b/console/hawtio/src/main/webapp/plugin/js/qdrSettings.js
@@ -28,6 +28,7 @@ var QDR = (function (QDR) {
    *
    * Controller that handles the QDR settings page
    */
+
   QDR.module.controller("QDR.SettingsController", ['$scope', 'QDRService', 
'$location', function($scope, QDRService, $location) {
 
     $scope.connecting = false;
@@ -51,16 +52,20 @@ var QDR = (function (QDR) {
       }
     };
 
-    
     $scope.connect = function() {
                if (QDRService.connected) {
                        QDRService.disconnect();
                        return;
                }
+
       if ($scope.settings.$valid) {
         $scope.connectionError = false;
         $scope.connecting = true;
-        console.log("attempting to connect");
+
+        if (!$scope.formEntity.address)
+            $scope.formEntity.address = "localhost"
+
+        console.log("attempting to connect to " + $scope.formEntity.address + 
':' + $scope.formEntity.port);
         QDRService.addDisconnectAction(function() {
           QDR.log.debug("disconnect action called");
           $scope.connecting = false;
@@ -82,11 +87,78 @@ var QDR = (function (QDR) {
           //QDR.log.debug("location after the connect " + $location.path());
           $scope.$apply();
         });
+
+
         QDRService.connect($scope.formEntity);
       }
     };
 
   }]);
 
+
+QDR.module.directive('posint', function (){
+   return {
+      require: 'ngModel',
+      link: function(scope, elem, attr, ctrl) {
+
+                 var isPortValid = function (value) {
+                       var port = value + ''
+                       var n = ~~Number(port);
+                       var valid = (port.length === 0) || (String(n) === port 
&& n >= 0)
+                       var nono = "-+.,"
+                       for (var i=0; i<port.length; ++i) {
+                               if (nono.indexOf(port[i]) >= 0) {
+                                       valid = false;
+                                       break
+                               }
+                       }
+                       return valid;
+                 }
+
+          //For DOM -> model validation
+          ctrl.$parsers.unshift(function(value) {
+                       var valid = isPortValid(value)
+                       ctrl.$setValidity('posint', valid)
+                       return valid ? value : undefined;
+          });
+
+          //For model -> DOM validation
+          ctrl.$formatters.unshift(function(value) {
+             ctrl.$setValidity('posint', isPortValid(value));
+             return value;
+          });
+      }
+   };
+});
+
+/*
+QDR.module.directive('posint', function() {
+  return {
+    require: 'ngModel',
+    link: function(scope, elm, attrs, ctrl) {
+      ctrl.$validators.posint = function(modelValue, viewValue) {
+        if (ctrl.$isEmpty(modelValue)) {
+          // consider empty models to be valid
+          return true;
+        }
+
+               var port = modelValue + ''
+               var n = ~~Number(port);
+               var valid = (String(n) === port && n >= 0)
+               var nono = "-+.,"
+               for (var i=0; i<port.length; ++i) {
+                       if (nono.indexOf(port[i]) >= 0) {
+                               valid = false;
+                               break
+                       }
+               }
+               return valid;
+      };
+    }
+  };
+});
+
+*/
+
   return QDR;
 }(QDR || {}));


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@qpid.apache.org
For additional commands, e-mail: commits-h...@qpid.apache.org

Reply via email to