diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb
index ccb02d939..8a3c58244 100644
--- a/app/controllers/courses_controller.rb
+++ b/app/controllers/courses_controller.rb
@@ -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
## 有角色参数的才是课程,没有的就是项目
diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb
index ccca6be9d..5da100fa9 100644
--- a/app/helpers/courses_helper.rb
+++ b/app/helpers/courses_helper.rb
@@ -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
diff --git a/app/helpers/watchers_helper.rb b/app/helpers/watchers_helper.rb
index 6d916f43e..3b49f3d48 100644
--- a/app/helpers/watchers_helper.rb
+++ b/app/helpers/watchers_helper.rb
@@ -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
diff --git a/app/models/course_group.rb b/app/models/course_group.rb
index 236a51145..bb7be5af9 100644
--- a/app/models/course_group.rb
+++ b/app/models/course_group.rb
@@ -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
diff --git a/app/models/principal.rb b/app/models/principal.rb
index 024480635..30c064f6f 100644
--- a/app/models/principal.rb
+++ b/app/models/principal.rb
@@ -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
diff --git a/app/models/user.rb b/app/models/user.rb
index ef327f47f..57077f167 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
diff --git a/app/views/courses/_groups_name.html.erb b/app/views/courses/_groups_name.html.erb
index 804b3f805..6256bd4f7 100644
--- a/app/views/courses/_groups_name.html.erb
+++ b/app/views/courses/_groups_name.html.erb
@@ -1,51 +1,59 @@
-
-<%# if course_groups.any? %>
+
+
- 分班:
- <% form_tag(searchgroupmembers_course_path(@course), :method => 'get', :remote => true) do %>
- -
- <%= hidden_field 'all', params[:group_id], name: 'all' %>
- <%= submit_tag l:(label_all), :onclick => "asign_id('all')" %>
-
- <% end %>
- -
+
-
+ <%= 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 %>
+ <% if course_groups.any? %>
<% course_groups.each do |group| %>
-
- <% 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 %>
+
+ <% end %>
<% end %>
-
-
+
-
- <% 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 %>
- <%= 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 %>
- <%= submit_tag group.name, :class => "submit f_1", :style => "width: 43px;", :update => "group_name_#{group.id}" %>
-
+ <%= submit_tag '', class: "submit f_l", style: "width: 43px;height: 21px;background: url(/images/btn.png) no-repeat 0 0;" %>
+
<% end %>
<% end %>
+ <% end %>
-
+添加分班
-
-
-
-
-
-
+
+ <%= 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 %>
+
-
+
+ <%= @group %><%= @subPage_title %>
+ <% if !@canShowCode %>
+ <%= join_in_course_group(@course.course_groups,@group, User.current) %>
+ <% end %>
- <%# end %>
\ No newline at end of file
diff --git a/app/views/courses/addgroups.js.erb b/app/views/courses/addgroups.js.erb
new file mode 100644
index 000000000..a6f6933b9
--- /dev/null
+++ b/app/views/courses/addgroups.js.erb
@@ -0,0 +1 @@
+$("#st_groups").html("<%= escape_javascript( render :partial => 'groups_name', locals: {:course_groups => @course_groups})%>");
\ No newline at end of file
diff --git a/app/views/courses/member.html.erb b/app/views/courses/member.html.erb
index 4f7b395b0..5d596efeb 100644
--- a/app/views/courses/member.html.erb
+++ b/app/views/courses/member.html.erb
@@ -12,13 +12,14 @@
<% end %>
- <%# if @canShowCode %>
-
+
+
<%= render :partial => 'groups_name', locals: {:course_groups => @course_groups} %>
- <%# end %>
+
+
<%= error_messages_for 'member' %>
<%= render :partial => @render_file, :locals => {:members => @members} %>
diff --git a/app/views/courses/searchgroupmembers.js.erb b/app/views/courses/searchgroupmembers.js.erb
new file mode 100644
index 000000000..c6ff97164
--- /dev/null
+++ b/app/views/courses/searchgroupmembers.js.erb
@@ -0,0 +1,4 @@
+/**
+ * Created by Administrator on 2014/12/3.
+ */
+$("#member_content").html("<%= escape_javascript( render :partial => @render_file, :locals => {:members => @results})%>");
\ No newline at end of file
diff --git a/app/views/courses/searchmembers.js b/app/views/courses/searchmembers.js.erb
similarity index 100%
rename from app/views/courses/searchmembers.js
rename to app/views/courses/searchmembers.js.erb
diff --git a/app/views/courses/updategroupname.js.erb b/app/views/courses/updategroupname.js.erb
new file mode 100644
index 000000000..8eb4e865c
--- /dev/null
+++ b/app/views/courses/updategroupname.js.erb
@@ -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})%>");
\ No newline at end of file
diff --git a/config/locales/zh.yml b/config/locales/zh.yml
index 5aedd93a7..13302a77c 100644
--- a/config/locales/zh.yml
+++ b/config/locales/zh.yml
@@ -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})"
diff --git a/config/routes.rb b/config/routes.rb
index 7a6a8aae0..f3f2a7e91 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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]