2016-07-07 18:03:32 +02:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016 VMware, Inc. All Rights Reserved.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
2016-06-07 10:49:38 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular
|
|
|
|
.module('harbor.user')
|
|
|
|
.directive('listUser', listUser);
|
|
|
|
|
2016-07-02 12:20:31 +02:00
|
|
|
ListUserController.$inject = ['$scope', 'ListUserService', 'DeleteUserService', '$filter', 'trFilter'];
|
2016-06-07 10:49:38 +02:00
|
|
|
|
2016-07-02 12:20:31 +02:00
|
|
|
function ListUserController($scope, ListUserService, DeleteUserService, $filter, $trFilter) {
|
2016-06-26 06:56:58 +02:00
|
|
|
|
|
|
|
$scope.subsSubPane = 226;
|
|
|
|
|
2016-06-07 10:49:38 +02:00
|
|
|
var vm = this;
|
2016-06-25 21:12:17 +02:00
|
|
|
|
2016-06-07 10:49:38 +02:00
|
|
|
vm.username = '';
|
|
|
|
vm.searchUser = searchUser;
|
|
|
|
vm.deleteUser = deleteUser;
|
2016-06-20 11:05:48 +02:00
|
|
|
vm.confirmToDelete = confirmToDelete;
|
2016-06-07 10:49:38 +02:00
|
|
|
vm.retrieve = retrieve;
|
|
|
|
|
|
|
|
vm.retrieve();
|
|
|
|
|
|
|
|
function searchUser() {
|
|
|
|
vm.retrieve();
|
|
|
|
}
|
|
|
|
|
2016-06-20 11:05:48 +02:00
|
|
|
function deleteUser() {
|
|
|
|
DeleteUserService(vm.selectedUserId)
|
2016-06-07 10:49:38 +02:00
|
|
|
.success(deleteUserSuccess)
|
|
|
|
.error(deleteUserFailed);
|
|
|
|
}
|
|
|
|
|
2016-07-06 14:22:45 +02:00
|
|
|
function confirmToDelete(userId, username) {
|
2016-06-20 11:05:48 +02:00
|
|
|
vm.selectedUserId = userId;
|
2016-07-02 12:20:31 +02:00
|
|
|
|
2016-07-04 06:34:34 +02:00
|
|
|
$scope.$emit('modalTitle', $filter('tr')('confirm_delete_user_title'));
|
2016-07-06 14:22:45 +02:00
|
|
|
$scope.$emit('modalMessage', $filter('tr')('confirm_delete_user', [username]));
|
2016-07-02 12:20:31 +02:00
|
|
|
|
|
|
|
var emitInfo = {
|
|
|
|
'confirmOnly': false,
|
|
|
|
'contentType': 'text/plain',
|
|
|
|
'action': vm.deleteUser
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$emit('raiseInfo', emitInfo);
|
2016-06-20 11:05:48 +02:00
|
|
|
}
|
|
|
|
|
2016-06-07 10:49:38 +02:00
|
|
|
function retrieve() {
|
|
|
|
ListUserService(vm.username)
|
|
|
|
.success(listUserSuccess)
|
|
|
|
.error(listUserFailed);
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteUserSuccess(data, status) {
|
|
|
|
console.log('Successful delete user.');
|
|
|
|
vm.retrieve();
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteUserFailed(data, status) {
|
2016-07-02 12:20:31 +02:00
|
|
|
$scope.$emit('modalTitle', $filter('tr')('error'));
|
2016-07-04 06:34:34 +02:00
|
|
|
$scope.$emit('modalMessage', $filter('tr')('failed_to_delete_user'));
|
2016-07-02 12:20:31 +02:00
|
|
|
$scope.$emit('raiseError', true);
|
2016-07-04 06:34:34 +02:00
|
|
|
console.log('Failed to delete user.');
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function listUserSuccess(data, status) {
|
|
|
|
vm.users = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function listUserFailed(data, status) {
|
2016-07-02 12:20:31 +02:00
|
|
|
$scope.$emit('modalTitle', $filter('tr')('error'));
|
2016-07-04 06:34:34 +02:00
|
|
|
$scope.$emit('modalMessage', $filter('tr')('failed_to_list_user'));
|
2016-07-02 12:20:31 +02:00
|
|
|
$scope.$emit('raiseError', true);
|
2016-07-04 06:34:34 +02:00
|
|
|
console.log('Failed to list user:' + data);
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function listUser() {
|
|
|
|
var directive = {
|
|
|
|
'restrict': 'E',
|
2016-06-16 08:10:35 +02:00
|
|
|
'templateUrl': '/static/resources/js/components/user/list-user.directive.html',
|
2016-06-25 21:12:17 +02:00
|
|
|
'link': link,
|
2016-06-07 10:49:38 +02:00
|
|
|
'controller': ListUserController,
|
|
|
|
'controllerAs': 'vm',
|
|
|
|
'bindToController': true
|
|
|
|
};
|
|
|
|
return directive;
|
2016-06-25 21:12:17 +02:00
|
|
|
|
2016-07-11 10:11:54 +02:00
|
|
|
function link(scope, element, attrs, ctrl) {
|
|
|
|
element.find('#txtSearchInput').on('keydown', function(e) {
|
|
|
|
if($(this).is(':focus') && e.keyCode === 13) {
|
|
|
|
ctrl.retrieve();
|
|
|
|
}
|
|
|
|
});
|
2016-06-25 21:12:17 +02:00
|
|
|
}
|
2016-06-07 10:49:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
})();
|