socialforge/app/views/users/_resources_list.html.erb

238 lines
12 KiB
Plaintext
Raw Normal View History

2016-03-05 03:16:04 +08:00
<% if attachments.nil? || attachments.empty? %>
<!--<p class="nodata">-->
<!--<%#= l(:label_no_data) %>-->
<!--</p>-->
<% else %>
<% attachments.each do |attach| %>
<ul class="resource-list" onmouseover="if($('#contextMenu').css('display') != 'block')$(this).children().css('background-color', '#e1e1e1')" onmouseout=" if($('#contextMenu').css('display') == 'none')$(this).children().css('background-color', 'white')">
<li class="resource-list-checkbox fl">
2016-05-20 20:27:32 +08:00
<% if attach.is_public == 0 && (@type == "6" || @type == "2") && attach.author != User.current && attach.get_apply_resource_status(attach.id, attach.author_id) != 2 && !attach_show_allow(attach) %>
<input name="checkbox1[]" type="checkbox" disabled="disabled" data-has-history="<%= attach.attachment_histories.count == 0 ? 'N' : 'Y' %>" data-deleteble="<%= User.current.id ==attach.author_id ? 'Y' : 'N' %>" onclick="checkAllBox($(this));" value="<%= attach.id%>" class="resourcesCheckbox" />
<% else %>
<input name="checkbox1[]" type="checkbox" data-has-history="<%= attach.attachment_histories.count == 0 ? 'N' : 'Y' %>" data-deleteble="<%= User.current.id ==attach.author_id ? 'Y' : 'N' %>" onclick="checkAllBox($(this));" value="<%= attach.id%>" class="resourcesCheckbox" />
<% end %>
2016-03-05 03:16:04 +08:00
<!--<input name="checkbox2" type="checkbox" value="" class="resourcesCheckbox" />-->
</li>
2016-05-16 15:00:08 +08:00
<li class="resource-list-name fl">
2016-05-20 20:27:32 +08:00
<% if attach.is_public == 0 && !attach_show_allow(attach) && attach.get_apply_resource_status(attach.id, attach.author_id) != "2" %>
2016-05-20 19:52:42 +08:00
<a style="cursor: default" class = "resourcesBlack resource-list-middle hidden mw280" title="<%= attach.filename %>"><%= attach.filename %> </a>
2016-05-20 17:04:20 +08:00
<% else %>
<%= link_to truncate(attach.filename, :length => 30), download_named_attachment_path(attach.id, attach.filename), :title => attach.filename, :class => 'resourcesBlack resource-list-middle hidden mw280' %>
<% end %>
2016-05-19 14:28:13 +08:00
<% if attach.is_public == 0 && (@type == "6" || @type == "2") && attach.author != User.current %>
<img src="/images/locked.png" alt="私有" title="私有" class="resource-list-middle" height="16" width="16">
<% end %>
</li>
<li class="resource-list-apply fr" id="resource_apply_status_<%=attach.id %>">
<% if attach.is_public == 0 && (@type == "6" || @type == "2") && attach.author != User.current && !attach_show_allow(attach) %>
<% ah = attach.get_status_by_attach(User.current.id) %>
<% if ah.nil? %>
2016-05-18 14:49:13 +08:00
<%= link_to("请求分享", apply_resource_user_path(User.current.id, :attachment_id => attach.id), :class => 'green_btn_share c_white', :remote => true) %>
<% elsif ah == 1 %>
2016-05-18 14:49:13 +08:00
等待回复
<% elsif ah == 2 %>
2016-05-18 14:49:13 +08:00
可引用
<% elsif ah == 3 %>
2016-05-18 14:49:13 +08:00
已拒绝
<% end %>
<% else %>
--
<% end %>
2016-03-05 03:16:04 +08:00
</li>
<li class="resource-list-time fr"><%= format_date(attach.created_on) %></li>
<li class="resource-list-quote fr"><%= attach.quotes.nil? ? 0 : attach.quotes %></li>
<li class="resource-list-download fr"><%= attach.downloads %></li>
<li style="display: none"><%= attach.author_id %></li>
2016-03-17 14:09:13 +08:00
<li class="resource-list-size fr"><%= (number_to_human_size(attach.filesize)).gsub("ytes", "") %></li>
2016-03-05 03:16:04 +08:00
<li class="resource-list-uploader fr hidden"><%=User.find(attach.author_id).realname.blank? ? User.find(attach.author_id).nickname : User.find(attach.author_id).realname %></li>
<li class="resource-list-type fr"><%= get_resource_type(attach.container_type)%></li>
<li class="resource-list-from fr hidden" title="<%= get_resource_origin(attach) %>"><%= get_resource_origin(attach) %></li>
2016-05-19 15:59:59 +08:00
<li style="display: none"><%= attach.is_public %></li>
<li style="display: none"><%= attach.get_apply_resource_status(attach.id, attach.author_id) %></li>
2016-05-20 18:46:19 +08:00
<li style="display: none"><%= attach_show_allow(attach) == true ? 0 : 1 %></li>
2016-03-05 03:16:04 +08:00
<li style="display: none"><%= attach.id %></li>
</ul>
<div class="cl"></div>
<% end %>
<% end %>
2016-03-28 14:50:26 +08:00
<script>
2016-03-29 10:15:18 +08:00
function show_upload(){
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'upload_resource' ,:locals => {:user=>User.current.id,:type=>@type,:status=>@status})%>');
showModal('ajax-modal', '452px');
$('#ajax-modal').siblings().remove();
$('#ajax-modal').before("<a href='javascript:void(0)' onclick='closeModal();' style='margin-left: 435px;' class='resourceClose'></a>");
$('#ajax-modal').parent().css("top","50%").css("left","50%").css("position","absolute");
$('#ajax-modal').parent().addClass("resourceUploadPopup");
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
}
//批量删除
function batch_delete(){
var data = $("#resources_list_form").serialize();
if($("input[type=checkbox][data-deleteble=N]:checked").length != 0){
alert("您只能删除自己上传的资源,请重新选择后再删除。");
return;
}
2016-05-20 18:55:17 +08:00
if($("input[type=checkbox][data-has-history=Y]:checked").length != 0){
alert("您只能删除没有历史记录的资源,请重新选择后再删除。");
return;
}
2016-03-29 10:15:18 +08:00
if(data != "" && confirm('确认要删除这些资源吗?')) {
$.post(
'<%= user_resource_delete_user_path(User.current.id,:type=>@type,:status=>@status)%>',
$("#resources_list_form").serialize(),//只会对选中的控件进行序列化提交
function (data) {
}
);
}
}
function show_send(){
$("#contextMenu").hide();
document.oncontextmenu = function() {return true;}
line.children().css("background-color",'white');
id = line.children().last().html();
2016-05-19 15:59:59 +08:00
is_public = line.children().eq(11).html();
user_id = line.children().eq(6).html();
apply_status = line.children().eq(12).html();
2016-05-20 18:46:19 +08:00
allow = line.children().eq(13).html();
if(is_public == 0 && user_id != '<%= User.current.id %>' && apply_status != 2 && allow == 1){
2016-05-19 15:59:59 +08:00
alert('您无权发送私有资源')
2016-03-29 10:15:18 +08:00
}else{
2016-05-19 15:59:59 +08:00
if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
$.ajax({
type: 'get',
url: '<%= search_user_project_user_path(User.current.id) %>' + "?send_id=" + id + "&type=<%= @type %>",
data:{send_type:'file'}
});
}else{
$.ajax({
type: 'get',
url: '<%= search_user_course_user_path(User.current.id)%>' + "?send_id=" + id + "&type=<%= @type %>",
data:{send_type:'file'}
});
}
2016-03-29 10:15:18 +08:00
}
2016-05-19 15:59:59 +08:00
2016-03-29 10:15:18 +08:00
}
function batch_send(){
if($("#resources_list_form").serialize() == ""){
alert('暂时不支持多页选择,您当前页没有选择任何资源');
return ;
}
if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
$.ajax({
type: 'get',
url: '<%= search_user_project_user_path(User.current.id)%>' + '?' + $("#resources_list_form").serialize() + "&type=<%= @type%>",
data:{send_type:'file'}
});
}else{
$.ajax({
type: 'get',
url: '<%= search_user_course_user_path(User.current.id)%>' + '?'+ $("#resources_list_form").serialize() + "&type=<%= @type%>",
data:{send_type:'file'}
});
}
}
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.current.id)%>'+"?resource_id="+id
});
}
String.prototype.trim = function() {
var str = this,
str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
}
//恢复编辑状态到链接状态
//如果当前是编辑状态,任何的不在输入框里的单击右键事件都需要将编辑状态变回链接状态
//如果是编辑状态,且做了修改,那么久要进行修改,并且将修改值经过处理替换到页面显示
function restore(){
//上一行不为空 且链接不为空
if( last_line != null && res_link != null && res_link != '') {
name = $("#res_name").lenght != 0 && $("#res_name").val() != undefined ? $("#res_name").val().trim() : undefined ;
if (name == undefined || name === 'undefined' ){ //只要res_name没有值那么就不是编辑状态
return;
}
if( name && name != res_name.trim()){
if(confirm('确定修改为 '+name)){
$.ajax({
url: '<%=rename_resource_user_path(User.current.id) %>'+ "?res_name="+$('#res_name').val() + "&res_id=" + $("#res_id").val(),
type:'get',
success:function (data)
{
if (data != 'fail' && name != undefined && name != 'undefined') {//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变
last_line.children().eq(1).html(res_link);
last_line.children().eq(1).children().attr('title', name);
last_line.children().eq(1).children().attr('href', data);
last_line.children().eq(1).children().html(name.length > 17 ? name.substring(0, 17) + '...' : name);
} else {
last_line.children().eq(1).html(res_link);
res_link = null; //如果修改失败恢复之后将res_link置空
}
}
} );
}else{
last_line.children().eq(1).html(res_link);
res_link = null; //如果没有做修改恢复之后将res_link置空
}
}else {
last_line.children().eq(1).html(res_link);
res_link = null;//如果没有做修改恢复之后将res_link置空
}
}
}
function delete_file() {
$("#contextMenu").hide();
document.oncontextmenu = function () {
return true;
}
line.children().css("background-color", 'white');
id = line.children().last().html();
2016-05-17 15:32:18 +08:00
user_id = line.children().eq(6).html();
2016-03-29 10:15:18 +08:00
if(user_id === '<%= User.current.id%>') {
2016-05-20 20:02:17 +08:00
if(line.children().first().children().data('hasHistory') == 'Y'){
alert('该资源存在历史版本,不能删除');
return;
}
2016-03-29 10:15:18 +08:00
if (confirm('确定要删除资源"' + line.children().eq(1).children().attr('title').trim() + '"么?')) {
$.ajax({
type: 'post',
url: '<%= user_resource_delete_user_path(User.current.id)%>' + '?resource_id=' + id + '&type=<%=@type %>&status=<%=@status %>'
});
}
2016-05-20 20:02:17 +08:00
2016-03-29 10:15:18 +08:00
}else{
alert('您无法删除此资源!')
}
2016-05-20 20:02:17 +08:00
2016-03-29 10:15:18 +08:00
}
2016-03-28 14:50:26 +08:00
</script>