2012-02-29 15:04:33 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
class CommentPresenter < ApplicationPresenter
|
|
|
|
|
|
|
|
attr_accessor :comment, :options
|
|
|
|
attr_reader :header, :image, :date, :caption, :content, :buttons
|
|
|
|
|
|
|
|
def initialize(comment, opts = {})
|
|
|
|
@comment = comment
|
|
|
|
@user = comment.user
|
|
|
|
@options = opts
|
|
|
|
|
2012-08-29 15:58:58 +01:00
|
|
|
@content = @comment.body
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def expandable?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def buttons?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def content?
|
2012-03-01 20:33:48 +00:00
|
|
|
true
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
2012-03-01 20:33:48 +00:00
|
|
|
def caption?
|
|
|
|
false
|
|
|
|
end
|
2012-02-29 15:04:33 +00:00
|
|
|
def buttons
|
|
|
|
project = options[:project]
|
|
|
|
commentable = options[:commentable]
|
2012-04-04 22:43:06 +01:00
|
|
|
(ep, dp) = if Comment.issue_comment?(commentable.class)
|
2012-02-29 15:04:33 +00:00
|
|
|
[edit_project_issue_comment_path(project, commentable, comment),
|
|
|
|
project_issue_comment_path(project, commentable, comment)]
|
2012-04-04 22:43:06 +01:00
|
|
|
elsif Comment.commit_comment?(commentable.class)
|
2012-02-29 15:04:33 +00:00
|
|
|
[edit_project_commit_comment_path(project, commentable, comment),
|
|
|
|
project_commit_comment_path(project, commentable, comment)]
|
|
|
|
end
|
|
|
|
|
|
|
|
res = []
|
|
|
|
if controller.can? :update, @comment
|
2012-09-18 19:42:22 +01:00
|
|
|
res << link_to(t("layout.edit"), ep, html_options = {:id => "comment-#{comment.id}", :class => "edit_comment"}).html_safe
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
if controller.can? :delete, @comment
|
|
|
|
res << link_to(t("layout.delete"), dp, :method => "delete",
|
|
|
|
:confirm => t("layout.comments.confirm_delete")).html_safe
|
|
|
|
end
|
2012-03-01 18:35:18 +00:00
|
|
|
res
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def header
|
2012-03-06 12:29:42 +00:00
|
|
|
res = link_to "#{@user.uname} (#{@user.name})", user_path(@user.uname)
|
2012-02-29 15:04:33 +00:00
|
|
|
res += ' ' + t("layout.comments.has_commented")
|
|
|
|
end
|
|
|
|
|
|
|
|
def image
|
2012-03-21 21:51:39 +00:00
|
|
|
@image ||= helpers.avatar_url(@user, :medium)
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def date
|
|
|
|
@date ||= I18n.l(@comment.updated_at, :format => :long)
|
|
|
|
end
|
|
|
|
|
2012-03-13 18:47:37 +00:00
|
|
|
def comment_id?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def comment_id
|
|
|
|
@comment.id
|
|
|
|
end
|
2012-02-29 15:04:33 +00:00
|
|
|
end
|