ViewPhotoAlbum: build edit menu in controller
This commit is contained in:
@@ -59,7 +59,6 @@ class ViewPhotoAlbum extends HTMLController
|
||||
$this->page->adopt($header_box);
|
||||
|
||||
// Can we do fancy things here?
|
||||
// !!! TODO: permission system?
|
||||
$buttons = $this->getAlbumButtons($id_tag, $tag ?? null);
|
||||
if (!empty($buttons))
|
||||
$this->page->adopt(new AlbumButtonBox($buttons));
|
||||
@@ -78,8 +77,12 @@ class ViewPhotoAlbum extends HTMLController
|
||||
{
|
||||
$index = new PhotosIndex($mosaic, Registry::get('user')->isAdmin());
|
||||
$this->page->adopt($index);
|
||||
if ($id_tag > 1)
|
||||
$index->setUrlSuffix('?in=' . $id_tag);
|
||||
|
||||
$url_suffix = $id_tag > 1 ? 'in=' . $id_tag : '';
|
||||
$index->setUrlSuffix('?' . $url_suffix);
|
||||
|
||||
$menu_items = $this->getEditMenuItems('&' . $url_suffix);
|
||||
$index->setEditMenuItems($menu_items);
|
||||
}
|
||||
|
||||
// Make a page index as needed, while we're at it.
|
||||
@@ -198,6 +201,46 @@ class ViewPhotoAlbum extends HTMLController
|
||||
return $buttons;
|
||||
}
|
||||
|
||||
private function getEditMenuItems($url_suffix)
|
||||
{
|
||||
$items = [];
|
||||
$sess = '&' . Session::getSessionTokenKey() . '=' . Session::getSessionToken();
|
||||
|
||||
if (Registry::get('user')->isLoggedIn())
|
||||
{
|
||||
$items[] = [
|
||||
'label' => 'Edit image',
|
||||
'uri' => fn($image) => $image->getEditUrl() . $url_suffix,
|
||||
];
|
||||
|
||||
$items[] = [
|
||||
'label' => 'Delete image',
|
||||
'uri' => fn($image) => $image->getDeleteUrl() . $url_suffix . $sess,
|
||||
'onclick' => 'return confirm(\'Are you sure you want to delete this image?\');',
|
||||
];
|
||||
}
|
||||
|
||||
if (Registry::get('user')->isAdmin())
|
||||
{
|
||||
$items[] = [
|
||||
'label' => 'Make album cover',
|
||||
'uri' => fn($image) => $image->getEditUrl() . $url_suffix . '&album_cover' . $sess,
|
||||
];
|
||||
|
||||
$items[] = [
|
||||
'label' => 'Increase priority',
|
||||
'uri' => fn($image) => $image->getEditUrl() . $url_suffix . '&inc_prio' . $sess,
|
||||
];
|
||||
|
||||
$items[] = [
|
||||
'label' => 'Decrease priority',
|
||||
'uri' => fn($image) => $image->getEditUrl() . $url_suffix . '&dec_prio' . $sess,
|
||||
];
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
if (isset($this->iterator))
|
||||
|
||||
Reference in New Issue
Block a user