diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 36104d765..63d8429ba 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -65,6 +65,17 @@ class ForumsController < ApplicationController end end + def forum_create_memo + @memo = Memo.new + @my_forums_count = Forum.where(:creator_id => User.current.id).count + @my_memos_count = Memo.where(:author_id => User.current.id).count + @forums = Forum.reorder("topic_count desc,updated_at desc") + respond_to do |format| + format.js + format.html {render layout: 'base_new_forum'} + end + end + def create_memo @memo = Memo.new(params[:memo]) @memo.forum_id = @forum.id @@ -107,35 +118,41 @@ class ForumsController < ApplicationController end def index - @offset, @limit = api_offset_and_limit({:limit => 10}) + order = "" + @order_str = "" if(params[:reorder_complex]) - @type="reorder_complex" - @str=params[:reorder_complex] - @forums_all = Forum.reorder("topic_count #{params[:reorder_complex]},updated_at #{params[:reorder_complex]}") + order = " last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}" + @order_str = "reorder_complex="+params[:reorder_complex] elsif(params[:reorder_popu]) - @type="reorder_popu" - @str=params[:reorder_popu] - @forums_all = Forum.reorder("topic_count #{params[:reorder_popu]}") + order = "replies_count #{params[:reorder_popu]}" + @order_str = "reorder_popu="+params[:reorder_popu] elsif(params[:reorder_time]) - @type="reorder_time" - @str=params[:reorder_time] - @forums_all = Forum.reorder("updated_at #{params[:reorder_time]}") + order = "#{Memo.table_name}.updated_at #{params[:reorder_time]}" + @order_str = "reorder_time="+params[:reorder_time] else - params[:reorder_complex] = "desc" - @type="reorder_complex" - @str=params[:reorder_complex] - @forums_all = Forum.reorder("topic_count desc,updated_at desc") + order = "#{Memo.table_name}.updated_at desc" + @order_str = "reorder_time=desc" end - @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 = Forum.all + @memo = Memo.new(:forum => @forum) + @memos = Memo.where("parent_id is null") + @topic_count = @memos.count + @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] + @memos = @memos.includes(:last_reply). + limit(@topic_pages.per_page). + offset(@topic_pages.offset). + reorder(order). + preload(:author, {:last_reply => :author}). + all + @forums = Forum.reorder("topic_count desc,updated_at desc") + @my_forums_count = Forum.where(:creator_id => User.current.id).count + @my_memos_count = Memo.where(:author_id => User.current.id).count + @errors = params[:errors] respond_to do |format| - format.html # index.html.erb format.js - format.json { render json: @forums } + format.html { + render :layout => 'base_new_forum' + }# show.html.erb + format.json { render json: @forum } end end @@ -164,22 +181,21 @@ class ForumsController < ApplicationController @memo = Memo.new(:forum => @forum) @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). + @memos = @forum.topics.includes(:last_reply). limit(@topic_pages.per_page). offset(@topic_pages.offset). reorder(order). preload(:author, {:last_reply => :author}). all - @memos - @my_topic_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is null").count - @my_replies_count = Memo.where("forum_id = #{@forum.id} and author_id = #{User.current.id} and parent_id is not null").count + @my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count + @my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count @errors = params[:errors] + # 推荐贴吧 + @forums = Forum.where("id !=?", @forum.id).reorder("topic_count desc,updated_at desc").first(3) respond_to do |format| format.js format.html { - render :layout => 'base_forums' + render :layout => 'base_new_forum' }# show.html.erb format.json { render json: @forum } end @@ -189,9 +205,9 @@ class ForumsController < ApplicationController # GET /forums/new.json def new @forum = Forum.new - respond_to do |format| format.html # new.html.erb + format.js format.json { render json: @forum } end end @@ -199,6 +215,10 @@ class ForumsController < ApplicationController # GET /forums/1/edit def edit @forum = Forum.find(params[:id]) + respond_to do |format| + format.html + format.js + end end # POST /forums @@ -211,18 +231,17 @@ class ForumsController < ApplicationController # Author lizanle # Description after save后需要进行资源记录的更新 # owner_type = 2 对应的是 forum - @save_flag=true + @save_flag = true if params[:asset_id] ids = params[:asset_id].split(',') - update_kindeditor_assets_owner ids ,@forum.id,OwnerTypeHelper::FORUM + update_kindeditor_assets_owner ids, @forum.id, OwnerTypeHelper::FORUM end #end respond_to do |format| - format.js + format.js{ redirect_to forums_path, notice: l(:label_forum_create_succ)} format.html { redirect_to @forum, notice: l(:label_forum_create_succ) } format.json { render json: @forum, status: :created, location: @forum } end - else @save_flag=false respond_to do |format| @@ -238,15 +257,14 @@ class ForumsController < ApplicationController # PUT /forums/1.json def update @forum = Forum.find(params[:id]) - respond_to do |format| if @forum.update_attributes(params[:forum]) - format.js {render :text=> true} + format.js format.html { redirect_to @forum, notice: l(:label_forum_update_succ) } format.json { head :no_content } else flash.now[:error] = "#{l :label_forum_update_fail}: #{@forum.errors.full_messages[0]}" - format.js { render :text=> false} + format.js format.html { render action: "edit" } format.json { render json: @forum.errors, status: :unprocessable_entity } end @@ -265,6 +283,19 @@ class ForumsController < ApplicationController end end + # 更新贴吧描述 + def update_memo_description + @forum = Forum.find(params[:id]) + if @forum.blank? + result = { :result => false } + else + forum_decription = params[:forum][:description] + @forum.update_attributes(:description => forum_decription ) + result = { :result => true } + end + render :json => result + end + def search_forum # @forums = paginateHelper Forum.where("name LIKE '%#{params[:name]}%'") q = "%#{params[:name].strip}%" @@ -307,15 +338,24 @@ class ForumsController < ApplicationController #检查forum的名字 def check_forum_name - forum_name_exist = true - if params[:forum_id] - forum_name_exist = Forum.where("name = '#{params[:forum_name]}' and id != #{params[:forum_id]}").count >= 1 ? true : false - else - forum_name_exist = Forum.where("name = '#{params[:forum_name]}' ").count >= 1 ? true : false + begin + forum_name = params[:forum_name] + result = Forum.find_by_name(forum_name).blank? ? {:result => true} : {:result => false} + rescue Exception => e + puts e end - render :text => forum_name_exist + render :json => result + # if params[:forum_id] + # forum_name_exist = Forum.where("name = '#{params[:forum_name]}' and id != #{params[:forum_id]}").count >= 1 ? true : false + # else + # forum_name_exist = Forum.where("name = '#{params[:forum_name]}' ").count >= 1 ? true : false + # end + # render :text => forum_name_exist end + + + #添加论坛tag def add_forum_tag @forum = Forum.find(params[:id]) diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 69a1b829c..25b12e52a 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -1,6 +1,6 @@ class MemosController < ApplicationController default_search_scope :memos - before_filter :find_forum, :only => [:new, :create, :preview] + before_filter :find_forum, :only => [:new, :create, :preview, :update] before_filter :find_attachments, :only => [:preview] before_filter :find_memo, :except => [:new, :create, :preview] before_filter :authenticate_user_edit, :only => [:edit, :update] @@ -29,32 +29,25 @@ class MemosController < ApplicationController def new @memo = Memo.new - @memo.forum_id = @forum.id - + @my_forums_count = Forum.where(:creator_id => User.current.id).count + @my_memos_count = Memo.where(:author_id => User.current.id).count + @forums = Forum.reorder("topic_count desc,updated_at desc") respond_to do |format| - format.html { - render action: :new ,layout: 'base' - } + format.js + format.html {render layout: 'base_new_forum'} format.json { render json: @memo } end end def create - if params[:quote].nil? @quote = "" else @quote = params[:quote] end - - - #unless params[:quote].nil? - # @quote = params[:quote][:quote] - #end - @memo = Memo.new(params[:memo]) - @memo.forum_id = params[:forum_id] + @memo.forum_id = @forum.id @memo.author_id = User.current.id if params[:memo][:parent_id] @@ -78,24 +71,20 @@ class MemosController < ApplicationController asset.save end end - #end - format.js - format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } - format.json { render json: @memo, status: :created, location: @memo } + format.js + format.html { redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}" } + format.json { render json: @memo, status: :created, location: @memo } else flash.now[:error] = "#{l :label_memo_create_fail}: #{@memo.errors.full_messages[0]}" format.js format.html { redirect_to( forum_path(Forum.find(params[:forum_id]),:errors=>@memo.errors.full_messages[0])) } format.json { render json: @memo.errors, status: :unprocessable_entity } - #end - end end end REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE) def show - # 更新贴吧帖子留言对应的memo_messages的viewed字段 unless @memo.children.blank? @memo.children.each do |child| @@ -148,7 +137,7 @@ class MemosController < ApplicationController respond_to do |format| format.js - format.html {render :layout=> 'base_forums'}#:layout=> 'base_forums', + format.html {render :layout => 'base_new_forum'} format.json { render json: @memo } format.xml { render xml: @memo } end @@ -157,13 +146,16 @@ class MemosController < ApplicationController def edit @my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is null").count @my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and author_id = #{User.current.id} and parent_id is not null").count + @forums = Forum.reorder("topic_count desc,updated_at desc") @replying = false respond_to do |format| - format.html {render :layout=>'base_forums'} + format.html {render :layout => 'base_new_forum'} end end def update + # 注意,如果不需要 + @flag = false respond_to do |format| if( #@memo.update_column(:subject, params[:memo][:subject]) && @@ -173,10 +165,11 @@ class MemosController < ApplicationController @memo.update_column(:subject,params[:memo][:subject]) && @memo.update_column(:updated_at,Time.now)) @memo.save_attachments(params[:attachments] || (params[:memo] && params[:memo][:uploads])) + @memo.forum_id = @forum.id @flag = @memo.save # @memo.root.update_attribute(:updated_at, @memo.updated_at) format.js - format.html {redirect_to back_memo_url, notice: "#{l :label_memo_create_succ}"} + format.html {redirect_to back_memo_url, notice: "#{l :label_memo_update_succ}"} else format.js format.html { render action: "edit" } @@ -207,7 +200,9 @@ class MemosController < ApplicationController end def find_forum - @forum = Forum.find(params[:forum_id]) + forum_name = params[:forum_name].strip unless params[:forum_name].nil? + @forum = forum_name ? Forum.find_by_name(forum_name) : Forum.find(params[:forum_id]) + # @forum = Forum.find(params[:forum_id]) rescue ActiveRecord::RecordNotFound render_404 nil diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a2e69c846..0d9694ac1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -37,6 +37,16 @@ module ApplicationHelper # super # end + # 公共分页 + def paginator_list objs, objs_count, limit, is_remote + @is_remote = is_remote + @objs_count = objs.count + @obj_pages = Paginator.new @objs_count, limit, params['page'] || 1 + @offset ||= @obj_pages.offset + @objs = paginateHelper @attachments,25 + end + + # 获取竞赛的管理人员 def contest_managers contest contest.contest_members.select{|cm| cm.roles.to_s.include?("ContestManager")} @@ -227,6 +237,16 @@ module ApplicationHelper xls_report.string end + # 用户资料是否完善 + def user_data_complete user + user_extension = UserExtensions.where(:user_id => user.id).first + data = true + if user_extension.gender.nil? || user_extension.school_id.nil? || user.lastname.blank? || (user_extension.identity == 3 && user_extension.school_id.nil?) + data = false + end + return data + end + # 获取用户单位 # 优先获取高校信息,如果改信息不存在则获取occupation def get_occupation_from_user user diff --git a/app/models/user.rb b/app/models/user.rb index d6722274c..8d9751a38 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -80,12 +80,12 @@ class User < Principal #每日一报、一事一报、不报 - MAIL_NOTIFICATION_OPTIONS = [ + # MAIL_NOTIFICATION_OPTIONS = [ #['week', :label_user_mail_option_week], # ['day', :label_user_mail_option_day], - ['all', :label_user_mail_option_all], - ['none', :label_user_mail_option_none] - ] + # ['all', :label_user_mail_option_all], + # ['none', :label_user_mail_option_none] + # ] has_many :homework_users has_many :homework_attaches, :through => :homework_users @@ -244,7 +244,7 @@ class User < Principal validates_format_of :mail, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :allow_blank => true validates_length_of :mail, :maximum => MAIL_LENGTH_LIMIT, :allow_nil => true validates_confirmation_of :password, :allow_nil => true - validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true + # validates_inclusion_of :mail_notification, :in => MAIL_NOTIFICATION_OPTIONS.collect(&:first), :allow_blank => true validate :validate_password_length # validates_email_realness_of :mail before_create :set_mail_notification diff --git a/app/views/forums/_edit.html.erb b/app/views/forums/_edit.html.erb new file mode 100644 index 000000000..e19068ef1 --- /dev/null +++ b/app/views/forums/_edit.html.erb @@ -0,0 +1,52 @@ +
+
+

新建贴吧

+ +
+
+
+ <%= labelled_form_for @forum, :html => {:id => "forum_new", :remote => true} do |f| %> + <%= render :partial => "forums/form", :locals => {:f => f} %> + <% end %> +
+
+ + \ No newline at end of file diff --git a/app/views/forums/_file_form.html.erb b/app/views/forums/_file_form.html.erb index 9bbbc9188..cbb53c2cc 100644 --- a/app/views/forums/_file_form.html.erb +++ b/app/views/forums/_file_form.html.erb @@ -47,7 +47,8 @@ <%#= button_tag "浏览", :type=>"button", :onclick=>"CompatibleSend();" %> <%#= button_tag "文件浏览", :type=>"button", :onclick=>"$('#_file').click();",:onmouseover => 'this.focus()',:class => 'AnnexBtn fl mt3' %> - 上传附件 + <%= button_tag "上传附件", :id => "upload_attachments", :type=>"button", :onclick=>"$('#_file').click();",:onmouseover => 'this.focus()',:class => 'sub_btn' %> + <%= file_field_tag 'attachments[dummy][file]', :id => '_file', :class => 'file_selector', diff --git a/app/views/forums/_form.html.erb b/app/views/forums/_form.html.erb new file mode 100644 index 000000000..cc2037e75 --- /dev/null +++ b/app/views/forums/_form.html.erb @@ -0,0 +1,70 @@ + +
+ 取消 + 确定 +
+ + + \ No newline at end of file diff --git a/app/views/forums/_forum_tag_list.html.erb b/app/views/forums/_forum_tag_list.html.erb index 1cae58619..e083840d2 100644 --- a/app/views/forums/_forum_tag_list.html.erb +++ b/app/views/forums/_forum_tag_list.html.erb @@ -1,8 +1,10 @@ <% forum.reload.tag_list.each do |tag|%> - <%= tag %> - <%if forum.creator.id == User.current.id%> - × + <% if forum.creator.id == User.current.id %> + <%= tag %> + × + <% else %> + <%= tag %> <% end %> <% end %> \ No newline at end of file diff --git a/app/views/forums/_my_count_message.html.erb b/app/views/forums/_my_count_message.html.erb new file mode 100644 index 000000000..fec466754 --- /dev/null +++ b/app/views/forums/_my_count_message.html.erb @@ -0,0 +1,16 @@ +
+
<%= link_to image_tag(url_to_avatar(User.current), :width => 50, :height => 50,:alt=>'贴吧图像' ), user_path( User.current) %>
+
+
我在问吧
+
+
<%= @my_memos_count %>
+
回答
+
+
+ +
+
+
diff --git a/app/views/forums/_new.html.erb b/app/views/forums/_new.html.erb new file mode 100644 index 000000000..05b5ff42e --- /dev/null +++ b/app/views/forums/_new.html.erb @@ -0,0 +1,12 @@ +
+
+

新建贴吧

+ +
+
+
+ <%= labelled_form_for @forum, :html => {:id => "forum_new", :remote => false} do |f| %> + <%= render :partial => "form", :locals => {:f => f} %> + <% end %> +
+
diff --git a/app/views/forums/_right_bar.html.erb b/app/views/forums/_right_bar.html.erb new file mode 100644 index 000000000..1bd6ead7a --- /dev/null +++ b/app/views/forums/_right_bar.html.erb @@ -0,0 +1,14 @@ + + <% @forums.each_with_index do |forum, i| %> +
+

<%= link_to forum.name, forum_path(forum), :class => "" %>

+ + +
+ <% end %> \ No newline at end of file diff --git a/app/views/forums/_show_topics.html.erb b/app/views/forums/_show_topics.html.erb index 80b77a79b..2bd29a748 100644 --- a/app/views/forums/_show_topics.html.erb +++ b/app/views/forums/_show_topics.html.erb @@ -5,6 +5,19 @@ $(function(){ showNormalImage('postDetailDes_<%= topic.id %>'); autoUrl('postDetailDes_<%= topic.id %>'); + if($("#intro_content_<%= topic.id %>").height() > 300) { + $("#intro_content_show_<%= topic.id %>").show(); + } + $("#intro_content_show_<%= topic.id %>").click(function(){ + $("#postDetailDes_<%= topic.id %>").toggleClass("maxh300"); + $("#intro_content_show_<%= topic.id %>").hide(); + $("#intro_content_hide_<%= topic.id %>").show(); + }); + $("#intro_content_hide_<%= topic.id %>").click(function(){ + $("#postDetailDes_<%= topic.id %>").toggleClass("maxh300"); + $("#intro_content_hide_<%= topic.id %>").hide(); + $("#intro_content_show_<%= topic.id %>").show(); + }); });
@@ -23,9 +36,14 @@ <%= get_praise_num(topic)%>
-
<%= topic.content.html_safe%> - +
+
+ <%= topic.content.html_safe%> +
+ + +
<% author = topic.last_reply.try(:author)%> <% if author%>
最后回复:<%= author.show_name%>
@@ -36,10 +54,10 @@
<% end %> -