|
1 | | -(function($) { |
2 | | - "use strict"; |
3 | | - $(function () { |
4 | | - $(document).on('click', '[data-runbot]', function (e) { |
5 | | - e.preventDefault(); |
6 | | - var data = $(this).data(); |
7 | | - var operation = data.runbot; |
8 | | - if (!operation) { |
9 | | - return; |
10 | | - } |
11 | | - var xhr = new XMLHttpRequest(); |
12 | | - var url = e.target.href |
13 | | - if (data.runbotBuild) { |
14 | | - url = '/runbot/build/' + data.runbotBuild + '/' + operation |
15 | | - } |
16 | | - var elem = e.target |
17 | | - xhr.addEventListener('load', function () { |
18 | | - if (operation == 'rebuild' && window.location.href.split('?')[0].endsWith('/build/' + data.runbotBuild)){ |
19 | | - window.location.href = window.location.href.replace('/build/' + data.runbotBuild, '/build/' + xhr.responseText); |
20 | | - } else if (operation == 'action') { |
21 | | - elem.parentElement.innerText = this.responseText |
22 | | - } else { |
23 | | - window.location.reload(); |
24 | | - } |
25 | | - }); |
26 | | - xhr.open('POST', url); |
27 | | - xhr.send(); |
28 | | - }); |
29 | | - }); |
30 | | -})(jQuery); |
| 1 | +import { registry } from '@web/core/registry'; |
| 2 | +import { Interaction } from '@web/public/interaction'; |
| 3 | + |
| 4 | + |
| 5 | +class Runbot extends Interaction { |
| 6 | + static selector = '.frontend'; |
| 7 | + dynamicContent = { |
| 8 | + '[data-runbot]': { |
| 9 | + 't-on-click.prevent': this.onClickDataRunbot, |
| 10 | + }, |
| 11 | + '[data-clipboard-copy]': { |
| 12 | + 't-on-click.prevent': this.onClickClipboardCopy |
| 13 | + } |
| 14 | + }; |
31 | 15 |
|
| 16 | + /** |
| 17 | + * @param {Event} ev |
| 18 | + */ |
| 19 | + async onClickDataRunbot({currentTarget: target}) { |
| 20 | + const {runbot: operation, runbotBuild} = target.dataset; |
| 21 | + if (!operation) { |
| 22 | + return; |
| 23 | + } |
| 24 | + let url = target.href; |
| 25 | + if (runbotBuild) { |
| 26 | + url = `/runbot/build/${runbotBuild}/${operation}`; |
| 27 | + } |
| 28 | + const response = await fetch(url, { |
| 29 | + method: 'POST', |
| 30 | + }); |
| 31 | + if (operation == 'rebuild' && window.location.href.split('?')[0].endsWith(`/build/${runbotBuild}`)) { |
| 32 | + window.location.href = window.location.href.replace('/build/' + runbotBuild, '/build/' + await response.text()); |
| 33 | + } else if (operation == 'action') { |
| 34 | + target.parentElement.innerText = await response.text(); |
| 35 | + } else { |
| 36 | + window.location.reload(); |
| 37 | + } |
| 38 | + } |
32 | 39 |
|
33 | | -function copyToClipboard(text) { |
34 | | - if (!navigator.clipboard) { |
35 | | - console.error('Clipboard not supported'); |
36 | | - return; |
| 40 | + /** |
| 41 | + * @param {Event} ev |
| 42 | + */ |
| 43 | + async onClickClipboardCopy({ currentTarget: target }) { |
| 44 | + if (!navigator.clipboard) { |
| 45 | + return; |
| 46 | + } |
| 47 | + navigator.clipboard.writeText(target.dataset.clipboardCopy); |
37 | 48 | } |
38 | | - navigator.clipboard.writeText(text); |
39 | 49 | } |
| 50 | + |
| 51 | +registry.category('public.interactions').add('runbot', Runbot); |
0 commit comments