课程添加成员后js提示

This commit is contained in:
sw 2015-03-30 14:55:41 +08:00
parent 083a3b9de6
commit 2af071a92e
3 changed files with 31 additions and 18 deletions

View File

@ -133,6 +133,9 @@ class MembersController < ApplicationController
elsif @course
course_info = []
if params[:membership]
@create_member_error_messages = "角色不能留空" unless params[:membership][:role_ids]
@create_member_error_messages = "用户不能留空" unless params[:membership][:user_ids]
if params[:membership][:user_ids]
attrs = params[:membership].dup
user_ids = attrs.delete(:user_ids)
@ -140,7 +143,7 @@ class MembersController < ApplicationController
member = Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
role = Role.find_by_id(params[:membership][:role_ids])
# 这里的判断只能通过角色名,可以弄成常量
if role.name == "学生" || role.name == "Student"
if role && (role.name == "学生" || role.name == "Student")
StudentsForCourse.create(:student_id => user_id, :course_id =>@course.id)
end
members << member
@ -159,6 +162,11 @@ class MembersController < ApplicationController
end
@course.members << members
@course.course_infos << course_info
@roles = Role.givable.all[3..5]
members = @course.member_principals.includes(:roles, :principal).all.sort
else
@create_member_error_messages = l(:label_user_role_null)
end
respond_to do |format|
format.html { redirect_to_settings_in_courses }

View File

@ -11,7 +11,7 @@
</li>
<div id="course_member_list">
<%= render :partial => "member" %>
<%= render :partial => "courses/member" %>
</div>
</ul>
</div><!-- 左边-->

View File

@ -1,22 +1,27 @@
<%if @project%>
$('#tab-content-members').html('<%= escape_javascript(render :partial => 'projects/settings/members') %>');
<%if !@applied_members%>
<% if @members.present? && @members.all? {|m| m.valid? } %>
<% @members.each do |member| %>
$("#member-<%= member.id %>").effect("highlight");
<% end %>
<% else %>
<% if @members %>
<% errors = @members.collect {|m| m.errors.full_messages}.flatten.uniq.join(', ')%>
alert('<%= raw(escape_javascript(l(:notice_failed_to_save_members, :errors => errors || ''))) %>');
<% else%>
// alert('');
<% end%>
<% end %>
<% end %>
<%elsif @course%>
$('#tab-content-members').html('<%= escape_javascript(render :partial => 'courses/settings/members') %>');
<% if @create_member_error_messages%>
alert("<%= @create_member_error_messages%>");
<% else%>
$('#tbc_02').html('<%= escape_javascript(render :partial => 'courses/course_members') %>');
alert("添加成功");
<% end%>
<%end%>
hideOnLoad();
<%if !@applied_members%>
<% if @members.present? && @members.all? {|m| m.valid? } %>
<% @members.each do |member| %>
$("#member-<%= member.id %>").effect("highlight");
<% end %>
<% else %>
<% if @members %>
<% errors = @members.collect {|m| m.errors.full_messages}.flatten.uniq.join(', ')%>
alert('<%= raw(escape_javascript(l(:notice_failed_to_save_members, :errors => errors || ''))) %>');
<% else%>
// alert('');
<% end%>
<% end %>
<% end %>