Skip to content

Commit

Permalink
Several album and photo handling changes
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
electerious committed May 14, 2015
1 parent 3131dea commit e64e29f
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 55 deletions.
12 changes: 6 additions & 6 deletions dist/main.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions php/modules/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public function getAll($public) {
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);
Expand Down Expand Up @@ -223,7 +223,7 @@ public function getAll($public) {
}

# Add to return
$return['albums'][$album['id']] = $album;
$return['albums'][] = $album;

}

Expand Down
14 changes: 7 additions & 7 deletions src/scripts/album.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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>";

Expand Down Expand Up @@ -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, '&apos;');
Expand All @@ -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);
});

Expand Down Expand Up @@ -580,15 +580,15 @@ 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, '&apos;');

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, '&apos;');
Expand Down
46 changes: 46 additions & 0 deletions src/scripts/albums.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 19 additions & 15 deletions src/scripts/contextMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
if (data.albums&&data.num>1) {

$.each(data.albums, function(){
$.each(data.albums, function(){

var that = this;

var that = this;
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.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 (that.id!=album.getID()) {
items.unshift({ type: 'item', title: that.contextTitle, fn: function() { album.merge([albumID, that.id]) } });
}
});

});
}

if (items.length===0) return false;
if (items.length===0) return false;

basicContext.show(items, e, contextMenu.close);
basicContext.show(items, e, contextMenu.close);

})
});

}

Expand Down Expand Up @@ -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' });

Expand Down
6 changes: 3 additions & 3 deletions src/scripts/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/photo.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ photo.delete = function(photoIDs) {

}

album.json.content[id] = null;
delete album.json.content[id];
view.album.content.delete(id);

});
Expand Down
34 changes: 14 additions & 20 deletions src/scripts/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

},

Expand All @@ -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();
});

}
Expand Down Expand Up @@ -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);

},

Expand Down

0 comments on commit e64e29f

Please sign in to comment.