|
|
|
@ -11,6 +11,42 @@ class ForumsController < ApplicationController
|
|
|
|
|
include SortHelper
|
|
|
|
|
|
|
|
|
|
PageLimit = 20
|
|
|
|
|
|
|
|
|
|
def create_memo
|
|
|
|
|
@memo = Memo.new(params[:memo])
|
|
|
|
|
@memo.forum_id = @forum.id
|
|
|
|
|
@memo.author_id = User.current.id
|
|
|
|
|
|
|
|
|
|
@memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads]))
|
|
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
|
if @memo.save
|
|
|
|
|
format.html { redirect_to (forum_memo_path(@forum, (@memo.parent_id.nil? ? @memo : @memo.parent_id))), notice: "#{l :label_memo_create_succ}" }
|
|
|
|
|
format.json { render json: @memo, status: :created, location: @memo }
|
|
|
|
|
else
|
|
|
|
|
sort_init 'updated_at', 'desc'
|
|
|
|
|
sort_update 'created_at' => "#{Memo.table_name}.created_at",
|
|
|
|
|
'replies' => "#{Memo.table_name}.replies_count",
|
|
|
|
|
'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
|
|
|
|
|
|
|
|
|
|
@topic_count = @forum.topics.count
|
|
|
|
|
@topic_pages = Paginator.new @topic_count, per_page_option, params['page']
|
|
|
|
|
@memos = @forum.topics.
|
|
|
|
|
reorder("#{Memo.table_name}.sticky DESC").
|
|
|
|
|
includes(:last_reply).
|
|
|
|
|
limit(@topic_pages.per_page).
|
|
|
|
|
offset(@topic_pages.offset).
|
|
|
|
|
order(sort_clause).
|
|
|
|
|
preload(:author, {:last_reply => :author}).
|
|
|
|
|
all
|
|
|
|
|
|
|
|
|
|
flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}"
|
|
|
|
|
# back_error_page = @memo.parent_id.nil? ? forum_path(@forum) : forum_memo_path(@forum, @memo.parent_id)
|
|
|
|
|
format.html { render action: :show, layout: 'base_forums' }#, error: "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" }
|
|
|
|
|
format.json { render json: @memo.errors, status: :unprocessable_entity }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
|
@offset, @limit = api_offset_and_limit({:limit => 10})
|
|
|
|
|