Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;(function() {
- 'use strict';
- angular
- .module('app.workspace-admin')
- .controller('WorkspaceUserManagement', WorkspaceUserManagement);
- /* @ngInject */
- function WorkspaceUserManagement($mdDialog, $stateParams, toastr, initData, workspace, site, theme) {
- var vm = this;
- vm.workspace = initData.workspace;
- vm.page = initData.page;
- vm.users = initData.res_models;
- vm.settings = {
- name: '',
- defaultPageSize: 5,
- order_attr: 'username',
- sort: 'asc',
- page: 1,
- };
- vm.addUsers = addUsers;
- vm.removeUser = removeUser;
- vm.resetPassword = resetPassword;
- vm.sendAgain = sendAgain;
- vm.cancelInvitation = cancelInvitation;
- vm.getUsers = getUsers;
- function getUsers() {
- workspace
- .getUsers({
- workspace_slug: $stateParams.workspace_slug,
- defaultPageSize: vm.settings.defaultPageSize,
- name: vm.settings.name,
- page: 1,
- sort: vm.settings.sort,
- order_attr: vm.settings.order_attr,
- })
- .then(function(res) {
- initData.res_models = res.res_models;
- vm.users = res.res_models;
- });
- }
- function addUsers(ev) {
- $mdDialog
- .show({
- controller: 'Share',
- controllerAs: 'vm',
- templateUrl: 'app/components/modals/share/share.html',
- parent: angular.element(document.body),
- targetEvent: ev,
- clickOutsideToClose: true,
- locals: {
- type: 'workspace',
- role: vm.workspace.role,
- },
- })
- .then(function(res) {
- var users = res.emails.map(function(v) {
- return { email: v };
- });
- return workspace.addUsers({
- workspace_slug: vm.workspace.slug,
- user_ids: res.ids,
- users: users,
- send_email: true,
- role: res.role,
- });
- })
- .then(function() {
- toastr.success('Invitations sent');
- });
- }
- function removeUser(id, ev) {
- var confirm = $mdDialog
- .confirm()
- .title('Are you sure you want to delete user from workspace?')
- .ariaLabel('Delete workspace member')
- .theme(theme.getThemeName())
- .targetEvent(ev)
- .ok('Yes, remove user')
- .cancel('Cancel');
- $mdDialog.show(confirm).then(function() {
- workspace
- .removeUser({
- workspace_slug: vm.workspace.slug,
- user_id: id,
- })
- .then(function() {
- toastr.success('User was removed from workspace');
- });
- });
- }
- function resetPassword(email) {
- site
- .resetUserPassword({ email: email, workspace_slug: $stateParams.workspace_slug })
- .then(function() {
- toastr.success('Done, user will receive an email');
- });
- }
- function sendAgain(id) {
- workspace
- .sendInvitationAgain({ workspace_id: vm.workspace.id, user_id: id })
- .then(function() {
- toastr.success('Done');
- });
- }
- function cancelInvitation(id, ev) {
- var confirm = $mdDialog
- .confirm()
- .title('Are you sure you want to cancel invitation?')
- .ariaLabel('Cancel invitation')
- .targetEvent(ev)
- .theme(theme.getThemeName())
- .ok('Yes, cancel invitation')
- .cancel('Cancel');
- $mdDialog.show(confirm).then(function() {
- workspace
- .cancelInvitation({
- user_id: id,
- workspace_slug: vm.workspace.slug,
- })
- .then(function() {
- toastr.success('Invitation canceled');
- });
- });
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement