Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger a proper event-bus event #728

Merged
merged 2 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions js/notifications-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/notifications-main.js.map

Large diffs are not rendered by default.

44 changes: 43 additions & 1 deletion src/Components/Action.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<NcButton v-if="isWebLink"
type="primary"
class="action-button pull-right"
:href="link">
:href="link"
@click="onClickActionButtonWeb">
{{ label }}
</NcButton>
<NcButton v-else-if="!isWebLink"
Expand All @@ -17,6 +18,7 @@
import axios from '@nextcloud/axios'
import { showError } from '@nextcloud/dialogs'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import { emit } from '@nextcloud/event-bus'

export default {
name: 'Action',
Expand Down Expand Up @@ -69,8 +71,45 @@ export default {
},

methods: {
async onClickActionButtonWeb(e) {
try {
const event = {
cancelAction: false,
notification: this.$parent.$props,
action: {
url: this.link,
type: this.typeWithDefault,
},
}
await emit('notifications:action:execute', event)

if (event.cancelAction) {
// Action cancelled by event
e.preventDefault()
}
} catch (error) {
console.error('Failed to perform action', error)
showError(t('notifications', 'Failed to perform action'))
}
},

async onClickActionButton() {
try {
const event = {
cancelAction: false,
notification: this.$parent.$props,
action: {
url: this.link,
type: this.typeWithDefault,
},
}
await emit('notifications:action:execute', event)

if (event.cancelAction) {
// Action cancelled by event
return
}

// execute action
await axios({
method: this.typeWithDefault,
Expand All @@ -80,6 +119,9 @@ export default {
// emit event to current app
this.$parent._$el.fadeOut(OC.menuSpeed)
this.$parent.$emit('remove')

emit('notifications:action:executed', event)

try {
$('body').trigger(new $.Event('OCA.Notification.Action', {
notification: this.$parent,
Expand Down