diff --git a/public_html/media/js/post-list.js b/public_html/media/js/post-list.js index d3f5d016..885588bb 100644 --- a/public_html/media/js/post-list.js +++ b/public_html/media/js/post-list.js @@ -15,14 +15,18 @@ $(function() return; aDom.addClass('inactive'); + var enable = !aDom.parents('.post').hasClass('tagged'); var url = $(this).attr('href') + '?json'; + url = url.replace('_enable_', enable ? '1' : '0'); $.get(url, {submit: 1}).always(function(data) { if (data['success']) { aDom.removeClass('inactive'); - aDom.parents('.post').toggleClass('tagged'); - aDom.text(aDom.parents('.post').hasClass('tagged') + aDom.parents('.post').removeClass('tagged'); + if (enable) + aDom.parents('.post').addClass('tagged'); + aDom.text(enable ? aDom.attr('data-text-tagged') : aDom.attr('data-text-untagged')); } diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index f0bbad38..56bc69d7 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -120,10 +120,11 @@ class PostController /** - * @route /post/{id}/toggle-tag/{tag} + * @route /post/{id}/toggle-tag/{tag}/{enable} * @validate tag [^\/]* + * @validate enable 0|1 */ - public function toggleTagAction($id, $tag) + public function toggleTagAction($id, $tag, $enable) { $post = Model_Post::locate($id); $this->context->transport->post = $post; @@ -137,12 +138,12 @@ class PostController PrivilegesHelper::confirmWithException(Privilege::MassTag); $tags = array_map(function($x) { return $x->name; }, $post->sharedTag); - if (in_array($tag, $tags)) + if (!$enable and in_array($tag, $tags)) { $tags = array_diff($tags, [$tag]); LogHelper::log('{user} untagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]); } - else + elseif ($enable) { $tags += [$tag]; LogHelper::log('{user} tagged {post} with {tag}', ['post' => TextHelper::reprPost($post), 'tag' => TextHelper::reprTag($tag)]); diff --git a/src/Views/post-small.phtml b/src/Views/post-small.phtml index 3203ac15..f6532aea 100644 --- a/src/Views/post-small.phtml +++ b/src/Views/post-small.phtml @@ -9,7 +9,7 @@