public/js/music_playlist.js
/**
 * Handle playlist form submit button.
 */
Handle playlist form submit button.
Handle playlist form submit button .
function sendPlaylistForm() {
    var nameField = document.getElementById('formPlaylistName');
    var nameFieldValue = nameField.value;
    var ratingField = document.getElementById('formPlaylistRating');
    var ratingFieldValue = ratingField.value;
    var imageField = document.getElementById('formPlaylistImage');
    var imageFieldValue = imageField.value;
    var statusField = document.getElementById('formPlaylistStatus');
    if (imageFieldValue == "") imageFieldValue = "https://media.tmicdn.com/catalog/product/cache/c687aa7517cf01e65c009f6943c2b1e9/m/u/music-note-temporary-tattoo_2597.jpg";
    if (nameFieldValue == "") {
        statusField.textContent = "Fill in the playlist name!";
        nameField.style.backgroundColor = "LightCoral";
    } else {
        var url = base_url + "/playlists";               
        var data = {'name': nameFieldValue, 'rating': ratingFieldValue, 'image': imageFieldValue};
        fetch(url, {
            method: 'POST',
            body: JSON.stringify(data),
            headers:{
                'Content-Type': 'application/json',
                'X-CSRF-TOKEN': getCSRFToken()
            }
        })
        .then(function(response) {
            if (response.status == 201) {
                statusField.textContent = "Playlist is created!";
                nameField.style.backgroundColor = "lightgreen";
            }
            else {
                statusField.textContent = "Playlist is not created!";
                nameField.style.backgroundColor = "LightCoral";
            }
        });
    }            
}
function sendPlaylistForm ( ) { var nameField = document . getElementById ( 'formPlaylistName' ) ; var nameFieldValue = nameField . value ; var ratingField = document . getElementById ( 'formPlaylistRating' ) ; var ratingFieldValue = ratingField . value ; var imageField = document . getElementById ( 'formPlaylistImage' ) ; var imageFieldValue = imageField . value ; var statusField = document . getElementById ( 'formPlaylistStatus' ) ; if ( imageFieldValue == "" ) imageFieldValue = "https://media.tmicdn.com/catalog/product/cache/c687aa7517cf01e65c009f6943c2b1e9/m/u/music-note-temporary-tattoo_2597.jpg" ; if ( nameFieldValue == "" ) { statusField . textContent = "Fill in the playlist name!" ; nameField . style . backgroundColor = "LightCoral" ; } else { var url = base_url + "/playlists" ; var data = { 'name' : nameFieldValue , 'rating' : ratingFieldValue , 'image' : imageFieldValue } ; fetch ( url , { method : 'POST' , body : JSON . stringify ( data ) , headers : { 'Content-Type' : 'application/json' , 'X-CSRF-TOKEN' : getCSRFToken ( ) } } ) . then ( function ( response ) { if ( response . status == 201 ) { statusField . textContent = "Playlist is created!" ; nameField . style . backgroundColor = "lightgreen" ; } else { statusField . textContent = "Playlist is not created!" ; nameField . style . backgroundColor = "LightCoral" ; } } ) ; } }
Handle playlist form submit button.
Handle playlist form submit button .
// credentials: "same-origin",