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

494 lines
21 KiB
Plaintext
Raw Normal View History

2015-09-25 10:35:04 +08:00
<%= javascript_include_tag 'bootstrap'%>
<%= stylesheet_link_tag 'project' %>
<%= stylesheet_link_tag 'leftside' %>
<%= javascript_include_tag 'attachments'%>
<!--<script type="text/css">-->
<!--html,body{ overflow-y:scroll;}-->
<!--html,body{ overflow:scroll; min-height:101%;}-->
<!--html{ overflow:-moz-scrollbars-vertical;}-->
<!--</script>-->
<script>
function remote_get_resources(user_id,type){
}
2016-03-01 17:33:44 +08:00
$(document).ready(function(){
$(".resource-switch").click(function(){
$(".resource-switch").children().removeClass("resource-tab-active");
$(this).children().addClass("resource-tab-active");
});
});
2015-09-25 10:35:04 +08:00
function remote_search(){
$("#resource_search_form").submit();
}
function show_upload(){
$("#ajax-modal").html('<%= escape_javascript( render :partial => 'upload_resource' ,:locals => {:user=>@user})%>');
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>");
2016-03-01 17:33:44 +08:00
$('#ajax-modal').parent().css("top","50%").css("left","50%").css("position","absolute");
2015-09-25 10:35:04 +08:00
$('#ajax-modal').parent().addClass("resourceUploadPopup");
$('#ajax-modal').css("padding-left","16px").css("padding-bottom","16px");
}
function closeModal()
{
hideModal($(".uploadBoxContainer"));
}
function closePopUp(){
hideModal($(".boxContainer"));
}
function check_files(){
return $("#attachments_fields").children().length == 0;
}
function submit_files(){
$("#upload_form").submit();
}
function check_des(event){
if($(".sectionContent").find('input[type="radio"]:checked').length <= 0){
event.preventDefault();
$(".orgDirection").text('目标地址组织不能为空')
return false;
}else if($(".columnContent").find('input[type="radio"]:checked').length <= 0){
event.preventDefault();
$(".orgDirection").text('目标地址栏目不能为空')
return false;
}else{
return true;
}
}
2015-09-25 10:35:04 +08:00
</script>
2016-03-01 17:33:44 +08:00
<div class="homepageContentContainer" >
<div class="homepageContent">
<div class="resource-wrapper">
<ul class="resource-banner">
<li class="fl resource-switch"><a href="javascript:void(0);" class="resource-tab resource-tab-active">公共资源</a></li>
<li class="fl resource-switch"><%=link_to "我的资源", {:controller => 'users', :action => 'user_resource', :id => User.current.id, :type => 1, :remote => true}, :class => "resource-tab" %></li>
<li class="fl w770 border-bottom h34">&nbsp;</li>
<li class="fr resource-banner-li border-bottom h34">
<ul class="resourcesSelect">
<li class="resourcesSelected"><a href="javascript:void(0);" class="resourcesIcon"></a>
<ul class="resourcesType">
<li>
<%= link_to '全部' ,user_resource_user_path(:id => @user.id, :type => 1), :remote => true, :method => 'get', :class => 'resourcesTypeAll resourcesGrey' %>
</li>
<li>
<%= link_to '课程资源' ,user_resource_user_path(:id => @user.id, :type => 2), :remote => true, :method => 'get', :class=> 'homepagePostTypeAssignment postTypeGrey' %>
</li>
<li>
<%= link_to '项目资源' ,user_resource_user_path(:id => @user.id, :type => 3), :remote => true, :method => 'get', :class => 'homepagePostTypeQuiz postTypeGrey' %>
</li>
<li>
<%= link_to '用户资源' ,user_resource_user_path(:id=>@user.id,:type=>5),:remote=>true,:method => 'get', :class=>'resourcesTypeUser resourcesGrey' %>
</li>
<li>
<%= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4),:remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %>
</li>
</ul>
</li>
</ul>
</li>
<div class="cl"></div>
</ul>
<div class="cl"></div>
<div id="users_setting">
<div class="resourcesUploadBox mt10"><a href="javascript:void(0);" onclick="show_upload();" class="uploadBoxIcon">上传资源</a></div>
<div id="search_div">
<%= render :partial => 'resource_search_form',:locals => {:user => @user, :type => @type} %>
</div>
<div style="float: left; margin-top: 7px; font-size: 14px; margin-left: 15px;"><span style="align:center ;font-size: 14px;color: gray;">为您找到<span id="res_all_count"><%= @atta_count %></span>个资源</span></div>
2015-09-25 10:35:04 +08:00
</div>
2016-03-01 17:33:44 +08:00
<div class="cl"></div>
<ul class="resource-list-tab mt10">
<li class="resource-list-checkbox fl"> </li>
<li class="resource-list-name fl">资源名称</li>
<li class="resource-list-time fr">上传时间</li>
<li class="resource-list-uploader fr">上传者</li>
<li class="resource-list-type fr">类别</li>
<li class="resource-list-size fr">大小</li>
<li class="resource-list-from fr">资源来源</li>
</ul>
<div class="cl"></div>
<form id="resources_list_form">
<div id="resources_list">
<%= render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments} %>
2015-09-25 10:35:04 +08:00
</div>
2016-03-01 17:33:44 +08:00
<div class="cl"></div>
<div class="resource-list-option fl">
<div class="resource-check-all">
<input id="checkboxAll" type="checkbox" value="" onclick="all_select();" class="resourcesCheckbox" />
</div>
<a href="javascript:void(0);" class="replyGrey1 mr15" onclick="all_select();">全选</a>
<a href="javascript:void(0);" class="replyGrey" onclick="batch_delete();">删除</a>
<div class="resourcesSelectSend">
<div class="fl">选择&nbsp;<span class="c_red" id="res_count">0</span>&nbsp;个资源</div>
<div class="resourcesSelectSendButton" onclick="batch_send();">
<a href="javascript:void(0);" class="sendButtonBlue db" data-remote="true" >发送</a>
</div>
</div>
</div>
</form>
<div class="cl"></div>
<div>
<ul class="wlist" id="pages" style="margin-top: 5px;">
<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true %>
</ul>
2015-09-25 10:35:04 +08:00
</div>
</div>
</div>
</div>
<div class="cl"></div>
<!--<div id="upload_box" style="display: none">-->
<!--<%#= render :partial => 'upload_resource' ,:locals => {:user=>@user}%>-->
<!--</div>-->
2016-03-01 17:33:44 +08:00
<ul class="resource-list">
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu" id="contextMenu">
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)preview();" onfocus="this.blur()">预览</a></li>
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)rename();" onfocus="this.blur()">重命名</a></li>
<!-- data-remote="true" 这个属性会让ajax请求状态标志就在当前按钮的上方显示就不会滚动浏览器因而弹出框也会在当前窗口中央展示-->
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)show_send_();" data-remote="true" onfocus="this.blur()" >发送</a></li>
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)delete_file();" onfocus="this.blur()">删除</a></li>
</ul>
2015-09-25 10:35:04 +08:00
</ul>
<script>
var pageX = 0;
var pageY = 0;
//当前选中的行
var line;
//已经选中的行和当前选中的行的区别是右键选中为line换一行右键后line变为last_line,line变为换行后的line
var last_line;
//资源名称
var res_name;
//资源名称的链接
var res_link;
var id; //资源id
var sendType = '1'; //发送到课程 1 发送到项目 2
2015-09-25 10:35:04 +08:00
var lastSendType; //保存上次发送的发送类型
$("#resources_list").mousedown(function(e) {
//如果是右键的话
if (3 == e.which) {
2015-12-18 17:55:15 +08:00
if( $("#res_name").length != 0 || $("#ajax-indicator").is(":hidden") == false){ //其他ajax在执行的时候阻止操作
e.preventDefault();
return ;
}
2015-09-25 10:35:04 +08:00
document.oncontextmenu = function() {return false;}
pageX = e.clientX;
pageY = e.clientY;
$("#contextMenu").hide();
$("#contextMenu").attr("style","display: block; position: fixed; top:"
+ pageY
+ "px; left:"
+ pageX
+ "px; width: 80px;");
$("#contextMenu").show();
//当前光标所在的对象
var ele = document.elementFromPoint(pageX,pageY);
//转换为jquery对象
line = $(ele).parent();
//如果上一条存在被选中,那么将上一条的背景色改为白色
if(last_line != null){
last_line.children().css("background-color", 'white');
restore();
last_line == null;
}
//如果当前的tag是li那么还要li的父级元素
if(line.get(0).tagName === 'LI'){
line = line.parent();
}
//将当前的元素的所有子元素的背景色改为蓝色
line.children().css("background-color", '#e1e1e1');
//将当前元素赋给 上一个对象 保存起来。
last_line = line;
}
});
//元素包含关系计算
var contains = function(root, el) {
if (root.compareDocumentPosition)
return root === el || !!(root.compareDocumentPosition(el) & 16);
if (root.contains && el.nodeType === 1){
return root.contains(el) && root !== el;
}
while ((el = el.parentNode))
if (el === root) return true;
return false;
}
$(document.body).click(function(e) {
//在列表上的任何单击事件都要恢复原来的样子
//隐藏右键菜单
//e.preventDefault();
$("#contextMenu").hide();
2015-12-18 17:55:15 +08:00
if( $("#ajax-indicator").is(":hidden") == false && $("#res_name").length != 0 ){ //其他ajax在执行的时候或者res_name仍然存在阻止操作
return ;
}
2015-09-25 10:35:04 +08:00
document.oncontextmenu = function() {return true;}
//如果当前行为空,那么要将当前行的拿到
var ele;
if(line == null){
ele = document.elementFromPoint(e.clientX, e.clientY);
line = $(ele).parent();
//如果是在li上点击事件那么要获得父组件
if(line.get(0).tagName === 'LI'){
line = line.parent();
}
}
//如果当前对象在表格里,将当前行改变为白色,这里主要是防止点击页面的其他链接的时候,那个链接背景色变白了
if( contains($("#resources_list").get(0),line.get(0))){
line.children().css("background-color", 'white');
}
//当前行恢复编辑状态到链接状态
if(ele && ele.nodeName != 'INPUT') {
restore();
}
line = null;
});
//只要有一个选中了就是true
function checkboxSelected(){
selected = false;
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
if($(this).attr('checked') == true){
selected = true;
}
});
return selected;
}
//只有全选才是true
function checkboxAllSelected(){
allSelected = true;
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
if($(this).attr('checked') == undefined){
allSelected = false;
}
});
return allSelected;
}
//只有全部不选才是true
function checkboxAllDeselected(){
allDeselected = true;
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
if($(this).attr('checked') == 'checked'){
allDeselected = false;
}
});
return allDeselected;
}
//查看所有的checkbox状态并且按情况更改$("#checkboxAll")的状态
function checkAllBox(checkbox){
//只有选中当前checkbox且这个时候所有的checkbox都被选中了$("#checkboxAll")才是被选中状态,其余都是非选中状态
if(checkbox.attr('checked') == 'checked' && checkboxAllSelected()){
$("#checkboxAll").attr('checked',true);
}else{
$("#checkboxAll").attr('checked',false);
}
$("#res_count").html(getCheckBoxSeletedCount());
}
//获取当前checkbox选中的数目
function getCheckBoxSeletedCount(){
var i = 0;
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
if($(this).attr('checked') == 'checked'){
i ++;
}
});
return i;
}
//全选反选
function all_select(){
if($("#checkboxAll").attr('checked')){
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
$(this).attr('checked',true);
});
$("#res_count").html(getCheckBoxSeletedCount());
}else{
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
$(this).attr('checked',false);
});
$("#res_count").html(0);
}
}
//批量删除
function batch_delete(){
var data = $("#resources_list_form").serialize();
if($("input[type=checkbox][data-has-history=Y]:checked").length != 0){
alert("您只能删除没有历史记录的资源,请重新选择后再删除。");
return;
}
2015-11-13 14:56:18 +08:00
if($("input[type=checkbox][data-deleteble=N]:checked").length != 0){
2015-11-13 15:38:16 +08:00
alert("您只能删除自己上传的资源,请重新选择后再删除。");
2015-11-13 14:56:18 +08:00
return;
}
2015-11-13 14:56:18 +08:00
if(data != "" && confirm('确认要删除这些资源吗?')) {
2015-09-25 10:35:04 +08:00
$.post(
'<%= user_resource_delete_user_path(@user)%>',
$("#resources_list_form").serialize(),//只会对选中的控件进行序列化提交
function (data) {
}
);
}
}
function show_send_(){
2015-09-25 10:35:04 +08:00
$("#contextMenu").hide();
document.oncontextmenu = function() {return true;}
line.children().css("background-color",'white');
id = line.children().last().html();
if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
2015-09-25 10:35:04 +08:00
$.ajax({
type: 'get',
url: '<%= search_user_project_user_path(@user)%>' + '?send_id=' + id,
data:{send_type:'file'}
2015-09-25 10:35:04 +08:00
});
}else{
$.ajax({
type: 'get',
url: '<%= search_user_course_user_path(@user)%>' + '?send_id=' + id,
data:{send_type:'file'}
2015-09-25 10:35:04 +08:00
});
}
}
function batch_send(){
if($("#resources_list_form").serialize() == ""){
alert('暂时不支持多页选择,您当前页没有选择任何资源');
return ;
}
if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
2015-09-25 10:35:04 +08:00
$.ajax({
type: 'get',
2016-02-19 13:23:32 +08:00
url: '<%= search_user_project_user_path(@user)%>' + '?' + $("#resources_list_form").serialize(),
data:{send_type:'file'}
2015-09-25 10:35:04 +08:00
});
}else{
$.ajax({
type: 'get',
2016-02-19 13:23:32 +08:00
url: '<%= search_user_course_user_path(@user)%>' + '?'+ $("#resources_list_form").serialize(),
data:{send_type:'file'}
2015-09-25 10:35:04 +08:00
});
2015-09-25 10:35:04 +08:00
}
}
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();
user_id = line.children().eq(5).html();
2016-03-01 17:33:44 +08:00
if(user_id === '<%= User.current.id %>') {
2015-09-25 10:35:04 +08:00
res_name = line.children().eq(1).children().attr('title');
res_link = line.children().eq(1).html();
2015-12-07 17:29:14 +08:00
line.children().eq(1).html(
2015-09-25 10:35:04 +08:00
'<input name="res_name" id="res_name" ' +
2015-12-18 17:55:15 +08:00
'style="height: 2em;line-height: 2em;overflow: hidden;" onblur="restore();" ' +
' onkeypress="if(event.keyCode==13){event.preventDefault();this.blur();}" ' +
2015-09-25 10:35:04 +08:00
'value="'+res_name+
2015-12-07 17:29:14 +08:00
'"/> <input type="hidden" id ="res_id" name="res_id" value="'+id+'"/>');
2015-09-25 10:35:04 +08:00
$("#res_name").focus();
$("html,body").animate({scrollTop:$("#res_name").offset().top},1000)
}else{
alert('您无法修改此资源!')
}
}
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);
}
2015-12-07 17:29:14 +08:00
2015-09-25 10:35:04 +08:00
//恢复编辑状态到链接状态
//如果当前是编辑状态,任何的不在输入框里的单击右键事件都需要将编辑状态变回链接状态
//如果是编辑状态,且做了修改,那么久要进行修改,并且将修改值经过处理替换到页面显示
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)){
2015-12-07 17:29:14 +08:00
$.ajax({
url: '<%=rename_resource_user_path(@user) %>'+ "?res_name="+$('#res_name').val() + "&res_id=" + $("#res_id").val(),
type:'get',
success:function (data)
{
2015-12-18 17:55:15 +08:00
if (data != 'fail' && name != undefined && name != 'undefined') {//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变
2015-09-25 10:35:04 +08:00
last_line.children().eq(1).html(res_link);
2015-12-07 17:29:14 +08:00
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 {
2015-09-25 10:35:04 +08:00
last_line.children().eq(1).html(res_link);
res_link = null; //如果修改失败恢复之后将res_link置空
}
2015-12-07 17:29:14 +08:00
}
} );
2015-09-25 10:35:04 +08:00
}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();
user_id = line.children().eq(5).html();
if(line.children().first().children().data('hasHistory') == 'Y'){
alert('该资源存在历史版本,不能删除');
return;
}
2015-09-25 10:35:04 +08:00
if(user_id === '<%= User.current.id%>') {
if (confirm('确定要删除资源"' + line.children().eq(1).children().attr('title').trim() + '"么?')) {
$.ajax({
type: 'post',
url: '<%= user_resource_delete_user_path(@user)%>' + '?resource_id=' + id + '&type=' + $('#type').val()
});
}
}else{
alert('您无法删除此资源!')
}
}
</script>