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