Adrià Vilanova MartÃnez | 1e10d19 | 2021-12-31 16:01:13 +0100 | [diff] [blame] | 1 | import {createApp} from 'vue'; |
| 2 | |
| 3 | import {isOptionEnabled} from '../../../common/optionsUtils.js'; |
| 4 | |
| 5 | import {addButtonToThreadListActions, shouldAddBtnToActionBar} from './../utils/common.js'; |
| 6 | import Overlay from './components/Overlay.vue'; |
| 7 | import VueMaterialAdapter from './vma.js'; |
| 8 | |
| 9 | const wfDebugId = 'twpt-workflows'; |
| 10 | |
| 11 | export default class Workflows { |
| 12 | constructor() { |
| 13 | this.overlayApp = null; |
| 14 | this.overlayVm = null; |
| 15 | } |
| 16 | |
| 17 | createOverlay() { |
| 18 | let menuEl = document.createElement('div'); |
| 19 | document.body.appendChild(menuEl); |
| 20 | |
| 21 | this.overlayApp = createApp(Overlay); |
| 22 | this.overlayApp.use(VueMaterialAdapter); |
| 23 | this.overlayVm = this.overlayApp.mount(menuEl); |
| 24 | } |
| 25 | |
| 26 | switchMenu(menuBtn) { |
| 27 | if (this.overlayApp === null) this.createOverlay(); |
| 28 | if (!this.overlayVm.shown) { |
| 29 | let rect = menuBtn.getBoundingClientRect(); |
| 30 | this.overlayVm.position = [rect.left + rect.width, rect.bottom]; |
| 31 | this.overlayVm.shown = true; |
| 32 | } else { |
| 33 | this.overlayVm.shown = false; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | addThreadListBtnIfEnabled(readToggle) { |
| 38 | isOptionEnabled('workflows').then(isEnabled => { |
| 39 | if (isEnabled) { |
| 40 | let tooltip = chrome.i18n.getMessage('inject_workflows_menubtn'); |
| 41 | let btn = addButtonToThreadListActions( |
| 42 | readToggle, 'more_vert', wfDebugId, tooltip); |
| 43 | btn.addEventListener('click', () => { |
| 44 | this.switchMenu(btn); |
| 45 | }); |
| 46 | } |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | shouldAddThreadListBtn(node) { |
| 51 | return shouldAddBtnToActionBar(wfDebugId, node); |
| 52 | } |
| 53 | }; |