Files
luos/resources/assets/js/components/utils/CustomTooltip.vue

79 lines
2.0 KiB
Vue
Raw Normal View History

<template>
<span
2021-08-17 21:48:08 +00:00
:id="`label-${data.id}`"
@mouseover="hoverHandler"
:title="labelTooltip"
>
2021-08-20 03:40:20 +00:00
{{ data.title }}
<b-tooltip
2021-08-17 21:48:08 +00:00
:target="`label-${data.id}`"
2021-08-20 03:40:20 +00:00
:ref="`tooltip-${data.id}`"
>
{{ labelTooltip }}
</b-tooltip>
2021-08-20 03:40:20 +00:00
</span>
</template>
<script>
import api from "./../../api/index";
export default {
name: "CustomTooltip",
props: {
data: Object,
},
data() {
return {
labelTooltip: "",
hovering: "",
show: false,
2021-08-20 03:40:20 +00:00
disabled: true,
menuMap: {
CASES_INBOX: "inbox",
CASES_DRAFT: "draft",
CASES_PAUSED: "paused",
2021-08-20 03:40:20 +00:00
CASES_SELFSERVICE: "unassigned",
todo: "inbox",
draft: "draft",
paused: "paused",
unassigned: "unassigned"
}
}
},
methods: {
/**
* Delay the hover event
*/
hoverHandler() {
2021-08-20 03:40:20 +00:00
// this.hovering = setTimeout(() => { this.setTooltip() }, 3000);
this.setTooltip();
},
/**
* Reset the delay and hide the tooltip
*/
unhoverHandler() {
2021-08-20 03:40:20 +00:00
let key =`tooltip-${this.data.id}`;
this.labelTooltip = "";
2021-08-20 03:40:20 +00:00
// this.show = false;
this.disabled = true;
this.$refs[key].$emit('close');
clearTimeout(this.hovering);
},
/**
* Set the label to show in the tooltip
2021-08-20 03:40:20 +00:00
*/
setTooltip() {
let that = this;
api.menu
.getTooltip(that.menuMap[that.data.id])
.then((response) => {
2021-08-20 03:40:20 +00:00
let key =`tooltip-${that.data.id}`;
that.disabled = false;
that.labelTooltip = response.data.label;
2021-08-20 03:40:20 +00:00
that.$refs[key].$emit('open');
});
},
}
}
</script>