From 9e73abf8f6b92c7192bb63cc831a89d163069af8 Mon Sep 17 00:00:00 2001 From: kunw Date: Thu, 8 Dec 2016 15:57:03 +0800 Subject: [PATCH] Update checking comment length. --- .../validator/chars-length.validator.js | 71 +++++++++++++++++++ .../validator/user-exist.validator.js | 7 +- .../components/validator/validator.config.js | 5 +- src/ui/views/account-settings.htm | 8 +-- src/ui/views/sections/script-include.htm | 1 + src/ui/views/sign-up.htm | 12 ++-- 6 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 src/ui/static/resources/js/components/validator/chars-length.validator.js diff --git a/src/ui/static/resources/js/components/validator/chars-length.validator.js b/src/ui/static/resources/js/components/validator/chars-length.validator.js new file mode 100644 index 000000000..bfab0cd84 --- /dev/null +++ b/src/ui/static/resources/js/components/validator/chars-length.validator.js @@ -0,0 +1,71 @@ +/* + Copyright (c) 2016 VMware, Inc. All Rights Reserved. + Licensed 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. +*/ +(function() { + + 'use strict'; + + angular + .module('harbor.validator') + .directive('charsLength', charsLength); + + charsLength.$inject = ['ASCII_CHARS']; + + function charsLength(ASCII_CHARS) { + var directive = { + 'require': 'ngModel', + 'scope': { + min: '@', + max: '@' + }, + 'link': link + }; + + return directive; + + function link(scope, element, attrs, ctrl) { + + ctrl.$validators.charsLength = validator; + + function validator(modelValue, viewValue) { + if(ctrl.$isEmpty(modelValue)) { + return true; + } + + var actualLength = 0; + + if(ASCII_CHARS.test(modelValue)) { + actualLength = modelValue.length; + }else{ + for(var i = 0; i < modelValue.length; i++) { + ASCII_CHARS.test(modelValue[i]) ? actualLength += 1 : actualLength += 2; + } + } + + if(attrs.min && actualLength < attrs.min) { + return false; + } + + if(attrs.max && actualLength > attrs.max) { + return false; + } + + return true; + } + + } + } + + +})(); \ No newline at end of file diff --git a/src/ui/static/resources/js/components/validator/user-exist.validator.js b/src/ui/static/resources/js/components/validator/user-exist.validator.js index 7fa7990ec..03d4fae92 100644 --- a/src/ui/static/resources/js/components/validator/user-exist.validator.js +++ b/src/ui/static/resources/js/components/validator/user-exist.validator.js @@ -39,14 +39,11 @@ ctrl.$validators.userExists = validator; function validator(modelValue, viewValue) { - - console.log('modelValue:' + modelValue + ', viewValue:' + viewValue); - + if(ctrl.$isEmpty(modelValue)) { - console.log('Model value is empty.'); return true; } - + UserExistService(attrs.target, modelValue) .success(userExistSuccess) .error(userExistFailed); diff --git a/src/ui/static/resources/js/components/validator/validator.config.js b/src/ui/static/resources/js/components/validator/validator.config.js index 08e892cdc..10148674d 100644 --- a/src/ui/static/resources/js/components/validator/validator.config.js +++ b/src/ui/static/resources/js/components/validator/validator.config.js @@ -21,6 +21,7 @@ .constant('INVALID_CHARS', [",","~","#", "$", "%"]) .constant('PASSWORD_REGEXP', /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?!.*\s).{8,20}$/) .constant('PROJECT_REGEXP', /^[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*$/) - .constant('EMAIL_REGEXP', /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/); - + .constant('EMAIL_REGEXP', /^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/) + .constant('ASCII_CHARS', /^[\000-\177]*$/); + })(); \ No newline at end of file diff --git a/src/ui/views/account-settings.htm b/src/ui/views/account-settings.htm index 752f409b6..39722bf1b 100644 --- a/src/ui/views/account-settings.htm +++ b/src/ui/views/account-settings.htm @@ -42,11 +42,11 @@
- +
// 'full_name_is_required' | tr // // 'full_name_contains_illegal_chars' | tr // - // 'full_name_is_too_long' | tr // + // 'full_name_is_too_long' | tr //
@@ -56,9 +56,9 @@
- +
- // 'comment_is_too_long' | tr // + // 'comment_is_too_long' | tr //
diff --git a/src/ui/views/sections/script-include.htm b/src/ui/views/sections/script-include.htm index 7404a9d82..187387a07 100644 --- a/src/ui/views/sections/script-include.htm +++ b/src/ui/views/sections/script-include.htm @@ -131,6 +131,7 @@ + diff --git a/src/ui/views/sign-up.htm b/src/ui/views/sign-up.htm index cd0be0308..841c4d8d7 100644 --- a/src/ui/views/sign-up.htm +++ b/src/ui/views/sign-up.htm @@ -30,12 +30,12 @@
- +
// 'username_is_required' | tr // // 'username_is_too_long' | tr // - // 'username_contains_illegal_chars' | tr // // 'username_has_been_taken' | tr // + // 'username_contains_illegal_chars' | tr //
@@ -60,11 +60,11 @@
- +
// 'full_name_is_required' | tr // // 'full_name_contains_illegal_chars' | tr // - // 'full_name_is_too_long' | tr // + // 'full_name_is_too_long' | tr //

// 'full_name_desc' | tr //

@@ -101,9 +101,9 @@
- +
- // 'comment_is_too_long' | tr // + // 'comment_is_too_long' | tr //