This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
quay/static/js/pages/org-view.js

186 lines
5.3 KiB
JavaScript
Raw Normal View History

(function() {
/**
* Page that displays details about an organization, such as its teams.
*/
angular.module('quayPages').config(['pages', function(pages) {
2015-03-25 19:31:05 +00:00
pages.create('org-view', 'org-view.html', OrgViewCtrl, {
'newLayout': true,
'title': 'Organization {{ organization.name }}',
'description': 'Organization {{ organization.name }}'
}, ['layout'])
pages.create('org-view', 'old-org-view.html', OldOrgViewCtrl, {
}, ['old-layout']);
}]);
2015-03-30 22:44:23 +00:00
function OrgViewCtrl($scope, $routeParams, $timeout, ApiService, UIService, AvatarService) {
2015-03-25 19:31:05 +00:00
var orgname = $routeParams.orgname;
$scope.showLogsCounter = 0;
$scope.showApplicationsCounter = 0;
$scope.showInvoicesCounter = 0;
2015-03-30 22:44:23 +00:00
$scope.orgScope = {
'changingOrganization': false,
'organizationEmail': ''
};
$scope.$watch('orgScope.organizationEmail', function(e) {
UIService.hidePopover('#changeEmailForm input');
2015-03-25 19:31:05 +00:00
});
var loadRepositories = function() {
var options = {
'public': false,
'private': true,
'sort': true,
'namespace': orgname,
};
$scope.repositoriesResource = ApiService.listReposAsResource().withOptions(options).get(function(resp) {
return resp.repositories;
});
};
var loadOrganization = function() {
$scope.orgResource = ApiService.getOrganizationAsResource({'orgname': orgname}).get(function(org) {
$scope.organization = org;
2015-03-30 22:44:23 +00:00
$scope.orgScope.organizationEmail = org.email;
2015-03-25 19:31:05 +00:00
$scope.isAdmin = org.is_admin;
$scope.isMember = org.is_member;
// Load the repositories.
$timeout(function() {
loadRepositories();
}, 10);
});
};
// Load the organization.
loadOrganization();
$scope.showInvoices = function() {
$scope.showInvoicesCounter++;
};
$scope.showApplications = function() {
$scope.showApplicationsCounter++;
};
$scope.showLogs = function() {
$scope.showLogsCounter++;
};
$scope.changeEmail = function() {
2015-03-30 22:44:23 +00:00
UIService.hidePopover('#changeEmailForm input');
2015-03-25 19:31:05 +00:00
2015-03-30 22:44:23 +00:00
$scope.orgScope.changingOrganization = true;
2015-03-25 19:31:05 +00:00
var params = {
'orgname': orgname
};
var data = {
2015-03-30 22:44:23 +00:00
'email': $scope.orgScope.organizationEmail
2015-03-25 19:31:05 +00:00
};
ApiService.changeOrganizationDetails(data, params).then(function(org) {
2015-03-30 22:44:23 +00:00
$scope.orgScope.changingOrganization = false;
2015-03-25 19:31:05 +00:00
$scope.organization = org;
}, function(result) {
2015-03-30 22:44:23 +00:00
$scope.orgScope.changingOrganization = false;
UIService.showFormError('#changeEmailForm input', result, 'right');
2015-03-25 19:31:05 +00:00
});
};
}
function OldOrgViewCtrl($rootScope, $scope, ApiService, $routeParams, CreateService) {
var orgname = $routeParams.orgname;
$scope.TEAM_PATTERN = TEAM_PATTERN;
$rootScope.title = 'Loading...';
$scope.teamRoles = [
{ 'id': 'member', 'title': 'Member', 'kind': 'default' },
{ 'id': 'creator', 'title': 'Creator', 'kind': 'success' },
{ 'id': 'admin', 'title': 'Admin', 'kind': 'primary' }
];
$scope.setRole = function(role, teamname) {
var previousRole = $scope.organization.teams[teamname].role;
$scope.organization.teams[teamname].role = role;
var params = {
'orgname': orgname,
'teamname': teamname
};
var data = $scope.organization.teams[teamname];
ApiService.updateOrganizationTeam(data, params).then(function(resp) {
}, function(resp) {
$scope.organization.teams[teamname].role = previousRole;
$scope.roleError = resp.data || '';
$('#cannotChangeTeamModal').modal({});
});
};
$scope.createTeam = function(teamname) {
if (!teamname) {
return;
}
if ($scope.organization.teams[teamname]) {
$('#team-' + teamname).removeClass('highlight');
setTimeout(function() {
$('#team-' + teamname).addClass('highlight');
}, 10);
return;
}
CreateService.createOrganizationTeam(ApiService, orgname, teamname, function(created) {
$scope.organization.teams[teamname] = created;
});
};
$scope.askDeleteTeam = function(teamname) {
$scope.currentDeleteTeam = teamname;
$('#confirmdeleteModal').modal({});
};
$scope.deleteTeam = function() {
$('#confirmdeleteModal').modal('hide');
if (!$scope.currentDeleteTeam) { return; }
var teamname = $scope.currentDeleteTeam;
var params = {
'orgname': orgname,
'teamname': teamname
};
var errorHandler = ApiService.errorDisplay('Cannot delete team', function() {
$scope.currentDeleteTeam = null;
});
ApiService.deleteOrganizationTeam(null, params).then(function() {
delete $scope.organization.teams[teamname];
$scope.currentDeleteTeam = null;
}, errorHandler);
};
var loadOrganization = function() {
$scope.orgResource = ApiService.getOrganizationAsResource({'orgname': orgname}).get(function(org) {
$scope.organization = org;
$rootScope.title = orgname;
$rootScope.description = 'Viewing organization ' + orgname;
$('.info-icon').popover({
'trigger': 'hover',
'html': true
});
});
};
// Load the organization.
loadOrganization();
}
})();