增加组织加入课程功能

This commit is contained in:
ouyangxuhua 2015-11-26 16:29:50 +08:00
parent 2dc31637d8
commit 9c3aed8028
8 changed files with 183 additions and 0 deletions

View File

@ -175,4 +175,40 @@ class OrganizationsController < ApplicationController
format.js
end
end
def join_course_menu
@organization = Organization.find(params[:id])
respond_to do |format|
format.js
end
end
def search_courses
@organization = Organization.find(params[:id])
condition = '%%'
if !params[:name].nil?
condition = "%#{params[:name].strip}%".gsub(" ","")
end
#sql = "select courses.* from courses inner join members on courses.id = members.course_id inner join org_courses on courses.id = org_courses.course_id where org_courses.organization_id != #{@organization.id} and members.user_id = #{User.current.id} and courses.name like '#{condition}'"
sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"
user_courses = Course.find_by_sql(sql)
@added_course_ids = @organization.courses.map(&:id)
@courses = []
user_courses.each do |course|
if @added_course_ids.include?(course.id)
@courses << course
end
end
end
def join_courses
@organization = Organization.find(params[:id])
course_ids = params[:courseNames]
course_ids.each do |id|
OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now)
end
respond_to do |format|
format.js
end
end
end

View File

@ -98,6 +98,18 @@
</ul>
</div>
<div class="homepageLeftMenuBlock"><a href="javascript:void(0);" class="homepageMenuText">课程</a>
<div class="courseMenu" id="courseMenu">
<ul>
<li class="courseMenuIcon" id="courseMenuIcon">
<ul class="topnav_course_menu" id="topnav_course_menu">
<!--<li><a href="javascript:void(0);" class="menuGrey">账号设置</a> </li>-->
<li>
<%= link_to "加入课程",join_course_menu_organization_path(@organization),:remote => true,:class => "menuGrey",:method => "post"%>
</li>
</ul>
</li>
</ul>
</div>
<!--<a href="javascript:void(0);" class="homepageMenuSetting fr" title="关联您的已有项目"></a>-->
</div>
<div class="homepageLeftMenuCourses borderBottomNone">
@ -122,9 +134,20 @@
<div class="cl"></div>
<div id="ajax-modal" style="display:none;"></div>
<div id="ajax-modal" style="display:none;"></div>
<div id="ajax-indicator" style="display:none;">
<span><%= l(:label_loading) %></span>
</div>
<script type="text/javascript">
$("#courseMenu").mouseenter(function(){
$("#topnav_course_menu").show();
});
$("#courseMenu").mouseleave(function(){
$("#topnav_course_menu").hide();
});
</script>
</body>
</html>

View File

@ -0,0 +1,98 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/public.css" rel="stylesheet" type="text/css" />
<link href="css/org.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.3.2.js" type="text/javascript"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script>
$(document).ready(function(){
var popupHeight = $(".resourceSharePopup").outerHeight(true);
$(".resourceSharePopup").css("marginTop",-popupHeight/2);
$(".resourcePopupClose").click(function(){
$(".resourceSharePopup").css("display","none");
});
});
</script>
</head>
<body>
<div class="resourceSharePopup">
<div>
<div class="relateText fl">请选择关联到组织的课程</div>
</div>
<div class="resourcePopupClose"> <a href="javascript:void(0);" class="resourceClose"></a></div>
<div class="fl">
<%=form_tag url_for(:controller => 'organizations', :action => 'join_courses', :organization_id => organization_id),:method => 'post', :id => 'join_courses_form', :remote => true,:class=>"resourcesSearchBox" do %>
<input type="text" name="courses" placeholder="输入课程名称搜索" class="searchCourse" />
<div id="search_courses_result_list" class="ml5"></div>
<div class="courseSendSubmit">
<a href="javascript:void(0);" onclick="org_join_courses(<%= organization_id %>);" class="sendSourceText">关联</a>
</div>
<div class="courseSendCancel"><a href="javascript:void(0);" onclick="cancel_join_courses();" class="sendSourceText">取消</a></div>
<% end %>
</div>
<div class="cl"></div>
<div>
</div>
<div class="cl"></div>
</div>
<script type="text/javascript">
var lastSearchCondition = '';
var page = 1;
var count = 0;
var maxPage = 0;
function search_courses(e){
if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
{
return;
}
lastSearchCondition = $(e.target).val().trim();
$.ajax({
url: '<%= url_for(:controller => 'organizations', :action => 'search_courses') %>'+'?name='+ e.target.value,
type:'get'
});
}
function throttle(method,context,e){
clearTimeout(method.tId);
method.tId=setTimeout(function(){
method.call(context,e);
},500);
}
//查询组织
$("input[name='courses']").on('input', function (e) {
throttle(search_courses,window,e);
});
$(document).ready(function(){
$.ajax({
url: '<%= url_for(:controller => 'organizations', :action => 'search_courses') %>',
type:'get'
});
});
function cancel_join_courses() {
$("#search_courses_result_list").html("");
}
function org_join_courses(orgId) {
$.ajax({
url: "/organizations/"+orgId + "/join_courses?" + $("#join_courses_form").serialize(),
type: "post",
success: function (data) {
$.ajax({
url: "/organizations/" + orgId + "/search_courses?name=" + $("input[name='courses']").val().trim(),
type: "get"
});
}
});
}
</script>
</body>
</html>

View File

@ -0,0 +1,12 @@
$('#topnav_course_menu').hide();
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'join_course_menu', :locals => {:organization_id => @organization.id}) %>');
$('#ajax-modal').show();
//showModal('ajax-modal', '540px');
//$('#ajax-modal').css('height','390px');
////$('#ajax-modal').siblings().remove();
////$('#ajax-modal').siblings().hide();
//$('#ajax-modal').before("<span style='float: right;cursor:pointer;padding-left: 513px;'>" +
// "<a href='javascript:' onclick=' hideModal($('#resourceSharePopup''));'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
//$('#ajax-modal').parent().removeClass("alert_praise");
//$('#ajax-modal').parent().css("top","").css("left","");
//$('#ajax-modal').parent().addClass("alert_box");

View File

@ -0,0 +1,9 @@
$("#search_courses_result_list").html("");
$("#search_courses_result_list").append('<ul class="ml5">');
<% @courses.each do |course|%>
link = "<li><label><input type='checkbox'class='mr5 fl mt3' name='courseNames[]' value='<%=course.id%>'/><span class='search_org fl'> <%=course.name %> </span></label></li><div class='cl mt5'></div>";
$("#search_courses_result_list").append(link );
<%end %>
$("#search_courses_result_list").append('</ul>')

View File

@ -39,6 +39,9 @@ RedmineApp::Application.routes.draw do
get 'members'
get 'more_org_projects'
get 'more_org_courses'
get 'search_courses'
post 'join_course_menu'
post 'join_courses'
end
collection do
get 'check_uniq'

View File

@ -384,6 +384,7 @@ a.resourcesGrey:hover {font-size:12px; color:#269ac9;}
a.uploadText {color:#ffffff; font-size:14px;}
.resourcesSearchloadBox {border:1px solid #e6e6e6; width:225px; float:left; background-color:#ffffff;}
.searchResource {border:none; outline:none; background-color:#ffffff; width:184px; height:32px; padding-left:10px; display:block; float:left;}
.searchCourse {border:none; outline:none; background-color:#ffffff; width:184px; padding-left:10px; display:block; margin-bottom:15px;}
.searchIcon{width:31px; height:32px; background-color:#ffffff; background:url(images/resource_icon_list.png) -40px -15px no-repeat; display:block; float:left;}
/*.resourcesSearchBanner {height:34px; margin-bottom:10px;}*/
.resourcesSearchBanner {width:710px; height:34px; margin-bottom:10px; margin-top:15px; margin-left:auto; margin-right:auto;}

View File

@ -44,6 +44,7 @@ a.cancelBtn:hover {background-color:#717171; color:#ffffff;}
.relatedListName {width:240px; text-align:left; max-width:240px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;}
.relatedListOption {width:80px; text-align:center;}
.relateOrgName {width:240px; max-width:240px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;color:#656565;}
.search_org {width:150px; max-width:200px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis;color:#656565;}
/*组织列表*/
.mt28 {margin-top:28px;}