From b7b02ace5fd3cf8a12f35789bd5fe137a531f245 Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Tue, 17 Dec 2013 22:19:52 +0000 Subject: [PATCH] Closes #4 --- spa/api/v1/CommentResource.py | 6 +++ static/js/app/lib/utils.coffee | 15 +++---- static/js/app/lib/utils.js | 15 +++---- .../app/views/comment/commentItemView.coffee | 10 ++++- .../js/app/views/comment/commentItemView.js | 13 ++++++- templates/views/CommentItemView.html | 39 ++++++++++++------- templates/views/CommentListView.html | 16 +++++++- templates/views/dlg/DeleteMixConfirm.html | 6 +-- templates/views/dlg/_DialogBase.html | 3 +- 9 files changed, 78 insertions(+), 45 deletions(-) diff --git a/spa/api/v1/CommentResource.py b/spa/api/v1/CommentResource.py index 3a70a1e..ec8f119 100755 --- a/spa/api/v1/CommentResource.py +++ b/spa/api/v1/CommentResource.py @@ -30,6 +30,12 @@ class CommentResource(BackboneCompatibleResource): bundle.data['avatar_image'] = UserProfile.get_default_avatar_image() bundle.data['user_url'] = "/" bundle.data['user_name'] = "Anonymouse" + + if bundle.request.user.is_authenticated(): + bundle.data['can_edit'] = bundle.request.user.is_staff or bundle.obj.user_id == bundle.request.user.id + else: + bundle.data['can_edit'] = False + return bundle def obj_create(self, bundle, **kwargs): diff --git a/static/js/app/lib/utils.coffee b/static/js/app/lib/utils.coffee index 029b481..47a1d19 100755 --- a/static/js/app/lib/utils.coffee +++ b/static/js/app/lib/utils.coffee @@ -16,21 +16,18 @@ define ['jquery', 'bootstrap', 'toastr'], ($, bootstrap, toastr) -> true true - messageBox: (url) -> + messageBox: (url, success) -> if url if url.indexOf("#") is 0 $(url).modal "open" else $.get(url,(data) -> - $("#yes-no-positive", data).click -> - alert("Oh yes") + $(data).modal('show').on("shown.bs.modal", (e) -> + $(this).find("#yes-no-positive").click -> + success() + ) + ) - $(data).modal().on "hidden", -> - $(this).remove() - true - ).success -> - $("input:text:visible:first").focus() - true true checkPlayCount: -> diff --git a/static/js/app/lib/utils.js b/static/js/app/lib/utils.js index 3fc31d9..74d3c4e 100755 --- a/static/js/app/lib/utils.js +++ b/static/js/app/lib/utils.js @@ -25,22 +25,17 @@ } return true; }, - messageBox: function(url) { + messageBox: function(url, success) { if (url) { if (url.indexOf("#") === 0) { $(url).modal("open"); } else { $.get(url, function(data) { - $("#yes-no-positive", data).click(function() { - return alert("Oh yes"); + return $(data).modal('show').on("shown.bs.modal", function(e) { + return $(this).find("#yes-no-positive").click(function() { + return success(); + }); }); - return $(data).modal().on("hidden", function() { - $(this).remove(); - return true; - }); - }).success(function() { - $("input:text:visible:first").focus(); - return true; }); } } diff --git a/static/js/app/views/comment/commentItemView.coffee b/static/js/app/views/comment/commentItemView.coffee index 01bb4ca..b14e258 100755 --- a/static/js/app/views/comment/commentItemView.coffee +++ b/static/js/app/views/comment/commentItemView.coffee @@ -1,6 +1,12 @@ -define ['app.lib/dssView', 'text!/tpl/CommentItemView'], -(DssView, Template) -> +define ['app.lib/dssView', 'utils', 'text!/tpl/CommentItemView'], +(DssView, utils, Template) -> class CommentItemView extends DssView template: _.template(Template) + events: { + "click #delete-comment": "deleteComment" + } + deleteComment: -> + utils.messageBox "/dlg/DeleteMixConfirm", => + @model.destroy() CommentItemView \ No newline at end of file diff --git a/static/js/app/views/comment/commentItemView.js b/static/js/app/views/comment/commentItemView.js index 0318684..666ab10 100755 --- a/static/js/app/views/comment/commentItemView.js +++ b/static/js/app/views/comment/commentItemView.js @@ -3,7 +3,7 @@ var __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; - define(['app.lib/dssView', 'text!/tpl/CommentItemView'], function(DssView, Template) { + define(['app.lib/dssView', 'utils', 'text!/tpl/CommentItemView'], function(DssView, utils, Template) { var CommentItemView; CommentItemView = (function(_super) { @@ -15,6 +15,17 @@ CommentItemView.prototype.template = _.template(Template); + CommentItemView.prototype.events = { + "click #delete-comment": "deleteComment" + }; + + CommentItemView.prototype.deleteComment = function() { + var _this = this; + return utils.messageBox("/dlg/DeleteMixConfirm", function() { + return _this.model.destroy(); + }); + }; + return CommentItemView; })(DssView); diff --git a/templates/views/CommentItemView.html b/templates/views/CommentItemView.html index 6836636..24e7630 100755 --- a/templates/views/CommentItemView.html +++ b/templates/views/CommentItemView.html @@ -1,17 +1,26 @@ {% load account_tags %} - -
- - - - -
- - <%= user_name %> - -
-

<%= comment %>

- <%= humanise(date_created) %> -
+
+
+ <%= user_name %>'s Avatar
-
+ +
+
+ + <%= humanise(date_created) %> +
+ + +
<%= comment %>
+ + <% if (can_edit) { %> +
+ + + +
+ <% } %> +
+
\ No newline at end of file diff --git a/templates/views/CommentListView.html b/templates/views/CommentListView.html index ae8cf96..ab5c99a 100755 --- a/templates/views/CommentListView.html +++ b/templates/views/CommentListView.html @@ -1,2 +1,14 @@ -

Comments

-
+
+
+

+ +

+
+ +
+
+
+
+
+
+ diff --git a/templates/views/dlg/DeleteMixConfirm.html b/templates/views/dlg/DeleteMixConfirm.html index 1b16bdb..0e8453a 100644 --- a/templates/views/dlg/DeleteMixConfirm.html +++ b/templates/views/dlg/DeleteMixConfirm.html @@ -11,8 +11,6 @@ Comments, likes, favourites, all gone, never to return. {% endblock %} {% block primarybutton %}Cancel{% endblock %} -{% block extrabuttons %} - - Proceed - +{% block extrabuttons %} + {% endblock %} \ No newline at end of file diff --git a/templates/views/dlg/_DialogBase.html b/templates/views/dlg/_DialogBase.html index 904d2e1..2f509a0 100755 --- a/templates/views/dlg/_DialogBase.html +++ b/templates/views/dlg/_DialogBase.html @@ -12,8 +12,7 @@