diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb
index 40c8f9e..6ac5a83 100644
--- a/app/controllers/public/content_viewer_controller.rb
+++ b/app/controllers/public/content_viewer_controller.rb
@@ -111,6 +111,15 @@ class ContentViewerController < ApplicationController
@comments = @plugins.filter(:unavailable_comments, @comments)
@comments_count = @comments.count
@comments = @comments.without_reply.paginate(:per_page => per_page, :page => params[:comment_page] )
+ @comment_order = params[:comment_order].nil? ? 'oldest' : params[:comment_order]
+
+ if request.xhr? and params[:comment_order]
+ if @comment_order == 'newest'
+ @comments = @comments.reverse
+ end
+
+ return render :partial => 'comment/comment', :collection => @comments
+ end
if params[:slideshow]
render :action => 'slideshow', :layout => 'slideshow'
diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml
index a64a1d5..9a36ba6 100644
--- a/app/views/content_viewer/view_page.rhtml
+++ b/app/views/content_viewer/view_page.rhtml
@@ -84,6 +84,16 @@
<%= link_to(_('Post a comment'), '#', :class => 'display-comment-form', :id => 'top-post-comment-button', :onclick => "jQuery('#page-comment-form .display-comment-form').first().click();") %>
<% end %>
+ <% if @page.accept_comments? and @comments.count > 1 %>
+ <%= hidden_field_tag("page_url", url_for(:controller=>'content_viewer', :action=>'view_page', :profile=>profile.identifier)) %>
+ <%= javascript_include_tag "comment_order.js" %>
+
+ <% end %>
+
<%= render :partial => 'comment/comment', :collection => @comments %>
<%= pagination_links @comments, :param_name => 'comment_page' %>
diff --git a/features/comment.feature b/features/comment.feature
index 059ea96..21cd9b2 100644
--- a/features/comment.feature
+++ b/features/comment.feature
@@ -97,3 +97,41 @@ Feature: comment
Given I am on /booking/article-to-comment
And I follow "Post a comment"
Then "Post a comment" should not be visible within "#article"
+
+ @selenium
+ Scenario: the newest post from a forum should be displayed first.
+ Given the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+ And the following forums
+ | owner | name |
+ | joaosilva | Forum |
+ And the following articles
+ | owner | name | parent |
+ | joaosilva | Post one | Forum |
+ And the following comments
+ | article | author | title | body |
+ | Post one | joaosilva | Hi all | Hi all |
+ | Post one | joaosilva | Hello | Hello |
+ When I go to /joaosilva/forum/post-one
+ And I select "Newest first" from "comment_order" within ".comment-order"
+ Then I should see "Hello" within ".article-comment"
+
+ @selenium
+ Scenario: the oldest post from a forum should be displayed first.
+ Given the following users
+ | login | name |
+ | joaosilva | Joao Silva |
+ And the following forums
+ | owner | name |
+ | joaosilva | Forum |
+ And the following articles
+ | owner | name | parent |
+ | joaosilva | Post one | Forum |
+ And the following comments
+ | article | author | title | body |
+ | Post one | joaosilva | Hi all | Hi all |
+ | Post one | joaosilva | Hello | Hello |
+ When I go to /joaosilva/forum/post-one
+ And I select "Oldest first" from "comment_order" within ".comment-order"
+ Then I should see "Hi all" within ".article-comment"
\ No newline at end of file
diff --git a/public/designs/themes/base/style.css b/public/designs/themes/base/style.css
index f3e098e..6f868a9 100644
--- a/public/designs/themes/base/style.css
+++ b/public/designs/themes/base/style.css
@@ -1275,6 +1275,11 @@ hr.pre-posts, hr.sep-posts {
padding-right: 9px;
}
+.comment-order {
+ float: right;
+ display: block;
+}
+
.comment-from-owner .comment-created-at {
color: #333;
}
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index 1c7d4ef..842b40d 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -1101,4 +1101,4 @@ jQuery(document).ready(function(){
jQuery("#article_has_terms_of_use").click(function(){
showHideTermsOfUse();
});
-});
\ No newline at end of file
+});
diff --git a/public/javascripts/comment_order.js b/public/javascripts/comment_order.js
new file mode 100644
index 0000000..cac6a1e
--- /dev/null
+++ b/public/javascripts/comment_order.js
@@ -0,0 +1,21 @@
+function send_order(order, url) {
+ open_loading(DEFAULT_LOADING_MESSAGE);
+
+ jQuery.ajax({
+ url:url,
+ data: {"comment_order":order},
+ success: function(response) {
+ close_loading();
+ jQuery(".article-comments-list").html(response);
+ },
+ error: function() { close_loading() }
+ });
+}
+
+
+jQuery(document).ready(function(){
+ jQuery("#comment_order").change(function(){
+ var url = jQuery("#page_url").val();
+ send_order(this.value, url);
+ });
+});
\ No newline at end of file
--
libgit2 0.21.2