|
|
|
@ -109,11 +109,17 @@
|
|
|
|
|
<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
|
|
|
|
|
$(".resourcesList").mousedown(function(e) {
|
|
|
|
|
//如果是右键的话
|
|
|
|
|
if (3 == e.which) {
|
|
|
|
|
document.oncontextmenu = function() {return false;}
|
|
|
|
|
pageX = e.clientX;
|
|
|
|
@ -130,8 +136,7 @@ $(".resourcesList").mousedown(function(e) {
|
|
|
|
|
//转换为jquery对象
|
|
|
|
|
line = $(ele).parent();
|
|
|
|
|
//如果上一条存在被选中,那么将上一条的背景色改为白色
|
|
|
|
|
if(last_line){
|
|
|
|
|
|
|
|
|
|
if(last_line != null){
|
|
|
|
|
last_line.children().css("background-color", 'white');
|
|
|
|
|
restore();
|
|
|
|
|
last_line == null;
|
|
|
|
@ -147,19 +152,27 @@ $(".resourcesList").mousedown(function(e) {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$(".resourcesList").click(function(e) {
|
|
|
|
|
//在列表上的任何单击事件都要恢复原来的样子
|
|
|
|
|
//隐藏右键菜单
|
|
|
|
|
$("#contextMenu").hide();
|
|
|
|
|
document.oncontextmenu = function() {return true;}
|
|
|
|
|
//如果当前行为空,那么要将当前行的拿到
|
|
|
|
|
var ele;
|
|
|
|
|
if(line == null){
|
|
|
|
|
var ele = document.elementFromPoint(e.clientX, e.clientY);
|
|
|
|
|
ele = document.elementFromPoint(e.clientX, e.clientY);
|
|
|
|
|
line = $(ele).parent();
|
|
|
|
|
//如果是在li上点击事件,那么要获得父组件
|
|
|
|
|
if(line.get(0).tagName === 'LI'){
|
|
|
|
|
line = line.parent();
|
|
|
|
|
}
|
|
|
|
|
}else{
|
|
|
|
|
restore();
|
|
|
|
|
}
|
|
|
|
|
//将当前行改变为白色
|
|
|
|
|
line.children().css("background-color", 'white');
|
|
|
|
|
|
|
|
|
|
//当前行恢复编辑状态
|
|
|
|
|
if(ele.nodeName != 'INPUT') {
|
|
|
|
|
restore();
|
|
|
|
|
}
|
|
|
|
|
line = null;
|
|
|
|
|
});
|
|
|
|
|
function show_send(){
|
|
|
|
|
$("#contextMenu").hide();
|
|
|
|
@ -188,27 +201,73 @@ $(".resourcesList").click(function(e) {
|
|
|
|
|
document.oncontextmenu = function() {return true;}
|
|
|
|
|
line.children().css("background-color",'white');
|
|
|
|
|
id = line.children().last().html();
|
|
|
|
|
res_name = line.children().first().children().html();
|
|
|
|
|
res_name = line.children().first().children().attr('title');
|
|
|
|
|
res_link = line.children().first().html();
|
|
|
|
|
line.children().first().html('<form id="res_name_form"><input name="res_name" id="res_name" class="" onblur="restore();" value="'+res_name+'"/> </form>');
|
|
|
|
|
line.children().first().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" name="res_id" value="'+id+'"/>'+
|
|
|
|
|
'<% end %>');
|
|
|
|
|
$("#res_name").focus();
|
|
|
|
|
}
|
|
|
|
|
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( line != null && res_link != null && res_link != '') {
|
|
|
|
|
line.children().first().html(res_link);
|
|
|
|
|
if( last_line != null && res_link != null && res_link != '') {
|
|
|
|
|
name = $("#res_name").val().trim();
|
|
|
|
|
if(name != res_name.trim()){
|
|
|
|
|
|
|
|
|
|
if(confirm('确定修改为 '+name)){
|
|
|
|
|
//$("#res_name_form").submit();
|
|
|
|
|
// $.ajax({
|
|
|
|
|
// type:'post',
|
|
|
|
|
// url:'<%#=rename_resource_user_path(@user) %>',
|
|
|
|
|
// data: $("#res_name_form").serialize()
|
|
|
|
|
// });
|
|
|
|
|
$.post(
|
|
|
|
|
'<%=rename_resource_user_path(@user) %>',
|
|
|
|
|
$("#res_name_form").serialize(),
|
|
|
|
|
function (data){
|
|
|
|
|
if(data =='sucess'){
|
|
|
|
|
last_line.children().first().html(res_link);
|
|
|
|
|
last_line.children().first().children().attr('title',name);
|
|
|
|
|
last_line.children().first().children().html(name);
|
|
|
|
|
}else{
|
|
|
|
|
last_line.children().first().html(res_link);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'text'
|
|
|
|
|
);
|
|
|
|
|
}else{
|
|
|
|
|
//last_line.children().first().html(res_link);
|
|
|
|
|
}
|
|
|
|
|
}else {
|
|
|
|
|
last_line.children().first().html(res_link);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete_file(){
|
|
|
|
|
function delete_file() {
|
|
|
|
|
$("#contextMenu").hide();
|
|
|
|
|
document.oncontextmenu = function() {return true;}
|
|
|
|
|
line.children().css("background-color",'white');
|
|
|
|
|
document.oncontextmenu = function () {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
line.children().css("background-color", 'white');
|
|
|
|
|
id = line.children().last().html();
|
|
|
|
|
if (confirm('确定要删除资源' + line.children().first().children().attr('title').trim() + '么')){
|
|
|
|
|
$.ajax({
|
|
|
|
|
type:'post',
|
|
|
|
|
url:'<%= user_resource_delete_user_path(@user)%>'+'?resource_id='+id
|
|
|
|
|
type: 'post',
|
|
|
|
|
url: '<%= user_resource_delete_user_path(@user)%>' + '?resource_id=' + id
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|