班级讨论区增加二级子栏目
This commit is contained in:
parent
39151c0e65
commit
12ad7c1612
|
@ -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
|
||||
|
@ -191,18 +195,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
|
||||
|
||||
|
@ -223,8 +240,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
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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!
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
<div class="homepageRight mt0 ml10">
|
||||
<div class="homepageRightBanner">
|
||||
<div class="NewsBannerName">
|
||||
班级讨论区
|
||||
<%= @board.parent_id.nil? ? "班级讨论区" : "#{@board.name}" %>
|
||||
</div>
|
||||
</div>
|
||||
<div nhname="topic_form">
|
||||
|
|
|
@ -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 %>
|
|
@ -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 %>
|
|
@ -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 %>
|
|
@ -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 %>
|
|
@ -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) %>
|
||||
<li>
|
||||
<a href="<%=course_boards_path(@course) %>">讨论区</a>
|
||||
<%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
|
||||
</li>
|
||||
<% unless course_board.children.empty? %>
|
||||
<ul class="sub-menu">
|
||||
<% course_board.children.each do |board| %>
|
||||
<li>
|
||||
<% count = board ? (board.topics.count + Message.where("board_id =? and parent_id is not ?", board.id, nil).count) : 0 %>
|
||||
<a href="<%=course_boards_path(@course, :board_id =>board.id) %>"><%=board.name %><span><%=count %></span></a>
|
||||
<%= link_to( "",course_boards_path(@course, :board_id =>board.id, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% if show_nav?(@course.homework_commons.count) %>
|
||||
<li>
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
<li id="tb_3" class="hwork_normaltab" onclick="course_setting(3);">
|
||||
组织
|
||||
</li>
|
||||
<li id="tb_4" class="hwork_normaltab" onclick="course_setting(4);">
|
||||
讨论区设置
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="hwork_dis" id="tbc_01" style="padding-top: 10px;">
|
||||
|
@ -131,6 +134,10 @@
|
|||
<div class="hwork_undis" id="tbc_03">
|
||||
<%= render :partial => 'courses/settings/join_org' %>
|
||||
</div>
|
||||
|
||||
<div class="hwork_undis" id="tbc_04">
|
||||
<%= render :partial => 'courses/settings/boards_setting' %>
|
||||
</div>
|
||||
</div><!--talknew end-->
|
||||
<div class="cl"></div>
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
<% board = @course.boards.where("parent_id is NULL").first %>
|
||||
<div class="w730 mt10" id="org_subfield_list">
|
||||
<ul class="orgListRow borderBottomNone orgListBg">
|
||||
<li class="w270 fb fl"><span class="ml15">名称</span></li>
|
||||
<li class="w140 fb fl">状态</li>
|
||||
<li class="w170 fb fl">类型</li>
|
||||
<li class="w150 fb fl"><span class="mr15 fr">操作</span></li>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
<ul class="orgListRow">
|
||||
<li class="w270 fl"> <span class="ml15">班级讨论区</span> </li>
|
||||
<li class="w140 fl">默认</li>
|
||||
<li class="w170 fl">帖子</li>
|
||||
<li class="w150 fl"> <a href="javascript:void(0)" class="link-blue fr mr15" id="addSubMenu">添加子栏目</a> </li>
|
||||
<div class="cl"></div>
|
||||
<% count = board.children.count %>
|
||||
<% board.children.reorder("position asc").each_with_index do |board, i|%>
|
||||
<ul class="orgSubList" style="border-top: 1px solid rgb(228, 228, 228);">
|
||||
<li class="<%= i == count - 1 ? 'orgSubTree2' : 'orgSubTree' %>"></li>
|
||||
<li class="w210 mr10 fl">
|
||||
<div id="board_sub_show_<%= board.id %>" class="w210 hidden" title="<%=board.name %>"><%=board.name %></div>
|
||||
<div id="board_sub_edit_<%= board.id %>" style="display:none;">
|
||||
<input type="text" name="name" onblur="update_sub_board_name('#board_sub_show_<%= board.id %>','#board_sub_edit_<%= board.id %>','<%= board.id %>','<%= @course.id %>',$(this).val());" value="<%= board.name %>" style="width:140px;"/>
|
||||
</div>
|
||||
</li>
|
||||
<li class="w140 fl">新增</li>
|
||||
<li class="w170 fl">帖子</li>
|
||||
<li class="w150 fl">
|
||||
<a href="javascript:void(0);" class="linkGrey fr ml5 mr15" onclick="edit('#board_sub_show_<%= board.id %>','#board_sub_edit_<%= board.id %>');">编辑</a>
|
||||
<%= link_to('删除', {:controller => 'boards', :action => 'destroy', :id => board.id, :course_id => @course.id},:remote => true, :method => 'delete', :confirm => l(:text_are_you_sure), :class => "linkGrey fr ml5 mr5", :title => l(:button_delete)) %>
|
||||
<% if i < count - 1 %>
|
||||
<%= link_to('下移', {:controller => 'boards', :action => 'update_position', :id => board.id, :course_id => @course.id, :opr => 'down'},:remote => true, :method => 'post', :class => "linkGrey fr ml5 mr5", :title => '下移') %>
|
||||
<% end %>
|
||||
<% unless i == 0 %>
|
||||
<%= link_to('上移', {:controller => 'boards', :action => 'update_position', :id => board.id, :course_id => @course.id, :opr => 'up'},:remote => true, :method => 'post', :class => "linkGrey fr ml5 mr5", :title => '上移') %>
|
||||
<% end %>
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<!--新增二级栏目-->
|
||||
<div class="mt10 fl orgListBg w730 undis" id="subMenuContent">
|
||||
<%= form_tag url_for(:controller => 'boards', :action => 'create', :course_id => @course.id, :board_id => board.id), :id=> 'add_board_form_subboard',:remote => true do %>
|
||||
<div class="ml15 mt10">
|
||||
<span class="fontGrey3 mb5 mr10">新增子栏目名称 :</span>
|
||||
<input id="subfield_name" name="name" placeholder="请输入子栏目名称" class="orgAddSearch mb10" type="text">
|
||||
<span id="new_notice" class="undis ml10">名称不能为空</span>
|
||||
</div>
|
||||
<div class="mb10">
|
||||
<span class="fontGrey3 ml50 mr15 fl">栏目类型 :</span>
|
||||
<input class="mr5" id="orgMng" value="Post" name="field_type" checked="checked" type="radio">
|
||||
<label for="orgMng">帖子</label>
|
||||
</div>
|
||||
<div class="mb10">
|
||||
<a href="javascript:void(0);" class="grey_btn_cir fr c_white mr15 ml15" id="subMenuCancel">取消</a>
|
||||
<a href="javascript:void(0);" class="blue_btn_cir fr c_white" id="subMenuSubmit">确定</a>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</form>
|
||||
<% end %>
|
||||
</div>
|
||||
<!--over-->
|
||||
|
||||
<script>
|
||||
$(function(){
|
||||
$("#subMenuSubmit").one('click', function(){
|
||||
sub_board_submit();
|
||||
});
|
||||
});
|
||||
function sub_board_submit(){
|
||||
if ($("#subfield_name").val().trim() != ""){
|
||||
$("#new_notice").hide();
|
||||
$("#add_board_form_subboard").submit();
|
||||
} else {
|
||||
$("#new_notice").show();
|
||||
$("#subMenuSubmit").one('click', function(){
|
||||
sub_board_submit();
|
||||
});
|
||||
}
|
||||
}
|
||||
$("#addSubMenu").click(function(){
|
||||
$("#subMenuContent").toggle();
|
||||
});
|
||||
$("#subMenuCancel").click(function(){
|
||||
$("#subMenuContent").hide();
|
||||
});
|
||||
|
||||
function update_sub_board_name(show_id, edit_id, field_id, domain_id, input_value) {
|
||||
if (input_value.trim() != "" && $(show_id).html().trim() != input_value.trim()) {
|
||||
if (confirm('确定修改为' + input_value + "?"))
|
||||
$.ajax({
|
||||
url: "/boards/" + field_id + "/update_name?course_id=" + domain_id + "&name=" + input_value,
|
||||
type: 'put'
|
||||
});
|
||||
else{
|
||||
$(edit_id).children("input").val($(show_id).html().trim());
|
||||
}
|
||||
}
|
||||
$(show_id).show();
|
||||
$(edit_id).hide();
|
||||
}
|
||||
|
||||
function edit(show_id, edit_id) {
|
||||
$(show_id).toggle();
|
||||
$(edit_id).toggle();
|
||||
$(edit_id).find('input').focus();
|
||||
$(edit_id).find('input').on('keypress', function (e) {
|
||||
if (e.keyCode == 13) {
|
||||
this.blur();
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,11 @@
|
|||
<% unless course_board.children.empty? %>
|
||||
<ul class="sub-menu">
|
||||
<% course_board.children.reorder("position asc").each do |board| %>
|
||||
<li>
|
||||
<% count = board ? (board.topics.count + Message.where("board_id =? and parent_id is not ?", board.id, nil).count) : 0 %>
|
||||
<a href="<%=course_boards_path(@course, :board_id =>board.id) %>"><%=board.name %><span><%=count %></span></a>
|
||||
<%= link_to( "",course_boards_path(@course, :board_id =>board.id, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
|
@ -64,12 +64,16 @@
|
|||
<a href="<%=course_path(@course) %>" >动态<span><%=@course.course_activities.count %></span></a>
|
||||
</li>
|
||||
<% 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) %>
|
||||
<li id="sy_02" class="sy_icons_boards">
|
||||
<% 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 %>
|
||||
<a href="<%=course_boards_path(@course) %>">讨论区<span><%=count %></span></a>
|
||||
<%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'sy_class_add', :title =>"#{l(:label_message_new)}") %>
|
||||
</li>
|
||||
<div id="board_children_list">
|
||||
<%= render :partial => 'layouts/board_children_list', :locals => {:course_board => course_board} %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% unless show_nav?(@course.homework_commons.count) %>
|
||||
<li id="sy_03" class="sy_icons_hwork">
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
<div class="talk_new ml15">
|
||||
<p class="talk_top"><%= l(:label_message_new) %></p>
|
||||
<ul>
|
||||
<%= 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} %>
|
||||
<a href="javascript:void(0)" onclick="submitCoursesBoard();"class="blue_btn fl c_white"><%= l(:button_submit)%></a>
|
||||
<%#= 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 %>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
TO
|
||||
<%=link_to activity.course.syllabus.title, syllabus_path(activity.course.syllabus_id), :class => 'newsBlue ml15', :target => '_blank' %>
|
||||
<span class="fb" style="color: #269ac9"> • </span>
|
||||
<%= link_to activity.course.name.to_s+" | 班级讨论区", course_boards_path(activity.course,:host=> Setting.host_course), :class => "newsBlue mr5"%>
|
||||
<%= link_to activity.course.name.to_s+" | #{activity.board.parent.nil? ? '班级讨论区' : activity.board.name}", course_boards_path(activity.course,:host=> Setting.host_course), :class => "newsBlue mr5"%>
|
||||
</div>
|
||||
<div class="homepagePostTitle hidden m_w530 fl">
|
||||
<% if activity.parent_id.nil? %> <!--+"(帖子标题)"-->
|
||||
|
|
|
@ -511,6 +511,8 @@ RedmineApp::Application.routes.draw do
|
|||
# boards
|
||||
match 'boards/:board_id/topics/new', :to => 'messages#new', :via => [:get, :post], :as => 'new_board_message'
|
||||
match 'boards/:id/join_to_org_subfields', :to => 'boards#join_to_org_subfields'
|
||||
match 'boards/:id/update_position', :to => 'boards#update_position', :via => :post
|
||||
match 'boards/:id/update_name', :to => 'boards#update_name', :via => :put
|
||||
get 'boards/:board_id/topics/:id', :to => 'messages#show', :as => 'board_message'
|
||||
match 'boards/:board_id/topics/quote/:id', :to => 'messages#quote', :via => [:get, :post]
|
||||
get 'boards/:board_id/topics/:id/edit', :to => 'messages#edit',:as=>'edit_board_message'
|
||||
|
|
|
@ -6,7 +6,7 @@ function course_setting(id)
|
|||
//$('#tbc_0'+id).removeClass().addClass("dis");
|
||||
//$('#tb_'+(3-id)).removeClass().addClass("hwork_normaltab");
|
||||
//$('#tbc_0'+(3-id)).removeClass().addClass("undis");
|
||||
for (var i = 1; i < 4; i++) {
|
||||
for (var i = 1; i < 5; i++) {
|
||||
if (i == id) {
|
||||
$("#tb_" + i).removeClass().addClass("hwork_hovertab");
|
||||
$("#tbc_0" + i).removeClass().addClass("dis");
|
||||
|
|
|
@ -282,6 +282,7 @@ h4{ font-size:14px;}/*color:#3b3b3b;*/
|
|||
.w712{width:712px; max-width:712px; min-width:712px;}
|
||||
.w713{width: 713px;}
|
||||
.w720{width:721px;}
|
||||
.w730{width:730px;}
|
||||
.w770{ width:770px;}
|
||||
.h20{height: 20px;}
|
||||
.h22{ height:22px;}
|
||||
|
|
Loading…
Reference in New Issue