Add single merge action with list select #341

pull/343/head
Tobias Reich 9 years ago
parent e67eca81ae
commit 9f7d6278ab

12
dist/main.js vendored

File diff suppressed because one or more lines are too long

@ -570,41 +570,73 @@ album.getArchive = function(albumID) {
}
album.merge = function(albumIDs) {
var action = {}
action.fn = function() {
var params;
basicModal.close();
params = {
albumIDs: albumIDs.join()
}
api.post('Album::merge', params, function(data) {
if (data!==true) {
lychee.error(null, params, data);
} else {
albums.json = null
albums.load()
}
})
}
basicModal.show({
body: '<p>Are you sure you want to merge all selected albums?</p>',
buttons: {
action: {
title: 'Merge Albums',
fn: action.fn,
class: 'red'
},
cancel: {
title: "Don't merge",
fn: basicModal.close
}
}
});
var action,
title = '',
sTitle = '',
msg = '';
if (!albumIDs) return false;
if (albumIDs instanceof Array===false) albumIDs = [albumIDs];
// Get title of first album
if (albums.json) title = albums.json.albums[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 (!sTitle) sTitle = '';
sTitle = sTitle.replace(/'/g, '&apos;');
msg = "<p>Are you sure you want to merge the album '" + sTitle + "' into the album '" + title + "'?</p>";
} else {
msg = "<p>Are you sure you want to merge all selected albums into the album '" + title + "'?</p>";
}
action = function() {
var params;
basicModal.close();
params = {
albumIDs: albumIDs.join()
}
api.post('Album::merge', params, function(data) {
if (data!==true) {
lychee.error(null, params, data);
} else {
albums.refresh();
albums.load();
}
});
}
basicModal.show({
body: msg,
buttons: {
action: {
title: 'Merge Albums',
fn: action,
class: 'red'
},
cancel: {
title: "Don't Merge",
fn: basicModal.close
}
}
});
}

@ -43,13 +43,21 @@ contextMenu.settings = function(e) {
contextMenu.album = function(albumID, e) {
// Notice for 'Merge':
// fn must call basicContext.close() first,
// in order to keep the selection
if (albumID==='0'||albumID==='f'||albumID==='s'||albumID==='r') return false;
var items = [
{ type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { album.setTitle([albumID]) } },
{ type: 'item', title: 'Merge', fn: function () { basicContext.close(); contextMenu.mergeAlbum(albumID, e) } },
{ type: 'item', title: build.iconic('trash') + 'Delete', fn: function() { album.delete([albumID]) } }
];
// Remove merge when there is only one album
if (albums.json&&albums.json.albums&&Object.keys(albums.json.albums).length<=1) items.splice(1, 1);
$('.album[data-id="' + albumID + '"]').addClass('active');
basicContext.show(items, e, contextMenu.close);
@ -61,8 +69,8 @@ contextMenu.albumMulti = function(albumIDs, e) {
multiselect.stopResize();
var items = [
{ type: 'item', title: 'Merge All', fn: function () { album.merge(albumIDs) } },
{ type: 'item', title: build.iconic('pencil') + 'Rename All', fn: function() { album.setTitle(albumIDs) } },
{ type: 'item', title: 'Merge All', fn: function () { album.merge(albumIDs) } },
{ type: 'item', title: build.iconic('trash') + 'Delete All', fn: function() { album.delete(albumIDs) } }
];
@ -104,6 +112,33 @@ contextMenu.albumTitle = function(albumID, e) {
}
contextMenu.mergeAlbum = function(albumID, e) {
var items = [];
api.post('Album::getAll', {}, function(data) {
$.each(data.albums, function(){
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.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);
})
}
contextMenu.photo = function(photoID, e) {
// Notice for 'Move':

Loading…
Cancel
Save