Add single merge action with list select #341
This commit is contained in:
parent
e67eca81ae
commit
9f7d6278ab
BIN
dist/main.js
vendored
BIN
dist/main.js
vendored
Binary file not shown.
@ -570,41 +570,73 @@ album.getArchive = function(albumID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
album.merge = function(albumIDs) {
|
album.merge = function(albumIDs) {
|
||||||
var action = {}
|
|
||||||
|
|
||||||
action.fn = function() {
|
var action,
|
||||||
|
title = '',
|
||||||
|
sTitle = '',
|
||||||
|
msg = '';
|
||||||
|
|
||||||
var params;
|
if (!albumIDs) return false;
|
||||||
|
if (albumIDs instanceof Array===false) albumIDs = [albumIDs];
|
||||||
|
|
||||||
basicModal.close();
|
// Get title of first album
|
||||||
|
if (albums.json) title = albums.json.albums[albumIDs[0]].title;
|
||||||
|
|
||||||
params = {
|
if (!title) title = '';
|
||||||
albumIDs: albumIDs.join()
|
title = title.replace(/'/g, ''');
|
||||||
}
|
|
||||||
|
|
||||||
api.post('Album::merge', params, function(data) {
|
if (albumIDs.length===2) {
|
||||||
if (data!==true) {
|
|
||||||
lychee.error(null, params, data);
|
|
||||||
} else {
|
|
||||||
albums.json = null
|
|
||||||
albums.load()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
// Get title of second album
|
||||||
|
if (albums.json) sTitle = albums.json.albums[albumIDs[1]].title;
|
||||||
|
|
||||||
|
if (!sTitle) sTitle = '';
|
||||||
|
sTitle = sTitle.replace(/'/g, ''');
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
@ -43,13 +43,21 @@ contextMenu.settings = function(e) {
|
|||||||
|
|
||||||
contextMenu.album = function(albumID, 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;
|
if (albumID==='0'||albumID==='f'||albumID==='s'||albumID==='r') return false;
|
||||||
|
|
||||||
var items = [
|
var items = [
|
||||||
{ type: 'item', title: build.iconic('pencil') + 'Rename', fn: function() { album.setTitle([albumID]) } },
|
{ 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]) } }
|
{ 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');
|
$('.album[data-id="' + albumID + '"]').addClass('active');
|
||||||
|
|
||||||
basicContext.show(items, e, contextMenu.close);
|
basicContext.show(items, e, contextMenu.close);
|
||||||
@ -61,8 +69,8 @@ contextMenu.albumMulti = function(albumIDs, e) {
|
|||||||
multiselect.stopResize();
|
multiselect.stopResize();
|
||||||
|
|
||||||
var items = [
|
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: 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) } }
|
{ 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) {
|
contextMenu.photo = function(photoID, e) {
|
||||||
|
|
||||||
// Notice for 'Move':
|
// Notice for 'Move':
|
||||||
|
Loading…
Reference in New Issue
Block a user