资源上传

This commit is contained in:
z9hang 2014-11-19 17:40:24 +08:00
parent eeda25add1
commit 63b91e2cfb
9 changed files with 140 additions and 6 deletions

View File

@ -49,7 +49,8 @@ class FilesController < ApplicationController
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"
sort = ""
@sort = ""
@order = ""
if params[:project_id]
@isproject = true
@ -73,7 +74,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
@ -135,6 +137,10 @@ class FilesController < ApplicationController
end
def upload_file_show
end
def new
@versions = @project.versions.sort
@course_tag = @project.project_type

View File

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

View File

@ -0,0 +1,46 @@
<div>
<span id="attachments_fields" xmlns="http://www.w3.org/1999/html">
<% if defined?(container) && container && container.saved_attachments %>
<% container.attachments.each_with_index do |attachment, i| %>
<span id="attachments_p<%= i %>" class="attachment">
<%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename readonly', :readonly=>'readonly')%>
<%= text_field_tag("attachments[p#{i}][description]", attachment.description, :maxlength => 254, :placeholder => l(:label_optional_description), :class => 'description', :style=>"display: inline-block;") %>
<span class="ispublic-label"><%= l(:field_is_public)%>:</span>
<%= check_box_tag("attachments[p#{i}][is_public_checkbox]", attachment.is_public,attachment.is_public == 1 ? true : false,:class => 'is_public')%>
<%= if attachment.id.nil?
#待补充代码
else
link_to('&nbsp;'.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload')
end
%>
<%#= render :partial => 'tags/tag', :locals => {:obj => attachment, :object_flag => "6"} %>
<%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %>
</span>
<% end %>
<% end %>
</span>
</div>
<button name="button" class="f_l ml10" onclick="_file.click()" onmouseover="this.focus()" type="button" style="width:80px; height:26px;">上传文件</button>
<%= file_field_tag 'attachments[dummy][file]',
:id => '_file',
:class => 'file_selector',
:multiple => true,
:onchange => 'addInputFiles(this);',
:style => 'display:none',
:data => {
:max_file_size => Setting.attachment_max_size.to_i.kilobytes,
:max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)),
:max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i,
:upload_path => uploads_path(:format => 'js'),
:description_placeholder => l(:label_optional_description)
} %>
<!--<input type="submit" name="" value="上传文件" class="f_l ml10" style="width:80px; height:26px;">-->
<label class="f_l ml10 c_grey">
<span id="upload_file_count">
<%= l(:label_no_file_uploaded)%>
</span>
(<%= l(:label_max_size) %>:
<%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>)
</label>

View File

@ -2,6 +2,22 @@
<% 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"));
}
</script>
<div class="container">
<div class="resource"><!--资源库内容开始--->
@ -11,14 +27,14 @@
<input type="submit" value="课内搜索" class="re_schbtn b_dblue" />
<input type="submit" value="全站搜索" class="re_schbtn b_lblue" />
</form>
<a href="#" class="re_fabu f_r b_lblue">上传资源</a>
<a href="javascript:void(0)" class="re_fabu f_r b_lblue" onclick="show_upload()">上传资源</a>
</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;<a href="#" class="f_b c_grey">时间</a>&nbsp;/&nbsp;<a href="#" class="f_b c_grey">下载次数</a>&nbsp;/&nbsp;<a href="#" class="f_b c_grey">引用次数</a>&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>
</div>
<div class="cl"></div>
<% @curse_attachments.each do |file| %>
@ -82,7 +98,7 @@
<%= link_to(l(:label_relation_files), 'javascript:void(0);', :onclick => "$('#upload_file_div').slideUp();$('#relation_file_div').slideToggle();", :class => 'icon m5p5 button_submit') if User.current.allowed_to?(:manage_files, @course) %>
<p></p>
<div id="upload_file_div" class="relation_file_div hidden">
<%= render :partial => 'course_new', locals: {course: @course} %>
<!-- <#%= render :partial => 'course_new', locals: {course: @course} %> -->
</div>
<div id="relation_file_div" class="relation_file_div hidden">

View File

@ -0,0 +1,26 @@
<div id="popbox_upload" style="margin-top: -30px;margin-left: -20px;margin-right: -10px;">
<div class="upload_con">
<h2>上传资源</h2>
<div class="upload_box">
<%= error_messages_for 'attachment' %>
<div id="network_issue" style="color: red; display: none;">上传出现错误,请您检查您的网络环境,并刷新页面重新上传。</div>
<%= form_tag(course_files_path(course), :multipart => true,:remote => true,:method => :post,:name=>"upload_form") do %>
<label style="margin-top:3px;">文件浏览:</label>
<%= render :partial => 'attachement_list',:locals => {:course => course} %>
<div class="cl"></div>
<a id="submit_resource" href="javascript:void(0);" class="upload_btn" onclick="submit_resource();">上传资源</a><a href="javascript:void(0);" class="upload_btn upload_btn_grey" onclick="closeModal();">取&nbsp;&nbsp;消</a>
<% end %>
</div>
</div>
<% content_for :header_tags do %>
<%= javascript_include_tag 'attachments' %>
<% end %>
</div>
<script>
function submit_resource()
{
$('#submit_resource').parent().submit();
}
</script>

View File

@ -27,6 +27,8 @@ $('#upload_file_div').slideToggle('slow');
$("#all_browse_div").html('<%= j(render partial: "show_all_attachment")%>');
<%elsif @course%>
$("#all_browse_div").html('<%= j(render partial: "course_show_all_attachment")%>');
closeModal();
$("#resource_list").html('<%= j(render partial: "course_file" ,locals: {course: @course}) %>');
<%end%>
<% end %>

View File

@ -1,10 +1,11 @@
<!-- <h3> --><!-- %=l(:label_attachment_plural)%></h3 -->
<div id="resource_list">
<% if @isproject %>
<%= render :partial => 'project_file', locals: {project: @project} %>
<% else %>
<%= render :partial => 'course_file', locals: {course: @course} %>
<% end %>
</div>
<script type='text/javascript'>
var slideHeight = 29;

View File

@ -0,0 +1,10 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'upload_show',:locals => {}) %>');
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='#' onclick='hidden_homework_atert_form("+
// <#%= @cur_page%> + "," + <#%= @cur_type%> +
// ");'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
$('#ajax-modal').parent().css("top","").css("left","");
$('#ajax-modal').parent().addClass("alert_box");

View File

@ -19,6 +19,9 @@ a:hover{ text-decoration:underline;}
.c_dblue{ color:#3e6d8e;}
.w90{width:90px;}
.ml10{margin-left:10px;}
.ml5{margin-left:5px;}
.b_grey{ background:#a3a3a3;}
.container{ }
@ -84,3 +87,19 @@ a.yellowBtn{ display:inline-block;color:#0d90c3; height:22px;}
.re_tag a{ color:#0d90c3;}
.tag_h span,.tag_h a{ margin-bottom:5px;}
/***弹框***/
.alert .close02{width:26px;height:26px;overflow:hidden;position:absolute;top:-10px;right:-490px;background:url(images/close.png) no-repeat;cursor:pointer;}
.upload_con { }
.upload_con h2{ display:block; background:#eaeaea; font-size:14px; color:#343333; height:31px; width: auto; margin-top:25px; padding-left:20px; padding-top:5px;}
.upload_box{ width:430px; margin:15px auto;}
a.upload_btn{ display:block; float:left; margin-top:15px; width:80px; height:30px; text-align: center; color:#fff; font-size:14px; background:#15bccf; margin-right:15px;}
a:hover.upload_btn{ background:#55a1b9;}
a.upload_btn_grey{background:#a3a3a3;}
a:hover.upload_btn_grey{background:#8a8a8a;}
.upload_con p{ color:#808181;}
.upload_con a:hover{ text-decoration:none;}
#upload_file_count #count {
color: #F00;
font-size: 1.1em;
}