Added a bunch of stuff

This commit is contained in:
Dobie Wollert
2015-08-05 06:03:02 -07:00
parent b4e727c0e6
commit fdc8727044
35 changed files with 1815 additions and 276 deletions

View File

@ -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);
});
}
};
})