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 %} - -
Comments
- ++ +
+