mirror of
https://github.com/bringout/oca-web.git
synced 2026-04-20 01:52:01 +02:00
Add oca-web submodule with 68 web modules
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
af56672c08
commit
53fddf87c8
2469 changed files with 101716 additions and 0 deletions
|
|
@ -0,0 +1,70 @@
|
|||
/** @odoo-module alias=web_notify.AudioPlayer **/
|
||||
|
||||
import {Component, useState} from "@odoo/owl";
|
||||
|
||||
/**
|
||||
* @typedef AudioPlayerProps
|
||||
* @property {string} src URL of the audio file to be played
|
||||
* @property {number} [volume=1.0] Volume level of the audio (from 0.0 to 1.0)
|
||||
* @property {boolean} [loop=false] Whether the audio should loop
|
||||
* @property {Function} [onEnded] Callback function to be called when the audio ends
|
||||
*/
|
||||
|
||||
/**
|
||||
* The AudioPlayer component is responsible for playing audio files with
|
||||
* specified settings like volume and looping. It also provides the ability
|
||||
* to trigger actions when the audio playback ends.
|
||||
*/
|
||||
export class AudioPlayer extends Component {
|
||||
setup() {
|
||||
this.state = useState({isPlaying: false});
|
||||
this.audioElement = new Audio(this.props.src);
|
||||
|
||||
// Set audio properties
|
||||
this.audioElement.volume = this.props.volume || 1.0;
|
||||
this.audioElement.loop = this.props.loop || false;
|
||||
|
||||
// Start playing the audio
|
||||
this.audioElement
|
||||
.play()
|
||||
.then(() => {
|
||||
this.state.isPlaying = true;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Audio playback failed:", error);
|
||||
});
|
||||
|
||||
// Listen for the end of the audio playback
|
||||
this.audioElement.addEventListener("ended", this.onAudioEnded.bind(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the audio playback and triggers the onEnded callback if provided.
|
||||
*/
|
||||
stopAudio() {
|
||||
this.audioElement.pause();
|
||||
this.audioElement.currentTime = 0;
|
||||
this.state.isPlaying = false;
|
||||
|
||||
if (this.props.onEnded) {
|
||||
this.props.onEnded();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handler for when the audio playback ends.
|
||||
*/
|
||||
onAudioEnded() {
|
||||
if (!this.props.loop) {
|
||||
this.stopAudio();
|
||||
}
|
||||
}
|
||||
|
||||
willUnmount() {
|
||||
// Clean up the audio element and listeners
|
||||
this.audioElement.removeEventListener("ended", this.onAudioEnded);
|
||||
this.audioElement.pause();
|
||||
}
|
||||
}
|
||||
|
||||
AudioPlayer.template = "web_notify.AudioPlayer";
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!-- Copyright 2024 Cetmix OÜ
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="web_notify.AudioPlayer" owl="1">
|
||||
<!-- No visual elements needed, audio is controlled programmatically -->
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
Loading…
Add table
Add a link
Reference in a new issue