个人单位修改。

聚焦就搜索所有的学校
This commit is contained in:
lizanle 2015-12-18 15:22:29 +08:00
parent eb02a3d34a
commit 084844941f
2 changed files with 42 additions and 41 deletions

View File

@ -120,15 +120,16 @@ class SchoolController < ApplicationController
condition.scan(/./).each_with_index do |char,index| condition.scan(/./).each_with_index do |char,index|
if char =~ /[a-zA-Z0-9]/ if char =~ /[a-zA-Z0-9]/
pinyin << char pinyin << char
elsif char =~ /\'/
else else
chinese << char chinese << char
end end
end end
if(condition == '') if(condition == '')
@school = School.page((params[:page].to_i || 1) - 1).per(100) @school = School.reorder('pinyin').page((params[:page].to_i || 1) - 1).per(100)
@school_count = School.count @school_count = School.count
else else
@school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").page((params[:page].to_i || 1) - 1).per(100) @school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").reorder('pinyin').page((params[:page].to_i || 1) - 1).per(100)
@school_count = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count @school_count = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").count
end end

View File

@ -642,45 +642,45 @@
$("#hint").hide(); $("#hint").hide();
} }
}); });
// $("input[name='province']").on('focus', function (e) { $("input[name='province']").on('focus', function (e) {
// if($(e.target).val() == ''){ // if( $("input[name='occupation']").val() != ''){ //如果已经有id了。肯定存在不用去找了。
// return; return;
// } }
// if( $("input[name='occupation']").val() != ''){ //如果已经有id了。肯定存在不用去找了。
// return; $.ajax({
// } url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value+'&page='+page,
// type: 'post',
// $.ajax({ success: function (data) {
// url: '<%#= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value, schoolsResult = data.schools;
// type: 'post', count = data.count;
// success: function (data) { maxPage = Math.ceil(count/100) //最大页码值
// if(data.length != undefined && data.length != 0) { if(schoolsResult.length != undefined && schoolsResult.length != 0) {
// var i = 0; var i = 0;
// $("#search_school_result_list").html(''); $("#search_school_result_list").html('');
// for (; i < data.length; i++) { for (; i < schoolsResult.length; i++) {
// link = '<a onclick="window.changeValue(\'' + data[i].school.name.replace(/\s/g," ") + '\',\'' + data[i].school.id + '\')" href="javascript:void(0)">' + data[i].school.name + '</a><br/>'; link = '<a onclick="window.changeValue(\'' + schoolsResult[i].school.name.replace(/\s/g," ") + '\',\'' + schoolsResult[i].school.id + '\')" href="javascript:void(0)">' + schoolsResult[i].school.name + '</a><br/>';
// $("#search_school_result_list").append(link); $("#search_school_result_list").append(link);
// } }
// $("#search_school_result_list").css('left', $(e.target).offset().left); $("#search_school_result_list").css('left', $(e.target).offset().left);
// $("#search_school_result_list").css('top', $(e.target).offset().top + 28); $("#search_school_result_list").css('top', $(e.target).offset().top + 28);
// $("#search_school_result_list").css("position", "absolute"); $("#search_school_result_list").css("position", "absolute");
// $("#search_school_result_list").show(); $("#search_school_result_list").show();
// if ($(e.target).val().trim() != '') { if($(e.target).val().trim() != '') {
// str = e.target.value.length > 8 ? e.target.value.substr(0, 6) + "..." : e.target.value; str = e.target.value.length > 8 ? e.target.value.substr(0, 6)+"..." : e.target.value;
// $("#hint").html('找到了' + data.length + '个包含"' + str + '"的高校'); $("#hint").html('找到了' + count + '个包含"' + str + '"的高校');
// $("#hint").show(); $("#hint").show();
// } else { }else{
// $("#hint").hide(); $("#hint").hide();
// } }
// }else { }else{
// $("#search_school_result_list").html(''); $("#search_school_result_list").html('');
// str = e.target.value.length > 4 ? e.target.value.substr(0, 4)+"..." : e.target.value; str = e.target.value.length > 4 ? e.target.value.substr(0, 4)+"..." : e.target.value;
// $("#hint").html('没有找到包含"'+str+'"的高校,<a style="color:#64bdd9" onclick="add_school(\''+ e.target.value+'\');" href="javascript:void(0);">创建高校</a>'); $("#hint").html('没有找到包含"'+str+'"的高校,<a style="color:#64bdd9" onclick="add_school(\''+ e.target.value+'\');" href="javascript:void(0);">创建高校</a>');
// $("#hint").show(); $("#hint").show();
// } }
// } }
// }); });
// }); });
// $("#province").leanModal({top: 100, closeButton: ".modal_close"}); // $("#province").leanModal({top: 100, closeButton: ".modal_close"});