You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

211 lines
11 KiB

const event_video = (function ($, window, jQuery) {
return {
"add_video": function(videoId) {
$.ajax({
url: app.get_vars().baseurl+"events/event_video/get_video_details?video_id="+videoId,
type: "GET",
success: function(result) {
const videoDetails = JSON.parse(result)
if(videoDetails.status && videoDetails.status === 200) {
event_video.append_video(event_video.format_video_details(videoDetails))
event_video.clear_inputs()
} else {
//popup up error message here
app._notify('error', videoDetails.body.error);
}
}
});
},
"format_video_details": function(videoDetails) {
const ws = events.get_vars().workshop_session
let json_format = {}
if(ws == 'DISTANCE-PRESENTIEL') {
json_format = {
image: videoDetails.body.pictures.base_link,
title: $('#video_title_distance').val(),//videoDetails.body.name,
duration: event_video.formatDuration(videoDetails.body.duration),
live_video_start_date: $('#live_video_start_date_distance').val() ? app._form.format_inputs("datetime", $('#live_video_start_date_distance').val()):'',
live_video_end_date: $('#live_video_end_date_distance').val()?app._form.format_inputs("datetime", $('#live_video_end_date_distance').val()):'',
description: $('#video_description_distance').val(),// videoDetails.body.description.replace(/\"/g, ""),
embed: JSON.stringify(videoDetails.body.embed.html),
url: videoDetails.body.link,
owner: videoDetails.body.user.name,
id: ''
}
} else {
json_format = {
image: videoDetails.body.pictures.base_link,
title: $('#video_title').val(),//videoDetails.body.name,
duration: event_video.formatDuration(videoDetails.body.duration),
live_video_start_date: $('#live_video_start_date').val() ? app._form.format_inputs("datetime", $('#live_video_start_date').val()):'',
live_video_end_date: $('#live_video_end_date').val()?app._form.format_inputs("datetime", $('#live_video_end_date').val()):'',
description: $('#video_description').val(),// videoDetails.body.description.replace(/\"/g, ""),
embed: JSON.stringify(videoDetails.body.embed.html),
url: videoDetails.body.link,
owner: videoDetails.body.user.name,
id: ''
}
}
return json_format
},
"clear_inputs": function() {
if(events.get_vars().workshop_session == 'DISTANCE-PRESENTIEL') {
$('#course_url_distance').val('')
$('#video_description_distance').val('')
$('#video_title_distance').val('')
$('#live_video_start_date_distance').val('')
$('#live_video_end_date_distance').val('')
$('#live_video_start_date_distance').data("DateTimePicker").clear()
$('#live_video_end_date_distance').data("DateTimePicker").clear()
$('#upload_course_url_distance').removeAttr('disabled', true);
} else {
$('#course_url').val('')
$('#video_description').val('')
$('#video_title').val('')
$('#live_video_start_date').val('')
$('#live_video_end_date').val('')
$('#live_video_start_date').data("DateTimePicker").clear()
$('#live_video_end_date').data("DateTimePicker").clear()
$('#upload_course_url').removeAttr('disabled', true);
}
},
"append_video": function(videoDetails) {
let html = `
<div class="row video-bo">
<div class="col-lg-3 col-md-3 image-div">
<img class="image" src="${videoDetails.image}" alt="">
</div>
<div class="col-lg-7 col-md-7 video-div">
<div class="video-title" contentEditable="true">${videoDetails.title}</div>
<div class="video-length">Duration : <span>${videoDetails.duration}</span></div>`;
if(events.get_vars().workshop_session == 'DISTANCE-PRESENTIEL' || events.get_vars().workshop_session == 'DISTANCE') {
html += `<div class="live_video_start_date">Date de commencement : <span contentEditable="true">${videoDetails.live_video_start_date}</span></div>
<div class="live_video_end_date">Date de fin : <span contentEditable="true">${videoDetails.live_video_end_date}</span></div>`
}
html += `<hr>
<div class="video-description" contentEditable="true"> ${videoDetails.description}</div>
</div>
<div class="col-lg-1 col-md-1 text-center">
<button class="remove_video">Delete</button>
</div>
<input type="hidden" class="embed" value='${videoDetails.embed}'>
<input type="hidden" class="url" value="${videoDetails.url}">
<input type="hidden" class="owner" value="${videoDetails.owner}">
<input type="hidden" class="id" value="${videoDetails.id}">
</div>
`;
if(events.get_vars().workshop_session == 'DISTANCE-PRESENTIEL') {
$('#course_url_container_distance').append(html)
} else {
$('#course_url_container').append(html)
}
},
"format_videos": function () {
let formattedVideos = []
const ws = events.get_vars().workshop_session
const trCount = (ws =='DISTANCE-PRESENTIEL') ? $('#course_url_container_distance .video-bo') : $('#course_url_container .video-bo')
if(trCount.length>0) {
for(let i=0; i<trCount.length; i++) {
const sDate = $(trCount[i]).find('.video-div > .live_video_start_date').text()
const eDate = $(trCount[i]).find('.video-div > .live_video_end_date').text()
const start_date = sDate ? moment(sDate).format("YYYY-MM-DD HH:mm") : null
const end_date = eDate ? moment(eDate).format("YYYY-MM-DD HH:mm") : null
formattedVideos.push({
image: $(trCount[i]).find('.image-div > img')[0].src,
title: $(trCount[i]).find('.video-div > .video-title').text(),
duration: $(trCount[i]).find('.video-div > .video-length > span').text(),
description: $(trCount[i]).find('.video-div > .video-description').text(),
live_video_start_date: start_date,
live_video_end_date: end_date,
embed: $(trCount[i]).find('input.embed').val(),
url: $(trCount[i]).find('input.url').val(),
owner: $(trCount[i]).find('input.owner').val(),
id: $(trCount[i]).find('input.id').val()
})
}
}
return JSON.stringify(formattedVideos)
},
"videos":[],
"formatDuration": function(sec) {
let hours = Math.floor(sec/3600);
(hours >= 1) ? sec = sec - (hours*3600) : hours = '00';
let min = Math.floor(sec/60);
(min >= 1) ? sec = sec - (min*60) : min = '00';
(sec < 1) ? sec='00' : void 0;
(min.toString().length == 1) ? min = '0'+min : void 0;
(sec.toString().length == 1) ? sec = '0'+sec : void 0;
return hours+':'+min+':'+sec;
}
}
})(jQuery, this)
$(function() {
/** ONLINE AND DISTANCE-PRESENTIEL */
$('#upload_course_url').on('click', function() {
let videoInput = $('#course_url')
let descriptionInput = $('#video_description')
let titleInput = $('#video_title')
let startDateInput = $('#live_video_start_date')
let endDateInput = $('#live_video_end_date')
if(videoInput.val() === '') {
videoInput.focus()
} else if(titleInput.val() === '') {
titleInput.focus()
} else if(descriptionInput.val() === '') {
descriptionInput.focus()
} else if(startDateInput.val() === '' &&
(events.get_vars().workshop_session == 'DISTANCE-PRESENTIEL' || events.get_vars().workshop_session == 'DISTANCE')) {
startDateInput.focus()
} else if(endDateInput.val() === '' &&
(events.get_vars().workshop_session == 'DISTANCE-PRESENTIEL' || events.get_vars().workshop_session == 'DISTANCE')) {
endDateInput.focus()
} else {
$('#upload_course_url').attr('disabled', true);
event_video.add_video(videoInput.val())
}
})
$('#course_url_container').on('click', '.remove_video', function () {
$(this).closest('.video-bo').remove();
});
/** END */
/** ATELIER A DISTANCE */
$('#upload_course_url_distance').on('click', function() {
let videoInput = $('#course_url_distance')
let descriptionInput = $('#video_description_distance')
let titleInput = $('#video_title_distance')
let startDateInput = $('#live_video_start_date_distance')
let endDateInput = $('#live_video_end_date_distance')
if(videoInput.val() === '') {
videoInput.focus()
} else if(titleInput.val() === '') {
titleInput.focus()
} else if(descriptionInput.val() === '') {
descriptionInput.focus()
} else if(startDateInput.val() === '' &&
(events.get_vars().workshop_session == 'DISTANCE-PRESENTIEL' || events.get_vars().workshop_session == 'DISTANCE')) {
startDateInput.focus()
} else if(endDateInput.val() === '' &&
(events.get_vars().workshop_session == 'DISTANCE-PRESENTIEL' || events.get_vars().workshop_session == 'DISTANCE')) {
endDateInput.focus()
} else {
$('#upload_course_url_distance').attr('disabled', true);
event_video.add_video(videoInput.val())
}
})
$('#course_url_container_distance').on('click', '.remove_video', function () {
$(this).closest('.video-bo').remove();
});
/** END */
})