班级资源的批量设置

This commit is contained in:
cxt 2017-09-13 16:05:55 +08:00
parent 9b51225c23
commit d5488ba806
9 changed files with 202 additions and 98 deletions

View File

@ -70,14 +70,37 @@ class AttachmentsController < ApplicationController
file.downcase.end_with?(".pdf") file.downcase.end_with?(".pdf")
end end
def upload_atta
@course = Course.find params[:course_id]
end
def batch_setting def batch_setting
@course = Course.find params[:course_id] @course = Course.find params[:course_id]
@attachments = @course.attachments.reorder("created_on desc") @attachments = @course.attachments.reorder("created_on desc")
@limit = 10 @all_attachment_ids = @attachments.map(&:id).join(",")
@limit = 8
@attachment_count = @attachments.count @attachment_count = @attachments.count
@attachment_pages = Paginator.new @attachment_count, @limit, params['page'] || 1 @attachment_pages = Paginator.new @attachment_count, @limit, params['page'] || 1
@offset ||= @attachment_pages.offset @offset ||= @attachment_pages.offset
@attachments = paginateHelper @attachments,10 @attachments = paginateHelper @attachments, @limit
end
def resource_batch_setting
@course = Course.find params[:course_id]
attachments = Attachment.where(:id => params[:choose_ids].split(','))
if params[:is_delete] && params[:is_delete] == "1"
attachments.each do |attachment|
attachment.container.attachments.delete(attachment)
end
else
unless params[:publish_time] == ""
attachments.update_all(:publish_time => params[:publish_time], :is_publish => 0)
end
if params[:is_public]
attachments.update_all(:is_public => 1)
end
end
redirect_to course_files_path(@course)
end end
def direct_download def direct_download

View File

@ -1,104 +1,49 @@
<script src="/javascripts/jquery.datetimepicker.js" type="text/javascript"></script>
<div id="muban_popup_box" style="width:550px;"> <div id="muban_popup_box" style="width:550px;">
<div class="muban_popup_top"> <div class="muban_popup_top">
<h3 class="fl">资源发布批量设置</h3> <h3 class="fl">资源发布批量设置</h3>
<a href="javascript:void(0);" class="muban_icons_close fr" onclick="$('#datetimepicker_mask').datetimepicker('destroy');"></a> <a href="javascript:void(0);" class="muban_icons_close fr" onclick="$('#datetimepicker_mask_batch').datetimepicker('destroy');"></a>
<div class="cl"></div> <div class="cl"></div>
</div> </div>
<div class="muban_popup_con clear"> <div class="muban_popup_con clear mt20 ml20 mr20">
<%= form_tag(resource_batch_setting_attachments_path(:course_id => @course), :id => 'batch_setting_form', :method => 'post') do %>
<input name="choose_ids" type="hidden" value="" id="choose_resource_ids">
<input type="hidden" name="all_check" value="0">
<input type="hidden" name="is_delete" value="0">
<div style="border-bottom: 1px solid #eeeeee;"> <div style="border-bottom: 1px solid #eeeeee;">
<div id="source_list"> <div id="source_list">
<table class="sy_new_table clear sy_new_table_width" cellpadding="0" cellspacing="0" id="student_list_table" style="border: none;text-align: left;"> <%= render :partial => "attachments/batch_setting_resources" %>
<thead>
<tr class="clear">
<th><input type="checkbox" name="check_all" class="fl mr5 mt8 ml10" />资源名称</th>
<th>上传者</th>
</tr>
</thead>
<tbody>
<% @attachments.each do |attachment| %>
<tr>
<td><input type="checkbox" name="attachments[]" class="fl mr5 mt8 ml10" /><%= attachment.filename %></td>
<td><%= attachment.author.show_name %>/td>
</tr>
<% end %>
</tbody>
</table>
</div>
<div class="clear">
<div class="resourcesSelectSendButton fl mt10 mr15 inactive-border">
<a href="javascript:void(0);" class="sendButtonBlue db inactive-text" data-remote="true">删除</a>
</div>
<ul class="wlist" id="pages" style="margin-top: 15px;">
<li><a href="" class="previous c_blue" data-remote="true">上一页</a></li>
<li class="wlist_select"><a class="current-page c_white">1</a></li>
<li><a href="" class="page c_blue" data-remote="true">2</a></li>
<li><a href="" class="next c_blue" data-remote="true">下一页</a></li>
</ul>
</div> </div>
</div> </div>
<ul class="ul-align"> <ul class="ul-align">
<li class="clear mt10">
<label class="fl">延期发布:&nbsp;</label>
<div class="calendar_div fl mt4">
<input type="text" name="publish_time" id="datetimepicker_mask_batch" placeholder="发布时间(可选)" style="width: 130px;" class="InputBox fl calendar_input" readonly="readonly">
</div>
<a href="javascript:void(0)" id="reset_time_batch" class="fl sy_btn_grey ml10" style="display: none;" onclick="reset_publish_time_batch();">清空</a>
<div class="cl"></div>
<span class="c_red f12" style="margin-top: 4px;" id="publish_time_notice_batch"></span>
</li>
<li class="clear"> <li class="clear">
<label class="fl">公开:&nbsp;</label> <label class="fl">公开:&nbsp;</label>
<span> <span>
<input type="checkbox" id="set_public" name="public" class="fl mt10 mr5" style="height: 20px;"/> <input type="checkbox" id="set_public" name="is_public" class="fl mt10 mr5" style="height: 20px;"/>
<label for="set_public">选中后所有用户可见,否则仅课堂成员可见</label> <label for="set_public">选中后所有用户可见,否则仅课堂成员可见</label>
</span> </span>
</li> </li>
<li class="clear">
<label class="fl">延期发布:&nbsp;</label>
<div class="calendar_div fl ml10">
<input type="text" name="publish_time" id="datetimepicker_mask" placeholder="发布时间(可选)" style="width: 130px;" class="InputBox fl calendar_input" readonly="readonly">
</div>
<a href="javascript:void(0)" id="reset_time" class="fl sy_btn_grey ml10" style="display: none;" onclick="reset_publish_time();">清空</a>
<div class="cl"></div>
<span class="c_red f12" style="margin-top: 4px;" id="publish_time_notice"></span>
<input type="text" placeholder="发布时间(可选)" />
</li>
</ul> </ul>
<p class="clear mt5"> <p class="clear mt5">
<a href="javascript:void(0);" onfocus="this.blur();" onclick="send_submit();" class="sy_btn_blue fr mr10">发&nbsp;&nbsp;送</a> <a href="javascript:void(0);" onclick="submit_course_resource_batch();" class="sy_btn_blue fr mr10">保&nbsp;&nbsp;存</a>
<a href="javascript:void(0);" onclick="hideModal();" class="sy_btn_grey fr mr10">取&nbsp;&nbsp;消</a> <a href="javascript:void(0);" onclick="$('#datetimepicker_mask_batch').datetimepicker('destroy'); hideModal();" class="sy_btn_grey fr mr10">取&nbsp;&nbsp;消</a>
</p> </p>
<% end %>
</div> </div>
</div> </div>
<script> <script>
function regex_publish_time()
{
var myDate = new Date();
if($.trim($("#datetimepicker_mask").val()) == "")
{
return true;
} else{
var publish_time = Date.parse($("#datetimepicker_mask").val());
if(Date.parse(formate_time(myDate)) > publish_time)
{
$("#publish_time_notice").text("发布时间不能小于当前时间");
return false;
}
else
{
$("#publish_time_notice").text("");
return true;
}
}
}
function submit_course_resource()
{
<% if User.current.allowed_to?(:as_teacher,course) %>
if(regex_publish_time()) {
$('#submit_resource').parent().submit();
}
<% else %>
$('#submit_resource').parent().submit();
<% end %>
}
function reset_publish_time(){
$("#datetimepicker_mask").val('');
$("#reset_time").hide();
}
$(function(){ $(function(){
$('#datetimepicker_mask').datetimepicker({ $('#datetimepicker_mask_batch').datetimepicker({
allowBlank:true, allowBlank:true,
lang:'ch', lang:'ch',
format:'Y-m-d H:i', format:'Y-m-d H:i',
@ -106,11 +51,74 @@
formatDate:'Y-m-d', formatDate:'Y-m-d',
validateOnBlur:false, validateOnBlur:false,
onSelectDate:function() { onSelectDate:function() {
$("#reset_time").show(); $("#reset_time_batch").show();
}, },
onSelectTime:function() { onSelectTime:function() {
$("#reset_time").show(); $("#reset_time_batch").show();
}
});
$("#source_list").on('change', "input[name='attachments[]']", function(){
var choose_ids = $("#choose_resource_ids").val() == "" ? [] : $("#choose_resource_ids").val().split(",");
if($(this).is(':checked')){
choose_ids.push($(this).val());
} else{
$("input[name='all_check']").val(0);
$("input[name='check_all']").attr('checked', false);
choose_ids.splice($.inArray($(this).val(),choose_ids),1);
}
if(choose_ids.length != 0){
$("#choose_resource_ids").val(choose_ids.join(","));
} else{
$("#choose_resource_ids").val('');
} }
}); });
}); });
function regex_publish_time_batch()
{
var myDate = new Date();
if($.trim($("#datetimepicker_mask_batch").val()) == "")
{
return true;
} else{
var publish_time = Date.parse($("#datetimepicker_mask_batch").val());
if(Date.parse(formate_time(myDate)) > publish_time)
{
$("#publish_time_notice_batch").text("发布时间不能小于当前时间");
return false;
}
else
{
$("#publish_time_notice_batch").text("");
return true;
}
}
}
function submit_course_resource_batch()
{
if($("input[name='attachments[]']:checked").length == 0){
$("#atta_check_notice_batch").show();
} else{
if(regex_publish_time_batch()) {
$('#batch_setting_form').submit();
hideModal();
}
}
}
function reset_publish_time_batch(){
$("#datetimepicker_mask_batch").val('');
$("#reset_time_batch").hide();
}
function delete_resources(){
$("input[name='is_delete']").val(1);
if($("input[name='attachments[]']:checked").length == 0){
$("#atta_check_notice_batch").show();
} else{
$("#atta_check_notice_batch").hide();
$('#batch_setting_form').submit();
hideModal();
}
}
</script> </script>

View File

@ -0,0 +1,60 @@
<table class="sy_new_table clear sy_new_table_width" cellpadding="0" cellspacing="0" id="student_list_table" style="border: none;text-align: left;">
<thead>
<tr class="clear">
<th style="width: 80%;"><input type="checkbox" name="check_all" class="fl mr5 mt8" />资源名称</th>
<th class="t_c">上传者</th>
</tr>
</thead>
<tbody>
<% @attachments.each do |attachment| %>
<tr>
<td style="text-align: left;">
<input type="checkbox" name="attachments[]" value="<%= attachment.id %>" id="attachment_<%= attachment.id %>" class="fl mr5 mt8" />
<label for="attachment_<%= attachment.id %>"><%= attachment.filename %></label>
</td>
<td class="t_c"><%= attachment.author.show_name %></td>
</tr>
<% end %>
</tbody>
</table>
<div class="clear">
<span class="c_red f12 none" style="margin-top: 4px;" id="atta_check_notice_batch">请至少选择一个资源</span>
<div class="cl"></div>
<div class="resourcesSelectSendButton fl mt10 mr15 inactive-border">
<a href="javascript:void(0);" class="sendButtonBlue db inactive-text" onclick="delete_resources()">删除</a>
</div>
<div class="pageRoll fr mt15">
<ul class="wlist" style="margin-top: 0px;">
<%= pagination_links_full @attachment_pages, @attachment_count, :per_page_links => false, :remote => true, :flag => true %>
</ul>
</div>
</div>
<script>
$(function(){
if($("#choose_resource_ids").val() != ""){
var choose_ids = $("#choose_resource_ids").val().split(",");
for (var i = 0; i < choose_ids.length; i++){
$("#attachment_" + choose_ids[i]).attr("checked", "checked");
}
}
if($("input[name='all_check']").val() == '1'){
$("input[name='check_all']").attr('checked', true);
$("input[name='attachments[]']").attr('checked', true);
}
$("input[name='check_all']").on('change', function(){
if($("input[name='check_all']").is(':checked')){
$("input[name='all_check']").val(1);
$("#choose_resource_ids").val("<%= @all_attachment_ids %>");
$("input[name='attachments[]']").attr('checked', true);
} else{
$("input[name='all_check']").val(0);
$("#choose_resource_ids").val("");
$("input[name='attachments[]']").attr('checked', false);
}
});
});
</script>

View File

@ -1,2 +1,6 @@
var htmlvalue = "<%= j(render :partial => 'attachments/batch_setting') %>"; <% if params[:page] %>
pop_box_new(htmlvalue, 500, 500); $("#source_list").html("<%= escape_javascript(render :partial => 'attachments/batch_setting_resources') %>");
<% else %>
var htmlvalue = "<%= escape_javascript(render :partial => 'attachments/batch_setting') %>";
pop_box_new(htmlvalue, 530, 500);
<% end %>

View File

@ -0,0 +1,2 @@
var htmlvalue = '<%= escape_javascript(render :partial => 'files/upload_course_files',:locals => {:course => @course,:course_attachment_type => 1}) %>';
pop_box_new(htmlvalue, 450, 275);

View File

@ -103,8 +103,8 @@
<%= submit_tag "班内搜索", :class => "blueBtn mr5 fl",:name => "incourse",:id => "incourse" %> <%= submit_tag "班内搜索", :class => "blueBtn mr5 fl",:name => "incourse",:id => "incourse" %>
<%#= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %> <%#= submit_tag "全站搜索", :class => "blueBtn mr5 fl",:name => "insite",:id => "insite" %>
<% if is_course_teacher(User.current,@course) || (@course.publish_resource==1 && User.current.member_of_course?(@course) ) %> <% if is_course_teacher(User.current,@course) || (@course.publish_resource==1 && User.current.member_of_course?(@course) ) %>
<%#= link_to("批量设置", batch_setting_attachments_path(:course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %> <%= link_to("批量设置", batch_setting_attachments_path(:course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %>
<a href="javascript:void(0);" class="blue-btn fr mr5" onclick="course_files_upload();">上传资源</a> <%= link_to("上传资源", upload_atta_attachments_path(:course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %>
<%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %> <%= link_to("导入资源", import_resources_user_path(User.current, :type => 6, :course_id => @course.id), :class => "blue-btn fr mr5", :remote => true) %>
<% end %> <% end %>
<% end %> <% end %>

View File

@ -242,10 +242,10 @@
}); });
//资源库上传附件 //资源库上传附件
function course_files_upload(){ // function course_files_upload(){
var htmlvalue = '<%= escape_javascript(render :partial => 'files/upload_course_files',:locals => {:course => @course,:course_attachment_type => 1}) %>'; // var htmlvalue = '<%#= escape_javascript(render :partial => 'files/upload_course_files',:locals => {:course => @course,:course_attachment_type => 1}) %>';
pop_box_new(htmlvalue, 450, 275); // pop_box_new(htmlvalue, 450, 275);
} // }
// 鼠标经过的时候显示内容 // 鼠标经过的时候显示内容
function message_titile_show(obj,e) function message_titile_show(obj,e)
{ {

View File

@ -1240,6 +1240,8 @@ RedmineApp::Application.routes.draw do
match "renderTag" , :via => [:get, :post] match "renderTag" , :via => [:get, :post]
match 'delete_softapplications', :via => [:get, :post] match 'delete_softapplications', :via => [:get, :post]
get 'batch_setting' get 'batch_setting'
post 'resource_batch_setting'
get 'upload_atta'
end end
end end
resources :groups do resources :groups do

View File

@ -549,3 +549,8 @@ a.question_choice_blue{ background: #3b94d6; color: #fff; width: 34px; height: 3
.question_answer_span{ background: #fff; color: #000000; padding: 6px 10px; border: 1px solid #c8cbce; text-align: center; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;} .question_answer_span{ background: #fff; color: #000000; padding: 6px 10px; border: 1px solid #c8cbce; text-align: center; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px;}
.bg_blue{ background: #3b94d6;} .bg_blue{ background: #3b94d6;}
.score_input{ width: 40px; border: 1px solid #d8d3d3;} .score_input{ width: 40px; border: 1px solid #d8d3d3;}
.sy_new_table tbody tr td{overflow:hidden; white-space: nowrap; text-overflow:ellipsis;}
.ul-align{width: 100%;}
.ul-align li{height: 40px;line-height: 40px;font-size: 14px;}
.ul-align li label{width: 15%;text-align: right;}