Commit 2f64da625ef0e28aa7c92f41be0e9bb10febfb37
1 parent
bfc4ec8f
Exists in
master
and in
3 other branches
Adding comment deletion
Showing
6 changed files
with
78 additions
and
3 deletions
Show diff stats
amadeus/static/css/base/amadeus.css
... | ... | @@ -1026,7 +1026,7 @@ li.item .notify_badge { |
1026 | 1026 | margin: 0; |
1027 | 1027 | } |
1028 | 1028 | |
1029 | -.post .post-user .btn-group .dropdown-menu a { | |
1029 | +.post .post-user .btn-group .dropdown-menu a, .comment .comment-user .btn-group .dropdown-menu a { | |
1030 | 1030 | cursor: pointer; |
1031 | 1031 | } |
1032 | 1032 | ... | ... |
amadeus/static/js/mural.js
... | ... | @@ -268,4 +268,47 @@ function setCommentFormSubmit(post, comment = "") { |
268 | 268 | |
269 | 269 | return false; |
270 | 270 | }); |
271 | +} | |
272 | + | |
273 | +function deleteComment(btn) { | |
274 | + var url = btn.data('url'); | |
275 | + var comment = btn.data('id'); | |
276 | + | |
277 | + console.log(comment); | |
278 | + | |
279 | + $.ajax({ | |
280 | + url: url, | |
281 | + success: function (data) { | |
282 | + $('#post-modal-form').html(data); | |
283 | + | |
284 | + setCommentDeleteSubmit(comment); | |
285 | + | |
286 | + $('#post-modal-form').modal('show'); | |
287 | + } | |
288 | + }); | |
289 | +} | |
290 | + | |
291 | +function setCommentDeleteSubmit (comment) { | |
292 | + var frm = $("#delete_form"); | |
293 | + | |
294 | + frm.submit(function () { | |
295 | + $.ajax({ | |
296 | + type: frm.attr('method'), | |
297 | + url: frm.attr('action'), | |
298 | + data: frm.serialize(), | |
299 | + success: function (response) { | |
300 | + | |
301 | + $("#comment-" + comment).remove(); | |
302 | + | |
303 | + $('#post-modal-form').modal('hide'); | |
304 | + | |
305 | + alertify.success(response.msg); | |
306 | + }, | |
307 | + error: function (data) { | |
308 | + console.log(data); | |
309 | + } | |
310 | + }); | |
311 | + | |
312 | + return false; | |
313 | + }); | |
271 | 314 | } |
272 | 315 | \ No newline at end of file | ... | ... |
mural/templates/mural/_view_comment.html
... | ... | @@ -21,7 +21,7 @@ |
21 | 21 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
22 | 22 | <li><a onclick="editComment($(this));" data-url="{% url 'mural:update_comment' comment.id %}" data-id="{{ comment.id }}" data-post="{{ comment.post.id }}"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> {% trans 'Edit' %}</a></li> |
23 | 23 | <li> |
24 | - <a onclick="deletePost($(this))" aria-hidden="true"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
24 | + <a onclick="deleteComment($(this))" data-url="{% url 'mural:delete_comment' comment.id %}" data-id="{{ comment.id }}" aria-hidden="true"><i class="fa fa-trash fa-fw" aria-hidden="true"></i> {% trans 'Remove' %}</a></li> | |
25 | 25 | </ul> |
26 | 26 | </span> |
27 | 27 | {% endif %} | ... | ... |
mural/templates/mural/delete.html
... | ... | @@ -5,7 +5,7 @@ |
5 | 5 | <div class="modal-body"> |
6 | 6 | <form id="delete_form" action="{{ form_url }}" method="post"> |
7 | 7 | {% csrf_token %} |
8 | - <h4>{% trans 'Are you sure you want to delete this post' %}?</h4> | |
8 | + <h4>{{ message }}</h4> | |
9 | 9 | </form> |
10 | 10 | </div> |
11 | 11 | <div class="modal-footer"> | ... | ... |
mural/urls.py
... | ... | @@ -10,6 +10,8 @@ urlpatterns = [ |
10 | 10 | url(r'^deleted/$', views.deleted_post, name='deleted_post'), |
11 | 11 | url(r'^comment/(?P<post>[\w_-]+)/$', views.CommentCreate.as_view(), name='create_comment'), |
12 | 12 | url(r'^update_comment/(?P<pk>[\w_-]+)/$', views.CommentUpdate.as_view(), name='update_comment'), |
13 | + url(r'^delete_comment/(?P<pk>[\w_-]+)/$', views.CommentDelete.as_view(), name='delete_comment'), | |
14 | + url(r'^deleted_comment/$', views.deleted_comment, name='deleted_comment'), | |
13 | 15 | url(r'^render_comment/([\w_-]+)/([\w_-]+)/$', views.render_comment, name='render_comment'), |
14 | 16 | url(r'^render_post/([\w_-]+)/([\w_-]+)/$', views.render_gen_post, name='render_post_general'), |
15 | 17 | url(r'^suggest_users/$', views.suggest_users, name='suggest_users'), | ... | ... |
mural/views.py
... | ... | @@ -186,6 +186,7 @@ class GeneralDelete(LoginRequiredMixin, generic.DeleteView): |
186 | 186 | context = super(GeneralDelete, self).get_context_data(*args, **kwargs) |
187 | 187 | |
188 | 188 | context['form_url'] = reverse_lazy("mural:delete_general", args = (), kwargs = {'pk': self.object.id}) |
189 | + context['message'] = _('Are you sure you want to delete this post?') | |
189 | 190 | |
190 | 191 | return context |
191 | 192 | |
... | ... | @@ -332,6 +333,32 @@ class CommentUpdate(LoginRequiredMixin, generic.UpdateView): |
332 | 333 | def get_success_url(self): |
333 | 334 | return reverse_lazy('mural:render_comment', args = (self.object.id, 'update', )) |
334 | 335 | |
336 | +class CommentDelete(LoginRequiredMixin, generic.DeleteView): | |
337 | + login_url = reverse_lazy("users:login") | |
338 | + redirect_field_name = 'next' | |
339 | + | |
340 | + template_name = 'mural/delete.html' | |
341 | + model = Comment | |
342 | + | |
343 | + def get_context_data(self, *args, **kwargs): | |
344 | + context = super(CommentDelete, self).get_context_data(*args, **kwargs) | |
345 | + | |
346 | + context['form_url'] = reverse_lazy("mural:delete_comment", args = (), kwargs = {'pk': self.object.id}) | |
347 | + context['message'] = _('Are you sure you want to delete this comment?') | |
348 | + | |
349 | + return context | |
350 | + | |
351 | + def get_success_url(self): | |
352 | + users = User.objects.all().exclude(id = self.request.user.id) | |
353 | + | |
354 | + notify_type = "mural" | |
355 | + pathname = reverse("mural:manage_general") | |
356 | + | |
357 | + #for user in users: | |
358 | + # Group("user-%s" % user.id).send({'text': json.dumps({"type": notify_type, "subtype": "delete", "pathname": pathname, "post_id": self.object.id})}) | |
359 | + | |
360 | + return reverse_lazy('mural:deleted_comment') | |
361 | + | |
335 | 362 | def render_comment(request, comment, msg): |
336 | 363 | comment = get_object_or_404(Comment, id = comment) |
337 | 364 | |
... | ... | @@ -349,6 +376,9 @@ def render_comment(request, comment, msg): |
349 | 376 | |
350 | 377 | return JsonResponse({'message': msg, 'view': html, 'new_id': comment.id}) |
351 | 378 | |
379 | +def deleted_comment(request): | |
380 | + return JsonResponse({'msg': _('Comment deleted successfully!')}) | |
381 | + | |
352 | 382 | def suggest_users(request): |
353 | 383 | param = request.GET.get('param', '') |
354 | 384 | ... | ... |