add topic moving front end

This commit is contained in:
flash 2016-12-11 02:00:47 +01:00
parent 843342d188
commit 065a39200d
5 changed files with 95 additions and 6 deletions

View file

@ -160,4 +160,14 @@ class ForumController extends Controller
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);
}
}

View file

@ -173,23 +173,26 @@ class TopicController extends Controller
/**
* Move a topic.
* @param int $id
* @throws HttpRouteNotFoundException
* @throws HttpMethodNotAllowedException
* @return string
*/
public function move(int $id): string
{
extract($this->modBase($id));
$dest_forum = new Forum($_REQUEST['forum_id'] ?? 0);
$dest_forum = new Forum($_POST['destination'] ?? 0);
if (!$forum->perms->topicMove
|| $dest_forum->id === 0
|| $dest_forum->perms->view) {
if ($dest_forum->id === 0 || !$dest_forum->perms->view) {
throw new HttpRouteNotFoundException;
}
if (!$forum->perms->topicMove) {
throw new HttpMethodNotAllowedException;
}
$topic->move($dest_forum->id);
return redirect(route('forums.topic', $topic->id));
return route('forums.topic', $topic->id);
}
/**

View file

@ -7,6 +7,9 @@
{% 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>
{% 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 %}
<a class="input__button" title="Restore" href="{{ route('forums.topic.restore', topic.id) }}?session={{ session_id() }}"><span class="fa fa-history"></span></a>
{% endif %}

View file

@ -29,6 +29,8 @@
{% endif %}
{% if forum.perms.topicMove %}
{% set forumMove = true %}
{% if topic.oldForum %}
{% set forumRestore = true %}
{% endif %}
@ -55,6 +57,7 @@
function deletePost(id) {
var confirm = new Sakura.Dialogue;
confirm.SetType(Sakura.DialogueType.Confirm);
confirm.Title = "Deleting post " + id;
confirm.Text = "Are you sure?";
confirm.AddCallback(Sakura.DialogueButton.Yes, function () {
var deleter = new Sakura.AJAX;
@ -74,6 +77,75 @@
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();
</script>
{% endblock %}

View file

@ -104,12 +104,13 @@ Router::group(['before' => 'maintenance'], function () {
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}/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');
});
// Forum
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}/mark', 'Forum.ForumController@markRead', 'forums.mark');
Router::get('/{id:i}/new', 'Forum.TopicController@create', 'forums.new');