File size: 3,671 Bytes
da96562 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | <!--
Matomo - free/libre analytics platform
@link https://matomo.org
@license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
-->
<template>
<transition
:name="type === 'toast' ? 'slow-fade-out' : undefined"
@after-leave="toastClosed()"
>
<div v-if="!deleted">
<transition :name="type === 'toast' ? 'toast-slide-up' : undefined" appear>
<div>
<transition :name="animate ? 'fade-in' : undefined" appear>
<div
class="notification system"
:class="cssClasses"
:style="style"
ref="root"
:data-notification-instance-id="notificationInstanceId"
>
<button
type="button"
class="close"
data-dismiss="alert"
v-if="canClose"
v-on:click="closeNotification($event)"
>
×
</button>
<strong v-if="title">{{ title }}</strong>
<!-- ng-transclude causes directive child elements to be added here -->
<div class="notification-body">
<div v-if="message" v-html="$sanitize(message)"/>
<div v-if="!message">
<slot />
</div>
</div>
</div>
</transition>
</div>
</transition>
</div>
</transition>
</template>
<script lang="ts">
import { defineComponent, nextTick } from 'vue';
import AjaxHelper from '../AjaxHelper/AjaxHelper';
const { $ } = window;
export default defineComponent({
props: {
notificationId: String,
// NOTE: notificationId refers to server side ID for notifications stored in the session.
// this ID is just so it can be selected outside of this component (just for scrolling).
notificationInstanceId: String,
title: String,
context: String,
type: String,
noclear: Boolean,
toastLength: {
type: Number,
default: 12 * 1000,
},
style: [String, Object],
animate: Boolean,
message: String,
cssClass: String,
},
computed: {
cssClasses() {
const result: Record<string, boolean> = {};
if (this.context) {
result[`notification-${this.context}`] = true;
}
if (this.cssClass) {
result[this.cssClass] = true;
}
return result;
},
canClose() {
if (this.type === 'persistent') {
// otherwise it is never possible to dismiss the notification
return true;
}
return !this.noclear;
},
},
emits: ['closed'],
data() {
return {
deleted: false,
};
},
mounted() {
const addToastEvent = () => {
setTimeout(() => {
this.deleted = true;
}, this.toastLength);
};
if (this.type === 'toast') {
addToastEvent();
}
if (this.style) {
$(this.$refs.root as HTMLElement).css(this.style as string);
}
},
methods: {
toastClosed() {
nextTick(() => {
this.$emit('closed');
});
},
closeNotification(event: MouseEvent) {
if (this.canClose && event && event.target) {
this.deleted = true;
nextTick(() => {
this.$emit('closed');
});
}
this.markNotificationAsRead();
},
markNotificationAsRead() {
if (!this.notificationId) {
return;
}
AjaxHelper.post({ // GET params
module: 'CoreHome',
action: 'markNotificationAsRead',
}, { // POST params
notificationId: this.notificationId,
},
{ withTokenInUrl: true });
},
},
});
</script>
|