fix crash when user is not logged in
[shapado:shapado.git] / app / views / questions / show.html.haml
1 = javascript_include_tag "modules/single/question"
2
3 -@current_class = 'question hentry entry post'
4
5
6 -show_close_request_form = !@question.closed && logged_in? && @question.can_be_requested_to_close_by?(current_user)
7
8 -if logged_in? && current_user.mod_of?(current_group) && @question.closed
9   -show_close_request_form = (@question.close_reason.user_id == current_user.id)
10
11 -if show_close_request_form
12   -@close_request = @question.close_requests.detect{ |rq| rq.user_id == current_user.id } || CloseRequest.new(:reason => "dupe")
13
14 -question_body = find_and_preserve(shapado_auto_link(markdown(@question.body.present? ? @question.body : @question.title)))
15
16 -content_for :head do
17   %meta{:name => "keywords", :content => clean_seo_keywords(@question.tags.dup, @question.title)}
18   %meta{:name => "description", :content => question_body.gsub(/<\/?[^>]*>/, "")[0, 255] }
19
20 -content_for :subtabs do
21   %h1.navtitle.title.entry-title
22     &= @question.title
23     -if @question.closed
24       =" [#{t("closed", :scope => "activerecord.attributes.question").upcase}]"
25
26 -source = question_path(@question)
27 =error_messages_for 'answer'
28
29 #question-vote-col
30   -if current_user && @question.watch_for?(current_user)
31     = link_to image_tag("layer-visible-on.png", 'data-src' => "/images/layer-visible-off.png"), unwatch_question_path(@question), :class => 'question-action', "data-undo" =>  watch_question_path(@question), "data-title" => t(".watch_tooltip"), :title => t(".unwatch_tooltip"), :id => "watch-question"
32   -else
33     = link_to image_tag("layer-visible-off.png", 'data-src' => "/images/layer-visible-on.png"), watch_question_path(@question), :title => t(".watch_tooltip"), :class => 'question-action', "data-undo" =>  unwatch_question_path(@question), "data-title" => t(".unwatch_tooltip"), :id => "watch-question"
34
35   =vote_box(@question, question_path(@question), @question.closed)
36
37   -if logged_in? && favorite = current_user.favorite(@question)
38     = 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'
39   -else
40     = 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'
41   .favorites_count
42     &= @question.favorites_count
43
44
45 #question-body-col.commentable.markdown
46   %a{:name => @question.id}
47   #body
48     -if @question.closed && @question.close_reason
49       #close_reason
50         = t(".close_reason")
51         = t(@question.close_reason.reason, :scope=>"close_requests.form")
52         -if !@question.close_reason.comment.empty?
53           .comment
54             =find_and_preserve(shapado_auto_link(@question.close_reason.comment))
55     .post-text.entry-content
56       = question_body
57   .tag-list
58     -@question.tags.each do |tag|
59       %span.tag
60         = link_to h(tag), url_for(:controller => "questions", :action => "index", :tags => tag), :rel => "tag"
61     - if logged_in? && (current_user.can_modify?(@question) || current_user.can_retag_others_questions_on?(current_group))
62       %span.retag
63         = link_to t('.retag'), retag_question_path(@question), :id => 'retag'
64   .post-info
65     .author.user_info.vcard
66       .gravatar.logo
67         = gravatar(@question.user.email.to_s, :size => 32)
68       .user_data
69         %span.asked_by
70           = t('activerecord.attributes.question.asked_by')
71         %span.fn.nickname
72           = link_to h(@question.user.login), user_path(@question.user)
73         %span.time_ago.published{:title => @question.created_at, :class => "relativetime"}
74           = t("time.ago", :time => time_ago_in_words(@question.created_at))
75           -if @question.wiki
76             .wiki_flag
77               wiki
78         %span.adr
79           -if !@question.user.hide_country
80             %span.country-name
81               = t("global.from", :site => @question.user.country_name)
82               = country_flag(@question.user.country_code, @question.user.country_name)
83       .clear
84     -if @question.updated_by.present?
85       .user_info
86         .gravatar.logo
87           = gravatar(@question.updated_by.email.to_s, :size => 32)
88         .user_data
89           %span.asked_by
90             = t('activerecord.attributes.question.updated_by')
91           %span.fn.nickname
92             = link_to h(@question.updated_by.login), user_path(@question.updated_by)
93           %span.time_ago.published{:title => @question.updated_at, :class => "relativetime"}
94             = t("time.ago", :time => time_ago_in_words(@question.updated_at))
95           %span.adr
96             -if !@question.updated_by.hide_country
97               %span.country-name
98                 = t("global.from", :site => @question.updated_by.country_name)
99                 = country_flag(@question.user.country_code, @question.updated_by.country_name)
100         .clear
101   .controls
102     .actions
103       -if logged_in?
104         - if flag = current_user.has_flagged?(@question)
105           %span.flagged= "#{t('.flagged_as')} #{t(flag.type, :scope=>'flags.form')}"
106         - else
107           =link_to t(".flag"), flag_question_path(@question), :class => "flag-link", :id => "question_flag_link", :rel => 'nofollow'
108         -if show_close_request_form
109           -close_link_label = current_user.mod_of?(current_group) ?  t(".close") : t(".request_closing")
110           =link_to close_link_label, new_question_close_request_path(@question), :id => "request-close-link", :rel => 'nofollow', :title => t('.request_closing_details')
111
112         -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)
113           = link_to t('scaffold.edit'), edit_question_path(@question), :class => "button"
114         -if @question.versions.count > 0
115           = link_to t(".history", :default => "history"), history_question_path(@question)
116         -if (current_user.can_modify?(@question) || current_user.owner_of?(@question.group))
117           = link_to t("scaffold.destroy"), question_path(@question.id), :confirm => "are you sure?", :method => :delete
118         -if current_user.mod_of?(@question.group)
119           = link_to t(".ban"), ban_path(:question_ids => [@question.id]), :class => "button", :confirm => "are you sure?"
120     .forms
121       -flag = Flag.new
122       - flag.flaggeable = @question
123       = render :partial => "flags/form", :locals => {:flag => flag, :source => source, :form_id => "question_flag_form" }
124
125       -if show_close_request_form
126         -form_for [@question, @close_request], :html => {:class => "form hide", :id => "request_close_question_form"} do |form|
127           -if !@close_request.new?
128             =link_to t(".retract_request"), question_close_request_path(:question_id => @question.slug, :id => @close_request.id), :method => :delete, :confirm => "are you sure?"
129           = render :partial => "close_requests/form", :object => form
130           .group.navform
131             = submit_tag t(".request_closing_details"), :class => "button"
132
133   -if logged_in?
134     =link_to t("comments.shared.add_comment"), "#", :id => "add_comment_link", :rel => 'nofollow'
135
136   .comments
137     -@question.comments.each do |comment|
138       = render :partial => "comments/comment", :object => comment, :locals => {:source => source, :mini => true}
139   .clear
140   .forms
141     .comment-form-question
142       -form_tag comments_path, :class => "form commentForm nestedAnswerForm", :id => "add_comment_form" do
143         -@comment = Comment.new
144         = render :partial => "comments/form", :locals => {:source => source, :commentable => @question}
145         .group.navform
146           = submit_tag t("comments.shared.comment_submit"), :class => "button"
147           = t("global.or")
148           = link_to t('scaffold.cancel'), '', :class => 'cancel_comment'
149
150 %a{:name=>"answers"}
151 #answers
152   .secondary-navigation{:class => @active_subtab.to_s}
153     .navtitle
154       = t(".answers_title", :count => @answers.total_entries + (@question.accepted ? 1 : 0))
155
156     %ul
157       %li.newest
158         = link_to t("questions.index.newest"), question_path(@question, :sort=>"newest", :anchor => "answers")
159       %li.votes
160         = link_to t("questions.index.votes"), question_path(@question, :sort=>"votes", :anchor => "answers")
161       %li.oldest
162         = link_to t("questions.index.oldest"), question_path(@question, :sort=>"oldest", :anchor => "answers")
163     .clear
164   .block
165     -if @question.accepted
166       -solution = @question.answer
167       =render :partial=> "answer", :locals=> {:question => @question, :answer => solution} unless solution.nil?
168     .hentry
169       -@answers.each do |answer|
170         =render :partial=> "answer", :locals=> {:question => @question, :answer => answer}
171     =will_paginate(@answers)
172
173 -unless @question.closed
174   %a{:name=>"to_answer"}
175   -form_for @answer, :url => question_answers_path(@question.id), :html => {:class => "form mainAnswerForm"} do |f|
176     = render :partial => "answers/form", :locals => {:f => f, :markdown => true}
177     .group.navform
178       .right
179         = f.label :wiki, "Wiki", :class => "radio"
180         = f.check_box :wiki, :class => "checkbox"
181       = submit_tag t('answers.form.submit'), :class => "button"
182     .clear
183
184 -content_for :sidebar do
185   -if logged_in? && (current_user.mod_of?(current_group) || current_user.can_view_offensive_counts_on?(current_group))
186     -unless @question.flags.count == 0
187       .block
188         %h3
189           = t(:flags, :scope => "activerecord.models")
190         .content
191           = render :partial => "flags/list", :locals => {:flaggeable => @question}
192
193     -unless @question.close_requests.size == 0
194       .block
195         %h3
196           = t(:prural_name, :scope => "close_requests.model")
197         .content
198           = render :partial => "close_requests/list", :locals => {:question => @question}
199
200   .block
201     %h3
202       = t('.tags', :default => [:"layouts.application.tags", :"activerecord.attributes.user.tags", "tags"])
203     = render :partial => "shared/tag_list", :object => @tag_cloud, :locals => { :extra_params => {:controller => "questions", :action => "index"} }
204     .clear
205
206   -if @question.badges.size > 0
207     .block
208       %h3
209         = t('badges', :scope => "activerecord.models")
210       .content
211         %ul.list
212           -@question.badges.each do |badge|
213             %li
214               = render :partial => "badges/badge", :object => badge, :locals => {:hide_user => false}
215
216   .block.stats
217     -if @question.group_id != current_group.id
218       = t(".asked_on")
219       &= @question.group.name
220
221     .entry
222       .text.asked
223         = t('activerecord.attributes.question.created_at')
224         .data
225           = t("time.ago", :time => time_ago_in_words(@question.created_at))
226     .entry
227       .text.viewed
228         = t('.viewed')
229       .data
230         = t('number.x_time', :count => number_with_delimiter(@question.views_count))
231     .entry
232       .text.last_activity
233         = t(".last_activity")
234       .data.updated{:title => @question.activity_at, :class => "relativetime"}
235         = t("time.ago", :time => time_ago_in_words(@question.activity_at))
236   -if AppConfig.enable_sharing
237     .block
238       %h3
239         = t(".share")
240       .content
241         %ul.navigation
242           %li
243             = render :partial => "twitter"
244           %li
245             = render :partial => "identica"
246           %li
247             = render :partial => "facebook"
248
249   -related_questions = Question.related_questions(@question, :language => find_languages)
250   -if !related_questions.empty?
251     .block
252       %h3
253         =t(".related_questions")
254       .content
255         %ul.list
256           -related_questions.each do |rq|
257             %li
258               =link_to h(rq.title), question_path(rq), :title => truncate(strip_tags(rq.body), :length => 200)
259
260
261 = javascript_include_tag 'jsMath/easy/load.js'