资源发送课程发送项目自动搜索

This commit is contained in:
lizanle 2015-12-02 14:38:41 +08:00
parent 2f0895c2c2
commit 9fe5cfbf76
4 changed files with 48 additions and 8 deletions

View File

@ -1429,6 +1429,7 @@ class UsersController < ApplicationController
@course = @user.courses
.select { |course| @user.allowed_to?(:as_teacher,course)}
end
@search = params[:search]
#这里仅仅是传递需要发送的资源id
@send_id = params[:send_id]
@send_ids = params[:checkbox1] || params[:send_ids]
@ -1445,6 +1446,7 @@ class UsersController < ApplicationController
else
@projects = @user.projects
end
@search = params[:search]
#这里仅仅是传递需要发送的资源id
@send_id = params[:send_id]
@send_ids = params[:checkbox1] || params[:send_ids] #搜索的时候 和 直接 用表格提交的时候的send_ids

View File

@ -17,7 +17,10 @@
:remote=>true,:id=>'search_user_project_form',:class=>'resourcesSearchBox' do %>
<%= hidden_field_tag(:send_id, send_id) %>
<%= hidden_field_tag(:send_ids, send_ids) %>
<input type="text" name="search" placeholder="输入项目ID或者名称搜索" class="searchResourcePopup" />
<input type="text" id="search_project_input" value="<%= @search %>" name="search" placeholder="输入项目ID或者名称搜索" class="searchResourcePopup" />
<script>
observeSearchfieldOnInput('search_project_input','<%= search_user_project_user_path(user)%>','<%= send_id %>','<%= send_ids%>')
</script>
<!--<a href="javascript:void(0);" class="searchIconPopup"></a>-->
<%= submit_tag '',:class=>'searchIconPopup',:onfocus=>"this.blur();",:style=>'border-style:none' %>
<% end %>

View File

@ -17,7 +17,10 @@
:remote=>true,:id=>'search_user_course_form',:class=>'resourcesSearchBox' do %>
<%= hidden_field_tag(:send_id, send_id) %>
<%= hidden_field_tag(:send_ids, send_ids) %>
<input type="text" name="search" placeholder="输入课程ID或者名称搜索" class="searchResourcePopup" />
<input type="text" id="search_course_input" value="<%= @search %>" name="search" placeholder="输入课程ID或者名称搜索" class="searchResourcePopup" />
<script>
observeSearchfieldOnInput('search_course_input','<%= search_user_course_user_path(user)%>','<%= send_id %>','<%= send_ids%>')
</script>
<!--<a href="javascript:void(0);" class="searchIconPopup"></a>-->
<%= submit_tag '',:class=>'searchIconPopup',:onfocus=>"this.blur();",:style=>'border-style:none' %>
<% end %>

View File

@ -327,16 +327,17 @@
alert('暂时不支持多页选择,您当前页没有选择任何资源');
return ;
}
if (lastSendType === '1'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
$.ajax({
type: 'get',
url: '<%= search_user_course_user_path(@user)%>' + '?'+ $("#resources_list_form").serialize()
});
}else{
if (lastSendType === '2'){ //如果已经发送过一次了,那么就应该沿用上次发送的类型。
$.ajax({
type: 'get',
url: '<%= search_user_project_user_path(@user)%>' + '?' + $("#resources_list_form").serialize()
});
}else{
$.ajax({
type: 'get',
url: '<%= search_user_course_user_path(@user)%>' + '?'+ $("#resources_list_form").serialize()
});
}
}
@ -480,5 +481,36 @@
lastSendType = sendType;
}
function observeSearchfieldOnInput(fieldId, url,send_id,send_ids) {
$('#'+fieldId).each(function() {
var $this = $(this);
$this.addClass('autocomplete');
$this.attr('data-value-was', $this.val());
var check = function() {
var val = $this.val();
if ($this.attr('data-value-was') != val){
$this.attr('data-value-was', val);
$.ajax({
url: url,
type: 'get',
data: {search: $this.val(),send_id:send_id,send_ids:send_ids},
success: function(data){ },
beforeSend: function(){ $this.addClass('ajax-loading'); },
complete: function(){ $this.removeClass('ajax-loading'); }
});
}
};
var reset = function() {
if (timer) {
clearInterval(timer);
timer = setInterval(check, 300);
}
};
var timer = setInterval(check, 300);
$this.bind('keyup click mousemove', reset);
});
}
</script>