Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
768cd071
Commit
768cd071
authored
Sep 23, 2016
by
Bryce Johnson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up username_validator private vars and members.
parent
d2bad46e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
44 deletions
+47
-44
app/assets/javascripts/username_validator.js.es6
app/assets/javascripts/username_validator.js.es6
+47
-44
No files found.
app/assets/javascripts/username_validator.js.es6
View file @
768cd071
((global) => {
const debounceTimeoutDuration = 1000;
const inputErrorClass = 'gl-field-error-outline';
const inputSuccessClass = 'gl-field-success-outline';
const messageErrorSelector = '.username .validation-error';
const messageSuccessSelector = '.username .validation-success';
const messagePendingSelector = '.username .validation-pending';
const invalidInputClass = 'gl-field-error-outline';
const successInputClass = 'gl-field-success-outline';
const unavailableMessageSelector = '.username .validation-error';
const successMessageSelector = '.username .validation-success';
const pendingMessageSelector = '.username .validation-pending';
const invalidMessageSelector = '.username .gl-field-error';
class UsernameValidator {
constructor() {
this.inputElement = $('#new_user_username');
this.inputDomElement = this.inputElement.get(0);
this.available = false;
this.valid = false;
this.pending = false;
this.fresh = true;
this.empty = true
;
this.state = {
available: false,
valid: false,
pending: false,
empty: true
}
;
const debounceTimeout = _.debounce((username) => {
this.validateUsername(username);
this.
state.
validateUsername(username);
}, debounceTimeoutDuration);
this.inputElement.on('keyup.username_check', () => {
const username = this.inputElement.val();
this.valid = this.inputDomElement.validity.valid;
this.fresh = false;
this.empty = !username.length;
this.state.valid = this.inputDomElement.validity.valid;
this.state.empty = !username.length;
if (this.valid) {
if (this.
state.
valid) {
return debounceTimeout(username);
}
...
...
@@ -36,43 +36,43 @@
});
// Override generic field validation
this.inputElement.on('invalid', this.
handleInvalidInput
.bind(this));
this.inputElement.on('invalid', this.
interceptInvalid
.bind(this));
}
renderState() {
// Clear all state
this.clearFieldValidationState();
if (this.
valid && this
.available) {
if (this.
state.valid && this.state
.available) {
return this.setSuccessState();
}
if (this.empty) {
if (this.
state.
empty) {
return this.clearFieldValidationState();
}
if (this.pending) {
if (this.
state.
pending) {
return this.setPendingState();
}
if (!this.available) {
if (!this.
state.
available) {
return this.setUnavailableState();
}
if (!this.valid) {
if (!this.
state.
valid) {
return this.setInvalidState();
}
}
handleInvalidInput
(event) {
interceptInvalid
(event) {
event.preventDefault();
event.stopPropagation();
}
validateUsername(username) {
if (this.valid) {
this.pending = true;
this.available = false;
if (this.
state.
valid) {
this.
state.
pending = true;
this.
state.
available = false;
this.renderState();
return $.ajax({
type: 'GET',
...
...
@@ -83,38 +83,40 @@
}
}
updateValidation
State(usernameTaken) {
setAvailability
State(usernameTaken) {
if (usernameTaken) {
this.valid = false;
this.available = false;
this.
state.
valid = false;
this.
state.
available = false;
} else {
this.available = true;
this.
state.
available = true;
}
this.pending = false;
this.
state.
pending = false;
this.renderState();
}
clearFieldValidationState() {
this.inputElement.siblings('p').hide();
this.inputElement.removeClass(inputErrorClass);
this.inputElement.removeClass(inputSuccessClass);
// TODO: Double check if this is valid chaining
const $input = this.inputElement
.siblings('p').hide().end()
.removeClass(invalidInputClass);
removeClass(successInputClass);
}
setUnavailableState() {
const $username
ErrorMessage = this.inputElement.siblings(messageError
Selector);
this.inputElement.addClass(in
putErrorClass).removeClass(inputSuccess
Class);
$username
Error
Message.show();
const $username
UnavailableMessage = this.inputElement.siblings(unavailableMessage
Selector);
this.inputElement.addClass(in
validInputClass).removeClass(successInput
Class);
$username
Unavailable
Message.show();
}
setSuccessState() {
const $usernameSuccessMessage = this.inputElement.siblings(
messageSuccess
Selector);
this.inputElement.addClass(
inputSuccessClass).removeClass(inputError
Class);
const $usernameSuccessMessage = this.inputElement.siblings(
successMessage
Selector);
this.inputElement.addClass(
successInputClass).removeClass(invalidInput
Class);
$usernameSuccessMessage.show();
}
setPendingState(
show
) {
const $usernamePendingMessage = $(
messagePending
Selector);
if (this.pending) {
setPendingState() {
const $usernamePendingMessage = $(
pendingMessage
Selector);
if (this.
state.
pending) {
$usernamePendingMessage.show();
} else {
$usernamePendingMessage.hide();
...
...
@@ -122,8 +124,9 @@
}
setInvalidState() {
this.inputElement.addClass(inputErrorClass).removeClass(inputSuccessClass);
$(`.gl-field-error`).show();
const $inputErrorMessage = $(invalidMessageSelector);
this.inputElement.addClass(invalidInputClass).removeClass(successInputClass);
$inputErrorMessage.show();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment