Allow regular users to unlink tags from photos.
This commit is contained in:
parent
05c48be785
commit
42e5c7fe37
@ -98,8 +98,19 @@ class ViewPhoto extends HTMLController
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We are!
|
// We are!
|
||||||
$photo->linkTags([(int) $_POST['id_tag']]);
|
if (!isset($_POST['delete']))
|
||||||
echo json_encode(['success' => true]);
|
{
|
||||||
exit;
|
$photo->linkTags([(int) $_POST['id_tag']]);
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ... deleting, that is.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$photo->unlinkTags([(int) $_POST['id_tag']]);
|
||||||
|
echo json_encode(['success' => true]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -588,14 +588,16 @@ a#previous_photo:hover, a#next_photo:hover {
|
|||||||
}
|
}
|
||||||
#sub_photo #tag_list li {
|
#sub_photo #tag_list li {
|
||||||
display: inline;
|
display: inline;
|
||||||
|
padding-right: 0.75em;
|
||||||
}
|
}
|
||||||
#sub_photo #tag_list li:after {
|
#tag_list .delete-tag {
|
||||||
content: ', ';
|
opacity: 0.25;
|
||||||
}
|
}
|
||||||
#sub_photo #tag_list li:last-child:after {
|
#tag_list .delete-tag:hover {
|
||||||
content: '';
|
opacity: 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#photo_exif_box {
|
#photo_exif_box {
|
||||||
background: #fff;
|
background: #fff;
|
||||||
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
|
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
|
||||||
|
@ -148,8 +148,14 @@ class PhotoPage extends SubTemplate
|
|||||||
foreach ($this->photo->getTags() as $tag)
|
foreach ($this->photo->getTags() as $tag)
|
||||||
{
|
{
|
||||||
echo '
|
echo '
|
||||||
<li>
|
<li id="tag-', $tag->id_tag, '">
|
||||||
<a rel="tag" title="View all posts tagged ', $tag->tag, '" href="', $tag->getUrl(), '" class="entry-tag">', $tag->tag, '</a>
|
<a rel="tag" title="View all posts tagged ', $tag->tag, '" href="', $tag->getUrl(), '" class="entry-tag">', $tag->tag, '</a>';
|
||||||
|
|
||||||
|
if ($tag->kind === 'Person')
|
||||||
|
echo '
|
||||||
|
<a class="delete-tag" title="Unlink this tag from this photo" href="#" data-id="', $tag->id_tag, '">❌</a>';
|
||||||
|
|
||||||
|
echo '
|
||||||
</li>';
|
</li>';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,6 +174,28 @@ class PhotoPage extends SubTemplate
|
|||||||
<script type="text/javascript" src="', BASEURL, '/js/autosuggest.js"></script>
|
<script type="text/javascript" src="', BASEURL, '/js/autosuggest.js"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
var removeTag = function(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
console.log(this);
|
||||||
|
console.log("Supposed to remove tag " + this.dataset["id"]);
|
||||||
|
|
||||||
|
var that = this;
|
||||||
|
var request = new HttpRequest("post", "', $this->photo->getPageUrl(), '",
|
||||||
|
"id_tag=" + this.dataset["id"] + "&delete", function(response) {
|
||||||
|
if (!response.success) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var tagNode = document.getElementById("tag-" + that.dataset["id"]);
|
||||||
|
tagNode.parentNode.removeChild(tagNode);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
var tagRemovalTargets = document.getElementsByClassName("delete-tag");
|
||||||
|
Array.forEach(tagRemovalTargets, function(el) {
|
||||||
|
el.addEventListener("click", removeTag);
|
||||||
|
});
|
||||||
|
|
||||||
var tag_autosuggest = new TagAutoSuggest({
|
var tag_autosuggest = new TagAutoSuggest({
|
||||||
inputElement: "new_tag",
|
inputElement: "new_tag",
|
||||||
listElement: "tag_list",
|
listElement: "tag_list",
|
||||||
@ -181,8 +209,19 @@ class PhotoPage extends SubTemplate
|
|||||||
var newLabel = document.createTextNode(item.label);
|
var newLabel = document.createTextNode(item.label);
|
||||||
newLink.appendChild(newLabel);
|
newLink.appendChild(newLabel);
|
||||||
|
|
||||||
|
var removeLink = document.createElement("a");
|
||||||
|
removeLink.className = "delete-tag";
|
||||||
|
removeLink.dataset["id"] = item.id_tag;
|
||||||
|
removeLink.href = "#";
|
||||||
|
removeLink.addEventListener("click", removeTag);
|
||||||
|
|
||||||
|
var crossmark = document.createTextNode("❌");
|
||||||
|
removeLink.appendChild(crossmark);
|
||||||
|
|
||||||
var newNode = document.createElement("li");
|
var newNode = document.createElement("li");
|
||||||
|
newNode.id = "tag-" + item.id_tag;
|
||||||
newNode.appendChild(newLink);
|
newNode.appendChild(newLink);
|
||||||
|
newNode.appendChild(removeLink);
|
||||||
|
|
||||||
var list = document.getElementById("tag_list");
|
var list = document.getElementById("tag_list");
|
||||||
list.appendChild(newNode);
|
list.appendChild(newNode);
|
||||||
|
Loading…
Reference in New Issue
Block a user