Delete all and Move all
This commit is contained in:
parent
7166a536e4
commit
ec8a80cd3f
@ -121,9 +121,9 @@ contextMenu = {
|
|||||||
|
|
||||||
contextMenu.fns = [
|
contextMenu.fns = [
|
||||||
function() { photo.setStar([photoID]) },
|
function() { photo.setStar([photoID]) },
|
||||||
function() { photo.setTitle(photoID) },
|
function() { photo.setTitle([photoID]) },
|
||||||
function() { contextMenu.move([photoID], e, "right") },
|
function() { contextMenu.move([photoID], e, "right") },
|
||||||
function() { photo.delete(photoID) }
|
function() { photo.delete([photoID]) }
|
||||||
];
|
];
|
||||||
|
|
||||||
items = [
|
items = [
|
||||||
|
@ -37,7 +37,7 @@ $(document).ready(function(){
|
|||||||
$("#button_download").on(event_name, function() { photo.getArchive(photo.getID()) });
|
$("#button_download").on(event_name, function() { photo.getArchive(photo.getID()) });
|
||||||
$("#button_trash_album").on(event_name, function() { album.delete(album.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_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_album").on(event_name, function() { view.infobox.show() });
|
||||||
$("#button_info").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()) });
|
$("#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, ".header a", function() { view.infobox.hide() })
|
||||||
.on(event_name, "#edit_title_album", function() { album.setTitle(album.getID()) })
|
.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_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()) });
|
.on(event_name, "#edit_description", function() { photo.setDescription(photo.getID()) });
|
||||||
|
|
||||||
/* Keyboard */
|
/* Keyboard */
|
||||||
Mousetrap
|
Mousetrap
|
||||||
.bind('u', function() { $("#upload_files").click() })
|
.bind('u', function() { $("#upload_files").click() })
|
||||||
.bind('s', function() { if (visible.photo()) $("#button_star").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('left', function() { if (visible.photo()) $("#imageview a#previous").click() })
|
||||||
.bind('right', function() { if (visible.photo()) $("#imageview a#next").click() })
|
.bind('right', function() { if (visible.photo()) $("#imageview a#next").click() })
|
||||||
.bind('i', function() {
|
.bind('i', function() {
|
||||||
@ -107,7 +107,7 @@ $(document).ready(function(){
|
|||||||
|
|
||||||
/* Header */
|
/* Header */
|
||||||
.on(event_name, "#title.editable", function() {
|
.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());
|
else album.setTitle(album.getID());
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -161,6 +161,7 @@ var lychee = {
|
|||||||
hash = document.location.hash.replace("#", "").split("/");
|
hash = document.location.hash.replace("#", "").split("/");
|
||||||
|
|
||||||
contextMenu.close();
|
contextMenu.close();
|
||||||
|
multiselect.close();
|
||||||
|
|
||||||
if (hash[0]!==undefined) albumID = hash[0];
|
if (hash[0]!==undefined) albumID = hash[0];
|
||||||
if (hash[1]!==undefined) photoID = hash[1];
|
if (hash[1]!==undefined) photoID = hash[1];
|
||||||
|
@ -56,40 +56,47 @@ photo = {
|
|||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
delete: function(photoID) {
|
delete: function(ids) {
|
||||||
|
|
||||||
var params,
|
var params,
|
||||||
buttons,
|
buttons,
|
||||||
photoTitle;
|
photoTitle;
|
||||||
|
|
||||||
if (!photoID) return false;
|
if (!ids) return false;
|
||||||
|
if (ids instanceof Array===false) ids = [ids];
|
||||||
|
|
||||||
if (visible.photo()) photoTitle = photo.json.title;
|
if (ids.length===1) {
|
||||||
else photoTitle = album.json.content[photoID].title;
|
// Get title if only one photo is selected
|
||||||
if (photoTitle=="") photoTitle = "Untitled";
|
if (visible.photo()) photoTitle = photo.json.title;
|
||||||
|
else photoTitle = album.json.content[ids].title;
|
||||||
|
if (photoTitle=="") photoTitle = "Untitled";
|
||||||
|
}
|
||||||
|
|
||||||
buttons = [
|
buttons = [
|
||||||
["Delete Photo", function() {
|
["Delete", function() {
|
||||||
|
|
||||||
|
ids.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[photoID].nextPhoto!==""||album.json.content[photoID].previousPhoto!=="") {
|
if (album.json.content[id].nextPhoto!==""||album.json.content[id].previousPhoto!=="") {
|
||||||
|
|
||||||
nextPhoto = album.json.content[photoID].nextPhoto;
|
nextPhoto = album.json.content[id].nextPhoto;
|
||||||
previousPhoto = album.json.content[photoID].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[photoID] = null;
|
album.json.content[id] = null;
|
||||||
|
view.album.content.delete(id);
|
||||||
view.album.content.delete(photoID);
|
|
||||||
|
});
|
||||||
|
|
||||||
// Only when search is not active
|
// Only when search is not active
|
||||||
if (!visible.albums()) lychee.goto(album.getID());
|
if (!visible.albums()) lychee.goto(album.getID());
|
||||||
|
|
||||||
params = "deletePhoto&photoID=" + photoID;
|
params = "deletePhoto&ids=" + ids;
|
||||||
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);
|
||||||
@ -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 = "",
|
var oldTitle = "",
|
||||||
newTitle,
|
newTitle,
|
||||||
params,
|
params,
|
||||||
buttons;
|
buttons;
|
||||||
|
|
||||||
if (!photoID) return false;
|
if (!ids) return false;
|
||||||
if (photo.json) oldTitle = photo.json.title;
|
if (ids instanceof Array===false) ids = [ids];
|
||||||
else if (album.json) oldTitle = album.json.content[photoID].title;
|
|
||||||
|
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 = [
|
buttons = [
|
||||||
["Set Title", function() {
|
["Set Title", function() {
|
||||||
|
|
||||||
newTitle = $(".message input.text").val();
|
newTitle = $(".message input.text").val();
|
||||||
|
|
||||||
if (photoID!=null&&photoID&&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(oldTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ids.forEach(function(id, index, array) {
|
||||||
|
album.json.content[id].title = newTitle;
|
||||||
|
view.album.content.title(id);
|
||||||
|
});
|
||||||
|
|
||||||
album.json.content[photoID].title = newTitle;
|
params = "setPhotoTitle&ids=" + ids + "&title=" + escape(encodeURI(newTitle));
|
||||||
view.album.content.title(photoID);
|
|
||||||
|
|
||||||
params = "setPhotoTitle&photoID=" + photoID + "&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 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() {}]
|
["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,
|
nextPhoto,
|
||||||
previousPhoto;
|
previousPhoto;
|
||||||
|
|
||||||
|
if (!ids) return false;
|
||||||
if (visible.photo) lychee.goto(album.getID());
|
if (visible.photo) lychee.goto(album.getID());
|
||||||
if (ids instanceof Array===false) ids = [ids];
|
if (ids instanceof Array===false) ids = [ids];
|
||||||
|
|
||||||
@ -185,6 +204,7 @@ photo = {
|
|||||||
|
|
||||||
var params;
|
var params;
|
||||||
|
|
||||||
|
if (!ids) return false;
|
||||||
if (visible.photo()) {
|
if (visible.photo()) {
|
||||||
photo.json.star = (photo.json.star==0) ? 1 : 0;
|
photo.json.star = (photo.json.star==0) ? 1 : 0;
|
||||||
view.photo.star();
|
view.photo.star();
|
||||||
|
@ -110,16 +110,16 @@ if (!empty($_POST['function'])||!empty($_GET['function'])) {
|
|||||||
echo json_encode(getPhoto($_POST['photoID'], $_POST['albumID']));
|
echo json_encode(getPhoto($_POST['photoID'], $_POST['albumID']));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'deletePhoto': if (isset($_POST['photoID']))
|
case 'deletePhoto': if (isset($_POST['ids']))
|
||||||
echo deletePhoto($_POST['photoID']);
|
echo deletePhoto($_POST['ids']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'setAlbum': if (isset($_POST['ids'])&&isset($_POST['albumID']))
|
case 'setAlbum': if (isset($_POST['ids'])&&isset($_POST['albumID']))
|
||||||
echo setAlbum($_POST['ids'], $_POST['albumID']);
|
echo setAlbum($_POST['ids'], $_POST['albumID']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'setPhotoTitle': if (isset($_POST['photoID'])&&isset($_POST['title']))
|
case 'setPhotoTitle': if (isset($_POST['ids'])&&isset($_POST['title']))
|
||||||
echo setPhotoTitle($_POST['photoID'], $_POST['title']);
|
echo setPhotoTitle($_POST['ids'], $_POST['title']);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'setPhotoStar': if (isset($_POST['ids']))
|
case 'setPhotoStar': if (isset($_POST['ids']))
|
||||||
|
@ -221,7 +221,7 @@ function deleteAlbum($albumID) {
|
|||||||
$error = false;
|
$error = false;
|
||||||
|
|
||||||
$result = $database->query("SELECT id FROM lychee_photos WHERE album = '$albumID';");
|
$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;
|
if (!deletePhoto($row->id)) $error = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,12 +104,12 @@ function setAlbum($ids, $albumID) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setPhotoTitle($photoID, $title) {
|
function setPhotoTitle($ids, $title) {
|
||||||
|
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
if (strlen($title)>30) return false;
|
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;
|
if (!$result) return false;
|
||||||
return true;
|
return true;
|
||||||
@ -129,22 +129,31 @@ function setPhotoDescription($photoID, $description) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function deletePhoto($photoID) {
|
function deletePhoto($ids) {
|
||||||
|
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$result = $database->query("SELECT * FROM lychee_photos WHERE id = '$photoID';");
|
$result = $database->query("SELECT * FROM lychee_photos WHERE id IN ($ids);");
|
||||||
if (!$result) return false;
|
|
||||||
$row = $result->fetch_object();
|
while ($row = $result->fetch_object()) {
|
||||||
$retinaUrl = explode(".", $row->thumbUrl);
|
|
||||||
$unlink1 = unlink("../uploads/big/".$row->url);
|
// Get retina thumb url
|
||||||
$unlink2 = unlink("../uploads/thumb/".$row->thumbUrl);
|
$thumbUrl2x = explode(".", $row->thumbUrl);
|
||||||
$unlink3 = unlink("../uploads/thumb/".$retinaUrl[0].'@2x.'.$retinaUrl[1]);
|
$thumbUrl2x = $thumbUrl2x[0] . '@2x.' . $thumbUrl2x[1];
|
||||||
$result = $database->query("DELETE FROM lychee_photos WHERE id = '$photoID';");
|
|
||||||
if (!$unlink1 || !$unlink2 || !$unlink3) return false;
|
// Delete files
|
||||||
if (!$result) return false;
|
if (!unlink('../uploads/big/' . $row->url)) return false;
|
||||||
|
if (!unlink('../uploads/thumb/' . $row->thumbUrl)) return false;
|
||||||
return true;
|
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…
Reference in New Issue
Block a user