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 @@ +
<%= l(:label_no_data) %>
+ <%= render :partial => "projects/no_data" %> <% end %> \ No newline at end of file diff --git a/app/views/forums/create.js.erb b/app/views/forums/create.js.erb index ee8172cbd..39bebe20a 100644 --- a/app/views/forums/create.js.erb +++ b/app/views/forums/create.js.erb @@ -1,7 +1,5 @@ <%if @save_flag%> -//$('#new_forum_div').slideToggle();$('#create_btn').parent().slideToggle(); -//$('#reorder_time').click(); - window.location.href= "<%= host_with_protocol %>"+"/forums/" + "<%= @forum.id%>" +$("#forum_right_bar").html('<%= escape_javascript( render :partial => 'forums/right_bar') %>'); <%else%> $("#error").html("<%= @forum.errors.full_messages[0]%>").show(); <%end %> diff --git a/app/views/forums/edit.js.erb b/app/views/forums/edit.js.erb new file mode 100644 index 000000000..98fbc95b7 --- /dev/null +++ b/app/views/forums/edit.js.erb @@ -0,0 +1,5 @@ +var htmlvalue = "<%= escape_javascript(render :partial => 'forums/edit') %>"; +pop_box_new(htmlvalue,460,190); + + + diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index 9b18070a8..bc6665913 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -1,176 +1,159 @@ -<%= javascript_include_tag 'new_user' %> -<%= stylesheet_link_tag 'css/common','css/public'%> - - -