group useredit functions

This commit is contained in:
Girish Ramakrishnan
2016-09-28 11:52:00 -07:00
parent 36a91bb51a
commit 601aa7f5cd
2 changed files with 99 additions and 99 deletions
+7 -7
View File
@@ -97,7 +97,7 @@
<h4 class="modal-title">Edit user {{ useredit.userInfo.username }}</h4>
</div>
<div class="modal-body">
<form name="useredit_form" role="form" ng-submit="doUserEdit()" autocomplete="off">
<form name="useredit_form" role="form" ng-submit="useredit.submit()" autocomplete="off">
<input type="password" style="display: none;">
<div class="form-group" ng-show="useredit.userInfo.alternateEmail">
<label class="control-label">Email</label>
@@ -117,7 +117,7 @@
<label class="control-label">Groups</label>
<div>
<span ng-repeat="group in groups | ignoreAdminGroup" ng-show="group.id !== 'admin'">
<button class="btn btn-default" type="button" ng-click="userEditToggleGroup(group);" ng-class="{ 'btn-primary': (useredit.groupIds.indexOf(group.id) !== -1) }">{{ group.name }}</button>
<button class="btn btn-default" type="button" ng-click="useredit.toggleGroup(group);" ng-class="{ 'btn-primary': (useredit.groupIds.indexOf(group.id) !== -1) }">{{ group.name }}</button>
</span>
</div>
<div ng-show="groups.length <= 1">No groups available.</div>
@@ -145,7 +145,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" ng-click="doUserEdit()" ng-disabled="useredit_form.$invalid || useredit.busy"><i class="fa fa-spinner fa-pulse" ng-show="useredit.busy"></i> Save</button>
<button type="button" class="btn btn-success" ng-click="useredit.submit()" ng-disabled="useredit_form.$invalid || useredit.busy"><i class="fa fa-spinner fa-pulse" ng-show="useredit.busy"></i> Save</button>
</div>
</div>
</div>
@@ -304,18 +304,18 @@
<td>
<i class="fa fa-briefcase arrow" ng-show="user.admin" uib-tooltip="This user can manage apps, groups and other users"></i>
</td>
<td class="hand elide-table-cell" ng-click="showUserEdit(user)" ng-show="user.username">
<td class="hand elide-table-cell" ng-click="useredit.show(user)" ng-show="user.username">
{{ user.username }}<span class="text-muted" ng-show="user.alternateEmail">{{ '@' + config.fqdn }}</span> &nbsp; <span class="text-muted" ng-hide="user.alternateEmail">{{ user.email }}</span>
</td>
<td class="hand elide-table-cell" ng-click="showUserEdit(user)" ng-hide="user.username">
<td class="hand elide-table-cell" ng-click="useredit.show(user)" ng-hide="user.username">
<span class="text-muted" uib-tooltip="User is not activated yet">{{ user.alternateEmail || user.email }}</span>
</td>
<td class="text-left hand elide-table-cell hidden-xs hidden-sm" ng-click="showUserEdit(user)">
<td class="text-left hand elide-table-cell hidden-xs hidden-sm" ng-click="useredit.show(user)">
<span class="group-badge" ng-repeat="groupId in user.groupIds | ignoreAdminGroup">{{ groupId }}</span>
</td>
<td class="text-right no-wrap" style="vertical-align: bottom">
<button ng-show="!isMe(user)" class="btn btn-xs btn-default" ng-click="sendInvite(user)" title="Send Invite"><i class="fa fa-paper-plane-o"></i></button>
<button class="btn btn-xs btn-default" ng-click="showUserEdit(user)" title="Edit User Profile"><i class="fa fa-pencil"></i></button>
<button class="btn btn-xs btn-default" ng-click="useredit.show(user)" title="Edit User Profile"><i class="fa fa-pencil"></i></button>
<button ng-show="!isMe(user)" class="btn btn-xs btn-danger" ng-click="userremove.show(user)" title="Remove User"><i class="fa fa-trash-o"></i></button>
</td>
</tr>
+92 -92
View File
@@ -156,7 +156,98 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
userInfo: {},
email: '',
aliases: '',
superuser: false
superuser: false,
show: function (userInfo) {
$scope.useredit.error.email = null;
$scope.useredit.email = userInfo.alternateEmail || userInfo.email;
$scope.useredit.userInfo = userInfo;
$scope.useredit.groupIds = angular.copy(userInfo.groupIds);
$scope.useredit.superuser = userInfo.groupIds.indexOf('admin') !== -1;
$scope.useredit.aliases = '';
Client.getAliases(userInfo.id, function (error, aliases) {
if (error) console.error(error);
$scope.useredit.aliases = aliases.join(',');
});
$scope.useredit_form.$setPristine();
$scope.useredit_form.$setUntouched();
$('#userEditModal').modal('show');
},
toggleGroup: function (group) {
var pos = $scope.useredit.groupIds.indexOf(group.id);
if (pos === -1) {
$scope.useredit.groupIds.push(group.id);
} else {
$scope.useredit.groupIds.splice(pos, 1);
}
},
submit: function () {
$scope.useredit.error.email = null;
$scope.useredit.busy = true;
var data = {
id: $scope.useredit.userInfo.id,
email: $scope.useredit.email
};
Client.updateUser(data, function (error) {
if (error) {
$scope.useredit.busy = false;
if (error.statusCode === 409) {
$scope.useredit.error.email = 'Email already taken';
$scope.useredit_form.email.$setPristine();
$('#inputUserEditEmail').focus();
} else {
console.error('Unable to update user:', error);
}
return;
}
if ($scope.useredit.superuser) {
if ($scope.useredit.groupIds.indexOf('admin') === -1) $scope.useredit.groupIds.push('admin');
} else {
$scope.useredit.groupIds = $scope.useredit.groupIds.filter(function (groupId) { return groupId !== 'admin'; });
}
Client.setGroups(data.id, $scope.useredit.groupIds, function (error) {
if (error) return console.error('Unable to update groups for user:', error);
var aliases = $scope.useredit.aliases ? $scope.useredit.aliases.split(',') : [ ];
var setAliasesFunc = Client.setAliases.bind(null, $scope.useredit.userInfo.id, aliases);
// cannot set aliases without username
if (!$scope.useredit.userInfo.username) setAliasesFunc = function (next) { return next(); };
setAliasesFunc(function (error) {
$scope.useredit.busy = false;
if (error) return console.error('Unable to update aliases for user:', error);
$scope.useredit.userInfo = {};
$scope.useredit.email = '';
$scope.useredit.superuser = false;
$scope.useredit.groupIds = [];
$scope.useredit.aliases = '';
$scope.useredit_form.$setPristine();
$scope.useredit_form.$setUntouched();
refresh();
$('#userEditModal').modal('hide');
});
});
});
}
};
$scope.showBubble = function ($event) {
@@ -287,97 +378,6 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
});
};
$scope.showUserEdit = function (userInfo) {
$scope.useredit.error.email = null;
$scope.useredit.email = userInfo.alternateEmail || userInfo.email;
$scope.useredit.userInfo = userInfo;
$scope.useredit.groupIds = angular.copy(userInfo.groupIds);
$scope.useredit.superuser = userInfo.groupIds.indexOf('admin') !== -1;
$scope.useredit.aliases = '';
Client.getAliases(userInfo.id, function (error, aliases) {
if (error) console.error(error);
$scope.useredit.aliases = aliases.join(',');
});
$scope.useredit_form.$setPristine();
$scope.useredit_form.$setUntouched();
$('#userEditModal').modal('show');
};
$scope.userEditToggleGroup = function (group) {
var pos = $scope.useredit.groupIds.indexOf(group.id);
if (pos === -1) {
$scope.useredit.groupIds.push(group.id);
} else {
$scope.useredit.groupIds.splice(pos, 1);
}
};
$scope.doUserEdit = function () {
$scope.useredit.error.email = null;
$scope.useredit.busy = true;
var data = {
id: $scope.useredit.userInfo.id,
email: $scope.useredit.email
};
Client.updateUser(data, function (error) {
if (error) {
$scope.useredit.busy = false;
if (error.statusCode === 409) {
$scope.useredit.error.email = 'Email already taken';
$scope.useredit_form.email.$setPristine();
$('#inputUserEditEmail').focus();
} else {
console.error('Unable to update user:', error);
}
return;
}
if ($scope.useredit.superuser) {
if ($scope.useredit.groupIds.indexOf('admin') === -1) $scope.useredit.groupIds.push('admin');
} else {
$scope.useredit.groupIds = $scope.useredit.groupIds.filter(function (groupId) { return groupId !== 'admin'; });
}
Client.setGroups(data.id, $scope.useredit.groupIds, function (error) {
if (error) return console.error('Unable to update groups for user:', error);
var aliases = $scope.useredit.aliases ? $scope.useredit.aliases.split(',') : [ ];
var setAliasesFunc = Client.setAliases.bind(null, $scope.useredit.userInfo.id, aliases);
// cannot set aliases without username
if (!$scope.useredit.userInfo.username) setAliasesFunc = function (next) { return next(); };
setAliasesFunc(function (error) {
$scope.useredit.busy = false;
if (error) return console.error('Unable to update aliases for user:', error);
$scope.useredit.userInfo = {};
$scope.useredit.email = '';
$scope.useredit.superuser = false;
$scope.useredit.groupIds = [];
$scope.useredit.aliases = '';
$scope.useredit_form.$setPristine();
$scope.useredit_form.$setUntouched();
refresh();
$('#userEditModal').modal('hide');
});
});
});
};
$scope.showUserHelp = function () {
$('#userHelpModal').modal('show');
};