Merge pull request #611 from hrniels/multiselect
Improvements to selection feature.
This commit is contained in:
commit
ab3a5a4d63
@ -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 = {}
|
||||||
|
|
||||||
contextMenu.add = function(albumID, e) {
|
contextMenu.add = function(albumID, e) {
|
||||||
@ -280,20 +260,6 @@ contextMenu.photo = function(photoID, e) {
|
|||||||
|
|
||||||
contextMenu.photoMulti = function(photoIDs, 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()
|
multiselect.stopResize()
|
||||||
|
|
||||||
// Notice for 'Move All':
|
// Notice for 'Move All':
|
||||||
|
@ -3,9 +3,17 @@
|
|||||||
* @copyright 2015 by Tobias Reich
|
* @copyright 2015 by Tobias Reich
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const isSelectKeyPressed = function(e) {
|
||||||
|
|
||||||
|
return e.metaKey || e.ctrlKey
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
multiselect = {
|
multiselect = {
|
||||||
|
|
||||||
ids: []
|
ids : [],
|
||||||
|
albumsSelected : 0,
|
||||||
|
photosSelected : 0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,9 +59,19 @@ multiselect.addItem = function(object, id) {
|
|||||||
if (album.isSmartID(id)) return
|
if (album.isSmartID(id)) return
|
||||||
if (multiselect.isSelected(id).selected===true) 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.ids.push(id)
|
||||||
multiselect.select(object)
|
multiselect.select(object)
|
||||||
|
|
||||||
|
if (isAlbum) multiselect.albumsSelected++
|
||||||
|
else multiselect.photosSelected++
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
multiselect.removeItem = function(object, id) {
|
multiselect.removeItem = function(object, id) {
|
||||||
@ -65,14 +83,18 @@ multiselect.removeItem = function(object, id) {
|
|||||||
multiselect.ids.splice(pos, 1)
|
multiselect.ids.splice(pos, 1)
|
||||||
multiselect.deselect(object)
|
multiselect.deselect(object)
|
||||||
|
|
||||||
|
let isAlbum = object.hasClass('album')
|
||||||
|
if (isAlbum) multiselect.albumsSelected--
|
||||||
|
else multiselect.photosSelected--
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
multiselect.albumClick = function(e, albumObj) {
|
multiselect.albumClick = function(e, albumObj) {
|
||||||
|
|
||||||
let id = albumObj.attr('data-id')
|
let id = albumObj.attr('data-id')
|
||||||
|
|
||||||
if (e.metaKey===true) multiselect.toggleItem(albumObj, id)
|
if (isSelectKeyPressed(e)) multiselect.toggleItem(albumObj, id)
|
||||||
else lychee.goto(id)
|
else lychee.goto(id)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,8 +102,8 @@ multiselect.photoClick = function(e, photoObj) {
|
|||||||
|
|
||||||
let id = photoObj.attr('data-id')
|
let id = photoObj.attr('data-id')
|
||||||
|
|
||||||
if (e.metaKey===true) multiselect.toggleItem(photoObj, id)
|
if (isSelectKeyPressed(e)) multiselect.toggleItem(photoObj, id)
|
||||||
else lychee.goto(album.getID() + '/' + id)
|
else lychee.goto(album.getID() + '/' + id)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,9 +112,9 @@ multiselect.albumContextMenu = function(e, albumObj) {
|
|||||||
let id = albumObj.attr('data-id')
|
let id = albumObj.attr('data-id')
|
||||||
let selected = multiselect.isSelected(id).selected
|
let selected = multiselect.isSelected(id).selected
|
||||||
|
|
||||||
if (selected===false) {
|
if (selected!==false) {
|
||||||
contextMenu.albumMulti(multiselect.ids, e)
|
contextMenu.albumMulti(multiselect.ids, e)
|
||||||
multiselect.ids = []
|
multiselect.clearSelection(false)
|
||||||
} else {
|
} else {
|
||||||
multiselect.clearSelection()
|
multiselect.clearSelection()
|
||||||
contextMenu.album(album.getID(), e)
|
contextMenu.album(album.getID(), e)
|
||||||
@ -105,9 +127,9 @@ multiselect.photoContextMenu = function(e, photoObj) {
|
|||||||
let id = photoObj.attr('data-id')
|
let id = photoObj.attr('data-id')
|
||||||
let selected = multiselect.isSelected(id).selected
|
let selected = multiselect.isSelected(id).selected
|
||||||
|
|
||||||
if (selected===false) {
|
if (selected!==false) {
|
||||||
contextMenu.photoMulti(multiselect.ids, e)
|
contextMenu.photoMulti(multiselect.ids, e)
|
||||||
multiselect.ids = []
|
multiselect.clearSelection(false)
|
||||||
} else {
|
} else {
|
||||||
multiselect.clearSelection()
|
multiselect.clearSelection()
|
||||||
contextMenu.photo(photo.getID(), e)
|
contextMenu.photo(photo.getID(), e)
|
||||||
@ -115,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.ids = []
|
||||||
|
multiselect.albumsSelected = 0
|
||||||
|
multiselect.photosSelected = 0
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -251,7 +276,7 @@ multiselect.getSelection = function(e) {
|
|||||||
if (visible.contextMenu()) return false
|
if (visible.contextMenu()) return false
|
||||||
if (!visible.multiselect()) return false
|
if (!visible.multiselect()) return false
|
||||||
|
|
||||||
if (e.metaKey===false && (size.width==0 || size.height==0)) {
|
if (!isSelectKeyPressed(e) && (size.width==0 || size.height==0)) {
|
||||||
multiselect.close()
|
multiselect.close()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user