Added a move album operation.
Since albums can have subalbums now, it makes sense to not only merge albums, but also move them.
This commit is contained in:
parent
9b5328d888
commit
b91759e6c1
@ -28,6 +28,7 @@ final class Admin extends Access {
|
||||
case 'Album::setPublic': self::setAlbumPublicAction(); break;
|
||||
case 'Album::delete': self::deleteAlbumAction(); break;
|
||||
case 'Album::merge': self::mergeAlbumsAction(); break;
|
||||
case 'Album::move': self::moveAlbumsAction(); break;
|
||||
|
||||
// Photo functions
|
||||
case 'Photo::get': self::getPhotoAction(); break;
|
||||
@ -143,6 +144,14 @@ final class Admin extends Access {
|
||||
|
||||
}
|
||||
|
||||
private static function moveAlbumsAction() {
|
||||
|
||||
Validator::required(isset($_POST['albumIDs']), __METHOD__);
|
||||
$album = new Album($_POST['albumIDs']);
|
||||
Response::json($album->move());
|
||||
|
||||
}
|
||||
|
||||
// Photo functions
|
||||
|
||||
private static function getPhotoAction() {
|
||||
|
@ -665,6 +665,40 @@ final class Album {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
public function move() {
|
||||
|
||||
// Check dependencies
|
||||
Validator::required(isset($this->albumIDs), __METHOD__);
|
||||
|
||||
// Call plugins
|
||||
Plugins::get()->activate(__METHOD__, 0, func_get_args());
|
||||
|
||||
// Convert to array
|
||||
$albumIDs = explode(',', $this->albumIDs);
|
||||
|
||||
// Get first albumID
|
||||
$albumID = array_splice($albumIDs, 0, 1);
|
||||
$albumID = $albumID[0];
|
||||
|
||||
// $albumIDs contains all IDs without the first albumID
|
||||
// Convert to string
|
||||
$filteredIDs = implode(',', $albumIDs);
|
||||
|
||||
// Move albums
|
||||
$query = Database::prepare(Database::get(), "UPDATE ? SET parent = ? WHERE id IN (?)", array(LYCHEE_TABLE_ALBUMS, $albumID, $filteredIDs));
|
||||
$result = Database::execute(Database::get(), $query, __METHOD__, __LINE__);
|
||||
|
||||
// Call plugins
|
||||
Plugins::get()->activate(__METHOD__, 1, func_get_args());
|
||||
|
||||
if ($result===false) return false;
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return boolean Returns true when successful.
|
||||
*/
|
||||
|
@ -635,7 +635,7 @@ album.getArchive = function(albumID) {
|
||||
|
||||
}
|
||||
|
||||
album.merge = function(albumIDs, titles = []) {
|
||||
const getMessage = function(albumIDs, titles, operation) {
|
||||
|
||||
let title = ''
|
||||
let sTitle = ''
|
||||
@ -660,14 +660,20 @@ album.merge = function(albumIDs, titles = []) {
|
||||
// Fallback for second album without a title
|
||||
if (sTitle==='') sTitle = 'Untitled'
|
||||
|
||||
msg = lychee.html`<p>Are you sure you want to merge the album '$${ sTitle }' into the album '$${ title }'?</p>`
|
||||
msg = lychee.html`<p>Are you sure you want to ${ operation } the album '$${ sTitle }' into the album '$${ title }'?</p>`
|
||||
|
||||
} else {
|
||||
|
||||
msg = lychee.html`<p>Are you sure you want to merge all selected albums into the album '$${ title }'?</p>`
|
||||
msg = lychee.html`<p>Are you sure you want to ${ operation } all selected albums into the album '$${ title }'?</p>`
|
||||
|
||||
}
|
||||
|
||||
return msg
|
||||
|
||||
}
|
||||
|
||||
album.merge = function(albumIDs, titles = []) {
|
||||
|
||||
const action = function() {
|
||||
|
||||
basicModal.close()
|
||||
@ -690,7 +696,7 @@ album.merge = function(albumIDs, titles = []) {
|
||||
}
|
||||
|
||||
basicModal.show({
|
||||
body: msg,
|
||||
body: getMessage(albumIDs, titles, 'merge'),
|
||||
buttons: {
|
||||
action: {
|
||||
title: 'Merge Albums',
|
||||
@ -704,4 +710,44 @@ album.merge = function(albumIDs, titles = []) {
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
album.move = function(albumIDs, titles = []) {
|
||||
|
||||
const action = function() {
|
||||
|
||||
basicModal.close()
|
||||
|
||||
let params = {
|
||||
albumIDs: albumIDs.join()
|
||||
}
|
||||
|
||||
api.post('Album::move', params, function(data) {
|
||||
|
||||
if (data!==true) {
|
||||
lychee.error(null, params, data)
|
||||
} else {
|
||||
albums.refresh()
|
||||
lychee.goto()
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
basicModal.show({
|
||||
body: getMessage(albumIDs, titles, 'move'),
|
||||
buttons: {
|
||||
action: {
|
||||
title: 'Move Albums',
|
||||
fn: action,
|
||||
class: 'red'
|
||||
},
|
||||
cancel: {
|
||||
title: "Don't Move",
|
||||
fn: basicModal.close
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
}
|
@ -51,6 +51,24 @@ const getAlbumFrom = function(albums, id) {
|
||||
|
||||
}
|
||||
|
||||
const getSubIDs = function(albums, albumID) {
|
||||
|
||||
let ids = [ albumID ]
|
||||
|
||||
for (a in albums) {
|
||||
if (albums[a].parent==albumID) {
|
||||
|
||||
let sub = getSubIDs(albums, albums[a].id)
|
||||
for (id in sub)
|
||||
ids.push(sub[id])
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return ids
|
||||
|
||||
}
|
||||
|
||||
const countSubAlbums = function(photoIDs) {
|
||||
|
||||
let count = 0
|
||||
@ -123,6 +141,7 @@ contextMenu.album = function(albumID, e) {
|
||||
let items = [
|
||||
{ title: build.iconic('pencil') + 'Rename', fn: () => album.setTitle([ albumID ]) },
|
||||
{ title: build.iconic('collapse-left') + 'Merge', visible: showMerge, fn: () => { basicContext.close(); contextMenu.mergeAlbum(albumID, e) } },
|
||||
{ title: build.iconic('folder') + 'Move', visible: showMerge, fn: () => { basicContext.close(); contextMenu.moveAlbum([ albumID ], e) } },
|
||||
{ title: build.iconic('trash') + 'Delete', fn: () => album.delete([ albumID ]) }
|
||||
]
|
||||
|
||||
@ -147,6 +166,7 @@ contextMenu.albumMulti = function(albumIDs, e) {
|
||||
{ title: build.iconic('pencil') + 'Rename All', fn: () => album.setTitle(albumIDs) },
|
||||
{ title: build.iconic('collapse-left') + 'Merge All', visible: showMerge && autoMerge, fn: () => album.merge(albumIDs) },
|
||||
{ title: build.iconic('collapse-left') + 'Merge', visible: showMerge && !autoMerge, fn: () => { basicContext.close(); contextMenu.mergeAlbum(albumIDs[0], e) } },
|
||||
{ title: build.iconic('folder') + 'Move All', visible: showMerge, fn: () => { basicContext.close(); contextMenu.moveAlbum(albumIDs, e) } },
|
||||
{ title: build.iconic('trash') + 'Delete All', fn: () => album.delete(albumIDs) }
|
||||
]
|
||||
|
||||
@ -210,6 +230,38 @@ contextMenu.mergeAlbum = function(albumID, e) {
|
||||
|
||||
}
|
||||
|
||||
contextMenu.moveAlbum = function(albumIDs, e) {
|
||||
|
||||
api.post('Albums::get', { parent: -1 }, function(data) {
|
||||
|
||||
let items = []
|
||||
|
||||
if (data.albums && data.num>1) {
|
||||
|
||||
let title = albums.getByID(albumIDs[0]).title
|
||||
// Disable all childs
|
||||
// It's not possible to move us into them
|
||||
let exclude = []
|
||||
for (i in albumIDs) {
|
||||
let sub = getSubIDs(data.albums, String(albumIDs[i]))
|
||||
for (s in sub)
|
||||
exclude.push(sub[s])
|
||||
}
|
||||
|
||||
items = buildAlbumList(data.albums, exclude, (a) => album.move([ a.id ].concat(albumIDs), [ a.title, title ]))
|
||||
|
||||
items.unshift({ title: 'Root', fn: () => album.move([ 0 ].concat(albumIDs), [ 'Root', title ]) })
|
||||
|
||||
}
|
||||
|
||||
if (items.length===0) return false
|
||||
|
||||
basicContext.show(items, e.originalEvent, contextMenu.close)
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
contextMenu.photo = function(photoID, e) {
|
||||
|
||||
// Notice for 'Move':
|
||||
|
Loading…
Reference in New Issue
Block a user