uniqueFolderDirective.js 870 B

123456789101112131415161718192021
  1. angular.module('syncthing.core')
  2. .directive('uniqueFolder', function () {
  3. return {
  4. require: 'ngModel',
  5. link: function (scope, elm, attrs, ctrl) {
  6. ctrl.$parsers.unshift(function (viewValue) {
  7. if (scope.currentFolder._editing != "add") {
  8. // we shouldn't validate
  9. ctrl.$setValidity('uniqueFolder', true);
  10. } else if (scope.folders.hasOwnProperty(viewValue)) {
  11. // the folder exists already
  12. ctrl.$setValidity('uniqueFolder', false);
  13. } else {
  14. // the folder is unique
  15. ctrl.$setValidity('uniqueFolder', true);
  16. }
  17. return viewValue;
  18. });
  19. }
  20. };
  21. });