添加学校

dev_xiangzheng
lizanle 10 years ago
parent 0c1d7d420e
commit e3a660cf18

@ -132,4 +132,15 @@ class SchoolController < ApplicationController
# end # end
render :json => @school.to_json render :json => @school.to_json
end end
#添加学校
def add_school
@school = School.new
@school.name = params[:name].strip
@school.pinyin = Pinyin.t(params[:name].strip, splitter: '')
@school.save
respond_to do |format|
format.js
end
end
end end

@ -72,22 +72,22 @@
<li nhname="tag" nh_tag_0="true" nh_tag_1="true" nh_tag_3="true" style="display:none;"> <li nhname="tag" nh_tag_0="true" nh_tag_1="true" nh_tag_3="true" style="display:none;">
<% if User.current.user_extensions.nil? %> <% if User.current.user_extensions.nil? %>
<input nhname="tag" autocomplete="off" nh_tag_0="true" nh_tag_1="true" id="province" name="province" style="display: none;width:130px;" class="w70" type="text" > <input nhname="tag" autocomplete="off" maxlength="36" nh_tag_0="true" nh_tag_1="true" id="province" name="province" style="display: none;" class="w210" type="text" >
<input nhname="tag" nh_tag_3="true" id="occupation" name="occupation" style="display: none;" class="w210" type="text" value="" /> <input nhname="tag" nh_tag_3="true" id="occupation" name="occupation" style="display: none;" class="w210" type="text" value="" />
<span id="hint" style="color: #7f7f7f;display: none">平台找到了<a id="school_num" href="javascript:void(0)" style="color: red" >0</a>个包含<a id="search_condition" href="javascript:void(0)">"国防"</a>的高校</span> <span id="hint" style="color: #7f7f7f;display: none">平台找到了<a id="school_num" href="javascript:void(0)" style="color: red" >0</a>个包含<a id="search_condition" href="javascript:void(0)">"国防"</a>的高校</span>
<!--<input nhname="tag" nh_tag_0="true" nh_tag_1="true" id="occupation_name" type="text" style="display: none;width:117px;" readonly/>--> <!--<input nhname="tag" nh_tag_0="true" nh_tag_1="true" id="occupation_name" type="text" style="display: none;width:117px;" readonly/>-->
<% elsif User.current.user_extensions.identity == 3 || User.current.user_extensions.identity == 2 %> <% elsif User.current.user_extensions.identity == 3 || User.current.user_extensions.identity == 2 %>
<input nhname="tag" autocomplete="off" nh_tag_0="true" nh_tag_1="true" id="province" name="province" style="display: none;width:130px;" class="w70" type="text" > <input nhname="tag" autocomplete="off" maxlength="36" nh_tag_0="true" nh_tag_1="true" id="province" name="province" style="display: none;" class="w210" type="text" >
<input nhname="tag" nh_tag_3="true" id="occupation" name="occupation" style="display: none;" class="w210" type="text" value="<%= @user.user_extensions.occupation %>" /> <input nhname="tag" nh_tag_3="true" id="occupation" name="occupation" style="display: none;" class="w210" type="text" value="<%= @user.user_extensions.occupation %>" />
<span id="hint" style="color: #7f7f7f;display: none">平台找到了<a id="school_num" href="javascript:void(0)" style="color: red" >0</a>个包含<a id="search_condition" href="javascript:void(0)">"国防"</a>的高校</span> <span id="hint" style="color: #7f7f7f;display: none">平台找到了<a id="school_num" href="javascript:void(0)" style="color: red" >0</a>个包含<a id="search_condition" href="javascript:void(0)">"国防"</a>的高校</span>
<!--<input nhname="tag" nh_tag_0="true" nh_tag_1="true" id="occupation_name" type="text" style="display: none;width:117px;" readonly/>--> <!--<input nhname="tag" nh_tag_0="true" nh_tag_1="true" id="occupation_name" type="text" style="display: none;width:117px;" readonly/>-->
<% elsif User.current.user_extensions.school.nil? %> <% elsif User.current.user_extensions.school.nil? %>
<input nhname="tag" autocomplete="off" nh_tag_0="true" nh_tag_1="true" id="province" name="province" style="display: none;width:130px;" class="w70" type="text" > <input nhname="tag" autocomplete="off" maxlength="36" nh_tag_0="true" nh_tag_1="true" id="province" name="province" style="display: none;" class="w210" type="text" >
<input nhname="tag" nh_tag_3="true" id="occupation" name="occupation" style="display: none;" class="w210" type="text" /> <input nhname="tag" nh_tag_3="true" id="occupation" name="occupation" style="display: none;" class="w210" type="text" />
<span id="hint" style="color: #7f7f7f;display: none">平台找到了<a id="school_num" href="javascript:void(0)" style="color: red" >0</a>个包含<a id="search_condition" href="javascript:void(0)">"国防"</a>的高校</span> <span id="hint" style="color: #7f7f7f;display: none">平台找到了<a id="school_num" href="javascript:void(0)" style="color: red" >0</a>个包含<a id="search_condition" href="javascript:void(0)">"国防"</a>的高校</span>
<!--<input nhname="tag" nh_tag_0="true" nh_tag_1="true" id="occupation_name" type="text" style="display: none;width:117px;" readonly/>--> <!--<input nhname="tag" nh_tag_0="true" nh_tag_1="true" id="occupation_name" type="text" style="display: none;width:117px;" readonly/>-->
<% else %> <% else %>
<input nhname="tag" autocomplete="off" nh_tag_0="true" nh_tag_1="true" id="province" name="province" style="display: none;width:130px;" class="w70" type="text" value="<%= User.current.user_extensions.school %>" /> <input nhname="tag" autocomplete="off" maxlength="36" nh_tag_0="true" nh_tag_1="true" id="province" name="province" style="display: none;" class="w210" type="text" value="<%= User.current.user_extensions.school %>" />
<input nhname="tag" nh_tag_3="true" id="occupation" name="occupation" type="text" style="display: none;" class="w210" value="<%= User.current.user_extensions.school.id %>"/> <input nhname="tag" nh_tag_3="true" id="occupation" name="occupation" type="text" style="display: none;" class="w210" value="<%= User.current.user_extensions.school.id %>"/>
<span id="hint" style="color: #7f7f7f;display: none" >平台找到了<a id="school_num" href="javascript:void(0)" style="color: red" >0</a>个包含<a id="search_condition" href="javascript:void(0)">"国防"</a>的高校</span> <span id="hint" style="color: #7f7f7f;display: none" >平台找到了<a id="school_num" href="javascript:void(0)" style="color: red" >0</a>个包含<a id="search_condition" href="javascript:void(0)">"国防"</a>的高校</span>
<!--<input nhname="tag" nh_tag_0="true" nh_tag_1="true" id="occupation_name" type="text" style="display: none;width:117px;" value="<%#= User.current.user_extensions.school.name %>" readonly="true" style="background-color: #E2E2E2;"/>--> <!--<input nhname="tag" nh_tag_0="true" nh_tag_1="true" id="occupation_name" type="text" style="display: none;width:117px;" value="<%#= User.current.user_extensions.school.name %>" readonly="true" style="background-color: #E2E2E2;"/>-->
@ -144,7 +144,7 @@
<li style="height:auto;"><textarea name="description" class="w450 h200" maxlength="255" style="resize:none;"><%= (@user.user_extensions.nil?) ? '' : @user.user_extensions.description %></textarea></li> <li style="height:auto;"><textarea name="description" class="w450 h200" maxlength="255" style="resize:none;"><%= (@user.user_extensions.nil?) ? '' : @user.user_extensions.description %></textarea></li>
<li style="display:none;"><%= f.select :language, :Chinese => :zh, :English => :en %></li> <li style="display:none;"><%= f.select :language, :Chinese => :zh, :English => :en %></li>
<li class="ml2"> <li class="ml2">
<a href="javascript:;" id="my_account_form_link" class="blue_btn fl">确认</a> <a href="javascript:void(0);" id="my_account_form_link" class="blue_btn fl">确认</a>
<input type="submit" id="my_account_form_btn" style="display:none;"/> <input type="submit" id="my_account_form_btn" style="display:none;"/>
<!--<a href="javascript:void(0);" class="grey_btn ml10 fl">取消</a>--> <!--<a href="javascript:void(0);" class="grey_btn ml10 fl">取消</a>-->
</li> </li>
@ -170,7 +170,7 @@
<li><input id="new_password_confirmation" name="new_password_confirmation" class="w210" type="password" required="true" nh_required="1"></li> <li><input id="new_password_confirmation" name="new_password_confirmation" class="w210" type="password" required="true" nh_required="1"></li>
<li class="ml2"> <li class="ml2">
<a href="javascript:;" id="my_password_form_link" class="blue_btn fl">确认</a> <a href="javascript:;" id="my_password_form_link" class="blue_btn fl">确认</a>
<input type="submit" id="my_password_form_btn" style="display:none;"/> <!--<input type="submit" id="my_password_form_btn" style="display:none;"/>-->
<!--<a href="javascript:void(0);" class="grey_btn ml10 fl">取消</a>--> <!--<a href="javascript:void(0);" class="grey_btn ml10 fl">取消</a>-->
</li> </li>
</ul> </ul>
@ -185,7 +185,7 @@
</div> </div>
<div id="search_school_result_list" <div id="search_school_result_list"
style="width: 135px;line-height: 1.5;min-height:20px; max-height: 200px; height: auto!; !important;display: none;background: white;overflow: scroll;border: solid 1px #cccccc; overflow-x: hidden; overflow-y: auto;"> style="width: 205px;line-height: 1.5;min-height:20px; max-height: 200px; height: auto!; !important;display: none;background: white;overflow: scroll;border: solid 1px #cccccc; overflow-x: hidden; overflow-y: auto;">
</div> </div>
<div id="WOpenWindow"> <div id="WOpenWindow">
<a class="modal_close" href="#"></a> <a class="modal_close" href="#"></a>
@ -532,12 +532,33 @@
$("#search_school_result_list").hide(); $("#search_school_result_list").hide();
$("#hint").hide(); $("#hint").hide();
} }
function add_school(name){
$.ajax({
url: '<%= url_for(:controller => 'school',:action => 'add_school') %>' + '?name=' + name,
type: 'post',
success: function (data) {
}
});
}
var lastSearchCondition = ''; var lastSearchCondition = '';
$(function() { $(function() {
// $("input[name='province']").keydown(function(e){
// if(e.keyCode == 13 && $("#search_school_result_list").css('display') == 'block'){
// str = $("#search_school_result_list").children().eq(0).attr('onclick').match(/\(.*\)/)[0]
//
// str = str.replace(/\(/,'').replace(/\)/,'');
// arr = str.split(',');
// id = arr[1].replace(/\'/,'')
// name = arr.replace(/\'/,'')
// changeValue(name,id);
// return false;
// }
// });
//查询学校 //查询学校
$("input[name='province']").on('input', function (e) { $("input[name='province']").on('input', function (e) {
$("input[name='occupation']").val(''); //一旦有输入就清空id。 $("input[name='occupation']").val(''); //一旦有输入就清空id。
if($(e.target).val().trim() == lastSearchCondition){ if($(e.target).val().trim() == lastSearchCondition && $(e.target).val().trim() != ''){
return; return;
} }
lastSearchCondition = $(e.target).val().trim(); lastSearchCondition = $(e.target).val().trim();
@ -545,7 +566,7 @@
url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value, url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value,
type: 'post', type: 'post',
success: function (data) { success: function (data) {
if(data.lengh != 0) { if(data.length != undefined && data.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 < data.length; i++) {
@ -557,13 +578,16 @@
$("#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() != '') {
$("#hint").html('平台找到了' + data.length + '个包含"' + e.target.value + '"的高校'); str = e.target.value.length > 8 ? e.target.value.substr(0, 6)+"..." : e.target.value;
$("#hint").html('找到了' + data.length + '个包含"' + str + '"的高校');
$("#hint").show(); $("#hint").show();
}else{ }else{
$("#hint").hide(); $("#hint").hide();
} }
}else{ }else{
$("#hint").html('平台没有找到包含"'+e.target.value+'"的高校,创建该高校'); $("#search_school_result_list").html('');
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").show(); $("#hint").show();
} }
} }
@ -577,20 +601,37 @@
} }
}) })
$("input[name='province']").on('focus', function (e) { $("input[name='province']").on('focus', function (e) {
if($(e.target).val() == ''){
return;
}
$.ajax({ $.ajax({
url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value, url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value,
type: 'post', type: 'post',
success: function (data) { success: function (data) {
var i = 0; if(data.length != undefined && data.length != 0) {
$("#search_school_result_list").html(''); var i = 0;
for ( ;i<data.length;i++){ $("#search_school_result_list").html('');
link = '<a onclick="window.changeValue(\''+data[i].school.name+'\',\''+data[i].school.id+'\')" href="javascript:void(0)">' +data[i].school.name+'</a><br/>'; for (; i < data.length; i++) {
$("#search_school_result_list").append(link); link = '<a onclick="window.changeValue(\'' + data[i].school.name + '\',\'' + data[i].school.id + '\')" href="javascript:void(0)">' + data[i].school.name + '</a><br/>';
$("#search_school_result_list").append(link);
}
$("#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("position", "absolute");
$("#search_school_result_list").show();
if ($(e.target).val().trim() != '') {
str = e.target.value.length > 8 ? e.target.value.substr(0, 6) + "..." : e.target.value;
$("#hint").html('找到了' + data.length + '个包含"' + str + '"的高校');
$("#hint").show();
} else {
$("#hint").hide();
}
}else {
$("#search_school_result_list").html('');
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").show();
} }
$("#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("position", "absolute");
$("#search_school_result_list").show();
} }
}); });
}); });

@ -0,0 +1 @@
$("input[name='occupation']").val('<%= @school.id%>');

@ -880,6 +880,7 @@ RedmineApp::Application.routes.draw do
get 'school/search_school/', :to => 'school#search_school' get 'school/search_school/', :to => 'school#search_school'
post 'school/on_search' post 'school/on_search'
post 'school/add_school'
######added by nie ######added by nie
match 'tags/show_projects_tags' match 'tags/show_projects_tags'
########### added by liuping ########### added by liuping

Loading…
Cancel
Save