ViewPhotoAlbum: build edit menu in controller

This commit is contained in:
2024-01-18 13:18:22 +01:00
parent 24c2e9cdcf
commit 6ec5994de0
3 changed files with 70 additions and 21 deletions

View File

@@ -14,7 +14,7 @@ class PhotosIndex extends Template
protected $show_labels;
protected $previous_header = '';
protected $edit_url_suffix;
protected $edit_menu_items = [];
protected $photo_url_suffix;
const PANORAMA_WIDTH = 1256;
@@ -85,27 +85,24 @@ class PhotosIndex extends Template
protected function editMenu(Image $image)
{
$edit_url = $image->getEditUrl() . $this->edit_url_suffix;
if (empty($this->edit_menu_items))
return;
echo '
<div class="edit dropdown">
<button class="btn btn-primary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="', $edit_url, '">Edit image</a></li>
<li><a class="dropdown-item" href="', $image->getDeleteUrl(), '&',
Session::getSessionTokenKey(), '=', Session::getSessionToken(),
'" onclick="return confirm(\'Are you sure you want to delete this image?\');',
'">Delete image</a></li>
<li><a class="dropdown-item" href="', $edit_url, '&album_cover&',
Session::getSessionTokenKey(), '=', Session::getSessionToken(),
'">Make album cover</a></li>
<li><a class="dropdown-item" href="', $edit_url, '&inc_prio&',
Session::getSessionTokenKey(), '=', Session::getSessionToken(),
'">Increase priority</a></li>
<li><a class="dropdown-item" href="', $edit_url, '&dec_prio&',
Session::getSessionTokenKey(), '=', Session::getSessionToken(),
'">Decrease priority</a></li>
<ul class="dropdown-menu">';
foreach ($this->edit_menu_items as $item)
{
echo '
<li><a class="dropdown-item" href="', $item['uri']($image), '"',
isset($item['onclick']) ? ' onclick="' . $item['onclick'] . '"' : '',
'>', $item['label'], '</a></li>';
}
echo '
</ul>
</div>';
}
@@ -118,7 +115,7 @@ class PhotosIndex extends Template
echo '
<div class="polaroid ', $className, '" style="aspect-ratio: ', $aspectRatio, '">';
if ($this->show_edit_buttons)
if ($this->show_edit_buttons && $image->canBeEditedBy(Registry::get('user')))
$this->editMenu($image);
echo '
@@ -347,9 +344,13 @@ class PhotosIndex extends Template
$this->threePortraits($photos, $altLayout);
}
public function setEditMenuItems(array $items)
{
$this->edit_menu_items = $items;
}
public function setUrlSuffix($suffix)
{
$this->photo_url_suffix = $suffix;
$this->edit_url_suffix = str_replace('?', '&', $suffix);
}
}