126 lines
3.8 KiB
JavaScript
126 lines
3.8 KiB
JavaScript
console.log("la");
|
|
console.log("la");
|
|
|
|
let es = null;
|
|
async function validatePath() {
|
|
const pathInput = document.getElementById('path-input');
|
|
const statusIcon = document.getElementById('path-status-icon');
|
|
const validateBtn = document.getElementById('validate-btn');
|
|
const pathNameHidden = document.getElementById('pathName');
|
|
const path = pathInput.value.trim();
|
|
|
|
if (!path) {
|
|
statusIcon.innerHTML = '<i class="fas fa-times has-text-danger"></i>';
|
|
validateBtn.disabled = true;
|
|
return;
|
|
}
|
|
|
|
// On assigne directement la valeur dans le champ hidden pour HTMX
|
|
pathNameHidden.value = path;
|
|
|
|
statusIcon.innerHTML = '<i class="fas fa-circle-notch fa-spin"></i>'; // Loading spinner
|
|
|
|
try {
|
|
const response = await fetch('/validate-path', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ pathName: path }), // <- ici on envoie pathName et plus path
|
|
});
|
|
|
|
if (response.ok) {
|
|
statusIcon.innerHTML = '<i class="fas fa-check-square has-text-success"></i>';
|
|
validateBtn.disabled = false;
|
|
} else {
|
|
const result = await response.json();
|
|
statusIcon.innerHTML = '<i class="fas fa-exclamation-triangle has-text-danger"></i>';
|
|
validateBtn.disabled = true;
|
|
console.error('Error:', result.error);
|
|
}
|
|
} catch (error) {
|
|
statusIcon.innerHTML = '<i class="fas fa-exclamation-triangle has-text-danger"></i>';
|
|
validateBtn.disabled = true;
|
|
console.error('Request failed:', error);
|
|
}
|
|
}
|
|
|
|
|
|
function disableAllInputPath(id){
|
|
console.log(this)
|
|
var inputs = document.querySelectorAll('#path-'+id+' .fff');
|
|
var btn =document.getElementById('btn-path-annuler-'+id)
|
|
btn.style.display = "none";
|
|
var btn2 =document.getElementById('btn-path-edit-'+id)
|
|
btn2.style.display = "block";
|
|
var btn3 =document.getElementById('btn-path-valider-'+id)
|
|
btn3.style.display = "none";
|
|
|
|
inputs.forEach(function(input) {
|
|
input.disabled = true;
|
|
});
|
|
|
|
}
|
|
function enableAllInputPath(id){
|
|
console.log(this)
|
|
var inputs = document.querySelectorAll('#path-'+id+' .fff');
|
|
var btn =document.getElementById('btn-path-annuler-'+id)
|
|
btn.style.display = "block";
|
|
var btn2 =document.getElementById('btn-path-edit-'+id)
|
|
btn2.style.display = "none";
|
|
var btn3 =document.getElementById('btn-path-valider-'+id)
|
|
btn3.style.display = "block";
|
|
inputs.forEach(function(input) {
|
|
input.disabled = false;
|
|
});
|
|
}
|
|
|
|
function setInputHidden(target,value){
|
|
document.getElementById(target).value = value;
|
|
|
|
}
|
|
function hide(target){
|
|
var btn =document.getElementById(target)
|
|
btn.style.display = "none";
|
|
}
|
|
|
|
document.addEventListener("htmx:afterOnLoad", function (event) {
|
|
// console.log("Réponse du serveur :", event.detail.xhr.responseText);
|
|
});
|
|
|
|
document.body.addEventListener('click', function(e) {
|
|
// Play
|
|
const playBtn = e.target.closest('.js-play-btn');
|
|
if (playBtn) {
|
|
const detailBlock = document.getElementById('detail-block');
|
|
const playerBlock = document.querySelector('.js-player-block');
|
|
const video = document.getElementById('hls-video');
|
|
const url = playBtn.dataset.hlsurl;
|
|
|
|
detailBlock.style.display = 'none';
|
|
playerBlock.style.display = 'block';
|
|
|
|
if (Hls.isSupported()) {
|
|
const hls = new Hls();
|
|
hls.loadSource(url);
|
|
hls.attachMedia(video);
|
|
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
|
video.src = url;
|
|
} else {
|
|
console.error('HLS non supporté');
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Fermer
|
|
const closeBtn = e.target.closest('.js-close-btn');
|
|
if (closeBtn) {
|
|
const detailBlock = document.getElementById('detail-block');
|
|
const playerBlock = document.querySelector('.js-player-block');
|
|
const video = document.getElementById('hls-video');
|
|
|
|
video.pause();
|
|
video.src = '';
|
|
playerBlock.style.display = 'none';
|
|
detailBlock.style.display = 'block';
|
|
}
|
|
});
|