File tree Expand file tree Collapse file tree 3 files changed +42
-32
lines changed
Expand file tree Collapse file tree 3 files changed +42
-32
lines changed Original file line number Diff line number Diff line change 11// @odoo -module ignore
2- ( function ( $ ) {
3- "use strict" ;
4- $ ( function ( ) {
5- $ ( document ) . on ( 'click' , '[data-runbot]' , function ( e ) {
6- e . preventDefault ( ) ;
7- var data = $ ( this ) . data ( ) ;
8- var operation = data . runbot ;
9- if ( ! operation ) {
10- return ;
11- }
12- var xhr = new XMLHttpRequest ( ) ;
13- var url = e . target . href
14- if ( data . runbotBuild ) {
15- url = '/runbot/build/' + data . runbotBuild + '/' + operation
16- }
17- var elem = e . target
18- xhr . addEventListener ( 'load' , function ( ) {
19- if ( operation == 'rebuild' && window . location . href . split ( '?' ) [ 0 ] . endsWith ( '/build/' + data . runbotBuild ) ) {
20- window . location . href = window . location . href . replace ( '/build/' + data . runbotBuild , '/build/' + xhr . responseText ) ;
21- } else if ( operation == 'action' ) {
22- elem . parentElement . innerText = this . responseText
23- } else {
24- window . location . reload ( ) ;
25- }
26- } ) ;
27- xhr . open ( 'POST' , url ) ;
28- xhr . send ( ) ;
29- } ) ;
30- } ) ;
31- } ) ( jQuery ) ;
32-
332
343function copyToClipboard ( text ) {
354 if ( ! navigator . clipboard ) {
Original file line number Diff line number Diff line change 1- const Interactions = [ ] ;
1+ import { Runbot } from "./runbot" ;
2+
3+ const Interactions = [ Runbot ] ;
24
35async function start ( ) {
46 for ( const I of Interactions ) {
Original file line number Diff line number Diff line change 1+ import { DelegatedInteractionLite } from "./delegated_interaction_lite" ;
2+
3+ export class Runbot extends DelegatedInteractionLite {
4+ // static selector = ".frontend";
5+
6+ dynamicContent = {
7+ "[data-runbot]" : {
8+ "t-on-click.prevent" : this . onDataRunbotClick ,
9+ } ,
10+ } ;
11+
12+ async onDataRunbotClick ( { delegatedTarget } ) {
13+ const { runbot : operation , runbotBuild } = delegatedTarget . dataset ;
14+ if ( ! operation ) {
15+ return ;
16+ }
17+ let { href : url } = delegatedTarget ;
18+ if ( runbotBuild ) {
19+ url = `/runbot/build/${ runbotBuild } /${ operation } ` ;
20+ }
21+ const response = await fetch ( url , { method : "POST" } ) ;
22+ const responseText = await response . text ( ) ;
23+ const { href : currentURL , pathname } = window . location ;
24+ switch ( operation ) {
25+ case "rebuild" :
26+ if ( pathname . endsWith ( `/build/${ runbotBuild } ` ) ) {
27+ const redirectURL = new URL ( currentURL ) ;
28+ redirectURL . pathname = redirectURL . pathname . replace ( `/build/${ runbotBuild } ` , `/build/${ responseText } ` ) ;
29+ window . location . href = redirectURL . toString ( ) ;
30+ }
31+ break ;
32+ case "action" :
33+ delegatedTarget . parentElement . innerText = responseText ;
34+ break ;
35+ default :
36+ window . location . reload ( ) ;
37+ }
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments