testapi.js
/*
Function showing the library of the selected user and showing associated function such as deleting and adding video
 */
Function showing the library of the selected user and showing associated function such as deleting and adding video
Function showing the library of the selected user and showing associated function such as deleting and adding video
function show_user() {
    hide_user();
    let username = $("#select_users").val();
    $.ajax({
        method: 'GET',
        data: {
            username: username,
        },
        url:'./library.php',
        success: function (response) {
            let videoLib = $("#video_library");
            videoLib.append("<p>Library of "+ username +"<p>");
            let ul = document.createElement('ul');
            document.getElementById('video_library').appendChild(ul);
            response.forEach(function(name){
                let li = document.createElement('li');
                ul.appendChild(li);
                li.innerHTML += " <a href=\"https://www.youtube.com/watch?v=" + name.id +"\" target=\"_blank\">" + name.title;
                li.innerHTML += "<button id=\"delete_video\" onclick=\"delete_video(\'"+ name.id +"\')\">Delete</button>"
            });
            videoLib.append("<label for=\"video_title\">Add a new video to the playlist</label>\n" +
                "<input type=\"text\" id=\"video_title\" name=\"video_title\" placeholder=\"Title of the YT video\">"+
                "<label for=\"video_id\">ID of the video</label>\n" +
                "<input type=\"text\" id=\"video_id\" name=\"video_id\" placeholder=\"end of the link, example : tOANmMG-KQg\" size=\"50\">"+
                "<button id=\"add_video\" onclick=\"add_video()\">Add</button>");
        },
        error: function(xhr, status, error) {
            alert(error);
        }
    })
}
function show_user ( ) { hide_user ( ) ; let username = $ ( "#select_users" ) . val ( ) ; $ . ajax ( { method : 'GET' , data : { username : username , } , url : './library.php' , success : function ( response ) { let videoLib = $ ( "#video_library" ) ; videoLib . append ( "<p>Library of " + username + "<p>" ) ; let ul = document . createElement ( 'ul' ) ; document . getElementById ( 'video_library' ) . appendChild ( ul ) ; response . forEach ( function ( name ) { let li = document . createElement ( 'li' ) ; ul . appendChild ( li ) ; li . innerHTML += " <a href=\"https://www.youtube.com/watch?v=" + name . id + "\" target=\"_blank\">" + name . title ; li . innerHTML += "<button id=\"delete_video\" onclick=\"delete_video(\'" + name . id + "\')\">Delete</button>" } ) ; videoLib . append ( "<label for=\"video_title\">Add a new video to the playlist</label>\n" + "<input type=\"text\" id=\"video_title\" name=\"video_title\" placeholder=\"Title of the YT video\">" + "<label for=\"video_id\">ID of the video</label>\n" + "<input type=\"text\" id=\"video_id\" name=\"video_id\" placeholder=\"end of the link, example : tOANmMG-KQg\" size=\"50\">" + "<button id=\"add_video\" onclick=\"add_video()\">Add</button>" ) ; } , error : function ( xhr , status , error ) { alert ( error ) ; } } ) }
Function showing the library of the selected user and showing associated function such as deleting and adding video
Function showing the library of the selected user and showing associated function such as deleting and adding video