73e2e2a794
* gui: Make ID read-only and hide nearby devices when adding pending devices (fixes #8083) Currently, there is no distinction between adding "new" and "pending" devices. For this reason, the user is always presented with a list of "nearby devices" to choose from. This commit adds such distinction to the code, and in the case of "pending" device, both the device ID is made read-only and the nearby devices list is hidden. As a by-product of the function rename and clean-up, this commit also hides the non-functional "remove" button that is shown when editing device defaults. Signed-off-by: Tomasz Wilczyński <twilczynski@naver.com>
25 lines
1005 B
JavaScript
25 lines
1005 B
JavaScript
angular.module('syncthing.core')
|
|
.directive('validDeviceid', function ($http) {
|
|
return {
|
|
require: 'ngModel',
|
|
link: function (scope, elm, attrs, ctrl) {
|
|
ctrl.$parsers.unshift(function (viewValue) {
|
|
$http.get(urlbase + '/svc/deviceid?id=' + viewValue).success(function (resp) {
|
|
if (resp.error) {
|
|
ctrl.$setValidity('validDeviceid', false);
|
|
} else {
|
|
ctrl.$setValidity('validDeviceid', true);
|
|
}
|
|
});
|
|
//Prevents user from adding a duplicate ID
|
|
if (scope.devices.hasOwnProperty(viewValue)) {
|
|
ctrl.$setValidity('unique', false);
|
|
} else {
|
|
ctrl.$setValidity('unique', true);
|
|
}
|
|
return viewValue;
|
|
});
|
|
}
|
|
};
|
|
});
|