增加<修改,添加分组>功能

Signed-off-by: alan <547533434@qq.com>
This commit is contained in:
alan 2014-12-04 19:09:10 +08:00
parent 3d12d6f0e8
commit 9765f11f7e
14 changed files with 136 additions and 37 deletions

View File

@ -78,7 +78,21 @@ class CoursesController < ApplicationController
format.js { render :partial => 'set_join', :locals => {:user => User.current, :course => Course.find(params[:object_id]), :object_id => params[:object_id]} }
end
end
def join_group
group = CourseGroup.find(params[:object_id])
member = Member.find(:conditions => {:course_id => @course.id, :user_id => User.current.id}).first
member.course_group_id = group.id
member.save
end
def unjoin_group
member = Member.find(:conditions => {:course_group_id => params[object_id], :user_id => User.current.id}).first
member.course_group_id = 0
member.save
end
def new_join_group
end
def join_private_courses
respond_to do |format|
format.js
@ -198,7 +212,7 @@ class CoursesController < ApplicationController
def searchmembers
@render_file = 'member_list'
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true
q = "#{params[:name].strip}"
#(redirect_to stores_url, :notice => l(:label_sumbit_empty);return) if params[:name].blank?
@ -208,15 +222,36 @@ class CoursesController < ApplicationController
end
def addgroups
if params[:group_name]
group = CourseGroup.new
group.name = params[:group_name]
group.course_id = @course.id
group.save
end
@course_groups = @course.course_groups
end
def updategroupname
if params[:group_name]
group = CourseGroup.find(params[:group_id])
group.name = params[:group_name]
group.save
end
@course_groups = @course.course_groups
end
def searchgroupmembers
@render_file = 'member_list'
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@is_remote = true
if params[:group_id] && params[:group_id] != "0"
@group = CourseGroup.find(params[:group_id])
@results = searchStudent_by_group(@group)
else
@results = searchStudent(@course)
end
@results = paginateHelper @results
end
def member
## 有角色参数的才是课程,没有的就是项目

View File

@ -199,6 +199,14 @@ module CoursesHelper
end
members
end
def searchStudent_by_group group
#searchPeopleByRoles(project, StudentRoles)
members = []
group.members.each do |m|
members << m if m && m.user && m.user.allowed_to?(:as_student,project)
end
members
end
# =====================================================================================
#def searchCountByRoles project, roles_id

View File

@ -109,6 +109,28 @@ module WatchersHelper
link_to text, url_f, :remote => true, :method => method, :id => "#{course.id}", :class => []+options
end
end
def join_in_course_group(coursegroups,group, user, options=[])
return '' unless user && user.logged?
@isjoin = false
coursegroups.each do |g|
@isjoin = user.member_of_course_group?(g)
end
url_t = join_group_path(:object_id => group.id)
url_f = try_join_group_path(:object_id => group.id)
if @isjoin == true
joined = user.member_of_course_group?(group)
text = l(:label_exit_course)
if joined
link_to text, url_t, :remote => true, :method => 'delete', :id => "#{group.id}", :confirm => l(:text_are_you_sure_out), :class => []+options
end
else
text = l(:label_new_join)
link_to text, url_f, :remote => true, :method => 'post', :id => "#{group.id}", :class => []+options
end
end
# 用户是否允许加入课程判断
# add by nwb

View File

@ -1,7 +1,13 @@
class CourseGroup < ActiveRecord::Base
# attr_accessible :title, :body
belongs_to :course
has_many :members
has_many :members, :include => [:principal, :roles], :conditions => "#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE}"
has_many :memberships, :class_name => 'Member'
has_many :member_principals, :class_name => 'Member',
:include => :principal,
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
has_many :principals, :through => :member_principals, :source => :principal
has_many :users, :through => :members
before_destroy :set_member_nil

View File

@ -30,6 +30,7 @@ class Principal < ActiveRecord::Base
has_many :projects, :through => :memberships
#add by nwb
has_many :courses, :through => :coursememberships
has_many :course_groups, :through => :coursememberships
has_many :issue_categories, :foreign_key => 'assigned_to_id', :dependent => :nullify
# Groups and active users

View File

@ -690,6 +690,9 @@ class User < Principal
courses.to_a.include?(course)
end
def member_of_course_group?(course_group)
course_groups.to_a.include?(course_group)
end
# Returns a hash of user's projects grouped by roles
def projects_by_role
return @projects_by_role if @projects_by_role

View File

@ -1,51 +1,59 @@
<script type="application/javascript">
function asign_id(id) {
document.getElementById(id).value = id;
}
</script>
<%# if course_groups.any? %>
<ul>
<li style=" color:#8b8b8b;">分班:</li>
<% form_tag(searchgroupmembers_course_path(@course), :method => 'get', :remote => true) do %>
<li class="classbox">
<%= hidden_field 'all', params[:group_id], name: 'all' %>
<%= submit_tag l:(label_all), :onclick => "asign_id('all')" %>
</li>
<% end %>
<li id="show_groups" class="classbox">
<li class="classbox">
<%= form_tag( searchgroupmembers_course_path(@course, :group_id => 0), method: 'get',:remote=>true) do %>
<%= hidden_field_tag "all", params[:group_id], name: 'all' %>
<%= submit_tag l(:label_all), :style => "background: #f8df8c; border:0px; color: black" %>
<% end %>
</li>
<% if course_groups.any? %>
<% course_groups.each do |group| %>
<li class="classbox" id="group_name_<%= group.id %>">
<% form_tag(searchgroupmembers_course_path(@course), :method => 'get', :remote => true) do %>
<%= hidden_field group, :id, :value => params[:group_id] %>
<%= submit_tag l:(label_all), :onclick => "asign_id(#{group.id})" %>
<%= form_tag(searchgroupmembers_course_path(@course,:group_id => group.id), method: 'get', remote: true) do %>
<%#= text_field_tag "group_id", params[:group_id] %>
<%= submit_tag group.name, :onclick => "$asign_id(#{group.id})",:style => "background: #f8df8c; border:0px; color: black; float:left;"%>
<% if @canShowCode %>
<a href="javascript:void(0)" class="f_l" onclick="$('#add_tag_<%= group.id %>').slideToggle();"><img src="/images/pic_edit.png" width="14" height="15" alt="编辑班级" /></a>
<% end %>
<% end %>
<a href="javascript:void(0)" class="f_l" onclick="$('#add_tag_<%= group.id %>').slideToggle();"><img src="images/pic_edit.png" width="14" height="15" alt="编辑班级" /></a>
</li>
</li>
<li>
<% form_tag(updategroupname_course_path(@course), :method => 'get', :remote => true, :update => 'group_name') do %>
<%= form_tag(updategroupname_course_path(@course,:group_id => group.id), method: 'get', remote:true, update: 'group_name') do %>
<span id="add_tag_<%= group.id %>" style="display:none; vertical-align: middle;" class=" f_l">
<%= text_field group, :value => params[:group_name], :size=>"20", :class=>"isTxt w90 f_l", :style=>"padding: 0px", :max => 100 %>
<%= text_field_tag "group_name", params[:group_name], :size=>10, :class=>"isTxt w90 f_l", :style=>"padding: 0px", :max => 100 %>
<!--<input type="button" class="submit f_l" onclick="addTag();" style="width: 43px"/>-->
<%= submit_tag group.name, :class => "submit f_1", :style => "width: 43px;", :update => "group_name_#{group.id}" %>
</span>
<%= submit_tag '', class: "submit f_l", style: "width: 43px;height: 21px;background: url(/images/btn.png) no-repeat 0 0;" %>
</span>
<% end %>
</li>
<% end %>
<% end %>
<li style="margin-left:15px;">
<a href="javascript:void(0)" class="st_add f_l" onclick="$('#add_tag04').slideToggle();">+添加分班</a>
</li>
<li>
<span id="add_tag04" style="display:none; vertical-align: middle;" class="ml10 f_l">
<input type="text" id="" name="" size="20" class="isTxt w90 f_l" style="padding: 0px" maxlength="100" />
<input type="button" class="submit f_l" onclick="addTag();" style="width: 43px"/>
<input type="button" class="submit_2" onclick="$('#add_tag04').slideToggle();" style="width: 43px"/>
</span>
<span id="add_tag04" style="display:none; vertical-align: middle;" class="ml10 f_l">
<%= form_tag( addgroups_course_path(@course), method: 'get',:remote=>true) do %>
<%= text_field_tag "group_name", params[:group_name], size: "20", class: "isTxt w90 f_l", style: "padding: 0px", maxlength: "100" %>
<%= submit_tag '', class: "submit f_l", style: "width: 43px;height: 21px;background: url(/images/btn.png) no-repeat 0 0;" %>
<%= link_to_function '', "$('#add_tag04').slideToggle();", class: "submit_2", style: "width: 43px"%>
<% end %>
</span>
</li>
</ul>
<div class="cl"></div>
<span class="f_l"><%= @group %><%= @subPage_title %></span>
<% if !@canShowCode %>
<%= join_in_course_group(@course.course_groups,@group, User.current) %>
<% end %>
<%# end %>

View File

@ -0,0 +1 @@
$("#st_groups").html("<%= escape_javascript( render :partial => 'groups_name', locals: {:course_groups => @course_groups})%>");

View File

@ -12,13 +12,14 @@
<% end %>
</div>
<div class="cl"></div>
<%# if @canShowCode %>
<div class="st_addclass">
<div class="st_addclass" id = "st_groups">
<%= render :partial => 'groups_name', locals: {:course_groups => @course_groups} %>
</div>
<%# end %>
<div class="cl"></div>
<div class="member_content" id = "member_content">
<%= error_messages_for 'member' %>
<%= render :partial => @render_file, :locals => {:members => @members} %>

View File

@ -0,0 +1,4 @@
/**
* Created by Administrator on 2014/12/3.
*/
$("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @results})%>");

View File

@ -0,0 +1,4 @@
/**
* Created by Administrator on 2014/12/3.
*/
$("#st_groups").html("<%= escape_javascript( render :partial => 'groups_name', locals: {:course_groups => @course_groups})%>");

View File

@ -1120,6 +1120,7 @@ zh:
text_workflow_edit: 选择角色和跟踪标签来编辑工作流程
text_are_you_sure: 您确定要删除吗?
text_are_you_sure_out: 你确定要退出该课程吗?
text_are_you_sure_out_group: 你确定要退出该分组吗?
text_journal_changed: "%{label} 从 %{old} 变更为 %{new}"
text_journal_set_to: "%{label} 被设置为 %{value}"
text_journal_deleted: "%{label} 已删除 (%{old})"

View File

@ -644,7 +644,9 @@ RedmineApp::Application.routes.draw do
post 'finishcourse'
post 'restartcourse'
match "searchmembers", :controller => 'courses', :action => 'searchmembers', :via => [:post,:get]
match "searchgroupmembers", :via => [:post, :get]
match "updategroupname", :via => [:post, :get]
match "addgroups", :via => [:post, :get]
end
collection do
match 'join_private_courses', :via => [:get, :post]
@ -741,6 +743,8 @@ RedmineApp::Application.routes.draw do
post 'join_in/join', :to => 'courses#join', :as => 'join'
delete 'join_in/join', :to => 'courses#unjoin'
post 'join_in/join_group', :to => 'courses#join_group', :as => 'join_group'
delete 'join_in/join_group', :to => 'courses#unjoin_group'
post 'calls/:id/join_in_contest', :to => 'bids#join_in_contest', :as => 'join_in_contest'
delete 'calls/:id/join_in_contest', :to => 'bids#unjoin_in_contest'
match 'calls/:id/show_participator', :to => 'bids#show_participator' # bai
@ -749,6 +753,7 @@ RedmineApp::Application.routes.draw do
delete 'attachment/:id', :to => 'attachments#delete_homework'
match 'new_join', :to => 'courses#new_join', :as => 'try_join'
match 'new_join_group', :to => 'courses#new_join_group', :as => 'try_join_group'
match 'new_join_in_contest', :to => 'bids#new_join', :as => 'try_join_in_contest'
match 'projects/:id/respond', :to => 'projects#project_respond', :via => :post
match 'calls/:id/manage',:to => 'bids#manage',:via => [:get,:post]