public/js/music_playlist.js
/**
 * Handle song form submit button.
 */
Handle song form submit button.
Handle song form submit button .
function sendSongForm() { 
    var youTubeCodeField = document.getElementById('formSongYoutubeCode');
    var youTubeCodeValue = youTubeCodeField.value;
    var playlistField = document.getElementById('formSelectPlaylist');
    var playlistValue = playlistField.value;
    var ratingField = document.getElementById('formSongRating');
    var ratingFieldValue = ratingField.value;
    var statusField = document.getElementById('formSongStatus');
    if (youTubeCodeValue == "") {
        statusField.textContent = "Fill in the YouTube code!";
        youTubeCodeField.style.backgroundColor = "LightCoral";
    } else {
        var url = base_url + "/songs";              
        var data = {'youtube_code': youTubeCodeValue, 'playlist_name': playlistValue, 'rating': ratingFieldValue};
        fetch(url, {
            credentials: "same-origin",
            method: 'POST',
            body: JSON.stringify(data),
            headers:{
                'Content-Type': 'application/json',
                'X-CSRF-TOKEN': getCSRFToken()
            }
        })
        .then(function(response) {
            if (response.status == 201) {
                statusField.textContent = "Song is added!";
                youTubeCodeField.style.backgroundColor = "lightgreen";
            }
            else {
                statusField.textContent = "Song is not added!";
                youTubeCodeField.style.backgroundColor = "LightCoral";
            }
        });
    }            
}
function sendSongForm ( ) { var youTubeCodeField = document . getElementById ( 'formSongYoutubeCode' ) ; var youTubeCodeValue = youTubeCodeField . value ; var playlistField = document . getElementById ( 'formSelectPlaylist' ) ; var playlistValue = playlistField . value ; var ratingField = document . getElementById ( 'formSongRating' ) ; var ratingFieldValue = ratingField . value ; var statusField = document . getElementById ( 'formSongStatus' ) ; if ( youTubeCodeValue == "" ) { statusField . textContent = "Fill in the YouTube code!" ; youTubeCodeField . style . backgroundColor = "LightCoral" ; } else { var url = base_url + "/songs" ; var data = { 'youtube_code' : youTubeCodeValue , 'playlist_name' : playlistValue , 'rating' : ratingFieldValue } ; fetch ( url , { credentials : "same-origin" , method : 'POST' , body : JSON . stringify ( data ) , headers : { 'Content-Type' : 'application/json' , 'X-CSRF-TOKEN' : getCSRFToken ( ) } } ) . then ( function ( response ) { if ( response . status == 201 ) { statusField . textContent = "Song is added!" ; youTubeCodeField . style . backgroundColor = "lightgreen" ; } else { statusField . textContent = "Song is not added!" ; youTubeCodeField . style . backgroundColor = "LightCoral" ; } } ) ; } }
Handle song form submit button.
Handle song form submit button .