管理员界面的课程名称双击可点击

This commit is contained in:
cxt 2016-07-15 14:48:39 +08:00
parent fd68479d72
commit b7e6725e1f
10 changed files with 121 additions and 44 deletions

View File

@ -96,7 +96,7 @@ class AdminController < ApplicationController
def courses def courses
@name = params[:name].to_s.strip.downcase @name = params[:name].to_s.strip.downcase
if @name && @name != "" if @name && @name != ""
@courses = Course.select{ |course| (course.teacher[:lastname].to_s.downcase + course.teacher[:firstname].to_s.downcase).include?(@name) || course.name.include?(@name)} @courses = Course.select{ |course| course.teacher && ((course.teacher.show_name).include?(@name) || course.name.include?(@name))}
@courses = @courses.sort{|x, y| y.created_at <=> x.created_at} @courses = @courses.sort{|x, y| y.created_at <=> x.created_at}
else else
@courses = Course.order('created_at desc') @courses = Course.order('created_at desc')
@ -135,6 +135,17 @@ class AdminController < ApplicationController
end end
end end
#修改课程名称
def update_syllabus_title
@syllabus = Syllabus.where("id = #{params[:syllabus_id].to_i}").first
unless @syllabus.nil?
@syllabus.update_column("title", params[:name])
respond_to do |format|
format.js
end
end
end
#管理员界面精品课程列表 #管理员界面精品课程列表
def excellent_courses def excellent_courses
@courses = Course.where("is_excellent =? or excellent_option =?", 1, 1 ) @courses = Course.where("is_excellent =? or excellent_option =?", 1, 1 )

View File

@ -0,0 +1,3 @@
<span>
<a title="<%= syllabus.title %>" id="rename_syllabus_title_<%= syllabus.id %>" ondblclick="rename_syllabus_title($(this),'<%=syllabus.title %>','<%=syllabus.id %>');"><%= syllabus.title %></a>
</span>

View File

@ -46,10 +46,8 @@
<td style="text-align: center;"> <td style="text-align: center;">
<%= syllabus.id %> <%= syllabus.id %>
</td> </td>
<td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<%=syllabus.title%>'> <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;" class="name" title='<%=syllabus.title%>' id="syllabus_title_<%=syllabus.id %>">
<span> <%= render :partial => 'admin/rename_syllabus_title', :locals => {:syllabus => syllabus} %>
<%= link_to(syllabus.title, syllabus_path(syllabus.id)) %>
</span>
</td> </td>
<td class="center"> <td class="center">
</td> </td>
@ -89,23 +87,24 @@
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var tagNameHtml; //当前双击的链接的父节点的html var CourseTagNameHtml; //当前双击的链接的父节点的html
var parentCssBorder; //当前双击的链接的父节点 var CourseParentCssBorder; //当前双击的链接的父节点
var ele; //当前双击的链接 var CourseEle; //当前双击的链接
var tagId; //班级的id var CourseTagId; //班级的id
var tagName; //班级名称 var CourseTagName; //班级名称
var CourseIsdb;
function rename_course_name(domEle,name,id){ function rename_course_name(domEle,name,id){
isdb = true; //这是双击 CourseIsdb = true; //这是双击
//clearTimeout(clickFunction); //clearTimeout(clickFunction);
if (domEle.children().get(0) != undefined) { //已经是编辑框的情况下不要动 if (domEle.children().get(0) != undefined) { //已经是编辑框的情况下不要动
return; return;
} }
tagNameHtml = domEle.parent().html(); CourseTagNameHtml = domEle.parent().html();
parentCssBorder = domEle.parent().css("border"); CourseParentCssBorder = domEle.parent().css("border");
ele = domEle; CourseEle = domEle;
tagId = id; CourseTagId = id;
tagName = name; CourseTagName = name;
domEle.html('<input name="" id="renameCourseName" maxlength="120" minlength="1" style="width:125px;" value="' + name + '"/>'); domEle.html('<input name="" id="renameCourseName" maxlength="120" minlength="1" style="width:125px;" value="' + name + '"/>');
domEle.parent().css("border", "1px solid #ffffff"); domEle.parent().css("border", "1px solid #ffffff");
$("#renameCourseName").focus(); $("#renameCourseName").focus();
@ -119,20 +118,66 @@
updateCourseName(); updateCourseName();
} }
}); });
$("#renameSyllabusTitle").live("blur",function(){
updateSyllabusTitle();
}).live("keypress",function(e){
if (e.keyCode == '13') {
updateSyllabusTitle();
}
});
}); });
//执行修改TAGName方法 //执行修改TAGName方法
function updateCourseName(){ function updateCourseName(){
if(isdb){ if(CourseIsdb){
isdb = false; CourseIsdb = false;
if($("#renameCourseName").val() == tagName){ //如果值一样,则恢复原来的状态 if($("#renameCourseName").val() == CourseTagName){ //如果值一样,则恢复原来的状态
ele.parent().css("border",""); ele.parent().css("border","");
ele.parent().html(tagNameHtml); ele.parent().html(CourseTagNameHtml);
} }
else{ else{
$.post( $.post(
'<%= admin_update_course_name_path %>', '<%= admin_update_course_name_path %>',
{"course_id": tagId, "name": $("#renameCourseName").val().trim()} {"course_id": CourseTagId, "name": $("#renameCourseName").val().trim()}
);
}
}
}
var SyllabusTagNameHtml; //当前双击的链接的父节点的html
var SyllabusParentCssBorder; //当前双击的链接的父节点
var SyllabusEle; //当前双击的链接
var SyllabusTagId; //课程的id
var SyllabusTagName; //课程名称
var SyllabusIsdb;
function rename_syllabus_title(domEle,name,id){
SyllabusIsdb = true; //这是双击
//clearTimeout(clickFunction);
if (domEle.children().get(0) != undefined) { //已经是编辑框的情况下不要动
return;
}
SyllabusTagNameHtml = domEle.parent().html();
SyllabusParentCssBorder = domEle.parent().css("border");
SyllabusEle = domEle;
SyllabusTagId = id;
SyllabusTagName = name;
domEle.html('<input name="" id="renameSyllabusTitle" maxlength="120" minlength="1" style="width:125px;" value="' + name + '"/>');
domEle.parent().css("border", "1px solid #ffffff");
$("#renameSyllabusTitle").focus();
}
//执行修改TAGName方法
function updateSyllabusTitle(){
if(SyllabusIsdb){
SyllabusIsdb = false;
if($("#renameSyllabusTitle").val() == SyllabusTagName){ //如果值一样,则恢复原来的状态
ele.parent().css("border","");
ele.parent().html(SyllabusTagNameHtml);
}
else{
$.post(
'<%= admin_update_syllabus_title_path %>',
{"syllabus_id": SyllabusTagId, "name": $("#renameSyllabusTitle").val().trim()}
); );
} }
} }

View File

@ -0,0 +1 @@
$("#syllabus_title_<%=@syllabus.id %>").html("<%=escape_javascript(render :partial => 'admin/rename_syllabus_title', :locals => {:syllabus => @syllabus}) %>");

View File

@ -8,14 +8,14 @@
<div id="syllabus_title_show" class="homepageSyllabusName mb5"> <div id="syllabus_title_show" class="homepageSyllabusName mb5">
<%= render :partial => 'layouts/syllabus_title', :locals => {:syllabus => @syllabus}%> <%= render :partial => 'layouts/syllabus_title', :locals => {:syllabus => @syllabus}%>
</div> </div>
<textarea class="syllabusTitleTextarea none" placeholder="请编辑课程名称" id="syllabus_title_edit" onblur="edit_syllabus_title('<%= edit_syllabus_title_syllabus_path(@syllabus.id)%>');"><%= @syllabus.title %></textarea> <textarea class="syllabusTitleTextarea none" placeholder="请编辑课程名称" id="syllabus_title_edit"></textarea>
</div> </div>
<div class="cl"></div> <div class="cl"></div>
<div> <div>
<div class="mb5" id="syllabus_eng_name_show" style="word-break:normal;word-wrap:normal;"> <div class="mb5" id="syllabus_eng_name_show" style="word-break:normal;word-wrap:normal;">
<%= render :partial => 'layouts/syllabus_eng_name', :locals => {:syllabus => @syllabus}%> <%= render :partial => 'layouts/syllabus_eng_name', :locals => {:syllabus => @syllabus}%>
</div> </div>
<textarea class="homepageSignatureTextarea none" placeholder="请编辑英文名称" id="syllabus_eng_name_edit" onblur="edit_syllabus_eng_name('<%= edit_syllabus_eng_name_syllabus_path(@syllabus.id)%>');"><%= @syllabus.eng_name %></textarea> <textarea class="homepageSignatureTextarea none" placeholder="请编辑英文名称" id="syllabus_eng_name_edit"></textarea>
</div> </div>
<!-- <!--
<div class="pr_info_foot "> <div class="pr_info_foot ">

View File

@ -1,5 +1,5 @@
<span style="word-break: normal; word-wrap: break-word;"><%=@syllabus.title %></span> <span style="word-break: normal; word-wrap: break-word;"><%=@syllabus.title %></span>
<% if User.current == syllabus.user || User.current.admin? %> <% if User.current == syllabus.user || User.current.admin? %>
<%= link_to image_tag("../images/signature_edit.png",width:"12px", height: "12px"), "javascript:void(0);",:id => "syllabus_edit_title_png", :class => "none", :onclick => "show_edit_title();"%> <%= link_to image_tag("../images/signature_edit.png",width:"12px", height: "12px"), "javascript:void(0);",:id => "syllabus_edit_title_png", :class => "none", :onclick => "show_edit_title('#{@syllabus.title}');"%>
<% end %> <% end %>

View File

@ -121,15 +121,21 @@
<span><%= l(:label_loading) %></span> <span><%= l(:label_loading) %></span>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$(function(){ $(function() {
$('#user_hide_course').hide(); $('#user_hide_course').hide();
}); $("#syllabus_title_edit").live("blur", function () {
edit_syllabus_title('<%= edit_syllabus_title_syllabus_path(@syllabus.id)%>');
});
$("#syllabus_eng_name_edit").live("blur", function () {
edit_syllabus_eng_name('<%= edit_syllabus_eng_name_syllabus_path(@syllabus.id)%>');
});
$("#courseMenu").mouseenter(function(){ $("#courseMenu").mouseenter(function () {
$("#topnav_course_menu").show(); $("#topnav_course_menu").show();
}); });
$("#courseMenu").mouseleave(function(){ $("#courseMenu").mouseleave(function () {
$("#topnav_course_menu").hide(); $("#topnav_course_menu").hide();
});
}); });
function leftCourseslistChange(){ function leftCourseslistChange(){
$('#homepageLeftMenuCourses').slideToggle(); $('#homepageLeftMenuCourses').slideToggle();

View File

@ -1,3 +1,4 @@
$("#syllabus_title_show").html("<%= escape_javascript render :partial => 'layouts/syllabus_title', :locals => {:syllabus => @syllabus} %>"); $("#syllabus_title_show").html("<%= escape_javascript render :partial => 'layouts/syllabus_title', :locals => {:syllabus => @syllabus} %>");
$("#syllabus_title_edit").text("");
$("#syllabus_title_show").show(); $("#syllabus_title_show").show();
$("#syllabus_title_edit").hide(); $("#syllabus_title_edit").hide();

View File

@ -1039,6 +1039,7 @@ RedmineApp::Application.routes.draw do
get 'admin/syllabuses', as: :all_syllabuses get 'admin/syllabuses', as: :all_syllabuses
get 'admin/non_syllabus_courses', as: :non_syllabus_courses get 'admin/non_syllabus_courses', as: :non_syllabus_courses
post 'admin/update_course_name' post 'admin/update_course_name'
post 'admin/update_syllabus_title'
get 'admin/excellent_courses', as: :excellent_courses get 'admin/excellent_courses', as: :excellent_courses
get 'admin/excellent_all_courses', as: :excellent_all_courses get 'admin/excellent_all_courses', as: :excellent_all_courses
match 'admin/set_excellent_course/:id', :to => 'admin#set_excellent_course' match 'admin/set_excellent_course/:id', :to => 'admin#set_excellent_course'

View File

@ -32,6 +32,7 @@ function submit_syllabus() {
//编辑英文名称 //编辑英文名称
function show_edit_eng_name() { function show_edit_eng_name() {
EngEdit = true;
$("#syllabus_eng_name_show").hide(); $("#syllabus_eng_name_show").hide();
$("#syllabus_eng_name_edit").show(); $("#syllabus_eng_name_edit").show();
$("#syllabus_eng_name_edit").focus(); $("#syllabus_eng_name_edit").focus();
@ -39,31 +40,39 @@ function show_edit_eng_name() {
//编辑英文名称之后提交 //编辑英文名称之后提交
function edit_syllabus_eng_name(url){ function edit_syllabus_eng_name(url){
$.get( if(EngEdit) {
url, EngEdit = false;
{ eng_name: $("#syllabus_eng_name_edit").val() }, $.get(
function (data) { url,
{ eng_name: $("#syllabus_eng_name_edit").val() },
function (data) {
} }
); );
}
} }
//编辑课程名称 //编辑课程名称
function show_edit_title() { function show_edit_title(str) {
IsEdit = true;
$("#syllabus_title_show").hide(); $("#syllabus_title_show").hide();
$("#syllabus_title_edit").show(); $("#syllabus_title_edit").show();
$("#syllabus_title_edit").text(str);
$("#syllabus_title_edit").focus(); $("#syllabus_title_edit").focus();
} }
//编辑课程名称之后提交 //编辑课程名称之后提交
function edit_syllabus_title(url){ function edit_syllabus_title(url){
$.get( if(IsEdit) {
url, IsEdit = false;
{ title: $("#syllabus_title_edit").val().trim() }, $.get(
function (data) { url,
{ title: $("#syllabus_title_edit").val().trim() },
function (data) {
} }
); );
}
} }
//展开所有属性 //展开所有属性