Advertisement
Guest User

Untitled

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