Handle disable and enable actions
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<div class="uk-container uk-padding">
|
<div class="uk-container uk-padding">
|
||||||
<h1>
|
<h1 v-text="$gettext('Accounts')" />
|
||||||
Accounts
|
|
||||||
</h1>
|
|
||||||
<oc-grid v-if="selectedAccountsAmount > 0" key="selected-accounts-info" gutter="small" class="uk-flex-middle">
|
<oc-grid v-if="selectedAccountsAmount > 0" key="selected-accounts-info" gutter="small" class="uk-flex-middle">
|
||||||
<span v-text="selectionInfoText" />
|
<span v-text="selectionInfoText" />
|
||||||
<div>
|
<div>
|
||||||
@@ -20,6 +18,7 @@
|
|||||||
role="menuitem"
|
role="menuitem"
|
||||||
:class="{ 'uk-margin-small-bottom': index + 1 !== actions.length }"
|
:class="{ 'uk-margin-small-bottom': index + 1 !== actions.length }"
|
||||||
class="uk-width-1-1 uk-flex-left"
|
class="uk-width-1-1 uk-flex-left"
|
||||||
|
@click="action.handler"
|
||||||
>
|
>
|
||||||
{{ action.label }}
|
{{ action.label }}
|
||||||
</oc-button>
|
</oc-button>
|
||||||
@@ -66,13 +65,15 @@ export default {
|
|||||||
|
|
||||||
if (isAnyAccountDisabled) {
|
if (isAnyAccountDisabled) {
|
||||||
actions.push({
|
actions.push({
|
||||||
label: this.$gettext('Enable')
|
label: this.$gettext('Enable'),
|
||||||
|
handler: this.enableAccounts
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAnyAccountEnabled) {
|
if (isAnyAccountEnabled) {
|
||||||
actions.push({
|
actions.push({
|
||||||
label: this.$gettext('Disable')
|
label: this.$gettext('Disable'),
|
||||||
|
handler: this.disableAccounts
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapActions('Accounts', ['initialize'])
|
...mapActions('Accounts', ['initialize', 'enableAccounts', 'disableAccounts'])
|
||||||
},
|
},
|
||||||
created () {
|
created () {
|
||||||
this.initialize()
|
this.initialize()
|
||||||
|
|||||||
+69
-1
@@ -1,5 +1,5 @@
|
|||||||
/* eslint-disable camelcase */
|
/* eslint-disable camelcase */
|
||||||
import { AccountsService_ListAccounts } from '../client/accounts'
|
import { AccountsService_ListAccounts, AccountsService_UpdateAccount } from '../client/accounts'
|
||||||
import { RoleService_ListRoles } from '../client/settings'
|
import { RoleService_ListRoles } from '../client/settings'
|
||||||
/* eslint-enable camelcase */
|
/* eslint-enable camelcase */
|
||||||
import { injectAuthToken } from '../helpers/auth'
|
import { injectAuthToken } from '../helpers/auth'
|
||||||
@@ -101,6 +101,74 @@ const actions = {
|
|||||||
|
|
||||||
toggleSelectionAll ({ commit, getters, state }) {
|
toggleSelectionAll ({ commit, getters, state }) {
|
||||||
getters.areAllAccountsSelected ? commit('SET_SELECTED_ACCOUNTS', []) : commit('SET_SELECTED_ACCOUNTS', [...state.accounts])
|
getters.areAllAccountsSelected ? commit('SET_SELECTED_ACCOUNTS', []) : commit('SET_SELECTED_ACCOUNTS', [...state.accounts])
|
||||||
|
},
|
||||||
|
|
||||||
|
async enableAccounts ({ dispatch, rootGetters }, accounts) {
|
||||||
|
const failedAccounts = []
|
||||||
|
injectAuthToken(rootGetters.user.token)
|
||||||
|
|
||||||
|
for (const account in accounts) {
|
||||||
|
const response = await AccountsService_UpdateAccount({
|
||||||
|
$domain: rootGetters.configuration.server,
|
||||||
|
body: {
|
||||||
|
account: account
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (response.status !== 201) {
|
||||||
|
failedAccounts.push({ account: account.diisplayName, statusText: response.statusText })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failedAccounts.length === 1) {
|
||||||
|
dispatch('showMessage', {
|
||||||
|
title: 'Failed to enable account.',
|
||||||
|
desc: failedAccounts[0].statusText,
|
||||||
|
status: 'danger'
|
||||||
|
}, { root: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failedAccounts.length > 1) {
|
||||||
|
dispatch('showMessage', {
|
||||||
|
title: 'Failed to enable accounts.',
|
||||||
|
desc: 'Could not enable multiple accounts',
|
||||||
|
status: 'danger'
|
||||||
|
}, { root: true })
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async disableAccounts ({ dispatch, state, rootGetters }) {
|
||||||
|
const failedAccounts = []
|
||||||
|
injectAuthToken(rootGetters.user.token)
|
||||||
|
|
||||||
|
for (const account of state.selectedAccounts) {
|
||||||
|
const response = await AccountsService_UpdateAccount({
|
||||||
|
$domain: rootGetters.configuration.server,
|
||||||
|
body: {
|
||||||
|
account: account
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (response.status !== 201) {
|
||||||
|
failedAccounts.push({ account: account.diisplayName, statusText: response.statusText })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failedAccounts.length === 1) {
|
||||||
|
dispatch('showMessage', {
|
||||||
|
title: 'Failed to disable account.',
|
||||||
|
desc: failedAccounts[0].statusText,
|
||||||
|
status: 'danger'
|
||||||
|
}, { root: true })
|
||||||
|
}
|
||||||
|
|
||||||
|
if (failedAccounts.length > 1) {
|
||||||
|
dispatch('showMessage', {
|
||||||
|
title: 'Failed to disable accounts.',
|
||||||
|
desc: 'Could not disable multiple accounts',
|
||||||
|
status: 'danger'
|
||||||
|
}, { root: true })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user