Delete all and Move all

pull/91/head
Tobias Reich 11 years ago
parent 7166a536e4
commit ec8a80cd3f

@ -121,9 +121,9 @@ contextMenu = {
contextMenu.fns = [
function() { photo.setStar([photoID]) },
function() { photo.setTitle(photoID) },
function() { photo.setTitle([photoID]) },
function() { contextMenu.move([photoID], e, "right") },
function() { photo.delete(photoID) }
function() { photo.delete([photoID]) }
];
items = [

@ -37,7 +37,7 @@ $(document).ready(function(){
$("#button_download").on(event_name, function() { photo.getArchive(photo.getID()) });
$("#button_trash_album").on(event_name, function() { album.delete(album.getID()) });
$("#button_move").on(event_name, function(e) { contextMenu.move([photo.getID()], e) });
$("#button_trash").on(event_name, function() { photo.delete(photo.getID()) });
$("#button_trash").on(event_name, function() { photo.delete([photo.getID()]) });
$("#button_info_album").on(event_name, function() { view.infobox.show() });
$("#button_info").on(event_name, function() { view.infobox.show() });
$("#button_archive").on(event_name, function() { album.getArchive(album.getID()) });
@ -70,14 +70,14 @@ $(document).ready(function(){
.on(event_name, ".header a", function() { view.infobox.hide() })
.on(event_name, "#edit_title_album", function() { album.setTitle(album.getID()) })
.on(event_name, "#edit_description_album", function() { album.setDescription(album.getID()) })
.on(event_name, "#edit_title", function() { photo.setTitle(photo.getID()) })
.on(event_name, "#edit_title", function() { photo.setTitle([photo.getID()]) })
.on(event_name, "#edit_description", function() { photo.setDescription(photo.getID()) });
/* Keyboard */
Mousetrap
.bind('u', function() { $("#upload_files").click() })
.bind('s', function() { if (visible.photo()) $("#button_star").click() })
.bind('command+backspace', function() { if (visible.photo()&&!visible.message()) photo.delete(photo.getID()) })
.bind('command+backspace', function() { if (visible.photo()&&!visible.message()) photo.delete([photo.getID()]) })
.bind('left', function() { if (visible.photo()) $("#imageview a#previous").click() })
.bind('right', function() { if (visible.photo()) $("#imageview a#next").click() })
.bind('i', function() {
@ -107,7 +107,7 @@ $(document).ready(function(){
/* Header */
.on(event_name, "#title.editable", function() {
if (visible.photo()) photo.setTitle(photo.getID());
if (visible.photo()) photo.setTitle([photo.getID()]);
else album.setTitle(album.getID());
})

@ -161,6 +161,7 @@ var lychee = {
hash = document.location.hash.replace("#", "").split("/");
contextMenu.close();
multiselect.close();
if (hash[0]!==undefined) albumID = hash[0];
if (hash[1]!==undefined) photoID = hash[1];

@ -56,40 +56,47 @@ photo = {
},
delete: function(photoID) {
delete: function(ids) {
var params,
buttons,
photoTitle;
if (!photoID) return false;
if (!ids) return false;
if (ids instanceof Array===false) ids = [ids];
if (visible.photo()) photoTitle = photo.json.title;
else photoTitle = album.json.content[photoID].title;
if (photoTitle=="") photoTitle = "Untitled";
if (ids.length===1) {
// Get title if only one photo is selected
if (visible.photo()) photoTitle = photo.json.title;
else photoTitle = album.json.content[ids].title;
if (photoTitle=="") photoTitle = "Untitled";
}
buttons = [
["Delete Photo", function() {
// Change reference for the next and previous photo
if (album.json.content[photoID].nextPhoto!==""||album.json.content[photoID].previousPhoto!=="") {
nextPhoto = album.json.content[photoID].nextPhoto;
previousPhoto = album.json.content[photoID].previousPhoto;
album.json.content[previousPhoto].nextPhoto = nextPhoto;
album.json.content[nextPhoto].previousPhoto = previousPhoto;
}
album.json.content[photoID] = null;
["Delete", function() {
ids.forEach(function(id, index, array) {
view.album.content.delete(photoID);
// 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
if (!visible.albums()) lychee.goto(album.getID());
params = "deletePhoto&photoID=" + photoID;
params = "deletePhoto&ids=" + ids;
lychee.api(params, function(data) {
if (data!==true) lychee.error(null, params, data);
@ -97,51 +104,62 @@ photo = {
});
}],
["Keep Photo", function() {}]
["Cancel", function() {}]
];
modal.show("Delete Photo", "Are you sure you want to delete the photo '" + photoTitle + "'?<br>This action can't be undone!", buttons);
if (ids.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 " + ids.length + " selected photo?<br>This action can't be undone!", buttons);
},
setTitle: function(photoID) {
setTitle: function(ids) {
var oldTitle = "",
newTitle,
params,
buttons;
if (!photoID) return false;
if (photo.json) oldTitle = photo.json.title;
else if (album.json) oldTitle = album.json.content[photoID].title;
if (!ids) return false;
if (ids instanceof Array===false) ids = [ids];
if (ids.length===1) {
// Get old title if only one photo is selected
if (photo.json) oldTitle = photo.json.title;
else if (album.json) oldTitle = album.json.content[ids].title;
}
buttons = [
["Set Title", function() {
newTitle = $(".message input.text").val();
if (photoID!=null&&photoID&&newTitle.length<31) {
if (newTitle.length<31) {
if (visible.photo()) {
photo.json.title = (newTitle==="") ? "Untitled" : newTitle;
view.photo.title(oldTitle);
}
ids.forEach(function(id, index, array) {
album.json.content[id].title = newTitle;
view.album.content.title(id);
});
album.json.content[photoID].title = newTitle;
view.album.content.title(photoID);
params = "setPhotoTitle&photoID=" + photoID + "&title=" + escape(encodeURI(newTitle));
params = "setPhotoTitle&ids=" + ids + "&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 to short or too long. Please try another one!");
} 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 photo: <input class='text' type='text' placeholder='Title' value='" + oldTitle + "'>", buttons);
if (ids.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);
},
@ -151,6 +169,7 @@ photo = {
nextPhoto,
previousPhoto;
if (!ids) return false;
if (visible.photo) lychee.goto(album.getID());
if (ids instanceof Array===false) ids = [ids];
@ -185,6 +204,7 @@ photo = {
var params;
if (!ids) return false;
if (visible.photo()) {
photo.json.star = (photo.json.star==0) ? 1 : 0;
view.photo.star();

@ -110,16 +110,16 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
echo json_encode(getPhoto($_POST['photoID'], $_POST['albumID']));
break;
case 'deletePhoto': if (isset($_POST['photoID']))
echo deletePhoto($_POST['photoID']);
case 'deletePhoto': if (isset($_POST['ids']))
echo deletePhoto($_POST['ids']);
break;
case 'setAlbum': if (isset($_POST['ids'])&&isset($_POST['albumID']))
echo setAlbum($_POST['ids'], $_POST['albumID']);
break;
case 'setPhotoTitle': if (isset($_POST['photoID'])&&isset($_POST['title']))
echo setPhotoTitle($_POST['photoID'], $_POST['title']);
case 'setPhotoTitle': if (isset($_POST['ids'])&&isset($_POST['title']))
echo setPhotoTitle($_POST['ids'], $_POST['title']);
break;
case 'setPhotoStar': if (isset($_POST['ids']))

@ -221,7 +221,7 @@ function deleteAlbum($albumID) {
$error = false;
$result = $database->query("SELECT id FROM lychee_photos WHERE album = '$albumID';");
while($row = $result->fetch_object()) {
while ($row = $result->fetch_object()) {
if (!deletePhoto($row->id)) $error = true;
}

@ -104,12 +104,12 @@ function setAlbum($ids, $albumID) {
}
function setPhotoTitle($photoID, $title) {
function setPhotoTitle($ids, $title) {
global $database;
if (strlen($title)>30) return false;
$result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id = '$photoID';");
$result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id IN ($ids);");
if (!$result) return false;
return true;
@ -129,22 +129,31 @@ function setPhotoDescription($photoID, $description) {
}
function deletePhoto($photoID) {
function deletePhoto($ids) {
global $database;
$result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
if (!$result) return false;
$row = $result->fetch_object();
$retinaUrl = explode(".", $row->thumbUrl);
$unlink1 = unlink("../uploads/big/".$row->url);
$unlink2 = unlink("../uploads/thumb/".$row->thumbUrl);
$unlink3 = unlink("../uploads/thumb/".$retinaUrl[0].'@2x.'.$retinaUrl[1]);
$result = $database->query("DELETE FROM lychee_photos WHERE id = '$photoID';");
if (!$unlink1 || !$unlink2 || !$unlink3) return false;
if (!$result) return false;
return true;
$result = $database->query("SELECT * FROM lychee_photos WHERE id IN ($ids);");
while ($row = $result->fetch_object()) {
// Get retina thumb url
$thumbUrl2x = explode(".", $row->thumbUrl);
$thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
// Delete files
if (!unlink('../uploads/big/' . $row->url)) return false;
if (!unlink('../uploads/thumb/' . $row->thumbUrl)) return false;
if (!unlink('../uploads/thumb/' . $thumbUrl2x)) return false;
// Delete db entry
$delete = $database->query("DELETE FROM lychee_photos WHERE id = $row->id;");
if (!$delete) return false;
}
if (!$result) return false;
return true;
}

Loading…
Cancel
Save