1、修改、删除分班是js方法重构

2、验证分班名是否重复重构
This commit is contained in:
sw 2015-03-26 11:30:00 +08:00
parent cfe487e217
commit ab7d12e514
8 changed files with 63 additions and 55 deletions

View File

@ -202,7 +202,7 @@ class CoursesController < ApplicationController
group.course_id = @course.id
group.save
end
@canShowCode = isCourseTeacher(User.current.id,@course) && params[:role] != '1'
@canShowCode = User.current.allowed_to?(:as_teacher,@course) && params[:role] != '1'
@is_remote = true
@course_groups = @course.course_groups
@ -236,17 +236,26 @@ class CoursesController < ApplicationController
valid_attr = params[:valid]
valid_value = params[:value]
faker = CourseGroup.new
group_id = params[:group_id]
# faker = CourseGroup.new
if valid_attr.eql?('name')
faker.name = valid_value
faker.course_id = params[:course_id]
faker.valid?
req[:valid] = faker.errors[:name].blank?
req[:message] = faker.errors[:name]
course = Course.find params[:course_id]
group_names = course.course_groups.map{|group| group.name unless group.id.to_s == group_id}.select{|group| !group.nil?}
if group_names.include?(valid_value)
req[:valid] = false
req[:message] = l(:modal_valid_unpassing)
else
req[:valid] = true
req[:message] = l(:modal_valid_passing)
end
# faker.name = valid_value
# faker.course_id = params[:course_id]
# faker.valid?
# req[:valid] = faker.errors[:name].blank?
# req[:message] = faker.errors[:name]
end
req[:message] = l(:modal_valid_passing) if req[:message].blank?
# req[:message] = l(:modal_valid_passing) if req[:message].blank?
render :json => req
end
def join_group

View File

@ -4,7 +4,7 @@
</div>
<div class="cl"></div>
<div class="st_addclass">
<div class="st_addclass" id="st_groups">
<%= render :partial => 'new_groups_name', :locals => {:course_groups => @course_groups} %>
</div>
<div class="cl"></div>

View File

@ -1,7 +1,7 @@
<ul>
<li style=" color:#8b8b8b;">分班:</li>
<li class="classbox">
<%= link_to l(:label_all), searchgroupmembers_course_path(@course,:group_id => 0), :onclick => "checkclass('group_name_0')", method: 'get', remote: true%>
<li class="classbox" id="course_group_0">
<%= link_to l(:label_all), searchgroupmembers_course_path(@course,:group_id => 0), :onclick => "checkclass('course_group_0')", method: 'get', remote: true%>
</li>
<% unless course_groups.nil? %>
@ -20,16 +20,16 @@
<img src="/images/pic_del.gif" width="11" height="12" alt="删除班级" title="删除该班级" />
</a>
<% end %>
<a href="javascript:void(0)" class="f_l" style="padding-left: 5px;" onclick="$('#group_name_<%= group.id %>').value='';$('#edit_group_<%= group.id %>').slideToggle();">
<a href="javascript:void(0)" class="f_l" style="padding-left: 5px;" onclick="$('#group_name_<%= group.id %>').val('');$('#edit_group_<%= group.id %>').slideToggle();">
<img src="/images/pic_edit.png" width="14" height="15" alt="编辑班级" />
</a>
</li>
<!-- 编辑分班 -->
<li>
<%= form_tag(updategroupname_course_path(@course,:group_id => group.id), method: 'get', remote:true, update: 'group_name') do %>
<%= form_tag(updategroupname_course_path(@course,:group_id => group.id), method: 'get', remote:true, :id => 'update_group_'+group.id.to_s) do %>
<span id="edit_group_<%= group.id %>" style="display:none; vertical-align: middle;" class=" f_l">
<input type="text" id="group_name_<%= group.id%>" name="group_name" size="20" class="isTxt w90 f_l" maxlength="100" />
<input type="button" class="submit f_l" onclick="edit_group('edit_group_<%= group.id%>');"/>
<input type="button" class="submit f_l" onclick="edit_group('group_name_<%= group.id%>','<%= valid_ajax_course_path%>','<%= @course.id%>','<%= group.id%>');"/>
</span>
<% end %>
</li>
@ -42,9 +42,9 @@
</li>
<li >
<span id="new_group_name" style="display:none; vertical-align: middle;" class="ml10 f_l">
<%= form_tag( addgroups_course_path(@course), method: 'get',:remote=>true) do %>
<%= form_tag( addgroups_course_path(@course), method: 'get',:remote=>true,:id => 'add_group_name') do %>
<input type="text" id="group_name" name="group_name" size="20" class="isTxt w90 f_l" maxlength="100" />
<input type="button" class="submit f_l" onclick="edit_group('group_name');"/>
<input type="button" class="submit f_l" onclick="add_group('<%= valid_ajax_course_path%>','<%= @course.id%>');"/>
<% end %>
</span>
</li>

View File

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

View File

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

View File

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

View File

@ -2088,6 +2088,7 @@ zh:
label_open_anonymous_evaluation: 是否匿评
label_evaluation_description: 即每份作业被允许匿评的人数
label_name_not_null: 名称不能为空
modal_valid_unpassing: 该分班已经存在

View File

@ -1,47 +1,45 @@
///////////////////////////////////////////////////////////////
function check_groupname(course_id) {
var $group_name = $('#group_name');
//添加分班
function add_group(url,course_id) {
var group_name = $('#group_name').val();
$.get(
'<%=valid_ajax_course_path%>',
url,
{ valid: "name",
value: document.getElementById('group_name').value,
value: group_name,
course_id: course_id },
function (data) {
if (!data.valid) {
if (data.valid) {
$("#add_group_name").submit();
}
else
{
alert(data.message);
}
});
}
function validate_groupname(value1) {
if(value1.length > 20) {
alert('<%= l(:label_limit_groupname) %>');
}
}
function checkclass(value) {
for(var i = 0; i < document.getElementsByName("check_group_name").length; i++) {
if(document.getElementsByName("check_group_name")[i].id == value) {
document.getElementById(value).className = "selected";
}
else {
document.getElementsByName("check_group_name")[i].className = "classbox";
);
}
//修改分班:修改分班时得考虑什么都不改但是点击确定的情况
function edit_group(id,url,course_id,group_id)
{
var group_name = $('#'+id).val();
$.get(
url,
{
valid: "name",
value: group_name,
course_id: course_id,
group_id: group_id
},
function (data) {
if (data.valid) {
$("#update_group_"+group_id).submit();
}
else
{
alert(data.message);
}
}
}
}
function validate_groupname_null(value1) {
value1 = value1.trim();
if(value1.length == 0 ) {
alert('<%= l(:label_limit_groupname_null) %>');
}
}
function validate_update(name) {
value1 = document.getElementById(name).value;
validate_groupname(value1);
}
function validate_add_group() {
check_groupname();
);
}
///////////////////////////////////////////////////////////////