add topic moving front end
This commit is contained in:
parent
843342d188
commit
065a39200d
5 changed files with 95 additions and 6 deletions
|
@ -160,4 +160,14 @@ class ForumController extends Controller
|
||||||
|
|
||||||
return redirect(route('forums.forum', $forum->id));
|
return redirect(route('forums.forum', $forum->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function moveDestinations(): string
|
||||||
|
{
|
||||||
|
$forums = array_column(DB::table('forums')
|
||||||
|
->where('forum_type', 0)
|
||||||
|
->where('forum_id', '!=', config('forum.trash'))
|
||||||
|
->get(['forum_id', 'forum_name']), 'forum_name', 'forum_id');
|
||||||
|
|
||||||
|
return $this->json($forums);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,23 +173,26 @@ class TopicController extends Controller
|
||||||
/**
|
/**
|
||||||
* Move a topic.
|
* Move a topic.
|
||||||
* @param int $id
|
* @param int $id
|
||||||
|
* @throws HttpRouteNotFoundException
|
||||||
* @throws HttpMethodNotAllowedException
|
* @throws HttpMethodNotAllowedException
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function move(int $id): string
|
public function move(int $id): string
|
||||||
{
|
{
|
||||||
extract($this->modBase($id));
|
extract($this->modBase($id));
|
||||||
$dest_forum = new Forum($_REQUEST['forum_id'] ?? 0);
|
$dest_forum = new Forum($_POST['destination'] ?? 0);
|
||||||
|
|
||||||
if (!$forum->perms->topicMove
|
if ($dest_forum->id === 0 || !$dest_forum->perms->view) {
|
||||||
|| $dest_forum->id === 0
|
throw new HttpRouteNotFoundException;
|
||||||
|| $dest_forum->perms->view) {
|
}
|
||||||
|
|
||||||
|
if (!$forum->perms->topicMove) {
|
||||||
throw new HttpMethodNotAllowedException;
|
throw new HttpMethodNotAllowedException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$topic->move($dest_forum->id);
|
$topic->move($dest_forum->id);
|
||||||
|
|
||||||
return redirect(route('forums.topic', $topic->id));
|
return route('forums.topic', $topic->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,6 +7,9 @@
|
||||||
{% if forumLock is defined %}
|
{% if forumLock is defined %}
|
||||||
<a class="input__button" title="{{ forumLock ? 'Unlock' : 'Lock' }}" href="{{ route('forums.topic.lock', topic.id) }}?session={{ session_id() }}"><span class="fa fa-{{ forumLock ? 'unlock' : 'lock' }}"></span></a>
|
<a class="input__button" title="{{ forumLock ? 'Unlock' : 'Lock' }}" href="{{ route('forums.topic.lock', topic.id) }}?session={{ session_id() }}"><span class="fa fa-{{ forumLock ? 'unlock' : 'lock' }}"></span></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if forumMove is defined %}
|
||||||
|
<a class="input__button" title="Move" href="javascript:void(0)" onclick="yuunoMoveTopic()" id="topic-move-btn"><span class="fa fa-arrow-circle-o-right"></span></a>
|
||||||
|
{% endif %}
|
||||||
{% if forumRestore is defined %}
|
{% if forumRestore is defined %}
|
||||||
<a class="input__button" title="Restore" href="{{ route('forums.topic.restore', topic.id) }}?session={{ session_id() }}"><span class="fa fa-history"></span></a>
|
<a class="input__button" title="Restore" href="{{ route('forums.topic.restore', topic.id) }}?session={{ session_id() }}"><span class="fa fa-history"></span></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if forum.perms.topicMove %}
|
{% if forum.perms.topicMove %}
|
||||||
|
{% set forumMove = true %}
|
||||||
|
|
||||||
{% if topic.oldForum %}
|
{% if topic.oldForum %}
|
||||||
{% set forumRestore = true %}
|
{% set forumRestore = true %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -55,6 +57,7 @@
|
||||||
function deletePost(id) {
|
function deletePost(id) {
|
||||||
var confirm = new Sakura.Dialogue;
|
var confirm = new Sakura.Dialogue;
|
||||||
confirm.SetType(Sakura.DialogueType.Confirm);
|
confirm.SetType(Sakura.DialogueType.Confirm);
|
||||||
|
confirm.Title = "Deleting post " + id;
|
||||||
confirm.Text = "Are you sure?";
|
confirm.Text = "Are you sure?";
|
||||||
confirm.AddCallback(Sakura.DialogueButton.Yes, function () {
|
confirm.AddCallback(Sakura.DialogueButton.Yes, function () {
|
||||||
var deleter = new Sakura.AJAX;
|
var deleter = new Sakura.AJAX;
|
||||||
|
@ -74,6 +77,75 @@
|
||||||
confirm.Display();
|
confirm.Display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{% if forumMove is defined %}
|
||||||
|
function yuunoMoveTopic() {
|
||||||
|
var btn = Sakura.DOM.ID('topic-move-btn'),
|
||||||
|
moveDiag = new Sakura.Dialogue,
|
||||||
|
client = new Sakura.AJAX,
|
||||||
|
title = "Moving topic '{{ topic.title }}'",
|
||||||
|
unsetSpinner = function () {
|
||||||
|
Sakura.DOM.RemoveClass(btn, ['input__button--disabled']);
|
||||||
|
btn.innerHTML = '<i class="fa fa-arrow-circle-o-right"></i>';
|
||||||
|
};
|
||||||
|
|
||||||
|
Sakura.DOM.AddClass(btn, ['input__button--disabled']);
|
||||||
|
btn.innerHTML = '<i class="fa fa-spinner fa-spin"></i>';
|
||||||
|
|
||||||
|
moveDiag.Title = title;
|
||||||
|
|
||||||
|
client.SetUrl("{{ route('forums.move-destinations') }}");
|
||||||
|
client.AddCallback(200, function () {
|
||||||
|
unsetSpinner();
|
||||||
|
|
||||||
|
moveDiag.SetType(Sakura.DialogueType.OKCancel);
|
||||||
|
moveDiag.Text = "Select a destination...";
|
||||||
|
moveDiag.DropDownItems.AddObject(client.JSON());
|
||||||
|
moveDiag.AddCallback(Sakura.DialogueButton.Ok, function () {
|
||||||
|
var returnDiag = new Sakura.Dialogue;
|
||||||
|
|
||||||
|
client.Reset();
|
||||||
|
client.SetUrl("{{ route('forums.topic.move', topic.id) }}");
|
||||||
|
client.Form();
|
||||||
|
client.SetSend({
|
||||||
|
"session": Sakura.Config.SessionId,
|
||||||
|
"destination": moveDiag.DropDownSelected.Key
|
||||||
|
});
|
||||||
|
|
||||||
|
client.AddCallback(200, function () {
|
||||||
|
window.location.assign(client.Response());
|
||||||
|
});
|
||||||
|
client.AddCallback(404, function () {
|
||||||
|
returnDiag.Title = "Error";
|
||||||
|
returnDiag.Text = "Destination forum doesn't exist!";
|
||||||
|
returnDiag.Display();
|
||||||
|
});
|
||||||
|
client.AddCallback(403, function () {
|
||||||
|
returnDiag.Title = "Error";
|
||||||
|
returnDiag.Text = "You aren't allowed to move topics!";
|
||||||
|
returnDiag.Display();
|
||||||
|
});
|
||||||
|
client.AddCallback(0, function () {
|
||||||
|
returnDiag.Title = "Something happened!";
|
||||||
|
returnDiag.Text = "Something happened!";
|
||||||
|
returnDiag.Display();
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Start(Sakura.HTTPMethod.POST);
|
||||||
|
moveDiag.Close();
|
||||||
|
});
|
||||||
|
moveDiag.Display();
|
||||||
|
});
|
||||||
|
client.AddCallback(0, function () {
|
||||||
|
unsetSpinner();
|
||||||
|
|
||||||
|
moveDiag.Text = "Failed to fetch destinations.";
|
||||||
|
moveDiag.Display();
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Start(Sakura.HTTPMethod.GET);
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
hljs.initHighlightingOnLoad();
|
hljs.initHighlightingOnLoad();
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -104,12 +104,13 @@ Router::group(['before' => 'maintenance'], function () {
|
||||||
Router::get('/{id:i}/lock', 'Forum.TopicController@lock', 'forums.topic.lock');
|
Router::get('/{id:i}/lock', 'Forum.TopicController@lock', 'forums.topic.lock');
|
||||||
Router::get('/{id:i}/delete', 'Forum.TopicController@delete', 'forums.topic.delete');
|
Router::get('/{id:i}/delete', 'Forum.TopicController@delete', 'forums.topic.delete');
|
||||||
Router::get('/{id:i}/restore', 'Forum.TopicController@restore', 'forums.topic.restore');
|
Router::get('/{id:i}/restore', 'Forum.TopicController@restore', 'forums.topic.restore');
|
||||||
Router::get('/{id:i}/move', 'Forum.TopicController@move', 'forums.topic.move');
|
Router::post('/{id:i}/move', 'Forum.TopicController@move', 'forums.topic.move');
|
||||||
Router::post('/{id:i}/reply', 'Forum.TopicController@reply', 'forums.topic.reply');
|
Router::post('/{id:i}/reply', 'Forum.TopicController@reply', 'forums.topic.reply');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Forum
|
// Forum
|
||||||
Router::get('/', 'Forum.ForumController@index', 'forums.index');
|
Router::get('/', 'Forum.ForumController@index', 'forums.index');
|
||||||
|
Router::get('/move-destinations', 'Forum.ForumController@moveDestinations', 'forums.move-destinations');
|
||||||
Router::get('/{id:i}', 'Forum.ForumController@forum', 'forums.forum');
|
Router::get('/{id:i}', 'Forum.ForumController@forum', 'forums.forum');
|
||||||
Router::get('/{id:i}/mark', 'Forum.ForumController@markRead', 'forums.mark');
|
Router::get('/{id:i}/mark', 'Forum.ForumController@markRead', 'forums.mark');
|
||||||
Router::get('/{id:i}/new', 'Forum.TopicController@create', 'forums.new');
|
Router::get('/{id:i}/new', 'Forum.TopicController@create', 'forums.new');
|
||||||
|
|
Reference in a new issue