﻿var currentTrackId = 0;
var currentTrackName = "";
var currentLink = "";

function AddPlaylist() {
    var playlistname = $("#newPlaylist").val();

    if (playlistname.length == 0) {
        alert("Пожалуйста, введите название плейлиста.");
        return;
    }

    $.getJSON('../../Songs/AddPlaylist/' + playlistname, { PlaylistName: playlistname }, function (playlistId) {
        $('#playlistItems').append($("<option></option>").attr("value", playlistId).text(playlistname));
        $("#newPlaylist").val('');
        $('#playlistItems').val(playlistId);
    });
}

function AddTrackToPlaylist() {
    var playlistId = $('#playlistItems').val();

    if (playlistId == null) {
        alert("Выберите плейлист. Если у Вас нет плейлистов, пожалуйста добавьте.");
        return;
    }

    $.getJSON('../../Songs/AddPlaylistTrack/' + playlistId, { PlaylistId: playlistId, TrackId: currentTrackId }, function (recordId) {
        
        var div = $("#" + currentLink);
        div.html("<span style='color:gray; white-space: nowrap;'><img alt='в плейлисте' src='../../Content/Images/playlist_disabled.png' border='0' /></span>");
        $('#playlistDialog').dialog('close');
    });
}
