Move all and Star all

This commit is contained in:
Tobias Reich 2014-01-28 20:44:25 +01:00
parent 7b07f43d19
commit ef46bd183a
6 changed files with 153 additions and 71 deletions

View File

@ -11,12 +11,13 @@ contextMenu = {
show: function(items, mouse_x, mouse_y, orientation) { show: function(items, mouse_x, mouse_y, orientation) {
if (visible.contextMenu()) contextMenu.close(); contextMenu.close();
$("body") $("body")
.css("overflow", "hidden") .css("overflow", "hidden")
.append(build.contextMenu(items)); .append(build.contextMenu(items));
// Do not leave the screen
if ((mouse_x+$(".contextmenu").outerWidth(true))>$("html").width()) orientation = "left"; if ((mouse_x+$(".contextmenu").outerWidth(true))>$("html").width()) orientation = "left";
if ((mouse_y+$(".contextmenu").outerHeight(true))>$("html").height()) mouse_y -= (mouse_y+$(".contextmenu").outerHeight(true)-$("html").height()) if ((mouse_y+$(".contextmenu").outerHeight(true))>$("html").height()) mouse_y -= (mouse_y+$(".contextmenu").outerHeight(true)-$("html").height())
@ -38,11 +39,9 @@ contextMenu = {
add: function(e) { add: function(e) {
var mouse_x = e.pageX, var mouse_x = e.pageX,
mouse_y = e.pageY, mouse_y = e.pageY - $(document).scrollTop(),
items; items;
mouse_y -= $(document).scrollTop();
contextMenu.fns = [ contextMenu.fns = [
function() { $("#upload_files").click() }, function() { $("#upload_files").click() },
function() { upload.start.url() }, function() { upload.start.url() },
@ -68,11 +67,9 @@ contextMenu = {
settings: function(e) { settings: function(e) {
var mouse_x = e.pageX, var mouse_x = e.pageX,
mouse_y = e.pageY, mouse_y = e.pageY - $(document).scrollTop(),
items; items;
mouse_y -= $(document).scrollTop();
contextMenu.fns = [ contextMenu.fns = [
function() { settings.setLogin() }, function() { settings.setLogin() },
function() { settings.setSorting() }, function() { settings.setSorting() },
@ -95,13 +92,11 @@ contextMenu = {
album: function(albumID, e) { album: function(albumID, e) {
var mouse_x = e.pageX, var mouse_x = e.pageX,
mouse_y = e.pageY, mouse_y = e.pageY - $(document).scrollTop(),
items; items;
if (albumID==="0"||albumID==="f"||albumID==="s") return false; if (albumID==="0"||albumID==="f"||albumID==="s") return false;
mouse_y -= $(document).scrollTop();
contextMenu.fns = [ contextMenu.fns = [
function() { album.setTitle(albumID) }, function() { album.setTitle(albumID) },
function() { album.delete(albumID) } function() { album.delete(albumID) }
@ -121,15 +116,13 @@ contextMenu = {
photo: function(photoID, e) { photo: function(photoID, e) {
var mouse_x = e.pageX, var mouse_x = e.pageX,
mouse_y = e.pageY, mouse_y = e.pageY - $(document).scrollTop(),
items; items;
mouse_y -= $(document).scrollTop();
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) }
]; ];
@ -146,18 +139,45 @@ contextMenu = {
$(".photo[data-id='" + photoID + "']").addClass("active"); $(".photo[data-id='" + photoID + "']").addClass("active");
}, },
photoMulti: function(ids, e) {
var mouse_x = e.pageX,
mouse_y = e.pageY - $(document).scrollTop(),
items;
move: function(photoID, e, orientation) { multiselect.stopResize();
contextMenu.fns = [
function() { photo.setStar(ids) },
function() { photo.setTitle(ids) },
function() { contextMenu.move(ids, e, "right") },
function() { photo.delete(ids) }
];
items = [
["<a class='icon-star'></a> Star All", 0],
["separator", -1],
["<a class='icon-edit'></a> Rename All", 1],
["<a class='icon-folder-open'></a> Move All", 2],
["<a class='icon-trash'></a> Delete All", 3]
];
contextMenu.show(items, mouse_x, mouse_y, "right");
},
move: function(ids, e, orientation) {
var mouse_x = e.pageX, var mouse_x = e.pageX,
mouse_y = e.pageY, mouse_y = e.pageY - $(document).scrollTop(),
items = []; items = [];
contextMenu.fns = []; contextMenu.close(true);
if (album.getID()!=="0") { if (album.getID()!=="0") {
items = [ items = [
["Unsorted", 0, "photo.setAlbum(0, " + photoID + ")"], ["Unsorted", 0, "photo.setAlbum([" + ids + "], 0)"],
["separator", -1] ["separator", -1]
]; ];
} }
@ -168,14 +188,10 @@ contextMenu = {
items = [["New Album", 0, "album.add()"]]; items = [["New Album", 0, "album.add()"]];
} else { } else {
$.each(data.content, function(index) { $.each(data.content, function(index) {
if (this.id!=album.getID()) items.push([this.title, 0, "photo.setAlbum(" + this.id + ", " + photoID + ")"]); if (this.id!=album.getID()) items.push([this.title, 0, "photo.setAlbum([" + ids + "], " + this.id + ")"]);
}); });
} }
contextMenu.close();
$(".photo[data-id='" + photoID + "']").addClass("active");
if (!visible.photo()) contextMenu.show(items, mouse_x, mouse_y, "right"); if (!visible.photo()) contextMenu.show(items, mouse_x, mouse_y, "right");
else contextMenu.show(items, mouse_x, mouse_y, "left"); else contextMenu.show(items, mouse_x, mouse_y, "left");
@ -255,13 +271,19 @@ contextMenu = {
}, },
close: function() { close: function(leaveSelection) {
contextMenu.js = null; if (!visible.contextMenu()) return false;
contextMenu.fns = [];
$(".contextmenu_bg, .contextmenu").remove(); $(".contextmenu_bg, .contextmenu").remove();
$(".photo.active, .album.active").removeClass("active");
$("body").css("overflow", "auto"); $("body").css("overflow", "auto");
if (leaveSelection!==true) {
$(".photo.active, .album.active").removeClass("active");
if (visible.multiselect()) multiselect.close();
}
} }

View File

@ -20,7 +20,7 @@ $(document).ready(function(){
/* Multiselect */ /* Multiselect */
$("#content").on("mousedown", multiselect.show); $("#content").on("mousedown", multiselect.show);
$(document).on("mouseup", multiselect.close); $(document).on("mouseup", multiselect.getSelection);
/* Header */ /* Header */
$("#hostedwith").on(event_name, function() { window.open(lychee.website,"_newtab") }); $("#hostedwith").on(event_name, function() { window.open(lychee.website,"_newtab") });
@ -36,12 +36,12 @@ $(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()) });
$("#button_star").on(event_name, function() { photo.setStar(photo.getID()) }); $("#button_star").on(event_name, function() { photo.setStar([photo.getID()]) });
/* Search */ /* Search */
$("#search").on("keyup click", function() { search.find($(this).val()) }); $("#search").on("keyup click", function() { search.find($(this).val()) });

View File

@ -90,10 +90,58 @@ multiselect = {
} }
}, },
stopResize: function() {
$(document).off('mousemove');
},
getSize: function() {
if (!visible.multiselect()) return false;
return {
top: $('#multiselect').offset().top,
left: $('#multiselect').offset().left,
width: parseInt($('#multiselect').css('width').replace('px', '')),
height: parseInt($('#multiselect').css('height').replace('px', ''))
}
},
getSelection: function(e) {
var ids = [],
offset,
size = multiselect.getSize();
if (visible.contextMenu()) return false;
if (!visible.multiselect()) return false;
$('.photo, .album').each(function() {
offset = $(this).offset();
if (offset.top>=size.top&&
offset.left>=size.left&&
(offset.top+206)<=(size.top+size.height)&&
(offset.left+206)<=(size.left+size.width)) {
ids.push($(this).data('id'));
$(this).addClass('active');
}
});
if (ids.length!=0&&visible.album()) contextMenu.photoMulti(ids, e);
else if (ids.length!=0&&visible.albums()) contextMenu.albumMulti(ids, e);
else multiselect.close();
},
close: function() { close: function() {
$(document).off('mousemove'); multiselect.stopResize();
multiselect.position.top = null; multiselect.position.top = null;
multiselect.position.right = null; multiselect.position.right = null;

View File

@ -145,39 +145,43 @@ photo = {
}, },
setAlbum: function(albumID, photoID) { setAlbum: function(ids, albumID) {
var params; var params,
nextPhoto,
if (albumID>=0) { previousPhoto;
if (visible.photo) lychee.goto(album.getID());
if (ids instanceof Array===false) ids = [ids];
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[id] = null;
view.album.content.delete(id);
});
if (visible.photo) lychee.goto(album.getID()); params = "setAlbum&ids=" + ids + "&albumID=" + albumID;
album.json.content[photoID] = null; lychee.api(params, function(data) {
view.album.content.delete(photoID);
params = "setAlbum&photoID=" + photoID + "&albumID=" + albumID; if (data!==true) lychee.error(null, params, data);
lychee.api(params, function(data) {
if (data!==true) lychee.error(null, params, data); });
});
}
}, },
setStar: function(photoID) { setStar: function(ids) {
var params; var params;
@ -186,10 +190,12 @@ photo = {
view.photo.star(); view.photo.star();
} }
album.json.content[photoID].star = (album.json.content[photoID].star==0) ? 1 : 0; ids.forEach(function(id, index, array) {
view.album.content.star(photoID); album.json.content[id].star = (album.json.content[id].star==0) ? 1 : 0;
view.album.content.star(id);
});
params = "setPhotoStar&photoID=" + photoID; params = "setPhotoStar&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);

View File

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

View File

@ -71,30 +71,36 @@ function setPhotoPublic($photoID, $url) {
} }
function setPhotoStar($photoID) { function setPhotoStar($ids) {
global $database; global $database;
$result = $database->query("SELECT star FROM lychee_photos WHERE id = '$photoID';"); $error = false;
$row = $result->fetch_object(); $result = $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($ids);");
if ($row->star == 0) {
$star = 1; while ($row = $result->fetch_object()) {
} else {
$star = 0; if ($row->star==0) $star = 1;
else $star = 0;
$star = $database->query("UPDATE lychee_photos SET star = '$star' WHERE id = '$row->id';");
if (!$star) $error = true;
} }
$result = $database->query("UPDATE lychee_photos SET star = '$star' WHERE id = '$photoID';");
if ($error) return false;
return true; return true;
} }
function setAlbum($photoID, $newAlbum) { function setAlbum($ids, $albumID) {
global $database; global $database;
$result = $database->query("UPDATE lychee_photos SET album = '$newAlbum' WHERE id = '$photoID';"); $result = $database->query("UPDATE lychee_photos SET album = '$albumID' WHERE id IN ($ids);");
if (!$result) return false; if (!$result) return false;
else return true; return true;
} }
@ -106,7 +112,7 @@ function setPhotoTitle($photoID, $title) {
$result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id = '$photoID';"); $result = $database->query("UPDATE lychee_photos SET title = '$title' WHERE id = '$photoID';");
if (!$result) return false; if (!$result) return false;
else return true; return true;
} }