资源库监听回车键

This commit is contained in:
lizanle 2015-12-07 17:29:14 +08:00
parent ee661bb6d4
commit 5fcbde2ff1
2 changed files with 18 additions and 17 deletions

View File

@ -361,12 +361,11 @@
if(user_id === '<%= User.current.id%>') { if(user_id === '<%= User.current.id%>') {
res_name = line.children().eq(1).children().attr('title'); res_name = line.children().eq(1).children().attr('title');
res_link = line.children().eq(1).html(); 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%>' + line.children().eq(1).html(
'<input name="res_name" id="res_name" ' + '<input name="res_name" id="res_name" ' +
'style="height: 2em;line-height: 2em;overflow: hidden;" onblur="restore();" ' + 'style="height: 2em;line-height: 2em;overflow: hidden;" onblur="restore();" onkeypress="if(event.keyCode==13){event.preventDefault();this.blur();}" ' +
'value="'+res_name+ 'value="'+res_name+
'"/> <input type="hidden" id ="res_id" name="res_id" value="'+id+'"/>'+ '"/> <input type="hidden" id ="res_id" name="res_id" value="'+id+'"/>');
'<% end %>');
$("#res_name").focus(); $("#res_name").focus();
$("html,body").animate({scrollTop:$("#res_name").offset().top},1000) $("html,body").animate({scrollTop:$("#res_name").offset().top},1000)
}else{ }else{
@ -382,6 +381,8 @@
return str.slice(0, i + 1); return str.slice(0, i + 1);
} }
//恢复编辑状态到链接状态 //恢复编辑状态到链接状态
//如果当前是编辑状态,任何的不在输入框里的单击右键事件都需要将编辑状态变回链接状态 //如果当前是编辑状态,任何的不在输入框里的单击右键事件都需要将编辑状态变回链接状态
//如果是编辑状态,且做了修改,那么久要进行修改,并且将修改值经过处理替换到页面显示 //如果是编辑状态,且做了修改,那么久要进行修改,并且将修改值经过处理替换到页面显示
@ -395,22 +396,22 @@
if( name && name != res_name.trim()){ if( name && name != res_name.trim()){
if(confirm('确定修改为 '+name)){ if(confirm('确定修改为 '+name)){
$.post( $.ajax({
'<%=rename_resource_user_path(@user) %>', url: '<%=rename_resource_user_path(@user) %>'+ "?res_name="+$('#res_name').val() + "&res_id=" + $("#res_id").val(),
"res_name="+$('#res_name').val()+"&res_id="+$("#res_id").val(), type:'get',
function (data){ success:function (data)
if(data != 'fail'){//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变 {
if (data != 'fail') {//修改成功,那么将链接恢复,并且将链接的显示内容改变。链接可以不变
last_line.children().eq(1).html(res_link); last_line.children().eq(1).html(res_link);
last_line.children().eq(1).children().attr('title',name); last_line.children().eq(1).children().attr('title', name);
last_line.children().eq(1).children().attr('href',data); last_line.children().eq(1).children().attr('href', data);
last_line.children().eq(1).children().html(name.length > 17? name.substring(0,17)+'...' : name); last_line.children().eq(1).children().html(name.length > 17 ? name.substring(0, 17) + '...' : name);
}else{ } else {
last_line.children().eq(1).html(res_link); last_line.children().eq(1).html(res_link);
res_link = null; //如果修改失败恢复之后将res_link置空 res_link = null; //如果修改失败恢复之后将res_link置空
} }
}, }
'text' } );
);
}else{ }else{
last_line.children().eq(1).html(res_link); last_line.children().eq(1).html(res_link);
res_link = null; //如果没有做修改恢复之后将res_link置空 res_link = null; //如果没有做修改恢复之后将res_link置空

View File

@ -478,7 +478,7 @@ RedmineApp::Application.routes.draw do
post "add_exist_file_to_course" post "add_exist_file_to_course"
post "add_exist_file_to_project" post "add_exist_file_to_project"
get 'resource_preview' get 'resource_preview'
post 'rename_resource' get 'rename_resource'
get 'search_user_project' get 'search_user_project'
get 'user_resource_type' get 'user_resource_type'
get 'user_ref_resource_search' get 'user_ref_resource_search'