1.在项目和课程在关联和删除关联组织后,翻页能链接到正确的位置

This commit is contained in:
ouyangxuhua 2015-11-18 10:57:17 +08:00
parent 71bf80c7a5
commit fc7e41ebf9
11 changed files with 61 additions and 135 deletions

View File

@ -5,23 +5,6 @@ class OrgCoursesController < ApplicationController
org_ids.each do |org_id|
OrgCourse.create(:organization_id => org_id.to_i, :course_id => params[:course_id].to_i, :created_at => Time.now)
end
condition = '%%'
if !params[:name].nil?
condition = "%#{params[:name].strip}%".gsub(" ","")
end
course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:course_id]}").map(&:organization_id)
if course_org_ids.empty?
@orgs_not_in_course = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(10)
@org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
else
course_org_ids = "(" + course_org_ids.join(',') + ")"
@orgs_not_in_course = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(10)
@org_count = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
end
# @course_count = Course.course_entities.visible.like(params[:name]).page(params[:page]).count
@orgs_page = Paginator.new @org_count, 10,params[:page]
#render :json => {:orgs => @orgs_not_in_course, :count => @org_count}.to_json
respond_to do |format|
format.js
end
@ -31,18 +14,5 @@ class OrgCoursesController < ApplicationController
@course = Course.find(params[:course_id])
@org_course = OrgCourse.find(params[:id])
@org_course.destroy
condition = '%%'
course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:course_id]}").map(&:organization_id)
if course_org_ids.empty?
@orgs_not_in_course = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page( 1).per(10)
@org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
else
course_org_ids = "(" + course_org_ids.join(',') + ")"
@orgs_not_in_course = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page( 1).per(10)
@org_count = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
end
# @course_count = Course.course_entities.visible.like(params[:name]).page(params[:page]).count
@orgs_page = Paginator.new @org_count, 10,1
end
end

View File

@ -5,24 +5,6 @@ class OrgProjectsController < ApplicationController
org_ids.each do |org_id|
OrgProject.create(:organization_id => org_id.to_i, :project_id => params[:project_id].to_i, :created_at => Time.now)
end
#更新组织列表
condition = '%%'
if !params[:orgs].nil?
condition = "%#{params[:orgs].strip}%".gsub(" ","")
end
project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:project_id]}").map(&:organization_id)
if project_org_ids.empty?
@orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(10)
@org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
else
project_org_ids = "(" + project_org_ids.join(',') + ")"
@orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(10)
@org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
end
# @project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count
@orgs_page = Paginator.new @org_count, 10,params[:page]
respond_to do |format|
format.js
end
@ -31,18 +13,5 @@ class OrgProjectsController < ApplicationController
@project = Project.find(params[:project_id])
@org_project = OrgProject.find(params[:id])
@org_project.destroy
condition = '%%'
project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:project_id]}").map(&:organization_id)
if project_org_ids.empty?
@orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page( 1).per(10)
@org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
else
project_org_ids = "(" + project_org_ids.join(',') + ")"
@orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page( 1).per(10)
@org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
end
# @project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count
@orgs_page = Paginator.new @org_count, 10,1
end
end

View File

@ -1,8 +1,11 @@
<ul>
<li><span class="relatedListName fb fl">名称</span><span class="relatedListOption fb fl">操作</span></li>
<% orgs.each do |org| %>
<li><a href="<%= organization_path(org) %>" class="relatedListName linkBlue fl"><%= org.name %></a>
<%= link_to "取消关联", org_course_path(:id => OrgCourse.where(:organization_id => org.id, :course_id => course_id).first.id, :course_id => course_id),
<li>
<a href="<%= organization_path(org) %>" class="relatedListName linkBlue fl"><%= org.name %></a>
<a href="javascript:void(0);" onclick="cancel_org_course_relation(<%= OrgCourse.where(:organization_id => org.id, :course_id => course_id).first.id %>, '<%= course_id %>');"
class = "relatedListOption fl linkGrey3">取消关联</a>
<%#= link_to "取消关联", org_course_path(:id => OrgCourse.where(:organization_id => org.id, :course_id => course_id).first.id, :course_id => course_id),
:method => 'delete',:remote => true, :class => "relatedListOption fl linkGrey3" %>
</li>
<% end %>

View File

@ -15,7 +15,7 @@
<input type="text" name="orgs" class="searchOrg mb5 ml20" placeholder="请输入组织名称" />
<div id="search_orgs_result_list" class="ml20"></div>
<ul id="paginator" class="wlist ml20" style="float:none;"></ul>
<a href="javascript:void(0);" class="saveBtn db fl ml20 mr15 mb5" onclick="$('#join_orgs_for_course').submit();">关联</a>
<a href="javascript:void(0);" class="saveBtn db fl ml20 mr15 mb5" onclick="course_join_org(<%= @course.id %>);">关联</a>
<a href="javascript:void(0);" class="cancelBtn db fl" onclick="cancel_join_orgs();">取消</a>
<% end %>
</div>
@ -71,4 +71,16 @@
$("#search_orgs_result_list").html("");
$("#paginator").css("display", "none")
}
function course_join_org(courseId) {
$.ajax({
url: "/org_courses?" + $("#join_orgs_for_course").serialize() + "&course_id=" + courseId,
type: "post",
success: function (data) {
$.ajax({
url: "/courses/" + courseId + "/search_public_orgs_not_in_course",
type: "get"
});
}
});
}
</script>

View File

@ -1,13 +1,2 @@
$("#search_orgs_result_list").html("");
$("#search_orgs_result_list").append('<ul class="ml20">');
<% @orgs_not_in_course.each do |org|%>
link = "<li><label><input type='checkbox'class='mr5 fl mt3' name='orgNames[]' value='<%=org.id%>'/><span class='relateOrgName fl'> <%=org.name %> </span></label></li><div class='cl mt5'></div>";
$("#search_orgs_result_list").append(link );
<% end %>
$("#search_orgs_result_list").append('</ul>')
<% if @org_count > 10 %>
$("#paginator").html(' <%= pagination_links_full @orgs_page, @org_count ,:per_page_links => true,:remote =>true,:flag=>true %>');
<% end %>
$("#added_orgs").html("");
$("#added_orgs").html('<%= escape_javascript(render :partial => "courses/settings/added_orgs", :locals => {:orgs => @course.organizations, :course_id => @course.id}) %>')
$("#added_orgs").html('<%= escape_javascript(render :partial => "courses/settings/added_orgs", :locals => {:orgs => @course.organizations, :course_id => @course.id}) %>');

View File

@ -1,17 +1,4 @@
$("#added_orgs").html("");
$("#added_orgs").html('<%= escape_javascript(render :partial => "courses/settings/added_orgs", :locals => {:orgs => @course.organizations, :course_id => @course.id}) %>')
$("#added_orgs").html('<%= escape_javascript(render :partial => "courses/settings/added_orgs", :locals => {:orgs => @course.organizations, :course_id => @course.id}) %>');
$("#search_orgs_result_list").html("");
$("#search_orgs_result_list").append('<ul class="ml20">');
<% @orgs_not_in_course.each do |org|%>
link = "<li><label><input type='checkbox'class='mr5 fl mt3' name='orgNames[]' value='<%=org.id%>'/><span class='relateOrgName fl'> <%=org.name %> </span></label></li><div class='cl mt5'></div>";
$("#search_orgs_result_list").append(link );
<%end %>
$("#search_orgs_result_list").append('</ul>')
<% if @org_count > 10 %>
$("#paginator").html(' <%= pagination_links_full @orgs_page, @org_count ,:per_page_links => true,:remote =>true,:flag=>true%>');
$("#paginator").css("display", "block");
<% else %>
$("#paginator").css("display", "none");
<% end %>

View File

@ -1,20 +1,2 @@
$("#search_orgs_result_list").html("");
$("#search_orgs_result_list").append('<ul class="ml20">');
<% @orgs_not_in_project.each do |org|%>
link = "<li><label><input type='checkbox'class='mr5 fl mt3' name='orgNames[]' value='<%=org.id%>'/><span class='relateOrgName fl'> <%=org.name %> </span></label></li><div class='cl mt5'></div>";
$("#search_orgs_result_list").append(link );
<%end %>
$("#search_orgs_result_list").append('</ul>')
<% if @org_count > 10 %>
$("#paginator").html(' <%= pagination_links_full @orgs_page, @org_count ,:per_page_links => true,:remote =>true,:flag=>true %>');
//$("#paginator").css("display", "block");
<!--<%# else %>-->
//$("#paginator").css("display", "none");
<% end %>
//$("#search_orgs_result_list").html("");
//$("#search_orgs_result_list").append('<ul class="ml20">');
//$("#paginator").css("display", "none");
$("#added_orgs").html("");
$("#added_orgs").html('<%= escape_javascript(render :partial => "projects/settings/added_orgs", :locals => {:orgs => @project.organizations, :project_id => @project.id}) %>')

View File

@ -1,22 +1,4 @@
//$("#search_orgs_result_list").html("");
////$("#paginator").css("display", "none");
$("#added_orgs").html("");
$("#added_orgs").html('<%= escape_javascript(render :partial => "projects/settings/added_orgs", :locals => {:orgs => @project.organizations, :project_id => @project.id}) %>')
//$.ajax({
// url: '<%#= url_for(:controller => 'projects', :action => 'search_public_orgs_not_in_project') %>'+'?page=1',
// type:'get'
//});
$("#search_orgs_result_list").html("");
$("#search_orgs_result_list").append('<ul class="ml20">');
<% @orgs_not_in_project.each do |org|%>
link = "<li><label><input type='checkbox'class='mr5 fl mt3' name='orgNames[]' value='<%=org.id%>'/><span class='relateOrgName fl'> <%=org.name %> </span></label></li><div class='cl mt5'></div>";
$("#search_orgs_result_list").append(link );
<%end %>
$("#search_orgs_result_list").append('</ul>')
<% if @org_count > 10 %>
$("#paginator").html(' <%= pagination_links_full @orgs_page, @org_count ,:per_page_links => true,:remote =>true,:flag=>true%>');
$("#paginator").css("display", "block");
<% else %>
$("#paginator").css("display", "none");
<% end %>
$("#added_orgs").html('<%= escape_javascript(render :partial => "projects/settings/added_orgs", :locals => {:orgs => @project.organizations, :project_id => @project.id}) %>');

View File

@ -1,3 +1,9 @@
//翻页提醒
if($("#join_orgs_for_project input:checked").size() > 0)
{
alert('翻页或搜索后将丢失当前选择的用户数据!');
}
$("#search_orgs_result_list").html("");
$("#search_orgs_result_list").append('<ul class="ml20">');
<% @orgs_not_in_project.each do |org|%>

View File

@ -11,12 +11,13 @@
<div class="relateOrg fl">
<span class="pic_add fl mr5 mt3"></span><span class="f14 fontBlue fl">关联组织</span>
<div class="cl mb5"></div>
<%= form_tag url_for(:controller => 'org_projects', :action => 'create', :project_id => @project.id), :id => 'join_orgs_for_project', :remote => true %>
<input type="text" name="orgs" class="searchOrg mb5 ml20" placeholder="请输入组织名称" />
<div id="search_orgs_result_list" class="ml20"></div>
<ul id="paginator" class="wlist ml20" style="float:none;"></ul>
<a href="javascript:void(0);" class="saveBtn db fl ml20 mr15 mb5" onclick="$('#join_orgs_for_project').submit();">关联</a>
<a href="javascript:void(0);" class="cancelBtn db fl" onclick="cancel_join_orgs();">取消</a>
<%= form_tag url_for(:controller => 'org_projects', :action => 'create', :project_id => @project.id), :id => 'join_orgs_for_project', :remote => true do %>
<input type="text" name="orgs" class="searchOrg mb5 ml20" placeholder="请输入组织名称" />
<div id="search_orgs_result_list" class="ml20"></div>
<ul id="paginator" class="wlist ml20" style="float:none;"></ul>
<a href="javascript:void(0);" class="saveBtn db fl ml20 mr15 mb5" onclick="join_org(<%= @project.id %>);">关联</a>
<a href="javascript:void(0);" class="cancelBtn db fl" onclick="cancel_join_orgs();">取消</a>
<% end %>
</div>
<div class="relatedList fr">
<div class="fr mr15">
@ -59,7 +60,6 @@
$("input[name='orgs']").on('input', function (e) {
throttle(search_orgs,window,e);
});
$(document).ready(function(){
$.ajax({
url: '<%= url_for(:controller => 'projects', :action => 'search_public_orgs_not_in_project') %>'+'?page=1',
@ -71,4 +71,16 @@
$("#paginator").html("");
$("#paginator").css("display", "none");
}
function join_org(projectId) {
$.ajax({
url: '/org_projects' + "?" + $('#join_orgs_for_project').serialize() + "&project_id=" + projectId,
type: 'post',
success: function (data) {
$.ajax({
url: '/projects/'+projectId+'/search_public_orgs_not_in_project',
type: 'get'
});
}
});
}
</script>

View File

@ -1286,6 +1286,20 @@ function course_outline(id){
' /courses/'+id+'/course_outline'+"?is_in_show_outline_page="+(arguments[1] ? arguments[1] : 'N')
)
}
//取消课程组织关联
function cancel_org_course_relation(id, courseId){
$.ajax({
url:"/org_courses/" + id + "?course_id=" + courseId,
type: "delete",
success:function(data){
$.ajax({
url: "/courses/" + courseId + "/search_public_orgs_not_in_course",
type:'get'
});
}
});
}
//$(function(){
// $('#course_outline_search').on('input',function(){
// alert('<%= @course.id%>')