parent
8aeae831b8
commit
71bf80c7a5
@ -0,0 +1,3 @@
|
||||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
@ -0,0 +1,3 @@
|
||||
// Place all the styles related to the org_courses controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
@ -0,0 +1,48 @@
|
||||
class OrgCoursesController < ApplicationController
|
||||
def create
|
||||
org_ids = params[:orgNames]
|
||||
@course = Course.find(params[:course_id])
|
||||
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
|
||||
end
|
||||
|
||||
def destroy
|
||||
@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
|
@ -0,0 +1,2 @@
|
||||
module OrgCoursesHelper
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class OrgCourse < ActiveRecord::Base
|
||||
#attr_accessible :organization, :course, :created_at
|
||||
belongs_to :organization
|
||||
belongs_to :course
|
||||
end
|
@ -0,0 +1,13 @@
|
||||
$("#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 %>
|
@ -0,0 +1,9 @@
|
||||
<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),
|
||||
:method => 'delete',:remote => true, :class => "relatedListOption fl linkGrey3" %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
@ -0,0 +1,74 @@
|
||||
<!--<div class="members_left">-->
|
||||
<!--<input type="text" id="orgs_not_course_member_search" name="orgAddSearch" placeholder="支持姓名、邮箱、昵称搜索" class="orgAddSearch mb20" />-->
|
||||
<!--<%#= javascript_tag "observeSearchfield('orgs_not_course_member_search', null, '#{ escape_javascript autocomplete_search_organizations_path(:course_id=> @course.id, :format => 'js') }')" %>-->
|
||||
<!--<div id="new_orgs_for_course">-->
|
||||
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
<%= stylesheet_link_tag 'org' %>
|
||||
|
||||
<div>
|
||||
<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_courses', :action => 'create', :course_id => @course.id), :id => 'join_orgs_for_course', :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_orgs_for_course').submit();">关联</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">
|
||||
<span class="f14 fontBlue">已关联组织</span>
|
||||
<div id="added_orgs">
|
||||
<%= render :partial => 'courses/settings/added_orgs', :locals => {:orgs => @course.organizations, :course_id => params[:id]} %>
|
||||
</div>
|
||||
<div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var lastSearchCondition = '';
|
||||
var page = 1;
|
||||
var count = 0;
|
||||
var maxPage = 0;
|
||||
function search_orgs(e){
|
||||
if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
lastSearchCondition = $(e.target).val().trim();
|
||||
page = 1;
|
||||
$.ajax({
|
||||
url: '<%= url_for(:controller => 'courses', :action => 'search_public_orgs_not_in_course') %>'+'?name='+ e.target.value+'&page='+page,
|
||||
type:'get'
|
||||
});
|
||||
}
|
||||
|
||||
function throttle(method,context,e){
|
||||
clearTimeout(method.tId);
|
||||
method.tId=setTimeout(function(){
|
||||
method.call(context,e);
|
||||
},500);
|
||||
}
|
||||
|
||||
//查询组织
|
||||
$("input[name='orgs']").on('input', function (e) {
|
||||
throttle(search_orgs,window,e);
|
||||
});
|
||||
|
||||
$(document).ready(function(){
|
||||
$.ajax({
|
||||
url: '<%= url_for(:controller => 'courses', :action => 'search_public_orgs_not_in_course') %>'+'?page=1',
|
||||
type:'get'
|
||||
});
|
||||
});
|
||||
function cancel_join_orgs() {
|
||||
$("#search_orgs_result_list").html("");
|
||||
$("#paginator").css("display", "none")
|
||||
}
|
||||
</script>
|
@ -0,0 +1,13 @@
|
||||
$("#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}) %>')
|
@ -0,0 +1,17 @@
|
||||
$("#added_orgs").html("");
|
||||
$("#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 %>
|
||||
|
@ -0,0 +1,12 @@
|
||||
class CreateOrgCourses < ActiveRecord::Migration
|
||||
def up
|
||||
create_table :org_courses do |t|
|
||||
t.integer :organization_id
|
||||
t.integer :course_id
|
||||
t.timestamp :created_at
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,5 @@
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe OrgCoursesController, :type => :controller do
|
||||
|
||||
end
|
Loading…
Reference in new issue