/**
* @name Album Module
* @description Takes care of every action an album can handle and execute.
* @author Tobias Reich
* @copyright 2014 by Tobias Reich
*/
upload = {
show: function(icon, text, html) {
if (icon===undefined) icon = "upload";
upload.close(true);
$("body").append(build.uploadModal(icon, text, html));
},
setIcon: function(icon) {
$(".upload_message a").remove();
$(".upload_message").prepend("");
},
setProgress: function(progress) {
$(".progressbar div").css("width", progress + "%");
},
setText: function(text) {
$(".progressbar").remove();
$(".upload_message").append("
" + text + "
");
},
notify: function(title) {
var popup;
if (!window.webkitNotifications) return false;
if (window.webkitNotifications.checkPermission()!==0) window.webkitNotifications.requestPermission();
if (window.webkitNotifications.checkPermission()===0&&title) {
popup = window.webkitNotifications.createNotification("", title, "You can now manage your new photo(s).");
popup.show();
}
},
start: {
local: function(files) {
var albumID = album.getID(),
html = "";
var process = function(files, file) {
var formData = new FormData(),
xhr = new XMLHttpRequest(),
pre_progress = 0,
progress;
formData.append("function", "upload");
formData.append("albumID", albumID);
formData.append(0, file);
xhr.open("POST", lychee.api_path);
xhr.onload = function() {
var wait;
if (xhr.status===200) {
$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status")
.html("Finished")
.addClass("success");
file.ready = true;
wait = false;
for (var i = 0; i < files.length; i++) {
if (files[i].ready===false) {
wait = true;
break;
}
}
if (wait===false) {
$("#upload_files").val("");
if (album.getID()===false) lychee.goto("0");
else album.load(albumID);
}
}
};
xhr.upload.onprogress = function(e) {
if (e.lengthComputable) {
progress = (e.loaded / e.total * 100 | 0);
if (progress>pre_progress) {
$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html(progress + "%");
pre_progress = progress;
}
if (progress>=100) {
$(".upload_message .rows .row:nth-child(" + (file.num+1) + ") .status").html("Processing");
if (file.next!==null) process(files, file.next);
}
}
};
xhr.send(formData);
}
if (files.length<=0) return false;
if (albumID===false) albumID = 0;
html = "
";
for (var i = 0; i < files.length; i++) {
files[i].num = i;
files[i].ready = false;
if (i < files.length-1) files[i].next = files[i+1];
else files[i].next = null;
if (files[i].type!=="image/jpeg"&&files[i].type!=="image/jpg"&&files[i].type!=="image/png"&&files[i].type!=="image/gif") {
files[i].ready = true;
// Generate html with error
html += "