mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-08 11:41:54 +01:00
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
(function() {
|
|
|
|
'use strict';
|
|
|
|
angular
|
|
.module('harbor.validator')
|
|
.directive('userExists', userExists);
|
|
|
|
userExists.$inject = ['UserExistService'];
|
|
|
|
function userExists(UserExistService) {
|
|
var directive = {
|
|
'require': 'ngModel',
|
|
'scope': {
|
|
'target': '@'
|
|
},
|
|
'link': link
|
|
};
|
|
return directive;
|
|
|
|
function link(scope, element, attrs, ctrl) {
|
|
|
|
var valid = true;
|
|
|
|
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);
|
|
|
|
function userExistSuccess(data, status) {
|
|
valid = !data;
|
|
if(!valid) {
|
|
console.log('Model value already exists');
|
|
}
|
|
}
|
|
|
|
function userExistFailed(data, status) {
|
|
console.log('Failed in retrieval:' + data);
|
|
}
|
|
|
|
return valid;
|
|
}
|
|
}
|
|
|
|
}
|
|
})(); |