Files
fnx_web/res/static/script/listmaker.js

83 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-01-17 01:16:06 +01:00
$("#btn_create_list").click(function (evt) {
2017-11-14 23:04:57 +01:00
createList();
});
2017-11-10 12:39:55 +01:00
function createList(){
2018-01-17 01:16:06 +01:00
let listfiles = new Array()
for (var i = 0; i < finishedUploads.length; i++) {
if (finishedUploads[i] === undefined) {
continue;
}
listfiles.push(finishedUploads[i]);
}
2017-11-14 23:04:57 +01:00
var url = "/api/list";
2018-07-09 23:19:16 +02:00
2017-11-10 12:39:55 +01:00
var postData = {};
2018-07-09 23:19:16 +02:00
2017-11-10 12:39:55 +01:00
var title = prompt(
2018-01-17 01:16:06 +01:00
"You are creating a list containing " + listfiles.length + " files.\n"
2017-11-10 12:39:55 +01:00
+ "What do you want to call it?", "My New Album"
);
if(title === null){
return;
}
2017-11-14 23:04:57 +01:00
var postData = {
"title": title,
"description": "yo",
"files": new Array()
};
2018-07-09 23:19:16 +02:00
2018-01-17 01:16:06 +01:00
for (var i = 0; i < listfiles.length; i++) {
postData.files.push({
"id": listfiles[i]
});
2017-11-10 12:39:55 +01:00
}
2018-07-09 23:19:16 +02:00
2017-11-14 23:04:57 +01:00
$.ajax({
url: url,
contentType: "application/json",
method: "POST",
data: JSON.stringify(postData),
dataType: "json",
success: listCreated,
error: listCreated
2017-11-10 12:39:55 +01:00
});
}
function listCreated(response){
2017-12-12 23:33:41 +01:00
if(response.success){
resultString = "<div class=\"file_button\">List creation finished!<br/>"
2017-11-10 12:39:55 +01:00
+ "Your List URL: <br/>"
2017-12-12 23:33:41 +01:00
+ "<a href=\"/l/" + response.id + "\" target=\"_blank\" style=\"font-weight: bold;\">"+window.location.hostname+"/l/" + response.id + "</a>"
2017-11-10 12:39:55 +01:00
+ "</div>";
2018-07-09 23:19:16 +02:00
2018-01-17 01:29:35 +01:00
$('#uploads_queue').prepend(
2018-07-09 23:19:16 +02:00
$(resultString).hide().fadeIn('slow').css("display", "")
2017-11-10 12:39:55 +01:00
);
2018-01-17 01:29:35 +01:00
window.open('/l/'+response.id, '_blank');
2017-11-10 12:39:55 +01:00
}else{
resultString = "<div class=\"file_button\">List creation failed<br/>"
2017-11-10 12:39:55 +01:00
+ "The server responded with this: <br/>"
+ response.type + ": " + response.value
+ "</div>";
2018-07-09 23:19:16 +02:00
2018-01-17 01:29:35 +01:00
$('#uploads_queue').prepend(
2018-07-09 23:19:16 +02:00
$(resultString).hide().fadeIn('slow').css("display", "")
2017-11-10 12:39:55 +01:00
);
}
}
//$("#btnAddToList").click(function (evt) {
// var fileId = $("#txtListId").val();
// var fileDesc = $("#txtListDesc").val();
//
// addToList(fileId, fileDesc);
2018-07-09 23:19:16 +02:00
//
2017-11-10 12:39:55 +01:00
// divItems.prepend("ID: " + fileId + "<br>Description:<br>" + fileDesc + "<br><br>");
2018-07-09 23:19:16 +02:00
//
2017-11-10 12:39:55 +01:00
// $("#txtListId").val("");
// $("#txtListDesc").val("");
2018-07-09 23:19:16 +02:00
//});