diff --git a/Gemfile b/Gemfile index a690b224b..d1993359e 100644 --- a/Gemfile +++ b/Gemfile @@ -28,6 +28,7 @@ gem 'ruby-ole' gem 'rails_kindeditor',path:'lib/rails_kindeditor' #gem "rmagick", ">= 2.0.0" gem 'binding_of_caller' +gem 'chinese_pinyin' group :development do gem 'grape-swagger' diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rb index 9728ddf11..16d516f82 100644 --- a/app/controllers/my_controller.rb +++ b/app/controllers/my_controller.rb @@ -126,11 +126,13 @@ class MyController < ApplicationController end @se = @user.extensions - if params[:occupation].to_i.to_s == params[:occupation] - @se.school_id = params[:occupation] - else - @se.occupation = params[:occupation] - end + # if params[:occupation].to_i.to_s == params[:occupation] + # @se.school_id = params[:occupation] + # else + # @se.occupation = params[:occupation] + # end + @se.school_id = params[:occupation] + @se.gender = params[:gender] @se.location = params[:province] if params[:province] @se.location_city = params[:city] if params[:city] diff --git a/app/controllers/school_controller.rb b/app/controllers/school_controller.rb index 3e0c280ac..5e68dc2bd 100644 --- a/app/controllers/school_controller.rb +++ b/app/controllers/school_controller.rb @@ -105,4 +105,31 @@ class SchoolController < ApplicationController render :text => options end + + #根据学校名字或者拼音来查询 + def on_search + condition = "#{params[:name].strip}".gsub(" ","") + #将条件截断为汉字和拼音(全汉字 或者 全拼音 或者 汉字和拼音), + #获取拼音的第一次出现的位置 + chinese = [] + pinyin = [] + condition.scan(/./).each_with_index do |char,index| + if char =~ /[a-zA-Z0-9]/ + pinyin << char + else + chinese << char + end + end + if(condition == '') + @school = School.all + else + @school = School.where("name like '%#{chinese.join("")}%' and pinyin like '%#{pinyin.join("")}%'").all + end + + result = [] + # @school.each do |sc| + # result << {:value=>sc.name,:data=>sc.id} + # end + render :json => @school.to_json + end end diff --git a/app/models/school.rb b/app/models/school.rb index a180eefbe..6cafb0473 100644 --- a/app/models/school.rb +++ b/app/models/school.rb @@ -1,5 +1,5 @@ class School < ActiveRecord::Base - attr_accessible :name, :province + attr_accessible :name, :province,:pinyin has_many :courses def to_s diff --git a/app/views/my/account.html.erb b/app/views/my/account.html.erb index 0e36d5fd9..356e46d86 100644 --- a/app/views/my/account.html.erb +++ b/app/views/my/account.html.erb @@ -18,8 +18,8 @@
  • 登录名 : *
  • 邮箱 : *
  • 身份 : 
  • -
  • 姓氏 : *
  • -
  • 名字 : *
  • +
  • 姓(First Name) : *
  • +
  • 名(Last Name) : *
  • 组织名 : *
  • 性别 : 
  • 工作单位 : 
  • @@ -72,21 +72,25 @@
  • <% if User.current.user_extensions.nil? %> - readonly> + - + + <% elsif User.current.user_extensions.identity == 3 || User.current.user_extensions.identity == 2 %> - readonly> + - + + <% elsif User.current.user_extensions.school.nil? %> - readonly> + - + + <% else %> - + - + + <% end %>
  • @@ -180,7 +184,9 @@ - +

    <%= l(:lable_school_list)%>

    @@ -202,6 +208,7 @@
    + <%= stylesheet_link_tag 'nyan' %> @@ -518,10 +525,77 @@ } } } - $(function(){ - //学校 - $("#province").attr("href", "#WOpenWindow") - $("#province").leanModal({top: 100, closeButton: ".modal_close"}); + function changeValue(value,data){ + //console.log(value+","+data) + $("input[name='province']").val(value); + $("input[name='occupation']").val(data); + $("#search_school_result_list").hide(); + $("#hint").hide(); + } + var lastSearchCondition = ''; + $(function() { + //查询学校 + $("input[name='province']").on('input', function (e) { + $("input[name='occupation']").val(''); //一旦有输入就清空id。 + if($(e.target).val().trim() == lastSearchCondition){ + return; + } + lastSearchCondition = $(e.target).val().trim(); + $.ajax({ + url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value, + type: 'post', + success: function (data) { + if(data.lengh != 0) { + var i = 0; + $("#search_school_result_list").html(''); + for (; i < data.length; i++) { + link = '' + data[i].school.name + '
    '; + $("#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() != '') { + $("#hint").html('平台找到了' + data.length + '个包含"' + e.target.value + '"的高校'); + $("#hint").show(); + }else{ + $("#hint").hide(); + } + }else{ + $("#hint").html('平台没有找到包含"'+e.target.value+'"的高校,创建该高校。'); + $("#hint").show(); + } + } + }); + }); + $(document.body).click(function(e){ + if($(e.target).attr("id") != 'search_school_result_list') + { + $("#search_school_result_list").hide(); + $("#hint").hide(); + } + }) + $("input[name='province']").on('focus', function (e) { + $.ajax({ + url: '<%= url_for(:controller => 'school',:action => 'on_search') %>' + '?name=' + e.target.value, + type: 'post', + success: function (data) { + var i = 0; + $("#search_school_result_list").html(''); + for ( ;i' +data[i].school.name+'
    '; + $("#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(); + } + }); + }); + +// $("#province").leanModal({top: 100, closeButton: ".modal_close"}); //地区 var province = "<%= "#{province}" %>" @@ -544,6 +618,9 @@ $("#users_tb_2").click(); <% end %> $('#my_account_form_link').click(function(){ + if( $("input[name='province']").val().trim() != '' && $("input[name='occupation']").val().trim() == ''){ //学校名字和id不对的话 + return; + } $('#my_account_form_btn').click(); }); $('#my_password_form_link').click(function(){ diff --git a/config/routes.rb b/config/routes.rb index 2e02cd3d2..01e9500d8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -879,6 +879,7 @@ RedmineApp::Application.routes.draw do post 'school/search_school/', :to => 'school#search_school' get 'school/search_school/', :to => 'school#search_school' + post 'school/on_search' ######added by nie match 'tags/show_projects_tags' ########### added by liuping diff --git a/db/migrate/20151014012627_add_column_pinyin_to_schools.rb b/db/migrate/20151014012627_add_column_pinyin_to_schools.rb new file mode 100644 index 000000000..8da287d4a --- /dev/null +++ b/db/migrate/20151014012627_add_column_pinyin_to_schools.rb @@ -0,0 +1,5 @@ +class AddColumnPinyinToSchools < ActiveRecord::Migration + def change + add_column :schools, :pinyin, :string + end +end diff --git a/db/migrate/20151014023806_transfer_name_column_value_to_pinyin_column_value.rb b/db/migrate/20151014023806_transfer_name_column_value_to_pinyin_column_value.rb new file mode 100644 index 000000000..a5aeba07a --- /dev/null +++ b/db/migrate/20151014023806_transfer_name_column_value_to_pinyin_column_value.rb @@ -0,0 +1,11 @@ +class TransferNameColumnValueToPinyinColumnValue < ActiveRecord::Migration + def up + School.all.each do |school| + school.pinyin = Pinyin.t(school.name, splitter: '') + school.save + end + end + + def down + end +end diff --git a/db/schema.rb b/db/schema.rb index 4bcde68d8..79b3599df 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20150930011457) do +ActiveRecord::Schema.define(:version => 20151014023806) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -782,6 +782,16 @@ ActiveRecord::Schema.define(:version => 20150930011457) do add_index "journal_details", ["journal_id"], :name => "journal_details_journal_id" + create_table "journal_details_copy", :force => true do |t| + t.integer "journal_id", :default => 0, :null => false + t.string "property", :limit => 30, :default => "", :null => false + t.string "prop_key", :limit => 30, :default => "", :null => false + t.text "old_value" + t.text "value" + end + + add_index "journal_details_copy", ["journal_id"], :name => "journal_details_journal_id" + create_table "journal_replies", :id => false, :force => true do |t| t.integer "journal_id" t.integer "user_id" @@ -1245,6 +1255,7 @@ ActiveRecord::Schema.define(:version => 20150930011457) do t.datetime "created_at", :null => false t.datetime "updated_at", :null => false t.string "logo_link" + t.string "pinyin" end create_table "seems_rateable_cached_ratings", :force => true do |t| @@ -1308,9 +1319,9 @@ ActiveRecord::Schema.define(:version => 20150930011457) do create_table "student_work_tests", :force => true do |t| t.integer "student_work_id" - t.integer "status" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + t.integer "status", :default => 9 t.text "results" t.text "src" end @@ -1558,7 +1569,6 @@ ActiveRecord::Schema.define(:version => 20150930011457) do t.string "identity_url" t.string "mail_notification", :default => "", :null => false t.string "salt", :limit => 64 - t.integer "gid" end add_index "users", ["auth_source_id"], :name => "index_users_on_auth_source_id" diff --git a/public/stylesheets/users.css b/public/stylesheets/users.css index 849aa1c02..7db6e121d 100644 --- a/public/stylesheets/users.css +++ b/public/stylesheets/users.css @@ -81,7 +81,7 @@ a.select_btn_select{ background:#64bddb; color:#fff;} .users_dis{display:block; } .users_undis{display:none;} .users_ctt{ font-size:14px; color:#666; margin-top:10px;} -.setting_left{ width:85px; text-align:right; float:left;} +.setting_left{ width:115px; text-align:right; float:left;} .setting_left li{ height:28px;line-height:28px;} .setting_right{width:500px; text-align:left; float:left; margin-left:8px;} .setting_right li{ height:28px;line-height:28px;}