From 3f7f2ffcd1a58569160c08c014230673c7e9d14c Mon Sep 17 00:00:00 2001 From: Nils Asmussen Date: Sun, 28 Aug 2016 16:51:39 +0200 Subject: [PATCH] Disallow to select a mixture of albums and photos. This commit uses a different approach than before. Now we prevent the selection and display an error to the user to explain him whats going on. Thus, we do no longer need to check in contextMenu whether a mixture of photos and albums has been selected. This fixes the open bug in #603. --- src/scripts/contextMenu.js | 34 ---------------------------------- src/scripts/multiselect.js | 29 ++++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 39 deletions(-) diff --git a/src/scripts/contextMenu.js b/src/scripts/contextMenu.js index f66666c..3426b7f 100644 --- a/src/scripts/contextMenu.js +++ b/src/scripts/contextMenu.js @@ -69,26 +69,6 @@ const getSubIDs = function(albums, albumID) { } -const countSubAlbums = function(photoIDs) { - - let count = 0 - - if (album.subjson) { - - for (i in photoIDs) { - for (j in album.subjson.albums) { - if (album.subjson.albums[j].id == photoIDs[i]) { - count++ - break - } - } - } - - } - - return count -} - contextMenu = {} contextMenu.add = function(albumID, e) { @@ -280,20 +260,6 @@ contextMenu.photo = function(photoID, e) { contextMenu.photoMulti = function(photoIDs, e) { - let subcount = countSubAlbums(photoIDs) - let photocount = photoIDs.length - subcount - - if (subcount && photocount) { - multiselect.deselect('.photo.active, .album.active') - multiselect.close() - lychee.error('Please select either albums or photos!') - return - } - if (subcount) { - contextMenu.albumMulti(photoIDs, e) - return - } - multiselect.stopResize() // Notice for 'Move All': diff --git a/src/scripts/multiselect.js b/src/scripts/multiselect.js index 615cdf4..35d309b 100644 --- a/src/scripts/multiselect.js +++ b/src/scripts/multiselect.js @@ -11,7 +11,9 @@ const isSelectKeyPressed = function(e) { multiselect = { - ids: [] + ids : [], + albumsSelected : 0, + photosSelected : 0 } @@ -57,9 +59,19 @@ multiselect.addItem = function(object, id) { if (album.isSmartID(id)) return if (multiselect.isSelected(id).selected===true) return + let isAlbum = object.hasClass('album') + if ((isAlbum && multiselect.photosSelected > 0) || + (!isAlbum && multiselect.albumsSelected > 0)) { + lychee.error('Please select either albums or photos!') + return + } + multiselect.ids.push(id) multiselect.select(object) + if (isAlbum) multiselect.albumsSelected++ + else multiselect.photosSelected++ + } multiselect.removeItem = function(object, id) { @@ -71,6 +83,10 @@ multiselect.removeItem = function(object, id) { multiselect.ids.splice(pos, 1) multiselect.deselect(object) + let isAlbum = object.hasClass('album') + if (isAlbum) multiselect.albumsSelected-- + else multiselect.photosSelected-- + } multiselect.albumClick = function(e, albumObj) { @@ -98,7 +114,7 @@ multiselect.albumContextMenu = function(e, albumObj) { if (selected!==false) { contextMenu.albumMulti(multiselect.ids, e) - multiselect.ids = [] + multiselect.clearSelection(false) } else { multiselect.clearSelection() contextMenu.album(album.getID(), e) @@ -113,7 +129,7 @@ multiselect.photoContextMenu = function(e, photoObj) { if (selected!==false) { contextMenu.photoMulti(multiselect.ids, e) - multiselect.ids = [] + multiselect.clearSelection(false) } else { multiselect.clearSelection() contextMenu.photo(photo.getID(), e) @@ -121,10 +137,13 @@ multiselect.photoContextMenu = function(e, photoObj) { } -multiselect.clearSelection = function() { +multiselect.clearSelection = function(deselect = true) { + + if (deselect) multiselect.deselect('.photo.active, .album.active') - multiselect.deselect('.photo.active, .album.active') multiselect.ids = [] + multiselect.albumsSelected = 0 + multiselect.photosSelected = 0 }