Add initial ghost creation UI

This commit is contained in:
Johannes Zellner
2021-09-17 15:53:11 +02:00
parent a9b257c9ca
commit 8057b2454c
3 changed files with 109 additions and 0 deletions

View File

@@ -585,6 +585,46 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
}
};
// https://stackoverflow.com/questions/1497481/javascript-password-generator
function generatePassword() {
var length = 12,
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
$scope.setGhost = {
busy: false,
error: null,
user: null,
password: '',
show: function (user) {
$scope.setGhost.busy = false;
$scope.setGhost.error = null;
$scope.setGhost.user = user;
$scope.setGhost.password = generatePassword();
$('#setGhostModal').modal('show');
},
submit: function () {
$scope.setGhost.busy = true;
Client.setGhost($scope.setGhost.user.id, $scope.setGhost.password, null, function (error) {
$scope.setGhost.busy = false;
if (error) {
$scope.setGhost.error = error.message;
return console.error(error);
}
});
}
};
$scope.directoryConfig = {
editableUserProfiles: true,
mandatory2FA: false,
@@ -903,5 +943,27 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
$timeout(function () { $('#setupLinkButton').tooltip('hide'); }, 2000);
});
var setGhostClipboardButton = new Clipboard('#setGhostClipboardButton');
setGhostClipboardButton.on('success', function(e) {
$('#setGhostClipboardButton').tooltip({
title: 'Copied!',
trigger: 'manual'
}).tooltip('show');
$timeout(function () { $('#setGhostClipboardButton').tooltip('hide'); }, 2000);
e.clearSelection();
});
setGhostClipboardButton.on('error', function(/*e*/) {
$('#setGhostClipboardButton').tooltip({
title: 'Press Ctrl+C to copy',
trigger: 'manual'
}).tooltip('show');
$timeout(function () { $('#setGhostClipboardButton').tooltip('hide'); }, 2000);
});
$('.modal-backdrop').remove();
}]);