资源库
This commit is contained in:
parent
421f86cdaf
commit
25460cd255
|
@ -828,6 +828,60 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#根据id或者名称搜索教师或者助教为当前用户的课程
|
||||||
|
def search_user_course
|
||||||
|
@user = User.current
|
||||||
|
if !params[:search].nil?
|
||||||
|
@course = @user.courses.where(" #{Course.table_name}.id = #{params[:search].to_i } or #{Course.table_name}.name like '%#{params[:search.to_s]}%'")
|
||||||
|
.select { |course| @user.allowed_to?(:as_teacher,course)}
|
||||||
|
else
|
||||||
|
@course = @user.courses
|
||||||
|
.select { |course| @user.allowed_to?(:as_teacher,course)}
|
||||||
|
end
|
||||||
|
@send_id = params[:send_id]
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# 将资源发送到对应的课程
|
||||||
|
def add_exist_file_to_course
|
||||||
|
send_id = params[:send_id]
|
||||||
|
course_ids = params[:course_ids]
|
||||||
|
unless course_ids.nil?
|
||||||
|
course_ids.each do |id|
|
||||||
|
ori = Attachment.find_by_id(send_id)
|
||||||
|
next if ori.blank?
|
||||||
|
attach_copied_obj = ori.copy
|
||||||
|
attach_copied_obj.tag_list.add(ori.tag_list) # tag关联
|
||||||
|
attach_copied_obj.container = Course.find(id)
|
||||||
|
attach_copied_obj.created_on = Time.now
|
||||||
|
attach_copied_obj.author_id = User.current.id
|
||||||
|
if attach_copied_obj.attachtype == nil
|
||||||
|
attach_copied_obj.attachtype = 4
|
||||||
|
end
|
||||||
|
attach_copied_obj.save
|
||||||
|
@save_message = attach_copied_obj.errors.full_messages
|
||||||
|
end
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# 资源预览
|
||||||
|
def resource_preview
|
||||||
|
preview_id = params[:resource_id]
|
||||||
|
@file = Attachment.find(preview_id)
|
||||||
|
@preview_able = false;
|
||||||
|
if %w(pdf pptx doc docx xls xlsx).any?{|x| @file.filename.downcase.end_with?(x)}
|
||||||
|
@preview_able = true;
|
||||||
|
end
|
||||||
|
respond_to do |format|
|
||||||
|
format.js
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@user.destroy
|
@user.destroy
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
|
||||||
|
|
||||||
|
<div class="resourceSharePopup"> <span class="sendText">将资源移动至 </span>
|
||||||
|
<div class="resourcePopupClose"> <a href="javascript:void(0);" class="resourceClose" onclick="closeModal();"></a></div>
|
||||||
|
<div>
|
||||||
|
<%= form_tag search_user_course_user_path(user),:method => 'get',
|
||||||
|
:remote=>true,:id=>'search_user_course_form',:class=>'resourcesSearchBox' do %>
|
||||||
|
<%= hidden_field_tag(:send_id, @send_id) %>
|
||||||
|
<input type="text" name="search" placeholder="输入课程ID或者名称搜索" class="searchResourcePopup" />
|
||||||
|
<!--<a href="javascript:void(0);" class="searchIconPopup"></a>-->
|
||||||
|
<%= submit_tag '',:class=>'searchIconPopup',:onfocus=>"this.blur();",:style=>'border-style:none' %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<%= form_tag add_exist_file_to_course_user_path(user),:remote=>true,:id=>'course_list_form' %>
|
||||||
|
<div>
|
||||||
|
|
||||||
|
<%= hidden_field_tag(:send_id, @send_id) %>
|
||||||
|
<% if !courses.empty? %>
|
||||||
|
<% courses.each do |course| %>
|
||||||
|
<ul class="courseSend">
|
||||||
|
<li class="fl">
|
||||||
|
<input name="course_ids[]" type="checkbox" value="<%= course.id %>" class="courseSendCheckbox"/>
|
||||||
|
</li>
|
||||||
|
<li class="sendCourseName fl"><%= course.name%></li>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="courseSendSubmit">
|
||||||
|
<!--<a href="javascript:void(0);" class="sendSourceText">确定</a>-->
|
||||||
|
<%= submit_tag '确定',:class=>'sendSourceText',:onfocus=>'this.blur();' %>
|
||||||
|
</div>
|
||||||
|
<div class="courseSendCancel"><a href="javascript:void(0);" class="sendSourceText" onclick="closeModal();">取消</a></div>
|
||||||
|
</div>
|
||||||
|
<div class="cl"></div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
closeModal();
|
|
@ -0,0 +1,3 @@
|
||||||
|
<% if @preview_able %>
|
||||||
|
top.location.href = '<%=download_named_attachment_path(@file.id, @file.filename, preview: true) %>'
|
||||||
|
<% end %>
|
|
@ -0,0 +1,11 @@
|
||||||
|
var screenWidth = $(window).width();
|
||||||
|
var screenHeight = $(window).height(); //当前浏览器窗口的 宽高
|
||||||
|
var scrolltop = $(document).scrollTop();//获取当前窗口距离页面顶部高度
|
||||||
|
var objLeft = (screenWidth - 2)/2.5 ; //2 可以根据需要修改
|
||||||
|
var objTop = (screenHeight - 100)/2 + scrolltop; //100可以根据需要修改
|
||||||
|
var popupHeight = $(".resourceSharePopup").outerHeight(true);
|
||||||
|
$(".resourceSharePopup").css("marginTop",-popupHeight/2);
|
||||||
|
|
||||||
|
$("#upload_box").css('left',objLeft).css('top',objTop);
|
||||||
|
$("#upload_box").html('<%= escape_javascript( render :partial => "resource_share_popup" ,:locals => {:courses=>@course,:user=>@user})%>');
|
||||||
|
$("#upload_box").css('display','block');
|
|
@ -100,10 +100,10 @@
|
||||||
<%= render :partial => 'upload_resource' ,:locals => {:user=>@user}%>
|
<%= render :partial => 'upload_resource' ,:locals => {:user=>@user}%>
|
||||||
</div>
|
</div>
|
||||||
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" id="contextMenu">
|
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" id="contextMenu">
|
||||||
<li><a tabindex="-1" href="#">预览</a></li>
|
<li><a tabindex="-1" href="#" onclick="preview();" onfocus="this.blur()">预览</a></li>
|
||||||
<li><a tabindex="-1" href="#">重命名</a></li>
|
<li><a tabindex="-1" href="#" onclick="rename();" onfocus="this.blur()">重命名</a></li>
|
||||||
<li><a tabindex="-1" href="#" onclick="show_send();">发送</a></li>
|
<li><a tabindex="-1" href="#" onclick="show_send();" onfocus="this.blur()" >发送</a></li>
|
||||||
<li><a tabindex="-1" href="#" onclick="delete_file();">删除</a></li>
|
<li><a tabindex="-1" href="#" onclick="delete_file();" onfocus="this.blur()">删除</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
@ -111,6 +111,8 @@
|
||||||
var pageY = 0;
|
var pageY = 0;
|
||||||
var line;
|
var line;
|
||||||
var last_line;
|
var last_line;
|
||||||
|
var res_name;
|
||||||
|
var res_link;
|
||||||
$(".resourcesList").mousedown(function(e) {
|
$(".resourcesList").mousedown(function(e) {
|
||||||
if (3 == e.which) {
|
if (3 == e.which) {
|
||||||
document.oncontextmenu = function() {return false;}
|
document.oncontextmenu = function() {return false;}
|
||||||
|
@ -129,7 +131,9 @@ $(".resourcesList").mousedown(function(e) {
|
||||||
line = $(ele).parent();
|
line = $(ele).parent();
|
||||||
//如果上一条存在被选中,那么将上一条的背景色改为白色
|
//如果上一条存在被选中,那么将上一条的背景色改为白色
|
||||||
if(last_line){
|
if(last_line){
|
||||||
|
|
||||||
last_line.children().css("background-color", 'white');
|
last_line.children().css("background-color", 'white');
|
||||||
|
restore();
|
||||||
last_line == null;
|
last_line == null;
|
||||||
}
|
}
|
||||||
//如果当前的tag是li,那么还要li的父级元素
|
//如果当前的tag是li,那么还要li的父级元素
|
||||||
|
@ -151,15 +155,48 @@ $(".resourcesList").click(function(e) {
|
||||||
if(line.get(0).tagName === 'LI'){
|
if(line.get(0).tagName === 'LI'){
|
||||||
line = line.parent();
|
line = line.parent();
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
restore();
|
||||||
}
|
}
|
||||||
line.children().css("background-color", 'white');
|
line.children().css("background-color", 'white');
|
||||||
line = null;
|
|
||||||
});
|
});
|
||||||
function show_send(){
|
function show_send(){
|
||||||
$("#contextMenu").hide();
|
$("#contextMenu").hide();
|
||||||
document.oncontextmenu = function() {return true;}
|
document.oncontextmenu = function() {return true;}
|
||||||
line.children().css("background-color",'white');
|
line.children().css("background-color",'white');
|
||||||
line.children().last().html();
|
id = line.children().last().html();
|
||||||
|
$.ajax({
|
||||||
|
type:'get',
|
||||||
|
url:'<%= search_user_course_user_path(@user)%>'+'?send_id='+id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function preview(){
|
||||||
|
$("#contextMenu").hide();
|
||||||
|
document.oncontextmenu = function() {return true;}
|
||||||
|
line.children().css("background-color",'white');
|
||||||
|
id = line.children().last().html();
|
||||||
|
$.ajax({
|
||||||
|
type:'get',
|
||||||
|
url:'<%= resource_preview_user_path(@user)%>'+"?resource_id="+id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function rename(){
|
||||||
|
$("#contextMenu").hide();
|
||||||
|
document.oncontextmenu = function() {return true;}
|
||||||
|
line.children().css("background-color",'white');
|
||||||
|
id = line.children().last().html();
|
||||||
|
res_name = line.children().first().children().html();
|
||||||
|
res_link = line.children().first().html();
|
||||||
|
line.children().first().html('<form id="res_name_form"><input name="res_name" id="res_name" class="" onblur="restore();" value="'+res_name+'"/> </form>');
|
||||||
|
$("#res_name").focus();
|
||||||
|
}
|
||||||
|
function restore(){
|
||||||
|
if( line != null && res_link != null && res_link != '') {
|
||||||
|
line.children().first().html(res_link);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delete_file(){
|
function delete_file(){
|
||||||
|
|
|
@ -348,6 +348,9 @@ RedmineApp::Application.routes.draw do
|
||||||
post "resource_search"
|
post "resource_search"
|
||||||
post "user_resource_create"
|
post "user_resource_create"
|
||||||
post "user_resource_delete"
|
post "user_resource_delete"
|
||||||
|
get "search_user_course"
|
||||||
|
post "add_exist_file_to_course"
|
||||||
|
get 'resource_preview'
|
||||||
# end
|
# end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue