Mass tag: fixed concurrent tag toggling
This commit is contained in:
parent
9819416f35
commit
505fe1bac3
3 changed files with 12 additions and 7 deletions
|
@ -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'));
|
||||
}
|
||||
|
|
|
@ -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)]);
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<div class="<?php echo implode(' ', $classNames) ?>">
|
||||
<?php if ($masstag): ?>
|
||||
<a class="toggle-tag" href="<?php echo \Chibi\UrlHelper::route('post', 'toggle-tag', ['id' => $this->context->post->id, 'tag' => $this->context->additionalInfo]) ?>" data-text-tagged="Tagged" data-text-untagged="Untagged">
|
||||
<a class="toggle-tag" href="<?php echo \Chibi\UrlHelper::route('post', 'toggle-tag', ['id' => $this->context->post->id, 'tag' => $this->context->additionalInfo, 'enable' => '_enable_']) ?>" data-text-tagged="Tagged" data-text-untagged="Untagged">
|
||||
<?php echo in_array('tagged', $classNames) ? 'Tagged' : 'Untagged' ?>
|
||||
</a>
|
||||
<?php endif ?>
|
||||
|
|
Loading…
Reference in a new issue