diff --git a/dist/main.js b/dist/main.js index c9bf556..c3d224c 100644 Binary files a/dist/main.js and b/dist/main.js differ diff --git a/src/scripts/album.js b/src/scripts/album.js index cf98d34..a97e47d 100644 --- a/src/scripts/album.js +++ b/src/scripts/album.js @@ -570,41 +570,73 @@ album.getArchive = function(albumID) { } 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 = { - albumIDs: albumIDs.join() - } + if (!title) title = ''; + title = title.replace(/'/g, '''); - api.post('Album::merge', params, function(data) { - if (data!==true) { - lychee.error(null, params, data); - } else { - albums.json = null - albums.load() - } - }) + 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, '''); + + msg = "
Are you sure you want to merge the album '" + sTitle + "' into the album '" + title + "'?
"; + + } else { + + msg = "Are you sure you want to merge all selected albums into the album '" + title + "'?
"; + + } + + 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: 'Are you sure you want to merge all selected albums?
', - buttons: { - action: { - title: 'Merge Albums', - fn: action.fn, - class: 'red' - }, - cancel: { - title: "Don't merge", - fn: basicModal.close - } - } - }); } \ No newline at end of file diff --git a/src/scripts/contextMenu.js b/src/scripts/contextMenu.js index 07ae17f..e3b6eed 100644 --- a/src/scripts/contextMenu.js +++ b/src/scripts/contextMenu.js @@ -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 = "