Advertisement
Guest User

Untitled

a guest
Sep 10th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.   'use strict';
  3.  
  4.   angular
  5.     .module('app.workspace-admin')
  6.     .controller('WorkspaceUserManagement', WorkspaceUserManagement);
  7.  
  8.   /* @ngInject */
  9.   function WorkspaceUserManagement(
  10.     $mdDialog,
  11.     $stateParams,
  12.     toastr,
  13.     initData,
  14.     workspace,
  15.     site,
  16.     theme,
  17.   ) {
  18.     var vm = this;
  19.  
  20.     vm.workspace = initData.workspace;
  21.     vm.page = initData.page;
  22.     vm.users = initData.res_models;
  23.     vm.settings = {
  24.       name: '',
  25.       defaultPageSize: 5,
  26.       order_attr: 'username',
  27.       sort: 'asc',
  28.       page: 1,
  29.     };
  30.  
  31.     vm.addUsers = addUsers;
  32.     vm.removeUser = removeUser;
  33.     vm.resetPassword = resetPassword;
  34.     vm.sendAgain = sendAgain;
  35.     vm.cancelInvitation = cancelInvitation;
  36.     vm.getUsers = getUsers;
  37.  
  38.     function getUsers() {
  39.       workspace
  40.         .getUsers({
  41.           workspace_slug: $stateParams.workspace_slug,
  42.           defaultPageSize: vm.settings.defaultPageSize,
  43.           name: vm.settings.name,
  44.           page: 1,
  45.           sort: vm.settings.sort,
  46.           order_attr: vm.settings.order_attr,
  47.         })
  48.         .then(function(res) {
  49.           initData.res_models = res.res_models;
  50.           vm.users = res.res_models;
  51.         });
  52.     }
  53.  
  54.     function addUsers(ev) {
  55.       $mdDialog
  56.         .show({
  57.           controller: 'Share',
  58.           controllerAs: 'vm',
  59.           templateUrl: 'app/components/modals/share/share.html',
  60.           parent: angular.element(document.body),
  61.           targetEvent: ev,
  62.           clickOutsideToClose: true,
  63.           locals: {
  64.             type: 'workspace',
  65.             role: vm.workspace.role,
  66.           },
  67.         })
  68.         .then(function(res) {
  69.           var users = res.emails.map(function(v) {
  70.             return { email: v };
  71.           });
  72.  
  73.           return workspace.addUsers({
  74.             workspace_slug: vm.workspace.slug,
  75.             user_ids: res.ids,
  76.             users: users,
  77.             send_email: true,
  78.             role: res.role,
  79.           });
  80.         })
  81.         .then(function() {
  82.           toastr.success('Invitations sent');
  83.         });
  84.     }
  85.  
  86.     function removeUser(id, ev) {
  87.       var confirm = $mdDialog
  88.         .confirm()
  89.         .title('Are you sure you want to delete user from workspace?')
  90.         .ariaLabel('Delete workspace member')
  91.         .theme(theme.getThemeName())
  92.         .targetEvent(ev)
  93.         .ok('Yes, remove user')
  94.         .cancel('Cancel');
  95.  
  96.       $mdDialog.show(confirm).then(function() {
  97.         workspace
  98.           .removeUser({
  99.             workspace_slug: vm.workspace.slug,
  100.             user_id: id,
  101.           })
  102.           .then(function() {
  103.             toastr.success('User was removed from workspace');
  104.           });
  105.       });
  106.     }
  107.  
  108.     function resetPassword(email) {
  109.       site
  110.         .resetUserPassword({ email: email, workspace_slug: $stateParams.workspace_slug })
  111.         .then(function() {
  112.           toastr.success('Done, user will receive an email');
  113.         });
  114.     }
  115.  
  116.     function sendAgain(id) {
  117.       workspace
  118.         .sendInvitationAgain({ workspace_id: vm.workspace.id, user_id: id })
  119.         .then(function() {
  120.           toastr.success('Done');
  121.         });
  122.     }
  123.  
  124.     function cancelInvitation(id, ev) {
  125.       var confirm = $mdDialog
  126.         .confirm()
  127.         .title('Are you sure you want to cancel invitation?')
  128.         .ariaLabel('Cancel invitation')
  129.         .targetEvent(ev)
  130.         .theme(theme.getThemeName())
  131.         .ok('Yes, cancel invitation')
  132.         .cancel('Cancel');
  133.  
  134.       $mdDialog.show(confirm).then(function() {
  135.         workspace
  136.           .cancelInvitation({
  137.             user_id: id,
  138.             workspace_slug: vm.workspace.slug,
  139.           })
  140.           .then(function() {
  141.             toastr.success('Invitation canceled');
  142.           });
  143.       });
  144.     }
  145.   }
  146. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement