dynamic post deletion
This commit is contained in:
parent
1c0ad653b2
commit
a6069caaa4
6 changed files with 38 additions and 10 deletions
|
@ -215,15 +215,9 @@ class PostController extends Controller
|
|||
if ($topic->replyCount() === 1) {
|
||||
// Delete the entire topic
|
||||
$topic->delete();
|
||||
|
||||
$redirect = route('forums.forum', $forum->id);
|
||||
} else {
|
||||
// Just delete the post (replace this with soft deleting)
|
||||
$post->purge();
|
||||
|
||||
$redirect = route('forums.topic', $topic->id);
|
||||
}
|
||||
|
||||
redirect($redirect);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
border: 0 solid transparent;
|
||||
padding: 2px 4px;
|
||||
cursor: pointer;
|
||||
margin-left: 2px;
|
||||
|
||||
&:last-child {
|
||||
font-weight: 700;
|
||||
|
|
|
@ -6,6 +6,7 @@ namespace Sakura
|
|||
private Type: DialogueType = DialogueType.Info;
|
||||
private Callbacks: Dictionary<DialogueButton, Function> = new Dictionary<DialogueButton, Function>();
|
||||
public static Container: string = "dialogues";
|
||||
public Reference: HTMLDivElement;
|
||||
|
||||
public SetType(type: DialogueType): void
|
||||
{
|
||||
|
@ -62,6 +63,13 @@ namespace Sakura
|
|||
DOM.Append(container, buttonCont);
|
||||
|
||||
DOM.Append(DOM.ID('dialogues'), container);
|
||||
this.Reference = container;
|
||||
}
|
||||
|
||||
public Close(): void
|
||||
{
|
||||
DOM.Remove(this.Reference);
|
||||
this.Reference = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
/// <reference path="Yuuno/Busy.ts" />
|
||||
/// <reference path="Yuuno/BusyMode.ts" />
|
||||
/// <reference path="Yuuno/Editor.ts" />
|
||||
/// <reference path="Yuuno/Main.ts" />
|
||||
/// <reference path="Yuuno/Notifications.ts" />
|
||||
/// <reference path="Yuuno/Ybabstat.ts" />
|
||||
|
|
|
@ -62,6 +62,33 @@
|
|||
{% block js %}
|
||||
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.5.0/highlight.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
function deletePost(id) {
|
||||
var confirm = new Sakura.Dialogue;
|
||||
confirm.SetType(Sakura.DialogueType.Confirm);
|
||||
confirm.Text = "Are you sure?";
|
||||
confirm.AddCallback(Sakura.DialogueButton.Yes, function () {
|
||||
var deleter = new Sakura.AJAX;
|
||||
deleter.SetUrl("{{ route('forums.post.delete', 1) }}".replace('1', id));
|
||||
deleter.AddCallback(200, function () {
|
||||
Sakura.DOM.Remove(Sakura.DOM.ID('p' + id));
|
||||
});
|
||||
deleter.AddCallback(0, function () {
|
||||
var error = new Sakura.Dialogue;
|
||||
error.Text = "Deletion failed!";
|
||||
error.AddCallback(Sakura.DialogueButton.Ok, function () {
|
||||
this.Close();
|
||||
});
|
||||
error.Display();
|
||||
});
|
||||
deleter.Start(Sakura.HTTPMethod.DELETE);
|
||||
this.Close();
|
||||
});
|
||||
confirm.AddCallback(Sakura.DialogueButton.No, function () {
|
||||
this.Close();
|
||||
});
|
||||
confirm.Display();
|
||||
}
|
||||
|
||||
hljs.initHighlightingOnLoad();
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
@ -93,7 +120,7 @@
|
|||
<a class="fa fa-pencil-square-o" title="Edit this post" href="javascript:void(0);" onclick="editPost({{ post.id }});"></a>
|
||||
{% endif %}
|
||||
{% if (user.id == post.poster.id and forum.permission(constant('Sakura\\Perms\\Forum::DELETE_OWN'), user.id)) or forum.permission(constant('Sakura\\Perms\\Forum::DELETE_ANY'), user.id) %}
|
||||
<a class="fa fa-trash" title="Delete this post" href="{{ route('forums.post.delete', post.id) }}"></a>
|
||||
<a class="fa fa-trash" title="Delete this post" href="javascript:;" onclick="deletePost({{ post.id }})"></a>
|
||||
{% endif %}
|
||||
{% if not (post.poster.permission(constant('Sakura\\Perms\\Site::DEACTIVATED')) or post.poster.permission(constant('Sakura\\Perms\\Site::RESTRICTED')) or user.id == post.poster.id) %}
|
||||
<a class="fa fa-{% if user.isFriends(post.poster.id) == 2 %}heart{% else %}star{% endif %} friend-{{ post.poster.id }}-level" title="You are friends" {% if user.isFriends(post.poster.id) == 0 %}style="display: none;"{% endif %}></a>
|
||||
|
|
|
@ -124,9 +124,8 @@ Routerv1::group(['before' => 'maintenance'], function () {
|
|||
Routerv1::group(['prefix' => 'post'], function () {
|
||||
Routerv1::get('/{id:i}', 'Forum.PostController@find', 'forums.post');
|
||||
Routerv1::group(['before' => 'loginCheck'], function () {
|
||||
Routerv1::delete('/{id:i}', 'Forum.PostController@delete', 'forums.post.delete');
|
||||
Routerv1::get('/{id:i}/raw', 'Forum.PostController@raw', 'forums.post.raw');
|
||||
Routerv1::get('/{id:i}/delete', 'Forum.PostController@delete', 'forums.post.delete');
|
||||
Routerv1::post('/{id:i}/delete', 'Forum.PostController@delete', 'forums.post.delete');
|
||||
Routerv1::post('/{id:i}/edit', 'Forum.PostController@edit', 'forums.post.edit');
|
||||
});
|
||||
});
|
||||
|
|
Reference in a new issue