Delete all and rename all albums

pull/91/head
Tobias Reich 11 years ago
parent f3aa01dc05
commit b4b50be732

@ -121,21 +121,28 @@ album = {
},
delete: function(albumID) {
delete: function(albumIDs) {
var params,
buttons,
albumTitle;
if (!albumIDs) return false;
if (albumIDs instanceof Array===false) albumIDs = [albumIDs];
buttons = [
["Delete Album and Photos", function() {
["", function() {
params = "deleteAlbum&albumID=" + albumID;
params = "deleteAlbum&albumIDs=" + albumIDs;
lychee.api(params, function(data) {
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("");
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[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)
} 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;
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);
} 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 = "",
newTitle,
params,
buttons;
if (!albumID) return false;
if (album.json) oldTitle = album.json.title;
else if (albums.json) oldTitle = albums.json.content[albumID].title;
if (!albumIDs) return false;
if (albumIDs instanceof Array===false) albumIDs = [albumIDs];
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 = [
["Set Title", function() {
newTitle = $(".message input.text").val();
if (newTitle==="") newTitle = "Untitled";
newTitle = ($(".message input.text").val()==="") ? "Untitled" : $(".message input.text").val();
if (albumID!==""&&albumID!=null&&albumID&&newTitle.length<31) {
if (newTitle.length<31) {
if (visible.album()) {
album.json.title = newTitle;
view.album.title(oldTitle);
view.album.title();
} else if (visible.albums()) {
albums.json.content[albumID].title = newTitle;
view.albums.content.title(albumID);
albumIDs.forEach(function(id, index, array) {
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) {
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() {}]
];
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);
},

@ -112,6 +112,28 @@ contextMenu = {
$(".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) {

@ -112,7 +112,8 @@ multiselect = {
getSelection: function(e) {
var photoIDs = [],
var id,
ids = [],
offset,
size = multiselect.getSize();
@ -127,14 +128,22 @@ multiselect = {
offset.left>=size.left&&
(offset.top+206)<=(size.top+size.height)&&
(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);
else if (photoIDs.length!=0&&visible.albums()) contextMenu.albumMulti(photoIDs, e);
if (ids.length!=0&&visible.album()) contextMenu.photoMulti(ids, e);
else if (ids.length!=0&&visible.albums()) contextMenu.albumMulti(ids, e);
else multiselect.close();
},

@ -73,24 +73,24 @@ photo = {
}
buttons = [
["Delete", function() {
["", function() {
photoIDs.forEach(function(id, index, array) {
// Change reference for the next and previous photo
if (album.json.content[id].nextPhoto!==""||album.json.content[id].previousPhoto!=="") {
nextPhoto = album.json.content[id].nextPhoto;
previousPhoto = album.json.content[id].previousPhoto;
album.json.content[previousPhoto].nextPhoto = nextPhoto;
album.json.content[nextPhoto].previousPhoto = previousPhoto;
}
album.json.content[id] = null;
view.album.content.delete(id);
});
// 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);
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);
if (photoIDs.length===1) {
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) {
var oldTitle = "",
newTitle,
params,
@ -121,7 +134,7 @@ photo = {
if (!photoIDs) return false;
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
if (photoIDs.length===1) {
// Get old title if only one photo is selected
if (photo.json) oldTitle = photo.json.title;
@ -134,12 +147,12 @@ photo = {
newTitle = $(".message input.text").val();
if (newTitle.length<31) {
if (visible.photo()) {
photo.json.title = (newTitle==="") ? "Untitled" : newTitle;
view.photo.title(oldTitle);
view.photo.title();
}
photoIDs.forEach(function(id, index, array) {
album.json.content[id].title = newTitle;
view.album.content.title(id);
@ -157,9 +170,9 @@ photo = {
}],
["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);
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,
nextPhoto,
previousPhoto;
if (!photoIDs) return false;
if (visible.photo) lychee.goto(album.getID());
if (photoIDs instanceof Array===false) photoIDs = [photoIDs];
photoIDs.forEach(function(id, index, array) {
// Change reference for the next and previous photo
@ -185,10 +198,10 @@ photo = {
album.json.content[nextPhoto].previousPhoto = previousPhoto;
}
album.json.content[id] = null;
view.album.content.delete(id);
});
params = "setAlbum&photoIDs=" + photoIDs + "&albumID=" + albumID;

@ -214,7 +214,7 @@ view = {
},
title: function(oldTitle) {
title: function() {
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"));
lychee.setTitle(photo.json.title, true);

@ -83,8 +83,8 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
echo addAlbum($_POST['title']);
break;
case 'setAlbumTitle': if (isset($_POST['albumID'])&&isset($_POST['title']))
echo setAlbumTitle($_POST['albumID'], $_POST['title']);
case 'setAlbumTitle': if (isset($_POST['albumIDs'])&&isset($_POST['title']))
echo setAlbumTitle($_POST['albumIDs'], $_POST['title']);
break;
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']);
break;
case 'deleteAlbum': if (isset($_POST['albumID']))
echo deleteAlbum($_POST['albumID']);
case 'deleteAlbum': if (isset($_POST['albumIDs']))
echo deleteAlbum($_POST['albumIDs']);
break;
// Photo Functions

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

Loading…
Cancel
Save