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) {
if (visible.contextMenu()) contextMenu.close();
contextMenu.close();
$("body")
.css("overflow", "hidden")
.append(build.contextMenu(items));
// Do not leave the screen
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())
@ -38,11 +39,9 @@ contextMenu = {
add: function(e) {
var mouse_x = e.pageX,
mouse_y = e.pageY,
mouse_y = e.pageY - $(document).scrollTop(),
items;
mouse_y -= $(document).scrollTop();
contextMenu.fns = [
function() { $("#upload_files").click() },
function() { upload.start.url() },
@ -68,11 +67,9 @@ contextMenu = {
settings: function(e) {
var mouse_x = e.pageX,
mouse_y = e.pageY,
mouse_y = e.pageY - $(document).scrollTop(),
items;
mouse_y -= $(document).scrollTop();
contextMenu.fns = [
function() { settings.setLogin() },
function() { settings.setSorting() },
@ -95,13 +92,11 @@ contextMenu = {
album: function(albumID, e) {
var mouse_x = e.pageX,
mouse_y = e.pageY,
mouse_y = e.pageY - $(document).scrollTop(),
items;
if (albumID==="0"||albumID==="f"||albumID==="s") return false;
mouse_y -= $(document).scrollTop();
contextMenu.fns = [
function() { album.setTitle(albumID) },
function() { album.delete(albumID) }
@ -121,15 +116,13 @@ contextMenu = {
photo: function(photoID, e) {
var mouse_x = e.pageX,
mouse_y = e.pageY,
mouse_y = e.pageY - $(document).scrollTop(),
items;
mouse_y -= $(document).scrollTop();
contextMenu.fns = [
function() { photo.setStar(photoID) },
function() { photo.setStar([photoID]) },
function() { photo.setTitle(photoID) },
function() { contextMenu.move(photoID, e, "right") },
function() { contextMenu.move([photoID], e, "right") },
function() { photo.delete(photoID) }
];
@ -147,17 +140,44 @@ contextMenu = {
},
move: function(photoID, e, orientation) {
photoMulti: function(ids, e) {
var mouse_x = e.pageX,
mouse_y = e.pageY,
mouse_y = e.pageY - $(document).scrollTop(),
items;
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,
mouse_y = e.pageY - $(document).scrollTop(),
items = [];
contextMenu.fns = [];
contextMenu.close(true);
if (album.getID()!=="0") {
items = [
["Unsorted", 0, "photo.setAlbum(0, " + photoID + ")"],
["Unsorted", 0, "photo.setAlbum([" + ids + "], 0)"],
["separator", -1]
];
}
@ -168,14 +188,10 @@ contextMenu = {
items = [["New Album", 0, "album.add()"]];
} else {
$.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");
else contextMenu.show(items, mouse_x, mouse_y, "left");
@ -255,14 +271,20 @@ contextMenu = {
},
close: function() {
close: function(leaveSelection) {
contextMenu.js = null;
if (!visible.contextMenu()) return false;
contextMenu.fns = [];
$(".contextmenu_bg, .contextmenu").remove();
$(".photo.active, .album.active").removeClass("active");
$("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 */
$("#content").on("mousedown", multiselect.show);
$(document).on("mouseup", multiselect.close);
$(document).on("mouseup", multiselect.getSelection);
/* Header */
$("#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_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_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()) });
$("#button_star").on(event_name, function() { photo.setStar(photo.getID()) });
$("#button_star").on(event_name, function() { photo.setStar([photo.getID()]) });
/* Search */
$("#search").on("keyup click", function() { search.find($(this).val()) });

View File

@ -91,10 +91,58 @@ multiselect = {
},
close: function() {
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() {
multiselect.stopResize();
multiselect.position.top = null;
multiselect.position.right = null;
multiselect.position.bottom = null;

View File

@ -145,39 +145,43 @@ photo = {
},
setAlbum: function(albumID, photoID) {
setAlbum: function(ids, albumID) {
var params;
var params,
nextPhoto,
previousPhoto;
if (albumID>=0) {
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
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;
previousPhoto = album.json.content[photoID].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;
}
if (visible.photo) lychee.goto(album.getID());
album.json.content[photoID] = null;
view.album.content.delete(photoID);
album.json.content[id] = null;
view.album.content.delete(id);
params = "setAlbum&photoID=" + photoID + "&albumID=" + albumID;
lychee.api(params, function(data) {
});
if (data!==true) lychee.error(null, params, data);
params = "setAlbum&ids=" + ids + "&albumID=" + albumID;
lychee.api(params, function(data) {
});
if (data!==true) lychee.error(null, params, data);
}
});
},
setStar: function(photoID) {
setStar: function(ids) {
var params;
@ -186,10 +190,12 @@ photo = {
view.photo.star();
}
album.json.content[photoID].star = (album.json.content[photoID].star==0) ? 1 : 0;
view.album.content.star(photoID);
ids.forEach(function(id, index, array) {
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) {
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']);
break;
case 'setAlbum': if (isset($_POST['photoID'])&&isset($_POST['albumID']))
echo setAlbum($_POST['photoID'], $_POST['albumID']);
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']);
break;
case 'setPhotoStar': if (isset($_POST['photoID']))
echo setPhotoStar($_POST['photoID']);
case 'setPhotoStar': if (isset($_POST['ids']))
echo setPhotoStar($_POST['ids']);
break;
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;
$result = $database->query("SELECT star FROM lychee_photos WHERE id = '$photoID';");
$row = $result->fetch_object();
if ($row->star == 0) {
$star = 1;
} else {
$star = 0;
$error = false;
$result = $database->query("SELECT id, star FROM lychee_photos WHERE id IN ($ids);");
while ($row = $result->fetch_object()) {
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;
}
function setAlbum($photoID, $newAlbum) {
function setAlbum($ids, $albumID) {
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;
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';");
if (!$result) return false;
else return true;
return true;
}