复制学期

This commit is contained in:
cxt 2016-01-07 15:29:25 +08:00
parent cf125159f2
commit 151c08ac5c
7 changed files with 285 additions and 10 deletions

View File

@ -1,3 +1,4 @@
#encoding: utf-8
class CoursesController < ApplicationController
# layout 'base_courses'
include CoursesHelper
@ -436,6 +437,73 @@ class CoursesController < ApplicationController
def create
cs = CoursesService.new
@course = cs.create_course(params,User.current)[:course]
if params[:copy_course]
copy_course = Course.find params[:copy_course].to_i
@course.update_attributes(:open_student => copy_course.open_student, :publish_resource => copy_course.publish_resource)
if params[:checkAll]
attachments = copy_course.attachments
attachments.each do |attachment|
attach_copied_obj = attachment.copy
attach_copied_obj.tag_list.add(attachment.tag_list) # tag关联
attach_copied_obj.container = @course
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = attachment.copy_from.nil? ? attachment.id : attachment.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
attach_copied_obj.save
update_quotes attach_copied_obj
end
elsif params[:course_attachment_type]
copy_attachments = []
params[:course_attachment_type].each do |type|
case type
when "1"
tag_name = l(:label_courseware)
when "2"
tag_name = l(:label_software)
when "3"
tag_name = l(:label_media)
when "4"
tag_name = l(:label_code)
when "6"
tag_name = "论文"
else
tag_name = ""
end
if tag_name == ""
tag_attachments = copy_course.attachments.select{|attachment|
!attachment.tag_list.include?('课件') &&
!attachment.tag_list.include?('软件') &&
!attachment.tag_list.include?('媒体') &&
!attachment.tag_list.include?('代码') &&
!attachment.tag_list.include?('论文') }
else
tag_attachments = copy_course.attachments.select{|attachment| attachment.tag_list.include?(tag_name)}
end
tag_attachments.each do |attach|
next if copy_attachments.include?(attach)
copy_attachments << attach
end
end
unless copy_attachments.blank?
copy_attachments.each do |c_attach|
attach_copied_obj = c_attach.copy
attach_copied_obj.tag_list.add(c_attach.tag_list) # tag关联
attach_copied_obj.container = @course
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = c_attach.copy_from.nil? ? c_attach.id : c_attach.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
attach_copied_obj.save
update_quotes attach_copied_obj
end
end
end
end
if @course
respond_to do |format|
flash[:notice] = l(:notice_successful_create)
@ -751,6 +819,11 @@ class CoursesController < ApplicationController
#param id:已有课程ID
def copy_course
if @course
@new_course = Course.new
respond_to do |format|
format.js
end
=begin
@new_course = Course.new @course.attributes
@new_course.tea_id = User.current.id
@new_course.created_at = DateTime.now
@ -769,6 +842,7 @@ class CoursesController < ApplicationController
@new_course.course_infos << course
redirect_to settings_course_url @new_course
end
=end
else
render_404
end
@ -829,6 +903,33 @@ class CoursesController < ApplicationController
end
private
def update_quotes attachment
if attachment.copy_from
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.copy_from} or id = #{attachment.copy_from}")
else
attachments = Attachment.find_by_sql("select * from attachments where copy_from = #{attachment.id} or id = #{attachment.copy_from}")
end
attachment.quotes = get_qute_number attachment
attachment.save
attachments.each do |att|
att.quotes = attachment.quotes
att.save
end
end
def get_qute_number attachment
if attachment.copy_from
result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.copy_from}")
else
result = Attachment.find_by_sql("select count(*) as number from attachments where copy_from = #{attachment.id}")
end
if result.nil? || result.count <= 0
return 0
else
return result[0].number
end
end
def allow_join course
if course_endTime_timeout? course
respond_to do |format|

View File

@ -2757,4 +2757,11 @@ int main(int argc, char** argv){
ss.html_safe
end
#代码提交数量
def changesets_num project
g = Gitlab.client
project.gpid.nil? ? 0 : g.commits_total_count(project.gpid).count
# # commits_total_count(project.gpid)
# project.changesets.count
end
end

View File

@ -20,14 +20,6 @@ module ProjectScoreHelper
project.documents.count
end
#代码提交数量
def changesets_num project
g = Gitlab.client
project.gpid.nil? ? 0 : g.commits_total_count(project.gpid).count
# # commits_total_count(project.gpid)
# project.changesets.count
end
#讨论区帖子数量
def board_message_num project
board_message_count = 0

View File

@ -0,0 +1,142 @@
<script type="text/javascript">
$(document).ready(function(){
$("#time").change(function(){
document.getElementById("end_time").options[document.getElementById("time").selectedIndex].selected = true;
});
$("#term").change(function(){
document.getElementById("end_term").options[document.getElementById("term").selectedIndex].selected = true;
});
var popupHeight = $(".referenceResourcesPopup").outerHeight(true);
$(".referenceResourcesPopup").css("marginTop",-popupHeight/2);
$(".resourcePopupClose").click(function(){
hideModal();
});
$("#copyResource").click(function(){
if ($("#allResource").is(":checked")){
$("input[name='course_attachment_type[]']").attr("checked",true);
}
else{
$("input[name='course_attachment_type[]']").attr("checked",false);
}
});
$("#copyResource2").click(function(){
if ($("input[name='course_attachment_type[]']:checked").length == 6){
$("#allResource").attr("checked",true);
}
else{
$("#allResource").attr("checked",false);
}
});
});
</script>
<div>
<div class="referenceText">信息配置</div>
</div>
<ul class="mt10">
<%=labelled_form_for @new_course do |f| %>
<input name="copy_course" value="<%=@course.id %>" style="display: none"/>
<li class="ml45 mb10"> <a href="javascript:void(0)" class="upimg fl"> <img alt="上传图片" id="avatar_image" src="images/courses/pic_courses.jpg" height="60" width="60"> </a> <a href="javascript:void(0)" class="upbtn fl" onclick="$('#upload_course_logo').click();">上传图片</a>
<!--</span>-->
<div class="cl"></div>
</li>
<li class="ml45">
<input type="text" style="display: none"/> <!--阻止表单自动填充 -->
<input type="password" style="display: none"/> <!--阻止表单自动填充 -->
<label><span class="c_red">*</span>&nbsp;<%= l(:label_tags_course_name)%>&nbsp;&nbsp;</label>
<input type="text" name="course[name]" id="course_name" class="courses_input" maxlength="100" onkeyup="regex_course_name();" value="<%=@course.name %>">
<span class="c_red" id="course_name_notice" style="display: none;">课程名称不能为空</span>
<div class="cl"></div>
<li class="ml45">
<label><span class="c_red">*</span>&nbsp;<%= l(:label_class_period)%>&nbsp;&nbsp;</label>
<input type="text" name="class_period" id="class_period" class="hwork_input02" onkeyup="regex_course_class_period();" maxlength="6" value="<%=@course.class_period %>">
<span class="c_red" id="course_class_period_notice" style="display: none;"></span>
</li>
<div class="cl"></div>
<li class="ml45 mb10">
<label><span class="c_red">*</span>&nbsp;<%= l(:label_course_term)%>&nbsp;&nbsp;</label>
<%= select_tag :time,options_for_select(course_time_option(@new_course.time),@new_course.time), {} %>
<%= select_tag :term,options_for_select(course_term_option,@new_course.term || cur_course_term),{} %>
<span class="c_red" id="course_time_term_notice"></span>
</li>
<div class="cl"></div>
<li class="ml45 mb10">
<label><span class="c_red">*</span>&nbsp;结束学期&nbsp;&nbsp;</label>
<%= select_tag :end_time,options_for_select(course_time_option(@new_course.end_time),@new_course.end_time), {} %>
<%= select_tag :end_term,options_for_select(course_term_option,@new_course.end_term || cur_course_term),{} %>
<span class="mr15 c_red">仅针对跨越多个学期的班级,否则不用修改。</span>
</li>
<div class="cl"></div>
<li class="ml45 mb10">
<label><span class="c_red">*</span>&nbsp;<%= l(:label_new_course_password)%>&nbsp;&nbsp;</label>
<input type="text" style="display: none;">
<input type="text" name="course[password]" id="course_course_password" class="hwork_input02" onkeyup="regex_course_password();" value="<%=@course.password %>">
<!--<a id="psw_btn" href="javascript:void(0)">显示明码</a>-->
<span class="c_red" id="course_course_password_notice"></span>
<div class="cl"></div>
<span class="ml80 c_red">学生或其他成员申请加入课程时候需要使用该口令,该口令可以由老师在课堂上公布。</span>
</li>
<li class="ml45">
<label class="fl" >&nbsp;&nbsp;<%= l(:label_new_course_description)%>&nbsp;&nbsp;</label>
<textarea name="course[description]" placeholder="最多3000个汉字(或6000个英文字符)" class="courses_text fl" ><%= @course.description.nil? ? "" : @course.description %></textarea>
<div class="cl"></div>
</li>
<li class=" mb5 ml80">
<label >公开&nbsp;&nbsp;</label>
<input <%= @course.is_public == 1 ? 'checked' : ''%> id="course_is_public" name="course[is_public]" type="checkbox" value="<%=@course.is_public.to_i %>">
<span class="c_grey">(选中后课外用户可见该课程,否则仅对课内成员可见)</span>
<div class="cl"></div>
</li>
<li class="ml48">
<label class="fl">&nbsp;&nbsp;复制资源&nbsp;&nbsp;</label>
<ul class="mb10 fl" id="copyResource">
<li class="sendCourseName fl mr15 ml5">
<label>
<input name="checkAll" type="checkbox" id="allResource" value="0" class="resourceCopy"/>
全部</label>
</li>
</ul>
<ul class="mb10 fl" id="copyResource2">
<li class="sendCourseName fl mr15">
<label>
<input name="course_attachment_type[]" type="checkbox" value="1" class="resourceCopy"/>
课件</label>
</li>
<li class="sendCourseName fl mr15">
<label>
<input name="course_attachment_type[]" type="checkbox" value="2" class="resourceCopy"/>
软件</label>
</li>
<li class="sendCourseName fl mr15">
<label>
<input name="course_attachment_type[]" type="checkbox" value="3" class="resourceCopy"/>
媒体</label>
</li>
<li class="sendCourseName fl mr15">
<label>
<input name="course_attachment_type[]" type="checkbox" value="4" class="resourceCopy"/>
代码</label>
</li>
<li class="sendCourseName fl mr15">
<label>
<input name="course_attachment_type[]" type="checkbox" value="6" class="resourceCopy"/>
论文</label>
</li>
<li class="sendCourseName fl mr15">
<label>
<input name="course_attachment_type[]" type="checkbox" value="5" class="resourceCopy"/>
其它</label>
</li>
<div class="cl"></div>
<span class="c_red ml5 fl">您可以通过选择资源类型,将对应资源复制到新课程中。</span>
</ul>
<div class="cl"></div>
</li>
<% end %>
</ul>
<div>
<a href="javascript:void(0);" class="greyBtn fr mr40" onclick="submit_new_course();">完成</a>
<a href="javascript:void(0);" class="greyBtn fr mr10" onclick="hideResource();">取消</a>
</div>
<div class="cl"></div>

View File

@ -0,0 +1,10 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'copy_course') %>');
showModal('ajax-modal', '730px');
$('#ajax-modal').css('height','530px').css('width','730px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<div class='resourcePopupClose mt5 mr-5'>" +
"<a href='javascript:void(0)' class='resourceClose' onclick='hideResource();'></a></div>");
$('#ajax-modal').parent().css("top","30%").css("left","").css("position","fixed");
$('#ajax-modal').parent().addClass("popbox").addClass("referenceResourcesPopup");

View File

@ -84,7 +84,7 @@ ID:<%= @course.id%>
<ul class="homepagePostSettiongText boxShadow">
<li><%= link_to "课程配置", {:controller => 'courses', :action => 'settings', :id => @course}, :class => "postOptionLink" %></li>
<li><%= link_to @course.is_public == 0 ? "设为公开" : "设为私有", {:controller => 'courses', :action => 'private_or_public', :id => @course},:remote=>true,:confirm=>"您确定要设置为"+(@course.is_public == 0 ? "公开" : "私有")+"吗", :class => "postOptionLink" %></li>
<!--<li><%#= link_to "复制学期", copy_course_course_path(@course.id), :class => "postOptionLink" %></li>-->
<li><%= link_to "复制学期", copy_course_course_path(@course.id),:remote=>true, :class => "postOptionLink" %></li>
</ul>
</li>
</ul>

View File

@ -962,4 +962,27 @@ span.at a{color:#269ac9;text-decoration: none;}
/*文本描述展开高度*/
.maxh360 {max-height: 810px;}
.lh18 { line-height: 18px;}
.lh18 { line-height: 18px;}
/*151228样式更新*/
.menuSetting {background:url(../images/hwork_icon.png) -5px -132px no-repeat; display:inline-block; width:20px; height:20px;}
.boxShadow {box-shadow:0px 2px 8px rgba(146, 153, 169, 0.5);}
a.greyBtn{ display:inline-block; background:#f2f3f3; padding:0px 5px; height:20px; border:1px solid #d3d3d3; color:#888888; line-height:1.9;-moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px;}
a:hover.greyBtn{border:1px solid #888888; }
a.blueBtn{ display:inline-block; background:#269ac9; padding:0px 5px; height:20px; border:1px solid #269ac9; color:#ffffff; line-height:1.9;-moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px;}
a.blueBtn:hover {background-color:#298fbd;}
a.cancelBtn{ display:inline-block; background:#c1c1c1; padding:0px 5px; height:20px; border:1px solid #d3d3d3; color:#ffffff; line-height:1.9;-moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px;}
a.cancelBtn:hover {background:#888888;}
a.userFollow{ display:inline-block; width:55px; height:20px; border:1px solid #d3d3d3; color:#888888; background:#f2f3f3 url(../images/homepage_icon2.png) -9px -6px no-repeat; padding-left:25px; line-height:1.9;-moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px;}
a:hover.userFollow{border:1px solid #888888; }
a.userCancel{ display:inline-block; width:55px; height:20px; border:1px solid #d3d3d3; color:#888888; background:#f2f3f3 url(../images/homepage_icon2.png) -177px -6px no-repeat; padding-left:25px; line-height:1.9;-moz-border-radius:2px; -webkit-border-radius:2px; border-radius:2px;}
a:hover.userCancel{border:1px solid #888888; }
.pAbsolute {position:absolute; z-index:999;}
.userAvatarWrap {width:50px; height:50px; position:relative; border:1px solid #cbcbcb; padding: 2px;}
.userAvatarWrap:hover {border:1px solid #269ac9;}
.mr27 {margin-right:27px;}
.userCard {width:208px; border:1px solid #dddddd; background-color:#ffffff; margin-top:10px; padding:15px; top:-176px; left:-95px; position:absolute; z-index:999; display:none;}
.userCard font {display:block; border-width:8px; position:absolute; bottom:-16px; left:110px; border-style:solid dashed dashed dashed; border-color:#FFF transparent transparent transparent; font-size:0; line-height:0;}
.userCard em {display:block; border-width:8px; position:absolute; bottom:-17px; left:110px; border-style:solid dashed dashed dashed; border-color:#eaeaea transparent transparent transparent; font-size:0; line-height:0;}
.userCardM {width:201px; height:20px; border:1px solid #dddddd; resize:none;}
.resourceCopy {padding:0px; margin:0px; width:12px; height:12px; display:inline-block;}