Improved all list importing, and added error-messages for faulty url/ids

This commit is contained in:
Kasper Rynning-Tønnesen
2016-08-27 15:44:34 +02:00
parent a0fd178eca
commit 93ed57e720
3 changed files with 35 additions and 17 deletions

File diff suppressed because one or more lines are too long

View File

@@ -418,7 +418,10 @@ $(document).on("submit", "#listImport", function(e){
document.getElementById("import").disabled = true; document.getElementById("import").disabled = true;
$("#import").addClass("hide"); $("#import").addClass("hide");
$("#playlist_loader").removeClass("hide"); $("#playlist_loader").removeClass("hide");
} else {
Materialize.toast("It seems you've entered a invalid url.", 4000);
} }
document.getElementById("import").value = "";
}); });
$(document).on("submit", "#listImportSpotify", function(e){ $(document).on("submit", "#listImportSpotify", function(e){
@@ -431,13 +434,16 @@ $(document).on("submit", "#listImportSpotify", function(e){
var user = url[0]; var user = url[0];
var playlist_id = url[2]; var playlist_id = url[2];
document.getElementById("import_spotify").disabled = true;
$("#import_spotify").addClass("hide");
$("#playlist_loader_spotify").removeClass("hide");
Search.importSpotifyPlaylist('https://api.spotify.com/v1/users/' + user + '/playlists/' + playlist_id + '/tracks'); Search.importSpotifyPlaylist('https://api.spotify.com/v1/users/' + user + '/playlists/' + playlist_id + '/tracks');
} else {
Materialize.toast("It seems you've entered a invalid url.", 4000);
} }
} }
document.getElementById("import_spotify").value = ""; document.getElementById("import_spotify").value = "";
document.getElementById("import_spotify").disabled = true;
$("#import_spotify").addClass("hide");
$("#playlist_loader_spotify").removeClass("hide");
}); });
$(window).focus(function(){ $(window).focus(function(){

View File

@@ -243,16 +243,23 @@ var Search = {
dataType:"jsonp", dataType:"jsonp",
success: function(response) success: function(response)
{ {
var ids=""; if(response.error){
//Search.addVideos(response.items[0].contentDetails.videoId); document.getElementById("import").disabled = false;
//response.items.shift(); $("#playlist_loader").addClass("hide");
$.each(response.items, function(i,data) $("#import").removeClass("hide");
{ Materialize.toast("It seems you've entered a invalid url.", 4000);
ids+=data.contentDetails.videoId+","; } else {
}); var ids="";
Search.addVideos(ids, true); //Search.addVideos(response.items[0].contentDetails.videoId);
if(response.nextPageToken) Search.importPlaylist(pId, response.nextPageToken); //response.items.shift();
document.getElementById("import").value = ""; $.each(response.items, function(i,data)
{
ids+=data.contentDetails.videoId+",";
});
Search.addVideos(ids, true);
if(response.nextPageToken) Search.importPlaylist(pId, response.nextPageToken);
document.getElementById("import").value = "";
}
} }
}); });
}, },
@@ -264,7 +271,6 @@ var Search = {
'Authorization': 'Bearer ' + access_token_data.access_token 'Authorization': 'Bearer ' + access_token_data.access_token
}, },
success: function(response) { success: function(response) {
console.log(response);
$.each(response.items, function(i,data) $.each(response.items, function(i,data)
{ {
//ids+=data.contentDetails.videoId+","; //ids+=data.contentDetails.videoId+",";
@@ -274,6 +280,12 @@ var Search = {
if(response.next){ if(response.next){
Search.importSpotifyPlaylist(response.next); Search.importSpotifyPlaylist(response.next);
} }
},
error: function() {
document.getElementById("import_spotify").disabled = false;
$("#import_spotify").removeClass("hide");
$("#playlist_loader_spotify").addClass("hide");
Materialize.toast("It seems you've entered a invalid url.", 4000);
} }
}); });
}, },