move tokens entirely into token page

This commit is contained in:
Girish Ramakrishnan
2019-11-07 14:41:28 -08:00
parent 0c5930d5cf
commit 97782d29cc
4 changed files with 146 additions and 213 deletions
+35 -10
View File
@@ -94,31 +94,56 @@ angular.module('Application').controller('TokensController', ['$scope', '$locati
}
};
$scope.tokenAdd = {
busy: false,
token: {},
show: function (client) {
$scope.tokenAdd = {
token: {},
tokenName: '',
busy: false,
error: {},
reset: function () {
$scope.tokenAdd.busy = false;
$scope.tokenAdd.token = {};
$scope.tokenAdd.error.tokenName = null;
$scope.tokenAdd.tokenName = '';
$scope.tokenAddForm.$setUntouched();
$scope.tokenAddForm.$setPristine();
},
show: function () {
$scope.tokenAdd.reset();
$('#tokenAddModal').modal('show');
},
submit: function (client) {
$scope.tokenAdd.busy = true;
$scope.tokenAdd.token = {};
var expiresAt = Date.now() + 100 * 365 * 24 * 60 * 60 * 1000; // ~100 years from now
Client.createTokenByClientId(client.id, '*' /* scope */, expiresAt, '' /* name */, function (error, result) {
if (error) return console.error(error);
Client.createTokenByClientId(client.id, '*' /* scope */, expiresAt, $scope.tokenAdd.tokenName, function (error, result) {
if (error) {
if (error.statusCode === 400) {
$scope.tokenAdd.error.tokenName = 'Invalid token name';
$scope.tokenAddForm.tokenName.$setPristine();
$('#inputTokenAddName').focus();
} else {
console.error('Unable to create token.', error);
}
return;
}
$scope.tokenAdd.busy = false;
$scope.tokenAdd.token = result;
$('#tokenAddModal').modal('show');
refreshClientTokens(client);
});
}
};
$scope.removeToken = function (client, token) {
Client.delToken(client.id, token.accessToken, function (error) {
Client.delToken(client.id, token.id, function (error) {
if (error) console.error(error);
refreshClientTokens(client);
@@ -159,7 +184,7 @@ angular.module('Application').controller('TokensController', ['$scope', '$locati
Client.onReady(refresh);
// setup all the dialog focus handling
['clientAddModal'].forEach(function (id) {
['clientAddModal', 'tokenAddModal'].forEach(function (id) {
$('#' + id).on('shown.bs.modal', function () {
$(this).find("[autofocus]:first").focus();
});