Several album and photo handling changes
- Stopped view.js from cutting album and photo titles (#332) - Fixed album sorting (getByID, deleteByID) - Fixed jQuery each bug when opening empty album - Stop showing deleted photos in photo switcher
This commit is contained in:
parent
3131dea789
commit
e64e29f81f
BIN
dist/main.js
vendored
BIN
dist/main.js
vendored
Binary file not shown.
@ -189,8 +189,8 @@ class Album extends Module {
|
||||
if ($public===false) $return['smartalbums'] = $this->getSmartInfo();
|
||||
|
||||
# Albums query
|
||||
$query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0', array(LYCHEE_TABLE_ALBUMS));
|
||||
if ($public===false) $query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ?', array(LYCHEE_TABLE_ALBUMS));
|
||||
if ($public===false) $query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ?', array(LYCHEE_TABLE_ALBUMS));
|
||||
else $query = Database::prepare($this->database, 'SELECT id, title, public, sysstamp, password FROM ? WHERE public = 1 AND visible <> 0', array(LYCHEE_TABLE_ALBUMS));
|
||||
|
||||
# Execute query
|
||||
$albums = $this->database->query($query);
|
||||
@ -223,7 +223,7 @@ class Album extends Module {
|
||||
}
|
||||
|
||||
# Add to return
|
||||
$return['albums'][$album['id']] = $album;
|
||||
$return['albums'][] = $album;
|
||||
|
||||
}
|
||||
|
||||
|
@ -180,7 +180,7 @@ album.delete = function(albumIDs) {
|
||||
albumIDs.forEach(function(id) {
|
||||
albums.json.num--;
|
||||
view.albums.content.delete(id);
|
||||
delete albums.json.albums[id];
|
||||
albums.deleteByID(id);
|
||||
});
|
||||
|
||||
} else {
|
||||
@ -210,7 +210,7 @@ album.delete = function(albumIDs) {
|
||||
|
||||
// Get title
|
||||
if (album.json) albumTitle = album.json.title;
|
||||
else if (albums.json) albumTitle = albums.json.albums[albumIDs].title;
|
||||
else if (albums.json) albumTitle = albums.getByID(albumIDs).title;
|
||||
|
||||
msg = "<p>Are you sure you want to delete the album '" + albumTitle + "' and all of the photos it contains? This action can't be undone!</p>";
|
||||
|
||||
@ -254,7 +254,7 @@ album.setTitle = function(albumIDs) {
|
||||
|
||||
// Get old title if only one album is selected
|
||||
if (album.json) oldTitle = album.json.title;
|
||||
else if (albums.json) oldTitle = albums.json.albums[albumIDs].title;
|
||||
else if (albums.json) oldTitle = albums.getByID(albumIDs).title;
|
||||
|
||||
if (!oldTitle) oldTitle = '';
|
||||
oldTitle = oldTitle.replace(/'/g, ''');
|
||||
@ -281,13 +281,13 @@ album.setTitle = function(albumIDs) {
|
||||
|
||||
if (albums.json) {
|
||||
var id = albumIDs[0];
|
||||
albums.json.albums[id].title = newTitle;
|
||||
albums.getByID(id).title = newTitle;
|
||||
}
|
||||
|
||||
} else if (visible.albums()) {
|
||||
|
||||
albumIDs.forEach(function(id) {
|
||||
albums.json.albums[id].title = newTitle;
|
||||
albums.getByID(id).title = newTitle;
|
||||
view.albums.content.title(id);
|
||||
});
|
||||
|
||||
@ -580,7 +580,7 @@ album.merge = function(albumIDs) {
|
||||
if (albumIDs instanceof Array===false) albumIDs = [albumIDs];
|
||||
|
||||
// Get title of first album
|
||||
if (albums.json) title = albums.json.albums[albumIDs[0]].title;
|
||||
if (albums.json) title = albums.getByID(albumIDs[0]).title;
|
||||
|
||||
if (!title) title = '';
|
||||
title = title.replace(/'/g, ''');
|
||||
@ -588,7 +588,7 @@ album.merge = function(albumIDs) {
|
||||
if (albumIDs.length===2) {
|
||||
|
||||
// Get title of second album
|
||||
if (albums.json) sTitle = albums.json.albums[albumIDs[1]].title;
|
||||
if (albums.json) sTitle = albums.getByID(albumIDs[1]).title;
|
||||
|
||||
if (!sTitle) sTitle = '';
|
||||
sTitle = sTitle.replace(/'/g, ''');
|
||||
|
@ -105,6 +105,52 @@ albums._createSmartAlbums = function(data) {
|
||||
|
||||
}
|
||||
|
||||
albums.getByID = function(albumID) {
|
||||
|
||||
// Function returns the JSON of an album
|
||||
|
||||
if (albumID===undefined||albumID===null) return undefined;
|
||||
if (!albums.json) return undefined;
|
||||
if (!albums.json.albums) return undefined;
|
||||
|
||||
var json = undefined;
|
||||
|
||||
$.each(albums.json.albums, function(i) {
|
||||
|
||||
let elem = albums.json.albums[i];
|
||||
|
||||
if (elem.id==albumID) json = elem;
|
||||
|
||||
});
|
||||
|
||||
return json;
|
||||
|
||||
}
|
||||
|
||||
albums.deleteByID = function(albumID) {
|
||||
|
||||
// Function returns the JSON of an album
|
||||
|
||||
if (albumID===undefined||albumID===null) return false;
|
||||
if (!albums.json) return false;
|
||||
if (!albums.json.albums) return false;
|
||||
|
||||
var deleted = false;
|
||||
|
||||
$.each(albums.json.albums, function(i) {
|
||||
|
||||
if (albums.json.albums[i].id==albumID) {
|
||||
albums.json.albums.splice(i, 1);
|
||||
deleted = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
return deleted;
|
||||
|
||||
}
|
||||
|
||||
albums.refresh = function() {
|
||||
|
||||
albums.json = null;
|
||||
|
@ -84,7 +84,7 @@ contextMenu.albumTitle = function(albumID, e) {
|
||||
|
||||
api.post('Album::getAll', {}, function(data) {
|
||||
|
||||
if (data.num>1) {
|
||||
if (data.albums&&data.num>1) {
|
||||
|
||||
// Generate list of albums
|
||||
$.each(data.albums, function(index) {
|
||||
@ -114,28 +114,32 @@ contextMenu.albumTitle = function(albumID, e) {
|
||||
|
||||
contextMenu.mergeAlbum = function(albumID, e) {
|
||||
|
||||
var items = [];
|
||||
var items = [];
|
||||
|
||||
api.post('Album::getAll', {}, function(data) {
|
||||
api.post('Album::getAll', {}, function(data) {
|
||||
|
||||
$.each(data.albums, function(){
|
||||
if (data.albums&&data.num>1) {
|
||||
|
||||
var that = this;
|
||||
$.each(data.albums, function(){
|
||||
|
||||
if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg';
|
||||
that.contextTitle = "<img class='cover' width='16' height='16' src='" + that.thumbs[0] + "'><div class='title'>" + that.title + "</div>";
|
||||
var that = this;
|
||||
|
||||
if (that.id!=album.getID()) {
|
||||
items.unshift({ type: 'item', title: that.contextTitle, fn: function() { album.merge([albumID, that.id]) } });
|
||||
}
|
||||
if (!that.thumbs[0]) that.thumbs[0] = 'src/images/no_cover.svg';
|
||||
that.contextTitle = "<img class='cover' width='16' height='16' src='" + that.thumbs[0] + "'><div class='title'>" + that.title + "</div>";
|
||||
|
||||
});
|
||||
if (that.id!=album.getID()) {
|
||||
items.unshift({ type: 'item', title: that.contextTitle, fn: function() { album.merge([albumID, that.id]) } });
|
||||
}
|
||||
|
||||
if (items.length===0) return false;
|
||||
});
|
||||
|
||||
basicContext.show(items, e, contextMenu.close);
|
||||
}
|
||||
|
||||
})
|
||||
if (items.length===0) return false;
|
||||
|
||||
basicContext.show(items, e, contextMenu.close);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@ -191,7 +195,7 @@ contextMenu.photoTitle = function(albumID, photoID, e) {
|
||||
|
||||
var data = album.json;
|
||||
|
||||
if (data.num>1) {
|
||||
if (data.content!==false&&data.num>1) {
|
||||
|
||||
items.push({ type: 'separator' });
|
||||
|
||||
|
@ -14,9 +14,9 @@ password.get = function(albumID, callback) {
|
||||
var passwd = $('.basicModal input.text').val(),
|
||||
params;
|
||||
|
||||
if (lychee.publicMode===false) callback();
|
||||
else if (album.json&&album.json.password==='0') callback();
|
||||
else if (albums.json&&albums.json.albums[albumID].password==='0') callback();
|
||||
if (lychee.publicMode===false) callback();
|
||||
else if (album.json&&album.json.password==='0') callback();
|
||||
else if (albums.json&&albums.getByID(albumID).password==='0') callback();
|
||||
else if (!albums.json&&!album.json) {
|
||||
|
||||
// Continue without password
|
||||
|
@ -223,7 +223,7 @@ photo.delete = function(photoIDs) {
|
||||
|
||||
}
|
||||
|
||||
album.json.content[id] = null;
|
||||
delete album.json.content[id];
|
||||
view.album.content.delete(id);
|
||||
|
||||
});
|
||||
|
@ -73,17 +73,11 @@ view.albums = {
|
||||
|
||||
title: function(albumID) {
|
||||
|
||||
var longTitle = '',
|
||||
title = albums.json.albums[albumID].title;
|
||||
|
||||
if (title!==null&&title.length>18) {
|
||||
longTitle = title;
|
||||
title = title.substr(0, 18) + '...';
|
||||
}
|
||||
var title = albums.getByID(albumID).title;
|
||||
|
||||
$('.album[data-id="' + albumID + '"] .overlay h1')
|
||||
.html(title)
|
||||
.attr('title', longTitle);
|
||||
.attr('title', title);
|
||||
|
||||
},
|
||||
|
||||
@ -94,7 +88,7 @@ view.albums = {
|
||||
marginLeft: 0
|
||||
}, 300, function() {
|
||||
$(this).remove();
|
||||
if (albums.json.num<=0) lychee.animate('#content .divider:last-of-type', 'fadeOut');
|
||||
if (albums.json.num<=0) lychee.content.find('.divider:last-child').remove();
|
||||
});
|
||||
|
||||
}
|
||||
@ -155,27 +149,27 @@ view.album = {
|
||||
view.albums.content.scrollPosition = $(document).scrollTop();
|
||||
$('html, body').scrollTop(0);
|
||||
|
||||
$.each(album.json.content, function() {
|
||||
photosData += build.photo(this);
|
||||
});
|
||||
if (album.json.content&&album.json.content!==false) {
|
||||
|
||||
// Build photos
|
||||
$.each(album.json.content, function() {
|
||||
photosData += build.photo(this);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Add photos to view
|
||||
lychee.content.html(photosData);
|
||||
|
||||
},
|
||||
|
||||
title: function(photoID) {
|
||||
|
||||
var longTitle = '',
|
||||
title = album.json.content[photoID].title;
|
||||
|
||||
if (title!==null&&title.length>18) {
|
||||
longTitle = title;
|
||||
title = title.substr(0, 18) + '...';
|
||||
}
|
||||
var title = album.json.content[photoID].title;
|
||||
|
||||
$('.photo[data-id="' + photoID + '"] .overlay h1')
|
||||
.html(title)
|
||||
.attr('title', longTitle);
|
||||
.attr('title', title);
|
||||
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user