Delete all and rename all albums

This commit is contained in:
Tobias Reich 2014-01-31 21:22:25 +01:00
parent f3aa01dc05
commit b4b50be732
7 changed files with 157 additions and 87 deletions

View File

@ -121,21 +121,28 @@ album = {
}, },
delete: function(albumID) { delete: function(albumIDs) {
var params, var params,
buttons, buttons,
albumTitle; albumTitle;
if (!albumIDs) return false;
if (albumIDs instanceof Array===false) albumIDs = [albumIDs];
buttons = [ buttons = [
["Delete Album and Photos", function() { ["", function() {
params = "deleteAlbum&albumID=" + albumID; params = "deleteAlbum&albumIDs=" + albumIDs;
lychee.api(params, function(data) { lychee.api(params, function(data) {
if (visible.albums()) { if (visible.albums()) {
albums.json.num--;
view.albums.content.delete(albumID); albumIDs.forEach(function(id, index, array) {
albums.json.num--;
view.albums.content.delete(id);
});
} else lychee.goto(""); } else lychee.goto("");
if (data!==true) lychee.error(null, params, data); if (data!==true) lychee.error(null, params, data);
@ -143,69 +150,90 @@ album = {
}); });
}], }],
["Keep Album", function() {}] ["", function() {}]
]; ];
if (albumID==="0") { if (albumIDs==="0") {
buttons[0][0] = "Clear Unsorted"; buttons[0][0] = "Clear Unsorted";
buttons[1][0] = "Keep Unsorted";
modal.show("Clear Unsorted", "Are you sure you want to delete all photos from 'Unsorted'?<br>This action can't be undone!", buttons) modal.show("Clear Unsorted", "Are you sure you want to delete all photos from 'Unsorted'?<br>This action can't be undone!", buttons)
} else { } else if (albumIDs.length===1) {
buttons[0][0] = "Delete Album and Photos";
buttons[1][0] = "Keep Album";
// Get title
if (album.json) albumTitle = album.json.title; if (album.json) albumTitle = album.json.title;
else if (albums.json) albumTitle = albums.json.content[albumID].title; else if (albums.json) albumTitle = albums.json.content[albumIDs].title;
modal.show("Delete Album", "Are you sure you want to delete the album '" + albumTitle + "' and all of the photos it contains? This action can't be undone!", buttons); modal.show("Delete Album", "Are you sure you want to delete the album '" + albumTitle + "' and all of the photos it contains? This action can't be undone!", buttons);
} else {
buttons[0][0] = "Delete Albums and Photos";
buttons[1][0] = "Keep Albums";
modal.show("Delete Albums", "Are you sure you want to delete all " + albumIDs.length + " selected albums and all of the photos they contain? This action can't be undone!", buttons);
} }
}, },
setTitle: function(albumID) { setTitle: function(albumIDs) {
var oldTitle = "", var oldTitle = "",
newTitle, newTitle,
params, params,
buttons; buttons;
if (!albumID) return false; if (!albumIDs) return false;
if (album.json) oldTitle = album.json.title; if (albumIDs instanceof Array===false) albumIDs = [albumIDs];
else if (albums.json) oldTitle = albums.json.content[albumID].title;
if (albumIDs.length===1) {
// Get old title if only one album is selected
if (album.json) oldTitle = album.json.title;
else if (albums.json) oldTitle = albums.json.content[albumIDs].title;
}
buttons = [ buttons = [
["Set Title", function() { ["Set Title", function() {
newTitle = $(".message input.text").val(); newTitle = ($(".message input.text").val()==="") ? "Untitled" : $(".message input.text").val();
if (newTitle==="") newTitle = "Untitled"; if (newTitle.length<31) {
if (albumID!==""&&albumID!=null&&albumID&&newTitle.length<31) {
if (visible.album()) { if (visible.album()) {
album.json.title = newTitle; album.json.title = newTitle;
view.album.title(oldTitle); view.album.title();
} else if (visible.albums()) { } else if (visible.albums()) {
albums.json.content[albumID].title = newTitle; albumIDs.forEach(function(id, index, array) {
view.albums.content.title(albumID); albums.json.content[id].title = newTitle;
view.albums.content.title(id);
});
} }
params = "setAlbumTitle&albumID=" + albumID + "&title=" + escape(encodeURI(newTitle)); params = "setAlbumTitle&albumIDs=" + albumIDs + "&title=" + escape(encodeURI(newTitle));
lychee.api(params, function(data) { lychee.api(params, function(data) {
if (data!==true) lychee.error(null, params, data); if (data!==true) lychee.error(null, params, data);
}); });
} else if (newTitle.length>0) loadingBar.show("error", "New title too short or too long. Please try again!"); } else if (newTitle.length>30) loadingBar.show("error", "New title too long. Please try another one!");
}], }],
["Cancel", function() {}] ["Cancel", function() {}]
]; ];
modal.show("Set Title", "Please enter a new title for this album: <input class='text' type='text' placeholder='Title' value='" + oldTitle + "'>", buttons);
if (albumIDs.length===1) modal.show("Set Title", "Please enter a new title for this album: <input class='text' type='text' placeholder='Title' value='" + oldTitle + "'>", buttons);
else modal.show("Set Titles", "Please enter a title for all " + albumIDs.length + " selected album: <input class='text' type='text' placeholder='Title' value='" + oldTitle + "'>", buttons);
}, },

View File

@ -112,6 +112,28 @@ contextMenu = {
$(".album[data-id='" + albumID + "']").addClass("active"); $(".album[data-id='" + albumID + "']").addClass("active");
}, },
albumMulti: function(albumIDs, e) {
var mouse_x = e.pageX,
mouse_y = e.pageY - $(document).scrollTop(),
items;
multiselect.stopResize();
contextMenu.fns = [
function() { album.setTitle(albumIDs) },
function() { album.delete(albumIDs) },
];
items = [
["<a class='icon-edit'></a> Rename All", 0],
["<a class='icon-trash'></a> Delete All", 1]
];
contextMenu.show(items, mouse_x, mouse_y, "right");
},
photo: function(photoID, e) { photo: function(photoID, e) {

View File

@ -112,7 +112,8 @@ multiselect = {
getSelection: function(e) { getSelection: function(e) {
var photoIDs = [], var id,
ids = [],
offset, offset,
size = multiselect.getSize(); size = multiselect.getSize();
@ -127,14 +128,22 @@ multiselect = {
offset.left>=size.left&& offset.left>=size.left&&
(offset.top+206)<=(size.top+size.height)&& (offset.top+206)<=(size.top+size.height)&&
(offset.left+206)<=(size.left+size.width)) { (offset.left+206)<=(size.left+size.width)) {
photoIDs.push($(this).data('id'));
$(this).addClass('active'); id = $(this).data('id');
if (id!=="0"&&id!==0&&id!=="f"&&id!=="s"&&id!==null&id!==undefined) {
ids.push(id);
$(this).addClass('active');
}
} }
}); });
if (photoIDs.length!=0&&visible.album()) contextMenu.photoMulti(photoIDs, e); if (ids.length!=0&&visible.album()) contextMenu.photoMulti(ids, e);
else if (photoIDs.length!=0&&visible.albums()) contextMenu.albumMulti(photoIDs, e); else if (ids.length!=0&&visible.albums()) contextMenu.albumMulti(ids, e);
else multiselect.close(); else multiselect.close();
}, },

View File

@ -73,24 +73,24 @@ photo = {
} }
buttons = [ buttons = [
["Delete", function() { ["", function() {
photoIDs.forEach(function(id, index, array) { photoIDs.forEach(function(id, index, array) {
// Change reference for the next and previous photo // Change reference for the next and previous photo
if (album.json.content[id].nextPhoto!==""||album.json.content[id].previousPhoto!=="") { if (album.json.content[id].nextPhoto!==""||album.json.content[id].previousPhoto!=="") {
nextPhoto = album.json.content[id].nextPhoto; nextPhoto = album.json.content[id].nextPhoto;
previousPhoto = album.json.content[id].previousPhoto; previousPhoto = album.json.content[id].previousPhoto;
album.json.content[previousPhoto].nextPhoto = nextPhoto; album.json.content[previousPhoto].nextPhoto = nextPhoto;
album.json.content[nextPhoto].previousPhoto = previousPhoto; album.json.content[nextPhoto].previousPhoto = previousPhoto;
} }
album.json.content[id] = null; album.json.content[id] = null;
view.album.content.delete(id); view.album.content.delete(id);
}); });
// Only when search is not active // Only when search is not active
@ -104,16 +104,29 @@ photo = {
}); });
}], }],
["Cancel", function() {}] ["", function() {}]
]; ];
if (photoIDs.length===1) modal.show("Delete Photo", "Are you sure you want to delete the photo '" + photoTitle + "'?<br>This action can't be undone!", buttons); if (photoIDs.length===1) {
else modal.show("Delete Photos", "Are you sure you want to delete all " + photoIDs.length + " selected photo?<br>This action can't be undone!", buttons);
buttons[0][0] = "Delete Photo";
buttons[1][0] = "Keep Photo";
modal.show("Delete Photo", "Are you sure you want to delete the photo '" + photoTitle + "'?<br>This action can't be undone!", buttons);
} else {
buttons[0][0] = "Delete Photos";
buttons[1][0] = "Keep Photos";
modal.show("Delete Photos", "Are you sure you want to delete all " + photoIDs.length + " selected photo?<br>This action can't be undone!", buttons);
}
}, },
setTitle: function(photoIDs) { setTitle: function(photoIDs) {
var oldTitle = "", var oldTitle = "",
newTitle, newTitle,
params, params,
@ -121,7 +134,7 @@ photo = {
if (!photoIDs) return false; if (!photoIDs) return false;
if (photoIDs instanceof Array===false) photoIDs = [photoIDs]; if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
if (photoIDs.length===1) { if (photoIDs.length===1) {
// Get old title if only one photo is selected // Get old title if only one photo is selected
if (photo.json) oldTitle = photo.json.title; if (photo.json) oldTitle = photo.json.title;
@ -134,12 +147,12 @@ photo = {
newTitle = $(".message input.text").val(); newTitle = $(".message input.text").val();
if (newTitle.length<31) { if (newTitle.length<31) {
if (visible.photo()) { if (visible.photo()) {
photo.json.title = (newTitle==="") ? "Untitled" : newTitle; photo.json.title = (newTitle==="") ? "Untitled" : newTitle;
view.photo.title(oldTitle); view.photo.title();
} }
photoIDs.forEach(function(id, index, array) { photoIDs.forEach(function(id, index, array) {
album.json.content[id].title = newTitle; album.json.content[id].title = newTitle;
view.album.content.title(id); view.album.content.title(id);
@ -157,9 +170,9 @@ photo = {
}], }],
["Cancel", function() {}] ["Cancel", function() {}]
]; ];
if (photoIDs.length===1) modal.show("Set Title", "Please enter a new title for this photo: <input class='text' type='text' placeholder='Title' value='" + oldTitle + "'>", buttons); if (photoIDs.length===1) modal.show("Set Title", "Please enter a new title for this photo: <input class='text' type='text' placeholder='Title' value='" + oldTitle + "'>", buttons);
else modal.show("Set Titles", "Please enter a title for all selected photos: <input class='text' type='text' placeholder='Title' value=''>", buttons); else modal.show("Set Titles", "Please enter a title for all " + photoIDs.length + " selected photos: <input class='text' type='text' placeholder='Title' value=''>", buttons);
}, },
@ -168,11 +181,11 @@ photo = {
var params, var params,
nextPhoto, nextPhoto,
previousPhoto; previousPhoto;
if (!photoIDs) return false; if (!photoIDs) return false;
if (visible.photo) lychee.goto(album.getID()); if (visible.photo) lychee.goto(album.getID());
if (photoIDs instanceof Array===false) photoIDs = [photoIDs]; if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
photoIDs.forEach(function(id, index, array) { photoIDs.forEach(function(id, index, array) {
// Change reference for the next and previous photo // Change reference for the next and previous photo
@ -185,10 +198,10 @@ photo = {
album.json.content[nextPhoto].previousPhoto = previousPhoto; album.json.content[nextPhoto].previousPhoto = previousPhoto;
} }
album.json.content[id] = null; album.json.content[id] = null;
view.album.content.delete(id); view.album.content.delete(id);
}); });
params = "setAlbum&photoIDs=" + photoIDs + "&albumID=" + albumID; params = "setAlbum&photoIDs=" + photoIDs + "&albumID=" + albumID;

View File

@ -214,7 +214,7 @@ view = {
}, },
title: function(oldTitle) { title: function() {
if ((visible.album()||!album.json.init)&&!visible.photo()) { if ((visible.album()||!album.json.init)&&!visible.photo()) {
@ -404,7 +404,7 @@ view = {
}, },
title: function(oldTitle) { title: function() {
if (photo.json.init) $("#infobox .attr_name").html(photo.json.title + " " + build.editIcon("edit_title")); if (photo.json.init) $("#infobox .attr_name").html(photo.json.title + " " + build.editIcon("edit_title"));
lychee.setTitle(photo.json.title, true); lychee.setTitle(photo.json.title, true);

View File

@ -83,8 +83,8 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
echo addAlbum($_POST['title']); echo addAlbum($_POST['title']);
break; break;
case 'setAlbumTitle': if (isset($_POST['albumID'])&&isset($_POST['title'])) case 'setAlbumTitle': if (isset($_POST['albumIDs'])&&isset($_POST['title']))
echo setAlbumTitle($_POST['albumID'], $_POST['title']); echo setAlbumTitle($_POST['albumIDs'], $_POST['title']);
break; break;
case 'setAlbumDescription': if (isset($_POST['albumID'])&&isset($_POST['description'])) case 'setAlbumDescription': if (isset($_POST['albumID'])&&isset($_POST['description']))
@ -100,8 +100,8 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
echo setAlbumPassword($_POST['albumID'], $_POST['password']); echo setAlbumPassword($_POST['albumID'], $_POST['password']);
break; break;
case 'deleteAlbum': if (isset($_POST['albumID'])) case 'deleteAlbum': if (isset($_POST['albumIDs']))
echo deleteAlbum($_POST['albumID']); echo deleteAlbum($_POST['albumIDs']);
break; break;
// Photo Functions // Photo Functions

View File

@ -189,14 +189,14 @@ function getAlbum($albumID) {
} }
function setAlbumTitle($albumID, $title) { function setAlbumTitle($albumIDs, $title) {
global $database; global $database;
if (strlen($title)<1||strlen($title)>30) return false; if (strlen($title)<1||strlen($title)>30) return false;
$result = $database->query("UPDATE lychee_albums SET title = '$title' WHERE id = '$albumID';"); $result = $database->query("UPDATE lychee_albums SET title = '$title' WHERE id IN ($albumIDs);");
if (!$result) return false; if (!$result) return false;
return true; return true;
} }
@ -204,34 +204,32 @@ function setAlbumTitle($albumID, $title) {
function setAlbumDescription($albumID, $description) { function setAlbumDescription($albumID, $description) {
global $database; global $database;
$description = htmlentities($description); $description = htmlentities($description);
if (strlen($description)>800) return false; if (strlen($description)>800) return false;
$result = $database->query("UPDATE lychee_albums SET description = '$description' WHERE id = '$albumID';"); $result = $database->query("UPDATE lychee_albums SET description = '$description' WHERE id = '$albumID';");
if (!$result) return false; if (!$result) return false;
return true; return true;
} }
function deleteAlbum($albumID) { function deleteAlbum($albumIDs) {
global $database; global $database;
$error = false; $error = false;
$result = $database->query("SELECT id FROM lychee_photos WHERE album IN ($albumIDs);");
$result = $database->query("SELECT id FROM lychee_photos WHERE album = '$albumID';");
while ($row = $result->fetch_object()) { // Delete photos
if (!deletePhoto($row->id)) $error = true; while ($row = $result->fetch_object())
} if (!deletePhoto($row->id)) $error = true;
if ($albumID!=0) { // Delete album
$result = $database->query("DELETE FROM lychee_albums WHERE id = '$albumID';"); $result = $database->query("DELETE FROM lychee_albums WHERE id IN ($albumIDs);");
if (!$result) return false;
} if ($error||!$result) return false;
return true;
if ($error) return false;
return true;
} }
@ -308,7 +306,7 @@ function setAlbumPublic($albumID, $password) {
} }
if (strlen($password)>0) return setAlbumPassword($albumID, $password); if (strlen($password)>0) return setAlbumPassword($albumID, $password);
else return true; return true;
} }
@ -329,10 +327,10 @@ function checkAlbumPassword($albumID, $password) {
$result = $database->query("SELECT password FROM lychee_albums WHERE id = '$albumID';"); $result = $database->query("SELECT password FROM lychee_albums WHERE id = '$albumID';");
$row = $result->fetch_object(); $row = $result->fetch_object();
if ($row->password=="") return true; if ($row->password=="") return true;
else if ($row->password==$password) return true; else if ($row->password==$password) return true;
else return false; return false;
} }
@ -344,7 +342,7 @@ function isAlbumPublic($albumID) {
$row = $result->fetch_object(); $row = $result->fetch_object();
if ($row->public==1) return true; if ($row->public==1) return true;
else return false; return false;
} }