Skip to content

Commit

Permalink
Fix add playlist current track enable/disable with section switching (#…
Browse files Browse the repository at this point in the history
…5552)

* Fix add playlist current track enable/disable with section switching

* Fix from code review
  • Loading branch information
Dananji authored Jan 9, 2024
1 parent 5b186c2 commit 34c4182
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
7 changes: 4 additions & 3 deletions app/assets/javascripts/ramp_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,12 @@ function collapseMoreDetails() {
* @param {String} sectionTitle name of the current section
*/
function disableEnableCurrentTrack(activeTrack, currentTime, isSeeked, sectionTitle) {
let title = sectionTitle;
// Return when add to playlist panel is not expanded
if($('#addToPlaylistPanel.show').length === 0) {
// Return when add to playlist form is not visible
let playlistForm = $('#add_to_playlist')[0];
if(!playlistForm) {
return;
}
let title = sectionTitle;
if(activeTrack != undefined) {
streamId = activeTrack.streamId;
let { label, times, sectionLabel } = activeTrack;
Expand Down
50 changes: 26 additions & 24 deletions app/views/media_objects/_add_to_playlist.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ Unless required by applicable law or agreed to in writing, software distributed

<div id="add-to-playlist-form-group">
<div class="form-check">
<label class="form-check-label" onclick="collapseMoreDetails()">
<input type="radio" name="post[playlistitem_scope]" id="playlistitem_scope_track" aria-label="playlist item current track">
<label class="form-check-label">
<input type="radio" onclick="collapseMoreDetails()" name="post[playlistitem_scope]" id="playlistitem_scope_track" aria-label="playlist item current track">
<span id="current-track-text">Current Track (<span id="current-track-name"></span>)</span>
</label>
</div>
<div class="form-check">
<label class="form-check-label" onclick="collapseMoreDetails()">
<input type="radio" name="post[playlistitem_scope]" id="playlistitem_timeselection" aria-label="playlist item time selection">
<label class="form-check-label">
<input type="radio" onclick="collapseMoreDetails()" name="post[playlistitem_scope]" id="playlistitem_timeselection" aria-label="playlist item time selection">
Custom Timespan
</label>
<input type="text" name="playlist_item_start" id="playlist_item_start" pattern="(\d+:){0,2}\d+(\.\d+)?" value="" aria-label="start time">
Expand Down Expand Up @@ -169,27 +169,29 @@ Unless required by applicable law or agreed to in writing, software distributed
}
function addPlayerEventListeners(player) {
player.on('loadedmetadata', () => {
enableAddToPlaylist();
});
player.on('seeked', () => {
if(getActiveItem() != undefined) {
activeTrack = getActiveItem(false);
if(activeTrack != undefined) {
streamId = activeTrack.streamId;
if (player && player != undefined) {
player.on('loadedmetadata', () => {
enableAddToPlaylist();
});
player.on('seeked', () => {
if(getActiveItem() != undefined) {
activeTrack = getActiveItem(false);
if(activeTrack != undefined) {
streamId = activeTrack.streamId;
}
disableEnableCurrentTrack(activeTrack, player.currentTime(), true, currentSectionLabel);
}
disableEnableCurrentTrack(activeTrack, player.currentTime(), true, currentSectionLabel);
}
});
player.on('dispose', () => {
let addToPlaylistBtn = document.getElementById('addToPlaylistBtn');
currentSectionLabel = undefined;
$('#addToPlaylistPanel').collapse('hide');
resetAddToPlaylistForm();
if (addToPlaylistBtn) {
addToPlaylistBtn.disabled = true;
}
});
});
player.on('dispose', () => {
let addToPlaylistBtn = document.getElementById('addToPlaylistBtn');
currentSectionLabel = undefined;
$('#addToPlaylistPanel').collapse('hide');
resetAddToPlaylistForm();
if (addToPlaylistBtn) {
addToPlaylistBtn.disabled = true;
}
});
}
}
function enableAddToPlaylist() {
Expand Down

0 comments on commit 34c4182

Please sign in to comment.