Changesets can be listed by changeset number.
The Git repository is here.
Changeset 448
Various forum patches to work better with page and per-page parameters
during replies and editing inside topics. Fixes Ticket #351.
- Comitted by: rool
- Date: Tuesday September 03 02:56:46 2013 (over 11 years ago)
Affected files:
- rool/rails/beast/trunk/app/controllers/forums_controller.rb (diff)
- rool/rails/beast/trunk/app/controllers/posts_controller.rb (diff)
- rool/rails/beast/trunk/app/helpers/application_helper.rb (diff)
- rool/rails/beast/trunk/app/models/topic.rb (diff)
- rool/rails/beast/trunk/app/views/posts/edit.rhtml (diff)
- rool/rails/beast/trunk/app/views/topics/show.rhtml (diff)
rool/rails/beast/trunk/app/controllers/forums_controller.rb:
prev. | current | |
def index | ||
@forums = Forum.find(:all, :order => "position") | ||
18 | ||
respond_to do |format| | ||
format.html | ||
format.xml { render :xml => @forums.to_xml } |
rool/rails/beast/trunk/app/controllers/posts_controller.rb:
prev. | current | |
respond_to do |format| | ||
format.html do | ||
flash[:notice] = 'This topic is locked.' | ||
57 | | |
57 | redirect_to(long_topic_path()) | |
end | ||
format.xml do | ||
render :text => 'This topic is locked.', :status => 400 | ||
... | ... | |
@post.save! | ||
respond_to do |format| | ||
format.html do | ||
71 | | |
71 | redirect_to(long_topic_path(@post.dom_id)) | |
end | ||
format.xml { head :created, :location => formatted_post_url(:forum_id => params[:forum_id], :topic_id => params[:topic_id], :id => @post, :format => :xml) } | ||
end | ||
... | ... | |
flash[:bad_reply] = 'Please post something at least...' | ||
respond_to do |format| | ||
format.html do | ||
79 | | |
79 | redirect_to(long_topic_path('reply-form')) | |
end | ||
format.xml { render :xml => @post.errors.to_xml, :status => 400 } | ||
end | ||
... | ... | |
ensure | ||
respond_to do |format| | ||
format.html do | ||
100 | | |
100 | redirect_to(long_topic_path(@post.dom_id)) | |
end | ||
format.js | ||
format.xml { head 200 } | ||
... | ... | |
@post.topic.destroy and redirect_to forum_path(params[:forum_id]) if @post.topic.posts_count == 1 | ||
respond_to do |format| | ||
format.html do | ||
114 | | |
114 | redirect_to(long_topic_path()) unless performed? | |
end | ||
format.xml { head 200 } | ||
end | ||
... | ... | |
end | ||
end | ||
145 | def long_topic_path(anchor = nil) | |
146 | options = { | |
147 | :forum_id => params[:forum_id], | |
148 | :id => params[:topic_id] | |
149 | } | |
150 | ||
151 | options[:anchor] = anchor unless (anchor.nil?) | |
152 | options[:page] = (params[:page] || '1').to_i.to_s if (params.has_key?(:page)) | |
153 | options[:posts_per_page] = (params[:posts_per_page] || '25').to_i.to_s if (params.has_key?(:posts_per_page)) | |
154 | ||
155 | topic_path(options) | |
156 | end | |
157 | ||
def per_page | ||
{ :per_page => [params[:posts_per_page].to_i, 25].max } | ||
end |
rool/rails/beast/trunk/app/helpers/application_helper.rb:
prev. | current | |
options[:q] ? all_search_posts_path(options) : send("#{prefix}all_posts_path", options) | ||
end | ||
40 | def apphelp_pagination_fields | |
41 | "#{hidden_field_tag :page, params[:page] if params.has_key?(:page)}" << | |
42 | "#{hidden_field_tag :posts_per_page, params[:posts_per_page] if params.has_key?(:posts_per_page)}" | |
43 | end | |
44 | ||
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false) | ||
from_time = from_time.to_time if from_time.respond_to?(:to_time) | ||
to_time = to_time.to_time if to_time.respond_to?(:to_time) |
rool/rails/beast/trunk/app/models/topic.rb:
prev. | current | |
def views() hits end | ||
35 | | |
36 | | |
37 | | |
38 | | |
35 | def paged?(per_page = 25) posts_count > per_page.to_i end | |
36 | ||
37 | def last_page(per_page = 25) | |
38 | (posts_count.to_f / per_page.to_f).ceil.to_i | |
end | ||
def editable_by?(user) |
rool/rails/beast/trunk/app/views/posts/edit.rhtml:
prev. | current | |
<%= error_messages_for :topic %> | ||
7 | ||
8 | | |
7 | <% form_for(:post, | |
8 | { | |
9 | :html => { :method => :put }, | |
10 | :url => post_path(:forum_id => params[:forum_id], | |
11 | :topic_id => params[:topic_id], | |
12 | :id => @post) | |
13 | } | |
14 | ) do |f| -%> | |
<p id="post_body"><%= f.text_area :body %></p> | ||
<p align="right"> | ||
18 | <%= apphelp_pagination_fields() %> | |
<%= submit_tag 'Save' %>, | ||
13 | | |
20 | <%= link_to 'cancel', topic_path(:forum_id => params[:forum_id], :id => params[:topic_id], :page => params[:page], :posts_per_page => params[:posts_per_page]) %>, | |
</p> | ||
<% end -%> | ||
<% form_for(:post, | ||
... | ... | |
}, | ||
:url => post_path(:forum_id => params[:forum_id], | ||
:topic_id => params[:topic_id], | ||
24 | | |
25 | | |
31 | :id => @post) | |
} | ||
) do |f| -%> | ||
<p align="right"> | ||
35 | <%= apphelp_pagination_fields() %> | |
or <%= submit_tag('Delete post forever') %> | ||
</p> | ||
<% end -%> |
rool/rails/beast/trunk/app/views/topics/show.rhtml:
prev. | current | |
<% if @post_pages.page_count > 1 -%> | ||
<div style="float: right; white-space: nowrap"> | ||
<% form_tag( @posts, { :method => 'get' } ) do %> | ||
73 | | |
73 | <%= hidden_field_tag(:q, params[:q] ) if params.has_key?(:q) %> | |
<small> | ||
Posts per page: | ||
<%= | ||
select_tag( | ||
'posts_per_page', | ||
options_for_select( | ||
80 | | |
81 | | |
80 | ['25', '50', '100'], | |
81 | params[:posts_per_page] | |
), | ||
:id => nil | ||
) | ||
... | ... | |
<% if logged_in? && post.editable_by?(current_user) -%> | ||
<p> | ||
<span class="edit"> | ||
121 | | |
121 | <%= link_to('Edit post', edit_post_path(:forum_id => @forum, :topic_id => @topic, :id => post, :page => @post_pages.current, :posts_per_page => params[:posts_per_page]), :class => "utility") %> | |
</span> | ||
</p> | ||
<% end -%> | ||
... | ... | |
<p /> | ||
<div class="editbox container"> | ||
<%= content_tag 'p', h(flash[:bad_reply]), :class => 'notice' if flash[:bad_reply] %> | ||
175 | | |
175 | <% form_for :post, :url => posts_path(:forum_id => @forum, :topic_id => @topic, :page => @topic.last_page(params[:posts_per_page])) do |f| -%> | |
<%= f.text_area :body, :rows => 8 %> | ||
<p /> | ||
... | ... | |
your message as many times as you like. | ||
<p align="right"> | ||
192 | <%= apphelp_pagination_fields() %> | |
<%= submit_tag "Save Reply" %> | ||
</p> | ||
<% end -%> |