班级的配置页面,管理员增加“更换管理员”功能

This commit is contained in:
cxt 2017-02-17 15:00:14 +08:00
parent 49c6b3be12
commit b81d9b86c4
8 changed files with 145 additions and 2 deletions

View File

@ -354,6 +354,41 @@ class CoursesController < ApplicationController
#search_group_members group #search_group_members group
end end
def change_manager
if params[:chooseteacher]
man_member = Member.where(:course_id => @course.id, :user_id => @course.tea_id).first
cha_member = Member.find params[:chooseteacher]
if man_member && cha_member
cha_member.member_roles.where("role_id = 9 || role_id = 7").first.update_attributes(:role_id => 3, :is_current => 1)
if cha_member.member_roles.where("role_id = 10").count > 0
cha_member.member_roles.where("role_id = 10").first.destroy
StudentsForCourse.where(:course_id => @course.id, :student_id => cha_member.user_id).destroy_all
end
@course.update_attributes(:tea_id => cha_member.user_id)
man_member.member_roles.first.update_attributes(:role_id => 9)
course_act = CourseActivity.where(:course_id => @course.id, :course_act_id => @course.id, :course_act_type => 'Course').first
course_act.update_column('user_id', cha_member.user_id)
UserActivity.where(:act_id => @course.id, :container_type => 'Course', :act_type => 'Course', :container_id => @course.id).first.update_column('user_id', cha_member.user_id)
end
end
end
def search_course_teacher_list
q = params[:search] ? "#{params[:search].strip}" : ""
@members = searchTeacherAndAssistantNoManager(@course)
if q.nil? || q == ""
else
members = []
@members.each do |m|
username = m.user[:lastname].to_s.downcase + m.user[:firstname].to_s.downcase
if m && m.user && (m.user[:login].to_s.downcase.include?(q) || m.user[:mail].to_s.downcase.include?(q) || username.include?(q))
members << m
end
end
@members = members
end
end
#查找未分班的学生 #查找未分班的学生
def search_not_group_member def search_not_group_member
@group = CourseGroup.find params[:group_id] @group = CourseGroup.find params[:group_id]

View File

@ -257,6 +257,14 @@ module CoursesHelper
count.to_s << '+' count.to_s << '+'
end end
def searchTeacherAndAssistantNoManager course
members = []
course.members.includes(:user).each do |m|
members << m if m && m.user && m.user != course.teacher && m.user.has_teacher_role(course)
end
members
end
# ===================================================================================== # =====================================================================================
# return people list # return people list
def searchTeacherAndAssistant project def searchTeacherAndAssistant project

View File

@ -0,0 +1 @@
window.location.href = "<%= settings_course_path(@course.id, :tab => 'member') %>";

View File

@ -0,0 +1 @@
$("#search_member_list").html("<%= escape_javascript(render :partial => 'courses/settings/search_teacher_list', :locals => {:members => @members}) %>");

View File

@ -0,0 +1,76 @@
<div id="muban_popup_box" style="width:424px;">
<div class="muban_popup_top">
<h3 class="fl">更换管理员</h3>
<a href="javascript:void(0);" class="muban_icons_close fr"></a>
<div class="cl"></div>
</div>
<div class="muban_popup_con clear">
<div class="mr10 ml10">
<div class="alert alert-orange mb10 mt10">
选择的成员将会成为新的管理员,您的角色将变更为“教师”
</div>
<div class="" style="border: 1px solid #ccc">
<input type="text" name="search" value="<%=@search %>" placeholder="支持姓名、邮箱、登录名搜索" class="subjectSearch" style="height: 32px; width: 380px; margin: 5px 7px 0 7px; border: 1px solid #e5e5e5;" />
<div class="cl"></div>
<%= form_tag(change_manager_course_path(@course), method: 'post', :remote => true, :class => "",:id => "change_manager_form") do %>
<div id="search_member_list" style="padding: 0 7px;">
<%=render :partial => 'courses/settings/search_teacher_list', :locals => {:members => nil} %>
</div>
<% end %>
<div class="cl"></div>
<div class="cl"></div>
</div>
<div class="mt10">
<span class="c_red none" id="add_members_notice"></span>
<a href="javascript:void(0);" class="fr sy_btn_blue" onclick="submit_add_members_form();">确定</a>
<a href="javascript:void(0);" class="fr sy_btn_grey mr10" onclick="hideModal();">取消</a>
<div class="cl"></div>
</div>
</div>
</div>
</div>
<script>
var lastSearchCondition = '';
var count = 0;
function search_mems(e){
if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
{
return;
}
lastSearchCondition = $(e.target).val().trim();
$.ajax({
url: '<%= url_for(:controller => 'courses', :action => 'search_course_teacher_list', :id => @course.id) %>'+'?search='+ e.target.value,
type:'get'
});
}
function throttle(method,context,e){
clearTimeout(method.tId);
method.tId=setTimeout(function(){
method.call(context,e);
},500);
}
//查询项目
$("input[name='search']").on('input', function (e) {
throttle(search_mems,window,e);
});
$(document).ready(function(){
$.ajax({
url: '<%= url_for(:controller => 'courses', :action => 'search_course_teacher_list', :id => @course.id) %>',
type:'get'
});
});
function submit_add_members_form(){
if($("input[name='chooseteacher']:checked").length == 0) {
$("#add_members_notice").show();
$("#add_members_notice").html("请先选择成员");
} else{
$("#change_manager_form").submit();
hideModal();
}
}
</script>

View File

@ -59,12 +59,16 @@
<% end %> <% end %>
</td> </td>
<td> <td>
<% unless member.user == @course.teacher %> <% if member.user == @course.teacher %>
<% if User.current == @course.teacher %>
<a href="javascript:void(0)" class="sy_btn_green" onclick="change_manager();">更换管理员</a>
<% end %>
<% else %>
<a href="javascript:void(0)" class="sy_btn_blue mr5" onclick="edit_member($(this), <%=member.id %>);">编辑</a> <a href="javascript:void(0)" class="sy_btn_blue mr5" onclick="edit_member($(this), <%=member.id %>);">编辑</a>
<a href="javascript:void(0)" class="sy_btn_blue mr5" style="display: none;" onclick="$('#member-<%= member.id%>-roles-form').submit();">保存</a> <a href="javascript:void(0)" class="sy_btn_blue mr5" style="display: none;" onclick="$('#member-<%= member.id%>-roles-form').submit();">保存</a>
<a href="javascript:void(0)" class="sy_btn_grey mr5" style="display: none;" onclick="cancel_edit($(this), <%=member.id %>);">取消</a> <a href="javascript:void(0)" class="sy_btn_grey mr5" style="display: none;" onclick="cancel_edit($(this), <%=member.id %>);">取消</a>
<a href="javascript:void(0)" class="sy_btn_grey mr5" id="delete_member_<%=member.id %>" onclick="delete_confirm_box_2('<%=membership_path(member) %>', '<%= l(:label_delete_confirm)%>')">删除</a> <a href="javascript:void(0)" class="sy_btn_grey mr5" id="delete_member_<%=member.id %>" onclick="delete_confirm_box_2('<%=membership_path(member) %>', '<%= l(:label_delete_confirm)%>')">删除</a>
<% end %> <% end %>
</td> </td>
</tr> </tr>
<% end %> <% end %>
@ -87,4 +91,8 @@
$('#delete_member_' + id).show(); $('#delete_member_' + id).show();
$(div).hide(); $(div).hide();
} }
function change_manager(){
var htmlvalue = "<%= escape_javascript(render :partial => 'courses/settings/change_manager') %>";
pop_box_new(htmlvalue, 424, 366);
}
</script> </script>

View File

@ -0,0 +1,12 @@
<ul class="mt10" style="height:160px; min-height:160px; max-height:160px; overflow:auto;">
<% unless members.nil? || members.empty? %>
<% members.each do |mem| %>
<li>
<input type="radio" name="chooseteacher" value="<%=mem.id %>" class="mr5" style="vertical-align:middle;" />
<span class="break_word" style="width: 350px;"><%=mem.user.show_name %><%= mem.user.login %></span>
</li>
<% end %>
<% end %>
</ul>
<div class="cl"></div>

View File

@ -1362,6 +1362,8 @@ RedmineApp::Application.routes.draw do
get "switch_role" get "switch_role"
get 'search_not_group_member' get 'search_not_group_member'
post 'add_members' post 'add_members'
get 'search_course_teacher_list'
post 'change_manager'
get 'delete_member' get 'delete_member'
get 'archive_course' get 'archive_course'
get 'set_invite_code_halt' get 'set_invite_code_halt'