-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy path_comment.html.erb
183 lines (160 loc) · 9.71 KB
/
_comment.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<div id="c<%= comment.cid %>" class="comment" style="margin-top: 20px;padding-bottom: 9px;">
<div style="margin-bottom: 0;border-bottom-left-radius: 0;border-bottom-right-radius: 0;border-bottom: 0;" class="navbar navbar-default">
<div class="navbar-text pull-left visible-xs"> </div>
<div class="navbar-text pull-left">
<% if comment.author %>
<% if comment.author.user && comment.author.user.photo_file_name %>
<img style="width:32px;margin-right:6px;" class="img-circle" src="<%= comment.author.user.photo_path(:thumb) %>" />
<% else %>
<div style="vertical-align:middle;display:inline-block;height:32px;width:32px;margin-right:6px;background:#ccc;" class="img-circle"></div>
<% end %>
<a href="/profile/<%= comment.author.name %>"><%= comment.author.name %></a>
<% end %>
<span class="hidden-xs"><%= t('notes._comment.commented') %></span>
<a style="color:#aaa;" href="#c<%= comment.cid %>"><%= distance_of_time_in_words(comment.created_at, Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %></a>
<% if comment.author && comment.author.user %>
<% streak = comment.author.user.streak %>
<% if streak[0] > 7 %>
<a href="/wiki/streaks"><i class="fa fa-fire" style="padding-left:4px; font-size:16px; color:#f63;" data-toggle="tooltip" data-placement="top" title="<%= raw t('notes._comment.streak_title', :author => comment.author.name, :streak_notes => streak[1][0], :streak_wiki => streak[1][1], :streak_comments => streak[1][2], :streak_days => streak[0]) %>"></i></a>
<% end %>
<% end %>
</div>
<div class="navbar-text navbar-right pull-right" style="padding-right:10px;">
<% if comment.author && comment.author.user && comment.author.user.role %>
<!-- Role icon for admins & moderators
<% if comment.author.user.role == 'admin' %>
<a href="/users/role/admin"><i class="fa fa-cog" style="font-size:20px; margin-top:8px;" data-toggle="tooltip" data-placement="top" title="Admin"></i></a>
<% elsif comment.author && comment.author.user.role == 'moderator' %>
<a href="/wiki/moderators"><i class="fa fa-star" style="font-size:20px; margin-top:8px;" data-toggle="tooltip" data-placement="top" title="Moderator"></i></a>
<% end %>
-->
<% end %>
<% if current_user && comment.uid == current_user.uid %>
<a class="btn btn-default btn-sm" href="javascript:void(0)" onClick="$('#c<%= comment.cid %>edit').toggle();$('#c<%= comment.cid %>show').toggle();setInit(<%= comment.cid %>);">
<i class="fa fa-pencil"></i>
</a>
<% end %>
<% if comment.comment_via == 1 %>
<i class="fa fa-envelope" rel="tooltip" title="Commented by email"></i>
<% end %>
<% if params[:controller] == "questions" && current_user && (current_user.role == "admin" || current_user.role == "moderator" || comment.uid == current_user.uid) %>
<a class="btn btn-default btn-sm" id="comment-<%= comment.id %>-reorder-btn" data-remote="true" data-confirm="Are you sure? <% if current_user && comment.uid != current_user.uid %>Please exercise caution in promoting others' comments; this cannot be undone.<% end %>" rel="tooltip" title="<%= t('questions._comment.promotion') %>" data-placement="left" href="/comment/make_answer/<%= comment.id %>"><i class="fa fa-plus"></i></a>
<% end %>
<% if current_user &. can_moderate? %>
<a rel="tooltip" title="Mark as spam" class="btn btn-sm btn-default btn-flag-spam-<%= comment.id %>" data-confirm="Are you sure? The user will no longer be able to log in or publish, and their content will be hidden except comments." href="/admin/mark_comment_spam/<%= comment.id %>">
<i class="fa fa-ban"></i>
</a>
<% else %>
<a rel="tooltip" title="Flag as spam" class="btn btn-sm btn-default btn-flag-spam-<%= comment.id %>" href="mailto:[email protected]?subject=Reporting+spam+on+Public+Lab&body=Hi,+I+found+this+comment+that+looks+like+spam+or+needs+to+be+moderated:+https://publiclab.org/<%= comment.parent.path %>#c<%= comment.cid %>+by+https://publiclab.org/profile/<% if comment.author %><%= comment.author.name %><% end %>+Thanks!">
<i class="fa fa-flag"></i>
</a>
<% end %>
<% if current_user && (current_user.role == "admin" || current_user.role == "moderator" || comment.uid == current_user.uid || comment.parent.uid == current_user.uid) %>
<a class="btn btn-default btn-sm" id="c<%= comment.cid %>delete-btn">
<i class='icon fa fa-trash'></i>
</a>
<% end %>
<% if current_user %>
<button style="background: white;border: 1px solid #ccc;padding: 4px 6px;" class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<i class='icon fa fa-smile-o'></i>
<sup style="font-size: 12px;">+</sup>
</button>
<ul id="emoji-dropdown" style="background: #f8f8f8" class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<% emoji_names, emoji_image_map = emoji_info %>
<% emoji_names.each do |e| %>
<li class="grow">
<% capitalized_emoji_name = e.split("-").map(&:capitalize).join %>
<% str = "/comment/like?comment_id=#{comment.cid}&user_id=#{current_user.uid}&emoji_type=#{capitalized_emoji_name}" %>
<%= link_to str, data: { method: "post", remote: true }, style: "padding: 0;" do %>
<img class="emoji" height="20" width="20" src="<%= emoji_image_map[e] %>">
<% end %>
</li>
<% end %>
</ul>
<% end %>
</div>
</div>
<script>
$("#c<%= comment.cid %>delete-btn").click(function () {
$.confirm({
title: 'Confirm!',
theme: 'Supervan',
content: 'Are you sure?',
buttons: {
confirm: function () {
$.ajax({
url : "/comment/delete/<%= comment.cid %>",
type: 'GET',
success: function(response){
notyNotification('sunset', 3000, 'error', 'topRight', 'Comment deleted');
$("#c<%= comment.cid %>").remove()
$('#comment-count')[0].innerHTML = parseInt($('#comment-count')[0].innerHTML)-1;
}
});
},
cancel: function () {
notyNotification('sunset', 3000, 'info', 'topRight', 'Comment deletion cancelled!');
},
}
});
});
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
<div style="border: 1px solid #e7e7e7;padding: 18px;" id="c<%= comment.cid %>show">
<% comment_body = render_comment_body(comment) %>
<p id="comment-body-<%= comment.cid %>"><%= raw filtered_comment_body(comment_body) %></p>
<% if contain_trimmed_body?(comment_body) %>
<span style="background-color: #DCDCDC; border-radius: 7px; cursor: pointer;" ><a class="email-toggle" data-toggle="collapse" data-target="#comment-<%= comment.cid %>-extra-content" style='text-decoration: none;'>  •••  </a></span>
<div class="collapse" id="comment-<%= comment.cid %>-extra-content" ><div class="blockquotestyle"><%= raw trimmed_body(comment_body) %></div></div>
<% end %>
<% if comment.body.include?('?') %>
<p class="alert alert-info">Is this a question? <a href="/questions/new?title=<%= comment.body %>">Click here</a> to post it to the <a href="/questions">Questions page</a>.
</p>
<% end %>
<% if comment.parent.has_power_tag('activity') && current_user && current_user.id == comment.uid %>
<div class="alert alert-info">Have you attempted or completed this activity? Consider <a href="/post?n=15798&tags=replication:<%= comment.nid %>,<%= comment.parent.tagnames.join(',') %>">sharing how it went</a> to help refine and improve it.</div>
<% end %>
</div>
<% str = "#{comment.id}-like-emojis" %>
<div id="<%= str %>" class="navbar-text navbar-right pull-right" style="margin: 0;width: 100%;display: flex;border: 1px solid #e7e7e7;border-top: 0;">
<% emoji_names, emoji_image_map = emoji_info %>
<% emoji_like_map = comment.emoji_likes %>
<% user_reactions_map = comment.user_reactions_map %>
<% emoji_names.each do |e| %>
<% capitalized_emoji_name = e.split("-").map(&:capitalize).join %>
<% str = "#{comment.id}-emoji-button-#{e}" %>
<% display = (emoji_like_map.has_key? capitalized_emoji_name) ? "display: flex;" : "display: none;" %>
<button id="<%= str %>" style="border: 0;background: #f1f8ff;border-radius: 0;border-right: 1px solid #e7e7e7;<%= display %>" type="button" class="btn btn-default btn-sm" data-toggle="tooltip" data-placement="bottom" title="<%= user_reactions_map[capitalized_emoji_name] %>">
<img height="20" width="20" src="<%= emoji_image_map[e] %>">
<div style="margin-left: 6px;font-size: 14px;"><%= emoji_like_map[capitalized_emoji_name] %></div>
</button>
<% end %>
</div>
<% if current_user %>
<% h = { title: I18n.t('notes._comment.edit_comment'), comment: comment, placeholder: I18n.t('notes._comment.edit_placeholder') } %>
<% h[:is_answer] = true if local_assigns[:is_answer] %>
<%= render :partial => "comments/edit", :locals => h %>
<% end %>
<br />
</div>
<style>
.open>#emoji-dropdown.dropdown-menu {
display: flex;
justify-content: space-around;
padding: 6px;
}
#emoji-dropdown .dropdown-menu {
min-width: 196px;
}
.grow {
transition: all .1s ease-in-out;
}
.grow:hover {
transform: scale(1.2);
}
.grow:active {
transform: scale(1);
}
</style>