nextcloud/apps/gallery/js/album_cover.js

109 lines
3.2 KiB
JavaScript
Raw Normal View History

2011-09-26 00:32:08 +04:00
var actual_cover;
2011-10-01 13:26:47 +04:00
$(document).ready(function() {
$.getJSON('ajax/getAlbums.php', function(r) {
if (r.status == 'success') {
for (var i in r.albums) {
var a = r.albums[i];
Albums.add(a.name, a.numOfItems);
2011-09-26 00:32:08 +04:00
}
2011-10-01 13:26:47 +04:00
var targetDiv = document.getElementById('gallery_list');
if (targetDiv) {
$(targetDiv).html('');
2011-10-01 13:26:47 +04:00
Albums.display(targetDiv);
} else {
alert('Error occured: no such layer `gallery_list`');
}
} else {
alert('Error occured: ' + r.message);
}
2011-09-26 00:32:08 +04:00
});
});
function createNewAlbum() {
var name = prompt("album name", "");
if (name != null && name != "") {
$.getJSON("ajax/createAlbum.php", {album_name: name}, function(r) {
if (r.status == "success") {
var v = '<div class="gallery_album_box"><a href="?view='+r.name+'"><img class="gallery_album_cover"/></a><h1>'+r.name+'</h1></div>';
$('div#gallery_list').append(v);
}
});
}
}
var albumCounter = 0;
var totalAlbums = 0;
2011-09-26 00:32:08 +04:00
function scanForAlbums() {
var albumCounter = 0;
var totalAlbums = 0;
$('#notification').text("Scanning directories");
$("#notification").fadeIn();
$("#notification").slideDown();
$.getJSON('ajax/galleryOp.php?operation=filescan', function(r) {
2011-09-26 00:32:08 +04:00
if (r.status == 'success') {
totalAlbums = r.paths.length;
$('#notification').text("Creating thumbnails ... " + Math.floor((albumCounter/totalAlbums)*100) + "%");
for(var a in r.paths) {
$.getJSON('ajax/galleryOp.php?operation=partial_create&path='+r.paths[a], function(r) {
if (r.status == 'success') {
Albums.add(r.album_details.albumName, r.album_details.imagesCount);
}
albumCounter++;
$('#notification').text("Creating thumbnails ... " + Math.floor((albumCounter/totalAlbums)*100) + "%");
if (albumCounter == totalAlbums) {
$("#notification").fadeOut();
$("#notification").slideUp();
var targetDiv = document.getElementById('gallery_list');
if (targetDiv) {
targetDiv.innerHTML = '';
Albums.display(targetDiv);
} else {
alert('Error occured: no such layer `gallery_list`');
}
}
});
}
2011-09-26 00:32:08 +04:00
} else {
alert('Error occured: ' + r.message);
}
});
}
2011-12-22 00:55:52 +04:00
function galleryRemove(albumName) {
if (confirm("Do you wan't to remove album " + albumName + "?")) {
$.getJSON("ajax/galleryOp.php", {operation: "remove", name: albumName}, function(r) {
if (r.status == "success") {
$("#gallery_album_box[title='"+albumName+"']").remove();
Albums.remove(albumName);
2011-12-22 00:55:52 +04:00
} else {
alert("Error: " + r.cause);
}
});
}
}
function galleryRename(name) {
var result = window.prompt("Input new gallery name", name);
2011-12-22 00:55:52 +04:00
if (result) {
if (Albums.find(result)) {
alert("Album named '" + result + "' already exists");
return;
}
$.getJSON("ajax/galleryOp.php", {operation: "rename", oldname: name, newname: result}, function(r) {
if (r.status == "success") {
Albums.rename($("#gallery_album_box[title='"+name+"']"), result);
} else {
alert("Error: " + r.cause);
}
});
} else {
alert("Album name can't be empty")
}
}