From 39ceceb18e982e68bba4e3fe1fd68f27301a2222 Mon Sep 17 00:00:00 2001 From: chouseknecht Date: Wed, 11 Sep 2013 15:35:45 -0400 Subject: [PATCH] AC-450 initialize SCM Branch title value when editing a project. Added awValidUrl directive. --- awx/ui/static/js/controllers/Projects.js | 1 + awx/ui/static/js/forms/Projects.js | 3 +-- awx/ui/static/js/lists/JobEvents.js | 2 +- awx/ui/static/lib/ansible/directives.js | 23 +++++++++++++++++++++ awx/ui/static/lib/ansible/form-generator.js | 5 +++++ 5 files changed, 31 insertions(+), 3 deletions(-) diff --git a/awx/ui/static/js/controllers/Projects.js b/awx/ui/static/js/controllers/Projects.js index dfcbe98bd2..edbac5062b 100644 --- a/awx/ui/static/js/controllers/Projects.js +++ b/awx/ui/static/js/controllers/Projects.js @@ -371,6 +371,7 @@ function ProjectsEdit ($scope, $rootScope, $compile, $location, $log, $routePara } master['scm_type'] = scope['scm_type']; + scope.scmBranchLabel = (scope.scm_type && scope.scm_type.value && scope.scm_type.value == 'svn') ? 'Revision #' : 'SCM Branch'; setAskCheckboxes(); // Initialize related search functions. Doing it here to make sure relatedSets object is populated. diff --git a/awx/ui/static/js/forms/Projects.js b/awx/ui/static/js/forms/Projects.js index 8fb91265b4..73f9342c27 100644 --- a/awx/ui/static/js/forms/Projects.js +++ b/awx/ui/static/js/forms/Projects.js @@ -96,8 +96,7 @@ angular.module('ProjectFormDefinition', []) label: 'SCM URL', type: 'text', ngShow: "scm_type !== '' && scm_type !== null", - addRequired: false, - editRequired: false, + awValidUrl: true, awRequiredWhen: {variable: "scm_type", init: "true" } }, scm_branch: { diff --git a/awx/ui/static/js/lists/JobEvents.js b/awx/ui/static/js/lists/JobEvents.js index d5a65fad3b..0e10901f44 100644 --- a/awx/ui/static/js/lists/JobEvents.js +++ b/awx/ui/static/js/lists/JobEvents.js @@ -33,7 +33,7 @@ angular.module('JobEventsListDefinition', []) fields: { created: { - label: 'Date', + label: 'Created On', key: true, nosort: true, searchable: false, diff --git a/awx/ui/static/lib/ansible/directives.js b/awx/ui/static/lib/ansible/directives.js index af0c2d38d4..2ac004191e 100644 --- a/awx/ui/static/lib/ansible/directives.js +++ b/awx/ui/static/lib/ansible/directives.js @@ -195,6 +195,29 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Hos } }]) + // + // awValidUrl + // + .directive('awValidUrl', [ function() { + return { + require: 'ngModel', + link: function(scope, elm, attrs, ctrl) { + ctrl.$parsers.unshift( function(viewValue) { + var validity = true; + if (viewValue !== '') { + ctrl.$setValidity('required', true); + var rgx = /^(https|http|ssh)\:\/\//; + var rgx2 = /\@/g; + if (!rgx.test(viewValue) || rgx2.test(viewValue)) { + validity = false; + } + } + ctrl.$setValidity('awvalidurl', validity); + }) + } + } + }]) + /* * Enable TB tooltips. To add a tooltip to an element, include the following directive in * the element's attributes: diff --git a/awx/ui/static/lib/ansible/form-generator.js b/awx/ui/static/lib/ansible/form-generator.js index efa9d50374..352b426e11 100644 --- a/awx/ui/static/lib/ansible/form-generator.js +++ b/awx/ui/static/lib/ansible/form-generator.js @@ -414,6 +414,7 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies']) html += (field.autocomplete !== undefined) ? this.attr(field, 'autocomplete') : ""; html += (field.awRequiredWhen) ? "data-awrequired-init=\"" + field.awRequiredWhen.init + "\" aw-required-when=\"" + field.awRequiredWhen.variable + "\" " : ""; + html += (field.awValidUrl) ? "aw-valid-url " : ""; html += (field.associated && this.form.fields[field.associated].ask) ? "ng-disabled=\"" + field.associated + "_ask\" " : ""; html += " >\n"; } @@ -450,6 +451,10 @@ angular.module('FormGenerator', ['GeneratorHelpers', 'ngCookies']) html += "
Must match Password value
\n"; } + if (field.awValidUrl) { + html += "
URL must begin with ssh, http or https and may not contain '@'
\n"; + } if (field.chkPass) { html += "