Merge pull request #340 from rhurling/feature/166-merge-albums

Merge Albums feature
pull/341/head
Tobias Reich 9 years ago
commit e2399a1794

12
dist/main.js vendored

File diff suppressed because one or more lines are too long

2
dist/view.js vendored

File diff suppressed because one or more lines are too long

@ -22,6 +22,7 @@ class Admin extends Access {
case 'Album::setDescription': $this->setAlbumDescription(); break;
case 'Album::setPublic': $this->setAlbumPublic(); break;
case 'Album::delete': $this->deleteAlbum(); break;
case 'Album::merge': $this->mergeAlbums(); break;
# Photo functions
case 'Photo::get': $this->getPhoto(); break;
@ -123,6 +124,12 @@ class Admin extends Access {
}
private function mergeAlbums() {
Module::dependencies(isset($_POST['albumIDs']));
$album = new Album($this->database, $this->plugins, $this->settings, $_POST['albumIDs']);
echo $album->merge();
}
# Photo functions
private function getPhoto() {

@ -715,6 +715,40 @@ class Album extends Module {
}
public function merge() {
# Check dependencies
self::dependencies(isset($this->database, $this->albumIDs));
# Call plugins
$this->plugins(__METHOD__, 0, func_get_args());
$albumIDs = explode(',', $this->albumIDs);
$albumID = array_splice($albumIDs, 0, 1)[0];
$inQuery = implode(',', array_fill(0, count($albumIDs), '?'));
$data = array_merge(array(LYCHEE_TABLE_PHOTOS, $albumID), $albumIDs);
$merge_query = Database::prepare($this->database, "UPDATE ? SET album = ? WHERE album IN ($inQuery)", $data);
$merge_result = $this->database->query($merge_query);
if (!$merge_result) {
Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
return false;
}
$data = array_merge( array(LYCHEE_TABLE_ALBUMS), $albumIDs);
$delete_query = Database::prepare($this->database, "DELETE FROM ? WHERE id IN ($inQuery)", $data);
$delete_result = $this->database->query($delete_query);
if (!$delete_result) {
Log::error($this->database, __METHOD__, __LINE__, $this->database->error);
return false;
}
return true;
}
}
?>

@ -567,4 +567,44 @@ album.getArchive = function(albumID) {
location.href = link;
}
album.merge = function(albumIDs) {
var action = {}
action.fn = 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.json = null
albums.load()
}
})
}
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
}
}
});
}

@ -61,6 +61,7 @@ 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: build.iconic('trash') + 'Delete All', fn: function() { album.delete(albumIDs) } }
];

Loading…
Cancel
Save