diff --git a/app/controllers/boards_controller.rb b/app/controllers/boards_controller.rb index d4eedb7e3..7952e0c9c 100644 --- a/app/controllers/boards_controller.rb +++ b/app/controllers/boards_controller.rb @@ -19,7 +19,7 @@ class BoardsController < ApplicationController layout 'base_projects'#by young default_search_scope :messages before_filter :find_project_by_project_id, :find_board_if_available, :except => [:join_to_org_subfields] - before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields] + before_filter :authorize, :except => [:new, :show, :create, :index, :join_to_org_subfields, :update_position, :update_name] accept_rss_auth :index, :show @@ -56,8 +56,12 @@ class BoardsController < ApplicationController @boards = @course.boards.includes(:last_message => :author).all end end - unless @course.boards.empty? - @board = @course.boards.first + if params[:board_id] + @board = Board.find params[:board_id].to_i + else + unless @course.boards.where("parent_id is NULL").empty? + @board = @course.boards.where("parent_id is NULL").first + end end show and return else @@ -192,18 +196,31 @@ class BoardsController < ApplicationController end end - def create - @board = @project.boards.build - @board.safe_attributes = params[:board] - - if @board.save - flash[:notice] = l(:notice_successful_create) - #Modified by young - #redirect_to_settings_in_projects - redirect_to project_board_url(@project, @board) - #Ended by young - else - render :action => 'new' + def create + if @project + @board = @project.boards.build + @board.safe_attributes = params[:board] + + if @board.save + flash[:notice] = l(:notice_successful_create) + #Modified by young + #redirect_to_settings_in_projects + redirect_to project_board_url(@project, @board) + #Ended by young + else + render :action => 'new' + end + elsif @course + parent = Board.find params[:board_id].to_i + board = @course.boards.build + board.name = params[:name] + board.description = board.name + board.project_id = -1 + board.position = parent.children.count + 1 + parent.children << board + respond_to do |format| + format.js + end end end @@ -224,8 +241,46 @@ class BoardsController < ApplicationController end def destroy + after_boards = @board.parent.children.where("position > #{@board.position}") + after_boards.update_all("position = position - 1") @board.destroy - redirect_to_settings_in_projects + if @course + respond_to do |format| + format.js + end + elsif @project + redirect_to_settings_in_projects + end + end + + def update_position + if @course + boards = @board.parent.children + if params[:opr] == 'up' && @board.position > 1 + before_board = boards.where("position = #{@board.position - 1}").first + if before_board && @board.update_attribute('position', @board.position - 1) + before_board.update_attribute('position', before_board.position + 1) + end + elsif params[:opr] == 'down' && @board.position < boards.count + after_board = boards.where("position = #{@board.position + 1}").first + if after_board && @board.update_attribute('position', @board.position + 1) + after_board.update_attribute('position', after_board.position - 1) + end + end + respond_to do |format| + format.js + end + end + end + + def update_name + if @course + @board.update_attribute("name", params[:name]) + @board.update_attribute("description", params[:name]) + respond_to do |format| + format.js + end + end end def join_to_org_subfields diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 31ca95789..f93599ee5 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -122,7 +122,7 @@ class MessagesController < ApplicationController if @project redirect_to project_boards_path(@project) elsif @course - redirect_to course_boards_path(@course) + redirect_to course_boards_path(@course, :board_id => @board.id) end else redirect_to board_message_url(@board, @message) @@ -132,7 +132,7 @@ class MessagesController < ApplicationController if @project redirect_to project_boards_path(@project, :flag => true) elsif @course - redirect_to course_boards_path(@course, :flag => true) + redirect_to course_boards_path(@course, :board_id => @board.id, :flag => true) end else layout_file = @project ? 'base_projects' : 'base_courses' diff --git a/app/models/board.rb b/app/models/board.rb index b66719edf..d8b29f5cd 100644 --- a/app/models/board.rb +++ b/app/models/board.rb @@ -35,7 +35,7 @@ class Board < ActiveRecord::Base includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_messages, *args)) } - safe_attributes 'name', 'description', 'parent_id', 'move_to' + safe_attributes 'name', 'description', 'parent_id', 'move_to', 'position' def visible?(user=User.current) !user.nil? && user.allowed_to?(:view_messages, project) @@ -51,7 +51,11 @@ class Board < ActiveRecord::Base end def valid_parents - @valid_parents ||= project.boards - self_and_descendants + if project + @valid_parents ||= project.boards - self_and_descendants + elsif course + @valid_parents ||= course.boards - self_and_descendants + end end def reset_counters! diff --git a/app/views/boards/_course_show.html.erb b/app/views/boards/_course_show.html.erb index 6759e33ce..55d4cca62 100644 --- a/app/views/boards/_course_show.html.erb +++ b/app/views/boards/_course_show.html.erb @@ -22,7 +22,7 @@
- 班级讨论区 + <%= @board.parent_id.nil? ? "班级讨论区" : "#{@board.name}" %>
diff --git a/app/views/boards/create.js.erb b/app/views/boards/create.js.erb new file mode 100644 index 000000000..8fe824e69 --- /dev/null +++ b/app/views/boards/create.js.erb @@ -0,0 +1,5 @@ +<% if @course %> + $("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>"); + <% course_board = @course.boards.where("parent_id is NULL").first %> + $("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>"); +<% end %> \ No newline at end of file diff --git a/app/views/boards/destroy.js.erb b/app/views/boards/destroy.js.erb new file mode 100644 index 000000000..3c997b725 --- /dev/null +++ b/app/views/boards/destroy.js.erb @@ -0,0 +1,5 @@ +<% if @course %> +$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>"); +<% course_board = @course.boards.where("parent_id is NULL").first %> +$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>"); +<% end %> \ No newline at end of file diff --git a/app/views/boards/update_name.js.erb b/app/views/boards/update_name.js.erb new file mode 100644 index 000000000..3c997b725 --- /dev/null +++ b/app/views/boards/update_name.js.erb @@ -0,0 +1,5 @@ +<% if @course %> +$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>"); +<% course_board = @course.boards.where("parent_id is NULL").first %> +$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>"); +<% end %> \ No newline at end of file diff --git a/app/views/boards/update_position.js.erb b/app/views/boards/update_position.js.erb new file mode 100644 index 000000000..3c997b725 --- /dev/null +++ b/app/views/boards/update_position.js.erb @@ -0,0 +1,5 @@ +<% if @course %> +$("#tbc_04").html("<%=escape_javascript(render :partial => 'courses/settings/boards_setting') %>"); +<% course_board = @course.boards.where("parent_id is NULL").first %> +$("#board_children_list").html("<%= escape_javascript(render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board})%>"); +<% end %> \ No newline at end of file diff --git a/app/views/courses/_tool_expand.html.erb b/app/views/courses/_tool_expand.html.erb index 893ea0cea..57ad2e570 100644 --- a/app/views/courses/_tool_expand.html.erb +++ b/app/views/courses/_tool_expand.html.erb @@ -1,10 +1,22 @@ <% course_file_num = visable_attachemnts_incourse(@course).count%> <% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %> -<% if show_nav?(@course.boards.first ? @course.boards.first.topics.count : 0) %> +<% course_board = @course.boards.where("parent_id is NULL").first %> +<% if show_nav?(course_board ? course_board.topics.count : 0) %>
  • 讨论区 <%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
  • + <% unless course_board.children.empty? %> + + <% end %> <% end %> <% if show_nav?(@course.homework_commons.count) %>
  • diff --git a/app/views/courses/settings.html.erb b/app/views/courses/settings.html.erb index 4c54e2289..654e9ac73 100644 --- a/app/views/courses/settings.html.erb +++ b/app/views/courses/settings.html.erb @@ -22,6 +22,9 @@
  • 组织
  • +
  • + 讨论区设置 +
  • @@ -131,6 +134,10 @@
    <%= render :partial => 'courses/settings/join_org' %>
    + +
    + <%= render :partial => 'courses/settings/boards_setting' %> +
    \ No newline at end of file diff --git a/app/views/layouts/_board_children_list.html.erb b/app/views/layouts/_board_children_list.html.erb new file mode 100644 index 000000000..9eb8938c5 --- /dev/null +++ b/app/views/layouts/_board_children_list.html.erb @@ -0,0 +1,11 @@ +<% unless course_board.children.empty? %> + +<% end %> \ No newline at end of file diff --git a/app/views/layouts/base_courses.html.erb b/app/views/layouts/base_courses.html.erb index c5a1a015e..711379b5f 100644 --- a/app/views/layouts/base_courses.html.erb +++ b/app/views/layouts/base_courses.html.erb @@ -64,12 +64,16 @@ 动态<%=@course.course_activities.count %> <% end %> - <% unless show_nav?(@course.boards.first ? @course.boards.first.topics.count : 0) %> + <% course_board = @course.boards.where("parent_id is NULL").first %> + <% unless show_nav?(course_board ? course_board.topics.count : 0) %>
  • - <% count = @course.boards.first ? (@course.boards.first.topics.count + Message.where("board_id =? and parent_id is not ?", @course.boards.first.id, nil).count) : 0 %> + <% count = course_board ? (course_board.topics.count + Message.where("board_id =? and parent_id is not ?", course_board.id, nil).count) : 0 %> 讨论区<%=count %> <%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") if is_teacher %>
  • +
    + <%= render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board} %> +
    <% end %> <% unless show_nav?(@course.homework_commons.count) %>
  • diff --git a/app/views/messages/_course_new.html.erb b/app/views/messages/_course_new.html.erb index bac064a9c..8c2be1588 100644 --- a/app/views/messages/_course_new.html.erb +++ b/app/views/messages/_course_new.html.erb @@ -4,11 +4,11 @@

    <%= l(:label_message_new) %>

      - <%= form_for @message, :url => {:action => 'new'}, :html => {:multipart => true, :id => 'message-form'} do |f| %> + <%= form_for @message, :url => {:action => 'new', :board_id => @board.id}, :html => {:multipart => true, :id => 'message-form'} do |f| %> <%= render :partial => 'form_course', :locals => {:f => f,:is_new => true} %> <%= l(:button_submit)%> <%#= preview_link({:controller => 'messages', :action => 'preview', :board_id => @board}, 'message-form' ,target='preview',{:class => 'blue_btn grey_btn fl c_white'} )%> - <%= link_to l(:button_cancel), course_boards_path(@course), :class => "grey_btn fl c_white ml10"%> + <%= link_to l(:button_cancel), course_boards_path(@course, :board_id => @board.id), :class => "grey_btn fl c_white ml10"%> <% end %>
    diff --git a/app/views/poll/_edit_MC.html.erb b/app/views/poll/_edit_MC.html.erb index 153874dd6..93e844b3a 100644 --- a/app/views/poll/_edit_MC.html.erb +++ b/app/views/poll/_edit_MC.html.erb @@ -3,7 +3,7 @@
    - + - + />
    diff --git a/app/views/poll/_edit_head.html.erb b/app/views/poll/_edit_head.html.erb index 76ada616c..90a12f20d 100644 --- a/app/views/poll/_edit_head.html.erb +++ b/app/views/poll/_edit_head.html.erb @@ -3,9 +3,7 @@
    - + 取消 保存
    diff --git a/app/views/poll/_edit_mulit.html.erb b/app/views/poll/_edit_mulit.html.erb index 921dfcb70..6b6279809 100644 --- a/app/views/poll/_edit_mulit.html.erb +++ b/app/views/poll/_edit_mulit.html.erb @@ -2,7 +2,7 @@
    - + - +