From f7c1b76b3dec19c87a1f2c27ac84e7c5d8c14e8a Mon Sep 17 00:00:00 2001 From: huang Date: Sat, 10 Jan 2015 15:39:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=8F=8D=E9=A6=88=E5=BC=B9?= =?UTF-8?q?=E6=A1=86=E6=A8=A1=E5=9D=97=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/forums_controller.rb | 57 ++++++-- app/helpers/application_helper.rb | 6 + app/views/forums/create_feedback.js.erb | 6 + app/views/layouts/_base_feedback.html.erb | 150 ++++++++++++++++++++++ app/views/layouts/_base_header.html.erb | 1 + config/routes.rb | 2 + public/images/f_opnion.jpg | Bin 0 -> 13652 bytes 7 files changed, 209 insertions(+), 13 deletions(-) create mode 100644 app/views/forums/create_feedback.js.erb create mode 100644 app/views/layouts/_base_feedback.html.erb create mode 100644 public/images/f_opnion.jpg diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index cd51d2e58..03d1454ef 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -13,6 +13,44 @@ class ForumsController < ApplicationController include SortHelper PageLimit = 20 + def create_feedback + if User.current.logged? + @memo = Memo.new(params[:memo]) + @memo.forum_id = "1" + @memo.author_id = User.current.id + #@forum = @memo.forum + respond_to do |format| + if @memo.save + format.html { redirect_to forum_path(@memo.forum) } + 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 + else + respond_to do |format| + format.html { redirect_to signin_path } + end + end + end def create_memo @memo = Memo.new(params[:memo]) @@ -49,16 +87,15 @@ class ForumsController < ApplicationController end end end - + def index @offset, @limit = api_offset_and_limit({:limit => 10}) @forums_all = Forum.reorder("sticky DESC") @forums_count = @forums_all.count @forums_pages = Paginator.new @forums_count, @limit, params['page'] - @offset ||= @forums_pages.offset - @forums = @forums_all.offset(@offset).limit(@limit).all + @forums = @forums_all.offset(@offset).limit(@limit).all #@forums = Forum.all respond_to do |format| format.html # index.html.erb @@ -86,14 +123,12 @@ class ForumsController < ApplicationController preload(:author, {:last_reply => :author}). all - - # @offset, @limit = api_offset_and_limit({:limit => 10}) # @forum = Forum.find(params[:id]) # @memos_all = @forum.topics # @topic_count = @memos_all.count # @topic_pages = Paginator.new @topic_count, @limit, params['page'] - + # @offset ||= @topic_pages.offset # @memos = @memos_all.offset(@offset).limit(@limit).all respond_to do |format| @@ -176,7 +211,6 @@ class ForumsController < ApplicationController @forums_count = @forums_all.count @forums_pages = Paginator.new @forums_count, @limit, params['page'] - @offset ||= @forums_pages.offset @forums = @forums_all.offset(@offset).limit(@limit).all respond_to do |format| @@ -197,7 +231,7 @@ class ForumsController < ApplicationController @memos_all = @forum.topics.where("subject LIKE ?", q) @topic_count = @memos_all.count @topic_pages = Paginator.new @topic_count, @limit, params['page'] - + @offset ||= @topic_pages.offset @memos = @memos_all.offset(@offset).limit(@limit).all respond_to do |format| @@ -205,20 +239,17 @@ class ForumsController < ApplicationController render 'show', :layout => 'base_forums' } format.json { render json: @forum } - end + end end - - private - def find_forum_if_available @forum = Forum.find(params[:id]) if params[:id] rescue ActiveRecord::RecordNotFound render_404 nil - end + end def authenticate_user_edit find_forum_if_available diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 8c2542aa2..cb88742ad 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1593,6 +1593,12 @@ module ApplicationHelper end s end + + def get_memo + @new_memo = Memo.new + #@new_memo.subject = "有什么想说的,尽管来咆哮吧~~" + @public_forum = Forum.find(1) + end private diff --git a/app/views/forums/create_feedback.js.erb b/app/views/forums/create_feedback.js.erb new file mode 100644 index 000000000..b94ac73aa --- /dev/null +++ b/app/views/forums/create_feedback.js.erb @@ -0,0 +1,6 @@ +$(function(){ + $("#button1").click(function(){ + myTips("您的意见已经反馈到公共贴吧的新手讨论吧,我们会第一时间解决您的问题,谢谢支持!","success"); + }); + +}) \ No newline at end of file diff --git a/app/views/layouts/_base_feedback.html.erb b/app/views/layouts/_base_feedback.html.erb new file mode 100644 index 000000000..859ed0361 --- /dev/null +++ b/app/views/layouts/_base_feedback.html.erb @@ -0,0 +1,150 @@ + + + + +意见反馈浮窗 + + + + + + + +
+
+ + <% get_memo %> + <%= form_for(@new_memo, :url => create_feedback_forum_path(@public_forum)) do |f| %> +
+

+ <%= f.text_area :subject, :class => "opnionText",:placeholder => "有什么想说的,尽管来咆哮吧~~"%> +

+

+ <%= f.hidden_field :content, :required => true ,:value=>'该贴来自用户反馈!'%> +

+ <%#= f.submit :value => l(:label_memo_create), :class => "opnionButton", :id => "button1" %> + 提  交 + <% end %> +
+ + + +
+
+ +
+
技术支持:
+

<%= l(:label_course_adcolick) %>黄井泉
+ <%= l(:label_course_adcolick) %>白羽

+
+ +
+ + + + + diff --git a/app/views/layouts/_base_header.html.erb b/app/views/layouts/_base_header.html.erb index 6f87d4171..445a5abf4 100644 --- a/app/views/layouts/_base_header.html.erb +++ b/app/views/layouts/_base_header.html.erb @@ -27,6 +27,7 @@ #@nav_dispaly_user_label = 1 end %> +<%= render :partial => "layouts/base_feedback" %>