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

501 lines
19 KiB
Plaintext
Raw Normal View History

2015-08-15 17:07:50 +08:00
<%= javascript_include_tag 'bootstrap'%>
<%= stylesheet_link_tag 'project' %>
<%= stylesheet_link_tag 'leftside' %>
<%= javascript_include_tag 'attachments'%>
2015-08-20 10:14:26 +08:00
<!--<script type="text/css">-->
<!--html,body{ overflow-y:scroll;}-->
<!--html,body{ overflow:scroll; min-height:101%;}-->
<!--html{ overflow:-moz-scrollbars-vertical;}-->
<!--</script>-->
2015-08-15 17:07:50 +08:00
<script>
function remote_get_resources(user_id,type){
}
function remote_search(){
$("#resource_search_form").submit();
}
function show_upload(){
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 = $(".resourceUploadPopup").outerHeight(true);
$(".resourceUploadPopup").css("marginTop",-popupHeight/2);
$("#upload_box").css('left',objLeft).css('top',objTop);
$("#upload_box").html('<%= escape_javascript( render :partial => 'upload_resource' ,:locals => {:user=>@user})%>');
$("#upload_box").css('display','block');
}
function closeModal()
{
$("#upload_box").css("display","none");
}
function check_files(){
return $("#attachments_fields").children().length == 0;
}
function submit_files(){
$("#upload_form").submit();
}
</script>
<div class="resources">
2015-08-19 17:13:57 +08:00
<div class="homepageRightBanner">
<div class="NewsBannerName">资源库</div>
2015-08-15 17:07:50 +08:00
<ul class="resourcesSelect">
<li class="resourcesSelected"><a href="javascript:void(0);" class="resourcesIcon"></a>
<ul class="resourcesType">
<li>
2015-08-19 17:13:57 +08:00
<%= link_to '全部' ,user_resource_user_path(:id=>@user.id,:type=>1),:remote=>true,:method => 'get',:class=>'resourcesTypeAll resourcesGrey' %>
2015-08-15 17:07:50 +08:00
</li>
<li>
2015-08-19 17:13:57 +08:00
<%= link_to '课程资源' ,user_resource_user_path(:id=>@user.id,:type=>2),:remote=>true,:method => 'get',:class=>'homepagePostTypeAssignment postTypeGrey' %>
2015-08-15 17:07:50 +08:00
</li>
<li>
2015-08-19 17:13:57 +08:00
<%= link_to '项目资源' ,user_resource_user_path(:id=>@user.id,:type=>3),:remote=>true,:method => 'get',:class=>'homepagePostTypeQuiz postTypeGrey' %>
2015-08-15 17:07:50 +08:00
</li>
<li>
2015-08-19 17:13:57 +08:00
<%= link_to '附件' ,user_resource_user_path(:id=>@user.id,:type=>4),:remote=>true,:method => 'get',:class=>'resourcesTypeAtt resourcesGrey' %>
2015-08-15 17:07:50 +08:00
</li>
</ul>
</li>
</ul>
</div>
<div class="resourcesSearchBanner">
<div class="resourcesUploadBox">
2015-08-19 17:13:57 +08:00
<a href="javascript:void(0);" onclick="show_upload();" class="uploadBoxIcon">上传资源</a></div>
2015-08-18 15:25:36 +08:00
<div id="search_div">
<%= render :partial => 'resource_search_form',:locals => {:user=>@user,:type=>@type} %>
2015-08-15 17:07:50 +08:00
</div>
</div>
<div class="resourcesListBanner">
<ul class="resourcesListTab">
2015-08-19 17:13:57 +08:00
<li class="resourcesListCheckbox fl"> </li>
2015-08-15 17:07:50 +08:00
<li class="resourcesListName fl">资源名称</li>
<li class="resourcesListSize fl">大小</li>
<li class="resourcesListType fl">类别</li>
<li class="resourcesListUploader fl">上传者</li>
<li class="resourcesListTime fl">上传时间</li>
</ul>
</div>
2015-08-20 14:01:33 +08:00
<form id="resources_list_form">
2015-08-19 17:13:57 +08:00
<div id="resources_list" class="resourcesList">
2015-08-20 14:01:33 +08:00
2015-08-15 17:07:50 +08:00
<%= render :partial => 'resources_list' ,:locals=>{ :attachments => @attachments} %>
2015-08-20 14:01:33 +08:00
2015-08-19 17:13:57 +08:00
</div>
<div class="resourcesListOption">
<div class="resourcesCheckAll">
2015-08-20 14:01:33 +08:00
<input id="checkboxAll" type="checkbox" value="" onclick="all_select();" class="resourcesCheckbox" />
2015-08-19 17:13:57 +08:00
</div>
2015-08-24 13:54:15 +08:00
<a href="javascript:void(0);" class="replyGrey1 mr15" onclick="all_select();">全选</a>
<a href="javascript:void(0);" class="replyGrey1" onclick="batch_delete();">删除</a>
2015-08-19 17:13:57 +08:00
<div class="resourcesSelectSend">
2015-08-20 11:37:32 +08:00
<div class="fl">选择&nbsp;<span class="c_red" id="res_count">0</span>&nbsp;个资源</div>
2015-08-20 16:05:58 +08:00
<div class="resourcesSelectSendButton" onclick="batch_send();">
<a href="javascript:void(0);" class="sendButtonBlue db" >发送</a>
2015-08-19 17:13:57 +08:00
</div>
</div>
2015-08-15 17:07:50 +08:00
</div>
2015-08-20 14:01:33 +08:00
</form>
2015-08-15 17:07:50 +08:00
</div>
2015-08-20 17:38:30 +08:00
<div>
<ul class="wlist" id="pages">
2015-08-24 10:31:25 +08:00
<%= pagination_links_full @atta_pages, @atta_count, :per_page_links => false, :remote => @is_remote, :flag => true%>
2015-08-20 17:00:54 +08:00
</ul>
2015-08-20 17:38:30 +08:00
</div>
2015-08-20 17:00:54 +08:00
<div class="cl"></div>
2015-08-15 17:07:50 +08:00
<div id="upload_box" style="display: none">
<%= render :partial => 'upload_resource' ,:locals => {:user=>@user}%>
</div>
<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>
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)show_send();" onfocus="this.blur()" >发送</a></li>
<li><a tabindex="-1" href="#" onclick="if(<%= User.current.logged?%>)delete_file();" onfocus="this.blur()">删除</a></li>
2015-08-15 17:07:50 +08:00
</ul>
<script>
var pageX = 0;
var pageY = 0;
2015-08-18 11:53:54 +08:00
//当前选中的行
2015-08-15 17:07:50 +08:00
var line;
2015-08-18 11:53:54 +08:00
//已经选中的行和当前选中的行的区别是右键选中为line换一行右键后line变为last_line,line变为换行后的line
2015-08-15 17:07:50 +08:00
var last_line;
2015-08-18 11:53:54 +08:00
//资源名称
2015-08-18 09:31:03 +08:00
var res_name;
2015-08-18 11:53:54 +08:00
//资源名称的链接
2015-08-18 09:31:03 +08:00
var res_link;
2015-08-18 11:53:54 +08:00
var id; //资源id
2015-08-20 10:14:26 +08:00
var sendType; //发送到课程 1 发送到项目 2
var lastSendType; //保存上次发送的发送类型
2015-08-18 11:53:54 +08:00
$(".resourcesList").mousedown(function(e) {
//如果是右键的话
2015-08-15 17:07:50 +08:00
if (3 == e.which) {
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();
//如果上一条存在被选中,那么将上一条的背景色改为白色
2015-08-18 11:53:54 +08:00
if(last_line != null){
2015-08-15 17:07:50 +08:00
last_line.children().css("background-color", 'white');
2015-08-18 09:31:03 +08:00
restore();
2015-08-15 17:07:50 +08:00
last_line == null;
}
//如果当前的tag是li那么还要li的父级元素
if(line.get(0).tagName === 'LI'){
line = line.parent();
}
//将当前的元素的所有子元素的背景色改为蓝色
line.children().css("background-color", '#00ffff');
//将当前元素赋给 上一个对象 保存起来。
last_line = line;
}
});
$(".resourcesList").click(function(e) {
2015-08-18 11:53:54 +08:00
//在列表上的任何单击事件都要恢复原来的样子
//隐藏右键菜单
2015-08-15 17:07:50 +08:00
$("#contextMenu").hide();
document.oncontextmenu = function() {return true;}
2015-08-18 11:53:54 +08:00
//如果当前行为空,那么要将当前行的拿到
var ele;
if(line == null){
ele = document.elementFromPoint(e.clientX, e.clientY);
2015-08-15 17:07:50 +08:00
line = $(ele).parent();
2015-08-18 11:53:54 +08:00
//如果是在li上点击事件那么要获得父组件
2015-08-15 17:07:50 +08:00
if(line.get(0).tagName === 'LI'){
line = line.parent();
}
}
2015-08-18 11:53:54 +08:00
//将当前行改变为白色
2015-08-15 17:07:50 +08:00
line.children().css("background-color", 'white');
2015-08-18 15:25:36 +08:00
//当前行恢复编辑状态到链接状态
2015-08-18 17:26:39 +08:00
if(ele && ele.nodeName != 'INPUT') {
2015-08-18 11:53:54 +08:00
restore();
}
line = null;
2015-08-15 17:07:50 +08:00
});
2015-08-20 11:37:32 +08:00
//只要有一个选中了就是true
function checkboxSelected(){
selected = false;
2015-08-20 14:01:33 +08:00
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
2015-08-20 11:37:32 +08:00
if($(this).attr('checked') == true){
selected = true;
}
});
return selected;
}
//只有全选才是true
function checkboxAllSelected(){
allSelected = true;
2015-08-20 14:01:33 +08:00
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
2015-08-20 11:37:32 +08:00
if($(this).attr('checked') == undefined){
allSelected = false;
}
});
return allSelected;
}
//只有全部不选才是true
function checkboxAllDeselected(){
allDeselected = true;
2015-08-20 14:01:33 +08:00
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
2015-08-20 11:37:32 +08:00
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;
2015-08-20 14:01:33 +08:00
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
2015-08-20 11:37:32 +08:00
if($(this).attr('checked') == 'checked'){
i ++;
}
});
return i;
}
2015-08-20 14:01:33 +08:00
//全选反选
function all_select(){
2015-08-20 11:37:32 +08:00
2015-08-20 14:01:33 +08:00
if($("#checkboxAll").attr('checked')){
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
2015-08-20 11:37:32 +08:00
$(this).attr('checked',true);
});
2015-08-20 14:01:33 +08:00
$("#res_count").html(getCheckBoxSeletedCount());
2015-08-20 11:37:32 +08:00
}else{
2015-08-20 14:01:33 +08:00
$("#resources_list").find("input[name='checkbox1[]']").each(function(){
2015-08-20 11:37:32 +08:00
$(this).attr('checked',false);
});
$("#res_count").html(0);
}
2015-08-20 14:01:33 +08:00
}
//批量删除
function batch_delete(){
var data = $("#resources_list_form").serialize();
if(data != "" && confirm('您可能会删不掉这其中上传者不是您的资源,确认要删除这些资源吗?')) {
2015-08-20 14:01:33 +08:00
$.post(
'<%= user_resource_delete_user_path(@user)%>',
$("#resources_list_form").serialize(),//只会对选中的控件进行序列化提交
function (data) {
}
);
}
}
2015-08-20 11:37:32 +08:00
2015-08-20 16:05:58 +08:00
2015-08-15 17:07:50 +08:00
function show_send(){
$("#contextMenu").hide();
document.oncontextmenu = function() {return true;}
line.children().css("background-color",'white');
2015-08-18 09:31:03 +08:00
id = line.children().last().html();
2015-08-20 10:14:26 +08:00
if (lastSendType === '1'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
$.ajax({
type: 'get',
url: '<%= search_user_course_user_path(@user)%>' + '?send_id=' + id
});
}else{
$.ajax({
type: 'get',
url: '<%= search_user_project_user_path(@user)%>' + '?send_id=' + id
});
}
2015-08-18 09:31:03 +08:00
}
2015-08-20 16:05:58 +08:00
function batch_send(){
2015-08-20 17:00:54 +08:00
if($("#resources_list_form").serialize() == ""){
2015-08-21 15:58:32 +08:00
alert('暂时不支持多页选择,您当前页没有选择任何资源');
2015-08-20 17:00:54 +08:00
return ;
}
2015-08-20 16:05:58 +08:00
if (lastSendType === '1'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
$.ajax({
type: 'get',
url: '<%= search_user_course_user_path(@user)%>' + '?'+ $("#resources_list_form").serialize()
});
}else{
$.ajax({
type: 'get',
url: '<%= search_user_project_user_path(@user)%>' + '?' + $("#resources_list_form").serialize()
});
}
}
2015-08-18 09:31:03 +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();
if(user_id === '<%= User.current.id%>') {
res_name = line.children().eq(1).children().attr('title');
res_link = line.children().eq(1).html();
line.children().eq(1).html('<%= form_tag(url_for(:controller => 'users',:action => 'rename_resource',:method => 'post',:remote=>true,:id=>@user.id),:id=>"res_name_form" ) do%>' +
'<input name="res_name" id="res_name" ' +
'style="height: 2em;line-height: 2em;overflow: hidden;" onblur="restore();" ' +
'value="'+res_name+
'"/> <input type="hidden" id ="res_id" name="res_id" value="'+id+'"/>'+
'<% end %>');
$("#res_name").focus();
$("html,body").animate({scrollTop:$("#res_name").offset().top},1000)
}else{
alert('您无法修改此资源!')
}
2015-08-18 09:31:03 +08:00
}
2015-08-18 11:53:54 +08:00
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-08-18 15:25:36 +08:00
//恢复编辑状态到链接状态
//如果当前是编辑状态,任何的不在输入框里的单击右键事件都需要将编辑状态变回链接状态
//如果是编辑状态,且做了修改,那么久要进行修改,并且将修改值经过处理替换到页面显示
2015-08-18 09:31:03 +08:00
function restore(){
2015-08-18 15:25:36 +08:00
//上一行不为空 且链接不为空
2015-08-18 11:53:54 +08:00
if( last_line != null && res_link != null && res_link != '') {
2015-08-18 17:45:14 +08:00
name = $("#res_name").lenght != 0 && $("#res_name").val() != undefined ? $("#res_name").val().trim() : undefined ;
if (name == undefined || name === 'undefined' ){ //只要res_name没有值那么就不是编辑状态
return;
}
2015-08-18 15:25:36 +08:00
if( name && name != res_name.trim()){
2015-08-18 11:53:54 +08:00
if(confirm('确定修改为 '+name)){
$.post(
'<%=rename_resource_user_path(@user) %>',
2015-08-20 17:38:30 +08:00
"res_name="+$('#res_name').val()+"&res_id="+$("#res_id").val(),
2015-08-18 11:53:54 +08:00
function (data){
2015-08-18 17:26:39 +08:00
if(data != 'fail'){//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变
2015-08-19 17:13:57 +08:00
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);
2015-08-18 11:53:54 +08:00
}else{
2015-08-19 17:13:57 +08:00
last_line.children().eq(1).html(res_link);
2015-08-18 15:25:36 +08:00
res_link = null; //如果修改失败恢复之后将res_link置空
2015-08-18 11:53:54 +08:00
}
},
'text'
);
}else{
2015-08-19 17:13:57 +08:00
last_line.children().eq(1).html(res_link);
2015-08-18 15:25:36 +08:00
res_link = null; //如果没有做修改恢复之后将res_link置空
2015-08-18 11:53:54 +08:00
}
}else {
2015-08-19 17:13:57 +08:00
last_line.children().eq(1).html(res_link);
2015-08-18 15:25:36 +08:00
res_link = null;//如果没有做修改恢复之后将res_link置空
2015-08-18 11:53:54 +08:00
}
2015-08-18 15:25:36 +08:00
2015-08-18 09:31:03 +08:00
}
2015-08-15 17:07:50 +08:00
}
2015-08-18 11:53:54 +08:00
function delete_file() {
2015-08-15 17:07:50 +08:00
$("#contextMenu").hide();
2015-08-18 11:53:54 +08:00
document.oncontextmenu = function () {
return true;
}
line.children().css("background-color", 'white');
2015-08-15 17:07:50 +08:00
id = line.children().last().html();
user_id = line.children().eq(5).html();
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('您无法删除此资源!')
2015-08-18 11:53:54 +08:00
}
2015-08-15 17:07:50 +08:00
}
2015-08-20 16:05:58 +08:00
//id 发送的id
//发送的id数组
function chooseSendType(res_id,res_ids){
sendType = $(".resourcesSendType").val();
if (sendType === lastSendType) {
return;
} else if (lastSendType != null) { //不是第一次点击的时候
if(res_ids == "") {//如果是单个发送
if (sendType === '1') {
$.ajax({
type: 'get',
url: '<%= search_user_course_user_path(@user)%>' + '?send_id=' + id
});
} else {
$.ajax({
type: 'get',
url: '<%= search_user_project_user_path(@user)%>' + '?send_id=' + id
});
}
}else{//如果是多个发送
2015-08-20 17:00:54 +08:00
if (sendType === '1'){
2015-08-20 16:05:58 +08:00
$.ajax({
type: 'get',
url: '<%= search_user_course_user_path(@user)%>' + '?'+ $("#resources_list_form").serialize()
});
}else{
$.ajax({
type: 'get',
url: '<%= search_user_project_user_path(@user)%>' + '?' + $("#resources_list_form").serialize()
});
}
}
2015-08-20 10:14:26 +08:00
}
2015-08-20 16:05:58 +08:00
2015-08-20 10:14:26 +08:00
lastSendType = sendType;
}
2015-08-24 14:53:30 +08:00
// var iWidth = document.documentElement.clientWidth;
// var iHeight = document.documentElement.clientHeight;
// var moveX = 0;
// var moveY = 0;
// var moveTop = 0;
// var moveLeft = 0;
// var moveable = false;
// var docMouseMoveEvent = document.onmousemove;
// var docMouseUpEvent = document.onmouseup;
// $("#upload_box").mousedown(function() {
// var evt = getEvent();
// moveable = true;
// moveX = evt.clientX;
// moveY = evt.clientY;
//
// moveTop = parseInt($("#upload_box").css('top'));
// moveLeft = parseInt($("#upload_box").css('left'));
//
// $(document).mousemove( function() {
// if (moveable) {
// var evt = getEvent();
// var x = moveLeft + evt.clientX - moveX;
// var y = moveTop + evt.clientY - moveY;
// if ( x > 0 &&( x + 322 < iWidth) && y > 0 && (y + 257 < iHeight) ) {
// $("#upload_box").css('left', x + "px");
// $("#upload_box").css('top', y + "px");
// console.log( moveX)
// console.log( moveY)
// }
// }
// });
// $(document).mouseup (function () {
// if (moveable) {
// document.onmousemove = docMouseMoveEvent;
// document.onmouseup = docMouseUpEvent;
// moveable = false;
// moveX = 0;
// moveY = 0;
// moveTop = 0;
// moveLeft = 0;
// }
// });
// });
//
// // 获得事件Event对象用于兼容IE和FireFox
// function getEvent() {
// return window.event || arguments.callee.caller.arguments[0];
// }
2015-08-20 10:14:26 +08:00
2015-08-15 17:07:50 +08:00
</script>