Merge branch 'master' into next
[shapado:shapado.git] / app / views / questions / show.html.haml
1 = javascript_include_merged(:show).html_safe
2 = include_latex
3
4 - @current_class = 'question hentry entry post'
5
6 - show_close_request_form = !@question.closed && logged_in? && @question.can_be_requested_to_close_by?(current_user)
7 - show_open_request_form = @question.closed && logged_in? && @question.can_be_requested_to_open_by?(current_user)
8
9 - if logged_in?
10   - if current_user.mod_of?(current_group) && @question.closed
11     - show_close_request_form = (@question.close_reason.user_id == current_user.id)
12   - @flag = current_user.has_flagged?(@question) || Flag.new
13
14 - @flag ||= Flag.new
15
16 - if show_open_request_form
17   - @open_request = current_user.has_requested_to_open?(@question) || OpenRequest.new
18
19 - if show_close_request_form
20   - @close_request = @question.close_requests.detect{ |rq| rq.user_id == current_user.id } || CloseRequest.new(:reason => "dupe")
21
22 - question_body = find_and_preserve(shapado_auto_link(markdown(@question.body.present? ? @question.body : @question.title)))
23
24 - content_for :head do
25   %meta{:name => "keywords", :content => clean_seo_keywords(@question.tags.dup, @question.title)}
26   %meta{:name => "description", :content => question_body.gsub(/<\/?[^>]*>/, "")[0, 255] }
27   %link{:rel => "canonical", :href => question_url(@question) }
28
29 - content_for :subtabs do
30   %h1.navtitle.title.entry-title
31     &= @question.title
32     - if @question.closed
33       =" [#{t("closed", :scope => "activerecord.attributes.question").upcase}]"
34
35 - source = question_path(@question)
36 = error_messages_for 'answer'
37
38 #question-vote-col
39   - if current_user && @question.follower?(current_user)
40     = link_to image_tag("layer-visible-on.png", 'data-src' => "/images/layer-visible-off.png"), unfollow_question_path(@question), :class => 'question-action', "data-undo" =>  follow_question_path(@question), "data-title" => t(".watch_tooltip"), :title => t(".unwatch_tooltip"), :id => "watch-question"
41   - else
42     = link_to image_tag("layer-visible-off.png", 'data-src' => "/images/layer-visible-on.png"), follow_question_path(@question), :title => t(".watch_tooltip"), :class => 'question-action', "data-undo" =>  unfollow_question_path(@question), "data-title" => t(".unwatch_tooltip"), :id => "watch-question"
43
44   =vote_box(@question, question_path(@question), @question.closed)
45
46   - if logged_in? && favorite = current_user.favorite(@question)
47     = link_to image_tag("favorites.png", 'data-src' => "/images/unfavorites.png"), unfavorite_question_path(@question), :id => "unfavorite-link", :title => t(".unfavorite_tooltip"), :class => 'question-action', "data-undo" =>  favorite_question_path(@question), "data-title" => t(".favorite_tooltip"), 'data-counter' => '.favorites_count'
48   - else
49     = link_to image_tag("unfavorites.png", 'data-src' => "/images/favorites.png"), favorite_question_path(@question), :id => "favorite-link", :title => t(".favorite_tooltip"), :class => 'question-action', "data-undo" =>  unfavorite_question_path(@question), "data-title" => t(".unfavorite_tooltip"), 'data-counter' => '.favorites_count'
50   .favorites_count
51     &= @question.favorites_count
52
53
54 #question-body-col.commentable.markdown
55   %a{:name => @question.id}
56   #body
57     - if @question.closed && @question.close_reason
58       #close_reason
59         = t(".close_reason")
60         = t(@question.close_reason.reason, :scope=>"close_requests.form")
61         - if !@question.close_reason.comment.empty?
62           .comment
63             =find_and_preserve(shapado_auto_link(@question.close_reason.comment))
64     .post-text.entry-content
65       = question_body
66   .tag-list
67     - @question.tags.each do |tag|
68       %span.tag
69         = link_to h(tag), url_for(:controller => "questions", :action => "index", :tags => tag), :rel => "tag"
70     - if logged_in? && (current_user.can_modify?(@question) || current_user.can_retag_others_questions_on?(current_group))
71       %span.retag
72         = link_to t('.retag'), retag_question_path(@question), :id => 'retag'
73   .post-info
74     .author.user_info.vcard
75       .gravatar.logo
76         -if !@question.anonymous
77           = gravatar(@question.user.email.to_s, :size => 32)
78       .user_data
79         %span.asked_by
80           = t('activerecord.attributes.question.asked_by')
81         -if @question.anonymous
82           =t("global.anonymous")
83         -else
84           =render :partial => "users/user_mini", :locals => {:user => @question.user}
85         %span.time_ago.published{:title => @question.created_at, :class => "relativetime"}
86           = t("time.ago", :time => time_ago_in_words(@question.created_at))
87           - if @question.wiki
88             .wiki_flag
89               wiki
90         %span.adr
91           - if !@question.user.hide_country
92             %span.country-name
93               = t("global.from", :site => @question.user.country_name)
94               = country_flag(@question.user.country_code, @question.user.country_name)
95       .clear
96     - if @question.updated_by.present?
97       .user_info
98         .gravatar.logo
99           = gravatar(@question.updated_by.email.to_s, :size => 32)
100         .user_data
101           %span.asked_by
102             = t('activerecord.attributes.question.updated_by')
103           =render :partial => "users/user_mini", :locals => {:user => @question.updated_by}
104           %span.time_ago.published{:title => @question.updated_at, :class => "relativetime"}
105             = t("time.ago", :time => time_ago_in_words(@question.updated_at))
106           %span.adr
107             - if !@question.updated_by.hide_country
108               %span.country-name
109                 = t("global.from", :site => @question.updated_by.country_name)
110                 = country_flag(@question.updated_by.country_code, @question.updated_by.country_name)
111         .clear
112   .controls
113     .actions
114       - if !@flag.new?
115         .flagged
116           = "#{t('.flagged_as')} #{t(@flag.reason, :scope=>'flags.form')}"
117           = link_to t("scaffold.edit"), edit_question_flag_path(@question,@flag), :class => "flag-link", :id => "edit_question_flag_link", :rel => 'nofollow'
118           = link_to t("scaffold.destroy"), question_flag_path(@question,@flag), :id => "destroy_question_flag_link", :rel => 'nofollow', :confirm => "are you sure?", :method => :delete
119       - elsif logged_in? && current_user != @question.user
120         = link_to t(".flag"), new_question_flag_path(@question), :class => "flag-link", :id => "question_flag_link", :rel => 'nofollow'
121
122       - if logged_in?
123         - if show_close_request_form
124           -if !@close_request.new?
125             .flagged
126               = "#{t('.requested_close_as')} #{t(@close_request.reason, :scope=>'close_requests.form')}"
127               = link_to t(".edit_request"), edit_question_close_request_path(@question,@close_request), :class => "flag-link", :id => "edit_question_close_request_link", :rel => 'nofollow'
128               = link_to t(".retract_request"), question_close_request_path(@question,@close_request), :id => "destroy_question_close_request_link", :rel => 'nofollow', :confirm => "are you sure?", :method => :delete
129           = link_to t(".request_closing"), @close_request.new? ? new_question_close_request_path(@question) : edit_question_close_request_path(@question, @close_request), :id => "request-close-link", :rel => 'nofollow', :title => t('.request_closing_details')
130
131         - if show_open_request_form
132           -if !@open_request.new?
133             .flagged
134               = "#{t('.requested_reopening')} #{@open_request.comment}"
135               = link_to t(".edit_request"), edit_question_open_request_path(@question, @open_request), :class => "flag-link", :id => "edit_question_open_request_link", :rel => 'nofollow'
136               = link_to t(".retract_request"), question_open_request_path(@question,@open_request), :id => "destroy_question_open_request_link", :rel => 'nofollow', :confirm => "are you sure?", :method => :delete
137
138           -if current_user.mod_of?(current_group)
139             = link_to t(".open"), open_question_path(@question), :rel => 'nofollow', :title => t('.request_opening_details'), :method => "put"
140           -else
141             = link_to t(".request_opening"), new_question_open_request_path(@question), :id => "request-open-link", :rel => 'nofollow', :title => t('.request_opening_details')
142
143         - if (@question.wiki && current_user.can_edit_wiki_post_on?(@question.group)) || current_user.can_edit_others_posts_on?(@question.group) || current_user.can_modify?(@question)
144           = link_to t('scaffold.edit'), edit_question_path(@question), :class => "button"
145         - if @question.versions.count > 0
146           = link_to t(".history", :default => "history"), history_question_path(@question)
147         - if (current_user.can_modify?(@question) || current_user.owner_of?(@question.group))
148           = link_to t("scaffold.destroy"), question_path(@question.id), :confirm => "are you sure?", :method => :delete
149         - if current_user.mod_of?(@question.group)
150           -if !@question.closed
151             = link_to t('.close'), question_close_requests_path(@question)
152           = link_to @question.banned ? t(".unban") : t(".ban"), manage_moderate_questions_path(:question_ids => [@question.id], :commit => @question.banned ? "unban": "ban"), :class => "button", :method => :put, :confirm => "are you sure?"
153     .forms
154       -# render :partial => "flags/form", :locals => {:flag => @flag, :flaggeable => @question, :source => source, :form_id => "question_flag_form" }
155
156       -# if !@question.closed && show_close_request_form
157         -#= render :partial => "close_requests/form", :locals => { :question => @question, :close_request => @close_request, :hide => true, :form_id => "request_close_question_form"}
158
159   - if logged_in?
160     = link_to t("comments.shared.add_comment"), new_question_comment_path(@question), :id => "add_comment_link", :rel => 'nofollow'
161
162   .comments
163     -@question.comments.each do |comment|
164       = render :partial => "comments/comment", :object => comment, :locals => {:source => source, :mini => true}
165   .clear
166   .forms
167     .comment-form-question
168       -form_tag question_comments_path(@question), :class => "form commentForm nestedAnswerForm", :id => "add_comment_form" do
169         -@comment = Comment.new
170         = render :partial => "comments/form", :locals => {:source => source, :commentable => @question}
171         .group.navform
172           = submit_tag t("comments.shared.comment_submit"), :class => "button"
173           = t("global.or")
174           = link_to t('scaffold.cancel'), '', :class => 'cancel_comment'
175
176 %a{:name=>"answers"}
177 #answers
178   .secondary-navigation{:class => @active_subtab.to_s}
179     .navtitle
180       = t(".answers_title", :count => @answers.total_entries + (@question.accepted ? 1 : 0))
181
182     %ul
183       %li.newest
184         = link_to t("questions.index.newest"), question_path(@question, :sort=>"newest", :anchor => "answers"), :rel => "nofollow"
185       %li.votes
186         = link_to t("questions.index.votes"), question_path(@question, :sort=>"votes", :anchor => "answers"), :rel => "nofollow"
187       %li.oldest
188         = link_to t("questions.index.oldest"), question_path(@question, :sort=>"oldest", :anchor => "answers"), :rel => "nofollow"
189     .clear
190   .block
191     - if @question.accepted
192       -solution = @question.answer
193       =render :partial=> "answer", :locals=> {:question => @question, :answer => solution} unless solution.nil?
194     .hentry
195       -@answers.each do |answer|
196         =render :partial=> "answer", :locals=> {:question => @question, :answer => answer}
197     =will_paginate(@answers)
198
199 -unless @question.closed
200   %a{:name=>"to_answer"}
201   -form_for @answer, :url => question_answers_path(@question.id), :html => {:class => "form mainAnswerForm"} do |f|
202     = render :partial => "answers/form", :locals => {:f => f, :markdown => true}
203     .group.navform
204       .controls.right{:style => "width: 50%"}
205         .left{:style => "width: 49.5%"}
206           = f.label :wiki, "Wiki", :class => "radio"
207           = f.check_box :wiki, :class => "checkbox"
208         .left{:style => "width: 49.5%"}
209           = f.label :anonymous, t("scaffold.post_as_anonymous"), :class => "radio"
210           = f.check_box :anonymous, {:class => "checkbox"}, true, false
211       = submit_tag t('answers.form.submit'), :class => "button"
212     .clear
213
214 -content_for :sidebar do
215   - if AppConfig.enable_sharing
216     .block
217       %h3
218         = t(".share")
219       .content
220         %ul.share
221           %li
222             = render :partial => "questions/share/identica"
223           - if current_group.domain != AppConfig.domain
224             %li
225               = render :partial => "questions/share/shapado"
226           %li
227             = render :partial => "questions/share/twitter"
228           %li
229             = render :partial => "questions/share/linkedin"
230           %li
231             = render :partial => "questions/share/think"
232           %li
233             = render :partial => "questions/share/facebook"
234       .clear
235
236   - if logged_in? && (current_user.mod_of?(current_group) || current_user.can_view_offensive_counts_on?(current_group))
237     -unless @question.flags.count == 0
238       .block
239         %h3
240           = t(:flags, :scope => "activerecord.models")
241         .content
242           = render :partial => "flags/list", :locals => {:flaggeable => @question}
243
244     -unless @question.close_requests.size == 0
245       .block
246         %h3
247           = t(:prural_name, :scope => "close_requests.model")
248         .content
249           = render :partial => "close_requests/list", :locals => {:question => @question}
250
251     -unless @question.open_requests.size == 0
252       .block
253         %h3
254           = t(:prural_name, :scope => "open_requests.model")
255         .content
256           = render :partial => "open_requests/list", :locals => {:question => @question}
257
258   .block
259     %h3
260       = t('.tags', :default => [:"layouts.application.tags", :"activerecord.attributes.user.tags", "tags"])
261     = render :partial => "shared/tag_list", :locals => {:tag_list => @tag_cloud, :extra_params => {:controller => "questions", :action => "index"} }
262     .clear
263
264   - if @question.badges.size > 0
265     .block
266       %h3
267         = t('badges', :scope => "activerecord.models")
268       .content
269         %ul.list
270           -@question.badges.each do |badge|
271             %li
272               = render :partial => "badges/badge", :object => badge, :locals => {:hide_user => false}
273
274   .block.stats
275     - if @question.group_id != current_group.id
276       = t(".asked_on")
277       &= @question.group.name
278
279     .entry
280       .text.asked
281         = t('activerecord.attributes.question.created_at')
282         .data
283           = t("time.ago", :time => time_ago_in_words(@question.created_at))
284     .entry
285       .text.viewed
286         = t('.viewed')
287       .data
288         = t('number.x_time', :count => number_with_delimiter(@question.views_count))
289     .entry
290       .text.last_activity
291         = t(".last_activity")
292       .data.updated{:title => @question.activity_at, :class => "relativetime"}
293         = t("time.ago", :time => time_ago_in_words(@question.activity_at))
294
295   -related_questions = Question.related_questions(@question, :language => find_languages)
296   - if !related_questions.empty?
297     .block
298       %h3
299         =t(".related_questions")
300       .content
301         %ul.list
302           -related_questions.each do |rq|
303             %li
304               = link_to h(rq.title), question_path(rq), :title => truncate(strip_tags(rq.body), :length => 200)