Guest User

controller

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