课程应用的功能实现

This commit is contained in:
z9hang 2014-11-20 17:44:30 +08:00
parent 63b91e2cfb
commit f2da5704ef
11 changed files with 115 additions and 17 deletions

View File

@ -343,6 +343,35 @@ class AttachmentsController < ApplicationController
end
end
def add_exist_file_to_courses
file = Attachment.find(params[:file_id])
courses = params[:courses][:course]
courses.each do |course|
c = Course.find(course);
attach_copied_obj = file.copy
attach_copied_obj.tag_list.add(file.tag_list) # tag关联
attach_copied_obj.container = c
attach_copied_obj.created_on = Time.now
attach_copied_obj.author_id = User.current.id
attach_copied_obj.copy_from = file.copy_from.nil? ? file.id:file.copy_from
if attach_copied_obj.attachtype == nil
attach_copied_obj.attachtype = 4
end
@obj = c
@save_flag = attach_copied_obj.save
@save_message = attach_copied_obj.errors.full_messages
end
respond_to do |format|
format.js
end
rescue NoMethodError
@save_flag = false
@save_message = [] << l(:error_attachment_empty)
respond_to do |format|
format.js
end
end
private
def find_project
@attachment = Attachment.find(params[:id])

View File

@ -22,7 +22,7 @@ class FilesController < ApplicationController
menu_item :files
before_filter :find_project_by_project_id#, :except => [:getattachtype]
before_filter :authorize, :except => [:getattachtype]
before_filter :authorize, :except => [:getattachtype,:quote_resource_show]
helper :sort
include SortHelper
@ -74,8 +74,7 @@ class FilesController < ApplicationController
when "created_on"
attribute = "created_on"
end
@sort = order_by[0]
@order = order_by[1]
if order_by.count == 1
sort += "#{Attachment.table_name}.#{attribute} asc "
elsif order_by.count == 2
@ -116,7 +115,8 @@ class FilesController < ApplicationController
when "created_on"
attribute = "created_on"
end
@sort = order_by[0]
@order = order_by[1]
if order_by.count == 1
sort += "#{Attachment.table_name}.#{attribute} asc "
elsif order_by.count == 2
@ -137,8 +137,8 @@ class FilesController < ApplicationController
end
def upload_file_show
def quote_resource_show
@file = Attachment.find(params[:id])
end
def new

View File

@ -177,6 +177,8 @@ module AttachmentsHelper
s.html_safe
end
# Modified by Longjun
# 有参数的方法要加()
def private_filter(resultSet)

View File

@ -44,6 +44,16 @@ module FilesHelper
File.new(zipfile_name,'w+')
end
def courses_check_box_tags(name,courses,current_course)
s = ''
courses.each do |course|
if course.id != current_course.id && is_course_teacher(User.current,course)
s << "<label>#{ check_box_tag name, course.id, false, :id => nil } #{h course.name}</label><br/>"
end
end
s.html_safe
end
# 判断指定的资源时候符合类型
def isTypeOk(attachment, type, contentType)
result = false

View File

@ -0,0 +1,5 @@
<% if !@save_flag%>
$("#error_show").html("<%= @save_message.join(', ') %>");
<% else %>
closeModal();
<% end %>

View File

@ -1,8 +1,10 @@
<!-- sort: @sort,order:@order,current:"created_on" -->
<% if sort == current %>
<% if order = "" || order =="asc" %>
<% if order =="asc" %>
<% elsif order == "desc" %>
<% else %>
<% end %>
<% end %>

View File

@ -1,17 +1,18 @@
<% attachmenttypes = @course.attachmenttypes %>
<% sufixtypes = @course.contenttypes %>
<% delete_allowed = User.current.allowed_to?(:manage_files, @course) %>
<%= stylesheet_link_tag 'resource', :media => 'all' %>
<script>
function show_upload()
{
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_show',:locals => {:course => @course}) %>');
showModal('ajax-modal', '513px');
// $('#ajax-modal').css('height','569px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<span style='float: right;cursor:pointer;padding-left: 513px;'><a href='javascript:void(0)' onclick='closeModal()'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
$('#ajax-modal').parent().css("top","5").css("left","511");
}
function closeModal()
{
hideModal($("#popbox_upload"));
@ -27,14 +28,25 @@
<input type="submit" value="课内搜索" class="re_schbtn b_dblue" />
<input type="submit" value="全站搜索" class="re_schbtn b_lblue" />
</form>
<a href="javascript:void(0)" class="re_fabu f_r b_lblue" onclick="show_upload()">上传资源</a>
<% if is_course_teacher(User.current,@course) %>
<a href="javascript:void(0)" class="re_fabu f_r b_lblue" onclick="show_upload()">上传资源</a>
<% end %>
</div><!---re_top end-->
<div class="cl"></div>
<div class="re_con">
<div class="re_con_top">
<p class="f_l c_blue f_b f_14">共有&nbsp;<%= User.current.member_of_course?(@course) ? @all_attachments.count : 0 %>&nbsp;个资源</p>
<p class="f_r">按&nbsp;<%= link_to "时间",course_files_path(@course,:sort=>"created_on"),:class => "f_b c_grey" %><%= render partial: 'arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %>&nbsp;/&nbsp;<%= link_to "下载次数",course_files_path(@course,:sort=>"downloads:desc"),:class => "f_b c_grey" %><%= render partial: 'arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %>&nbsp;/&nbsp;<a href="#" class="f_b c_grey">引用次数</a>&nbsp;排序</p>
<p class="f_r">
<% if @order == "asc" %>
按&nbsp;<%= link_to "时间",course_files_path(@course,:sort=>"created_on:desc"),:class => "f_b c_grey" %><%= render partial: 'arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %>&nbsp;/&nbsp;
<%= link_to "下载次数",course_files_path(@course,:sort=>"downloads:desc"),:class => "f_b c_grey" %><%= render partial: 'arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %>&nbsp;/&nbsp;
<a href="#" class="f_b c_grey">引用次数</a>&nbsp;排序</p>
<%else%>
按&nbsp;<%= link_to "时间",course_files_path(@course,:sort=>"created_on:asc"),:class => "f_b c_grey" %><%= render partial: 'arrow_show',locals: { sort: @sort,order:@order,current:"created_on"} %>&nbsp;/&nbsp;
<%= link_to "下载次数",course_files_path(@course,:sort=>"downloads:asc"),:class => "f_b c_grey" %><%= render partial: 'arrow_show',locals: { sort: @sort,order:@order,current:"downloads"} %>&nbsp;/&nbsp;
<a href="#" class="f_b c_grey">引用次数</a>&nbsp;排序</p>
<% end %>
</div>
<div class="cl"></div>
<% @curse_attachments.each do |file| %>
@ -44,10 +56,14 @@
<div class="re_con_box">
<div class=" ">
<%= link_to_attachment file, :download => true, :title => file.filename+"\n"+file.description.to_s, :style => "overflow: hidden; white-space: nowrap;text-overflow: ellipsis;",:class => "c_dblue f_14 f_b f_l" %>
<a href="#" class="f_l re_select">选入我的课程</a>
<span id="is_public_<%= file.id %>">
<%= link_to (file.is_public? ? "公开":"私有"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"f_l re_open",:method => :post %>
</span>
<% if is_course_teacher(User.current,@course) %>
<%= link_to "选入我的课程",quote_resource_show_course_file_path(@course,file),:class => "f_l re_select",:remote => true %>
<span id="is_public_<%= file.id %>">
<%= link_to (file.is_public? ? "公开":"私有"), update_file_dense_attachments_path(:attachmentid=>file.id,:newtype=>(file.is_public? ? 0:1)),:remote=>true,:class=>"f_l re_open",:method => :post %>
</span>
<% else %>
<%= link_to (file.is_public? ? "公开":"私有"),"javascript:void(0)",:class=>"f_l re_open" %>
<% end %>
</div>
<div class="cl"></div>
<div class="">

View File

@ -0,0 +1,24 @@
<div id="popbox_upload" style="margin-top: -30px;margin-left: -20px;margin-right: -10px;">
<div class="upload_con">
<div id="error_show"></div>
<h2>将此课件引入我的课程资源库</h2>
<div class="upload_box">
<%= form_tag course_attach_relations_path,
method: :post,
remote: true,
id: "relation_file_form" do %>
<%= hidden_field_tag(:file_id, file.id) %>
<%= content_tag('div', courses_check_box_tags('courses[course][]', User.current.courses,course), :id => 'courses')%>
<a id="submit_quote" href="javascript:void(0)" class="upload_btn" onclick="submit_quote();">引&nbsp;&nbsp;用</a><a href="javascript:void(0)" class="upload_btn upload_btn_grey" onclick="closeModal();">取&nbsp;&nbsp;消</a>
<% end -%>
</div>
</div>
</div>
<script>
function submit_quote()
{
$('#submit_quote').parent().submit();
}
</script>

View File

@ -0,0 +1,5 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'show_quote_resource',:locals => {:course => @course,:file => @file}) %>');
showModal('ajax-modal', '513px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<span style='float: right;cursor:pointer;padding-left: 513px;'><a href='javascript:void(0)' onclick='closeModal()'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
$('#ajax-modal').parent().css("top","5").css("left","511");

View File

@ -558,6 +558,7 @@ RedmineApp::Application.routes.draw do
match 'attachments/autocomplete', :to => 'attachments#autocomplete', :via => [:post]
post 'attachments/relationfile', to: 'attachments#add_exist_file_to_project', as: 'attach_relation'
post 'attachments/courserelationfile', to: 'attachments#add_exist_file_to_course', as: 'course_attach_relation'
post 'attachments/courserelationfiles', to: 'attachments#add_exist_file_to_courses', as: 'course_attach_relations'
get 'attachments/renderTag/:attchmentId', :to => 'attachments#renderTag', :attchmentId => /\d+/
resources :attachments, :only => [:show, :destroy] do
collection do
@ -654,6 +655,9 @@ RedmineApp::Application.routes.draw do
collection do
match "getattachtype", :via => [:get, :post]
end
member do
match "quote_resource_show", :via => [:get]
end
end
resources :memberships, :shallow => true, :controller => 'members', :only => [:index, :show, :new, :create, :update, :destroy] do
collection do

View File

@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20141105012624) do
ActiveRecord::Schema.define(:version => 20141120091234) do
create_table "activities", :force => true do |t|
t.integer "act_id", :null => false
@ -52,6 +52,7 @@ ActiveRecord::Schema.define(:version => 20141105012624) do
t.string "disk_directory"
t.integer "attachtype", :default => 1
t.integer "is_public", :default => 1
t.integer "copy_from"
end
add_index "attachments", ["author_id"], :name => "index_attachments_on_author_id"