Skip to content

Commit

Permalink
Fix typo and add url validation
Browse files Browse the repository at this point in the history
Url validation needed because default ng url validation was positive for any web protocol but it was needed to be positive only for http or https
  • Loading branch information
ZitaNemeckova committed Mar 24, 2017
1 parent d63cff8 commit 3c4b3c4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ ManageIQ.angular.app.controller('repositoryFormController', ['$scope', 'reposito
};

$scope.cancelClicked = function() {
var message = $scope.newRecord ? __('Add of Repository canceled by user.') : sprintf(__('Edit of Repository \"%s\" canceled by user.'), vm.repositoryModel.name);
var message = $scope.newRecord ? __('Add of Repository cancelled by user.') : sprintf(__('Edit of Repository \"%s\" cancelled by user.'), vm.repositoryModel.name);
var url = '/ansible_repository/show_list' + '?flash_msg=' + message + '&escape=true&flash_warning=true&flash_error=false';
window.location.href = url;
};
Expand Down
18 changes: 18 additions & 0 deletions app/assets/javascripts/directives/url_validation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ManageIQ.angular.app.directive('urlValidation', function() {
return {
require: 'ngModel',
link: function (_scope, _elem, _attrs, ctrl) {
ctrl.$validators.urlValidation = function (modelValue, viewValue) {
if (!viewValue) {
return true;
}
return validUrl(viewValue);
};

var validUrl = function(s) {
debugger;
return s.substring(0, 8) === 'https://' || s.substring(0, 7) === 'http://';
};
}
}
});
17 changes: 9 additions & 8 deletions app/views/ansible_repository/_repository_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,20 @@
options_for_select([["#{_('GIT')}", "git"]], 'git'),
"ng-model" => "vm.repositoryModel.scm_type",
:disabled => true)
.form-group{"ng-class" => "{'has-error': angularForm.scm_url.$error.required || angularForm.scm_url.$error.url}"}
.form-group{"ng-class" => "{'has-error': angularForm.scm_url.$error.required || angularForm.scm_url.$error.urlValidation}"}
%label.col-md-2.control-label
= _('URL')
.col-md-8
%input.form-control{:type => "url",
:name => "scm_url",
:id => "scm_url",
'ng-model' => "vm.repositoryModel.scm_url",
:required => "",
:checkchange => true}
%input.form-control{:type => "text",
:name => "scm_url",
:id => "scm_url",
'ng-model' => "vm.repositoryModel.scm_url",
:required => "",
:checkchange => true,
'url-validation' => true}
%span.help-block{"ng-show" => "angularForm.scm_url.$error.required"}
= _("Required")
%span.help-block{"ng-show" => "angularForm.scm_url.$error.url"}
%span.help-block{"ng-show" => "angularForm.scm_url.$error.urlValidation"}
= _("URL must include a protocol (http:// or https://)")
.form-group
%label.col-md-2.control-label
Expand Down

0 comments on commit 3c4b3c4

Please sign in to comment.