Add workflow menu button to thread lists

Bug: twpowertools:74
Change-Id: I703950394d674c2084278bf9e876014d08fa5cfb
diff --git a/src/contentScripts/communityConsole/workflows/workflows.js b/src/contentScripts/communityConsole/workflows/workflows.js
new file mode 100644
index 0000000..dc542fa
--- /dev/null
+++ b/src/contentScripts/communityConsole/workflows/workflows.js
@@ -0,0 +1,53 @@
+import {createApp} from 'vue';
+
+import {isOptionEnabled} from '../../../common/optionsUtils.js';
+
+import {addButtonToThreadListActions, shouldAddBtnToActionBar} from './../utils/common.js';
+import Overlay from './components/Overlay.vue';
+import VueMaterialAdapter from './vma.js';
+
+const wfDebugId = 'twpt-workflows';
+
+export default class Workflows {
+  constructor() {
+    this.overlayApp = null;
+    this.overlayVm = null;
+  }
+
+  createOverlay() {
+    let menuEl = document.createElement('div');
+    document.body.appendChild(menuEl);
+
+    this.overlayApp = createApp(Overlay);
+    this.overlayApp.use(VueMaterialAdapter);
+    this.overlayVm = this.overlayApp.mount(menuEl);
+  }
+
+  switchMenu(menuBtn) {
+    if (this.overlayApp === null) this.createOverlay();
+    if (!this.overlayVm.shown) {
+      let rect = menuBtn.getBoundingClientRect();
+      this.overlayVm.position = [rect.left + rect.width, rect.bottom];
+      this.overlayVm.shown = true;
+    } else {
+      this.overlayVm.shown = false;
+    }
+  }
+
+  addThreadListBtnIfEnabled(readToggle) {
+    isOptionEnabled('workflows').then(isEnabled => {
+      if (isEnabled) {
+        let tooltip = chrome.i18n.getMessage('inject_workflows_menubtn');
+        let btn = addButtonToThreadListActions(
+            readToggle, 'more_vert', wfDebugId, tooltip);
+        btn.addEventListener('click', () => {
+          this.switchMenu(btn);
+        });
+      }
+    });
+  }
+
+  shouldAddThreadListBtn(node) {
+    return shouldAddBtnToActionBar(wfDebugId, node);
+  }
+};