Skip to content

Commit 723f9c4

Browse files
[REF] runbot: rewrite runbot.js
Rewrites runbot.js in modern js with the new Interaction framework.
1 parent 6ba9aaf commit 723f9c4

File tree

3 files changed

+49
-37
lines changed

3 files changed

+49
-37
lines changed

runbot/__manifest__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
'runbot/static/src/vendored/**/*', # Vendored files coming from odoo modules
7777

7878
'runbot/static/src/frontend/root.js',
79+
'runbot/static/src/frontend/runbot.js',
7980
]
8081
},
8182
'post_load': 'runbot_post_load',
Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,51 @@
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+
};
3115

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+
}
3239

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);
3748
}
38-
navigator.clipboard.writeText(text);
3949
}
50+
51+
registry.category('public.interactions').add('runbot', Runbot);

runbot/templates/utils.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<script src="/runbot/static/libs/jquery/jquery.js" type="text/javascript"/>
1414
<script type="text/javascript" src="/runbot/static/libs/popper/popper.js"/>
1515
<script type="text/javascript" src="/runbot/static/libs/bootstrap/js/bootstrap.bundle.js"/>
16-
<script type="text/javascript" src="/runbot/static/src/frontend/runbot.js"/>
1716

1817
<t t-call-assets="runbot.assets_frontend"/>
1918

@@ -392,7 +391,7 @@
392391
</template>
393392

394393
<template id="runbot.branch_copy_button">
395-
<button t-attf-class="btn btn-default {{btn_size or 'btn-ssm'}}" title="Copy Bundle name" aria-label="Copy Bundle name" t-attf-onclick="copyToClipboard('{{ bundle.name.split(':')[-1] }}')">
394+
<button t-attf-class="btn btn-default {{btn_size or 'btn-ssm'}}" title="Copy Bundle name" aria-label="Copy Bundle name" t-attf-data-clipboard-copy="{{ bundle.name.split(':')[-1] }}">
396395
<i t-attf-class="fa fa-clipboard"/>
397396
</button>
398397
</template>

0 commit comments

Comments
 (0)