Skip to content

Commit 1b6f80d

Browse files
committed
abstracted close modal into a posts/_close_modal partial
1 parent 5fce96a commit 1b6f80d

2 files changed

Lines changed: 63 additions & 47 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<%#
2+
"Renders post closure modal
3+
4+
Variables:
5+
post : Post to render the modal for
6+
"%>
7+
8+
<div class="post--action-dialog js-close-box">
9+
<div class="widget">
10+
<div class="widget--header">Why should this post be closed?</div>
11+
<% CloseReason.active.each do |reason| %>
12+
<div class="widget--body">
13+
<div class="grid">
14+
<div class="grid--cell">
15+
<input class="form-radio-element"
16+
type="radio"
17+
name="close-reason"
18+
value="<%= reason.id %>"
19+
id="close-reason-<%= reason.id %>"
20+
data-rop="<%= reason.requires_other_post %>">
21+
</div>
22+
<div class="grid--cell is-flexible">
23+
<label class="form-element" for="close-reason-<%= reason.id %>">
24+
<%= reason.name %>
25+
<div class="form-caption">
26+
<%= raw render_markdown(reason.description.gsub "$SiteName", SiteSetting['SiteName']) %>
27+
</div>
28+
</label>
29+
<% if reason.requires_other_post %>
30+
<input required
31+
class="form-element has-margin-top-8 js-close-other-post"
32+
id="close-reason-other-post-<%= reason.id %>"
33+
placeholder="Please enter the URL or ID of the other post in this community."
34+
name="close-reason-other-post" />
35+
<% end %>
36+
</div>
37+
</div>
38+
</div>
39+
<% end %>
40+
<div class="widget--footer">
41+
<button class="js-close-question button is-filled is-muted" data-post-id="<%= post.id %>">
42+
Close this post
43+
</button>
44+
</div>
45+
</div>
46+
</div>

app/views/posts/_expanded.html.erb

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -278,18 +278,21 @@
278278
Flag
279279
</a>
280280
<% end %>
281-
<% unless post.locked? || !post_type.is_closeable %>
282-
<% if check_your_privilege('flag_close') || (post.user_id === current_user&.id)%>
283-
<% if !post.closed %>
284-
<a href="#" class="close-dialog-link tools--item" role="button" aria-label="Close this post">
285-
<i class="fa fa-lock"></i>
286-
Close
287-
</a>
288-
<% elsif post.closed %>
289-
<%= link_to reopen_post_path(post), method: :post, class: 'reopen-question tools--item', role: 'button', 'aria-label': 'Reopen this post' do %>
290-
<i class="fa fa-unlock"></i>
291-
Reopen
292-
<% end %>
281+
<% if current_user&.can_close?(post) %>
282+
<% if !post.closed %>
283+
<a href="#"
284+
class="close-dialog-link tools--item"
285+
role="button"
286+
aria-label="Close this post">
287+
<i class="fa fa-lock"></i>
288+
Close
289+
</a>
290+
<% else %>
291+
<%= link_to reopen_post_path(post), method: :post,
292+
class: 'reopen-question tools--item',
293+
role: 'button', 'aria-label': 'Reopen this post' do %>
294+
<i class="fa fa-unlock"></i>
295+
Reopen
293296
<% end %>
294297
<% end %>
295298
<% end %>
@@ -347,41 +350,8 @@
347350

348351
<%= render 'posts/flag_modal', post: post, user: current_user %>
349352

350-
<% if post_type.is_closeable %>
351-
<div class="post--action-dialog js-close-box">
352-
<div class="widget">
353-
<div class="widget--header">Why should this post be closed?</div>
354-
<% CloseReason.active.each do |reason| %>
355-
<div class="widget--body">
356-
<div class="grid">
357-
<div class="grid--cell">
358-
<input class="form-radio-element" type="radio" name="close-reason" value="<%= reason.id %>"
359-
id="close-reason-<%= reason.id %>" data-rop="<%= reason.requires_other_post %>">
360-
</div>
361-
<div class="grid--cell is-flexible">
362-
<label class="form-element" for="close-reason-<%= reason.id %>">
363-
<%= reason.name %>
364-
<div class="form-caption">
365-
<%= raw render_markdown(reason.description.gsub "$SiteName", SiteSetting['SiteName']) %>
366-
</div>
367-
</label>
368-
<% if reason.requires_other_post %>
369-
<input required class="form-element has-margin-top-8 js-close-other-post"
370-
id="close-reason-other-post-<%= reason.id %>"
371-
placeholder="Please enter the URL or ID of the other post in this community."
372-
name="close-reason-other-post" />
373-
<% end %>
374-
</div>
375-
</div>
376-
</div>
377-
<% end %>
378-
<div class="widget--footer">
379-
<button class="js-close-question button is-filled is-muted" data-post-id="<%= post.id %>">
380-
Close this post
381-
</button>
382-
</div>
383-
</div>
384-
</div>
353+
<% if current_user&.can_close?(post) %>
354+
<%= render 'posts/close_modal', post: post %>
385355
<% end %>
386356

387357
<% if current_user&.privilege?('flag_curate') %>

0 commit comments

Comments
 (0)