forked from eclipse/vorto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
directives.js
27 lines (25 loc) · 833 Bytes
/
directives.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
define(["angular"], function(angular) {
var app = angular.module('apps.directive', []);
app.directive('ngUniqueProjectName', ['$http', function($http) {
return {
require: 'ngModel',
link: function(scope, elem, attrs, ctrl) {
elem.on('blur', function(evt) {
scope.$apply(function() {
if (elem.val()) {
$http.get('./project/' + elem.val() + '/check').success(
function(data, status, headers, config) {
ctrl.$setValidity('unique', true);
}).error(function(data, status, headers, config) {
ctrl.$setValidity('unique', false);
});
}else{
ctrl.$setValidity('unique', true);
}
});
});
}
}
}]);
return app;
});