mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Added a bunch of stuff
This commit is contained in:
@ -872,3 +872,36 @@ angular.module('biomed.directives', [])
|
||||
}
|
||||
};
|
||||
})
|
||||
.directive('abDeviceUnique', function(Devices, $timeout) {
|
||||
return {
|
||||
restrict: 'A',
|
||||
require: 'ngModel',
|
||||
link: function(scope, element, attrs, ngModel) {
|
||||
var stop_timeout;
|
||||
return scope.$watch(function() {
|
||||
return ngModel.$modelValue;
|
||||
}, function(name) {
|
||||
$timeout.cancel(stop_timeout);
|
||||
|
||||
if (!name) {
|
||||
ngModel.$setValidity('unique', true);
|
||||
}
|
||||
|
||||
stop_timeout = $timeout(function() {
|
||||
var keyProperty = scope.$eval(attrs.abDeviceUnique);
|
||||
|
||||
if (name) {
|
||||
Devices.isUnique({
|
||||
key: keyProperty.key,
|
||||
field: keyProperty.field,
|
||||
value: name
|
||||
}, function(result) {
|
||||
console.log('unique = ' + result.isUnique);
|
||||
ngModel.$setValidity('unique', result.isUnique);
|
||||
});
|
||||
}
|
||||
}, 200);
|
||||
});
|
||||
}
|
||||
};
|
||||
})
|
Reference in New Issue
Block a user