diff --git a/app/controllers/ind_users_controller.rb b/app/controllers/ind_users_controller.rb index 7fe1743..5677942 100644 --- a/app/controllers/ind_users_controller.rb +++ b/app/controllers/ind_users_controller.rb @@ -9,6 +9,10 @@ def index def show @user = User.find(params[:id]) + if @user!=current_user + @message=Message.new + @message.user = @user + end end @@ -30,7 +34,7 @@ def edit def update @user = User.find(params[:id]) - if params[:ind_user][:old_password] &&!current_user.valid_password?(params[:ind_user][:old_password]) + if params[:ind_user][:old_password] &&!current_user.valid_password?(params[:ind_user][:old_password]) flash[:error]="请正确输入旧密码" redirect_to :back else @@ -65,7 +69,25 @@ def bookmarked_companies def bookmarked_jobs @job_posts = current_user.bookmarked("JobPost") end - + + def messages_users + @message = Message.new(params[:message]) + if !@message.user.nil? && @message.user!=current_user # message.user must not be nil or current_url + @message.sender=current_user + if @message.save + else + end + mail=Notifier.to_message(@message) + mail.deliver + @result={:url=>ind_user_path(current_user.id),:result=>true,:info=>"留言已经发送!"} + if current_user.is_a? OrgUser + #@url=org_user_path(current_user.id) + end + respond_to do |format| + format.json { render :json => @result } + end + end + end def job_posts @user = User.find(params[:id]) diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb new file mode 100644 index 0000000..19788ee --- /dev/null +++ b/app/mailers/notifier.rb @@ -0,0 +1,11 @@ +class Notifier < ActionMailer::Base + default :from=>ActionMailer::Base.smtp_settings[:user_name], + :return_path =>ActionMailer::Base.smtp_settings[:user_name] + + def to_message(message) + mail(:to => message.user.email,:subject=>"#{message.title}" ) do |format| + format.text { render :text => message.content } + #format.html { render :text => message.content } + end + end +end diff --git a/app/models/message.rb b/app/models/message.rb new file mode 100644 index 0000000..4db20c6 --- /dev/null +++ b/app/models/message.rb @@ -0,0 +1,11 @@ +# encoding: UTF-8 +class Message + include Mongoid::Document + include Mongoid::Timestamps + + field :title , type: String + field :content ,type: String + belongs_to :user #message receiver + belongs_to :sender, :class_name => "User",:foreign_key => "sender_id" + + end diff --git a/app/views/ind_users/_side_nav_public.html.haml b/app/views/ind_users/_side_nav_public.html.haml index 5d74899..2cb60a1 100644 --- a/app/views/ind_users/_side_nav_public.html.haml +++ b/app/views/ind_users/_side_nav_public.html.haml @@ -6,11 +6,51 @@ %h5="#{@user.profile.age}岁, #{@user.profile.gender}" %h5="#{@user.profile.residence}, #{@user.profile.nationality}国籍" =link_to "关注","" ,:class=>'btn' unless @user==current_user - =link_to "留言","",:class=>'btn' unless @user==current_user + =link_to "留言","###",:id=>'message',:class=>'btn',"data-backdrop"=>"true",:"data-controls-modal"=>'messageModal' unless @user==current_user %h4 中文简历 =link_to "下载", @user.chinese_resume.to_s %h4 英文简历 =link_to "下载", @user.english_resume.to_s - + + - unless @user==current_user + %div{:id=>"messageModal",:class=>"modal hide fade in"} + = form_for @message,:url=>{:action=>"messages_users"},:remote => true,:"data-type"=>"json" do |f| + .modal-header + %a{:class=>"close",:href=>"###"}="x" + %h3{:style=>"background-color:#ffffff;"}="给#{@user.profile.name}留言" + .modal-body{:style=>"height:300px;"} + %fieldset + = f.hidden_field :user_id + .row + .span2= f.label :title,"标题*" + .span6= f.text_field :title,:placeholder=> "请填写标题",:required=>"required" + .row + .span2= f.label :content,"留言内容*" + .span6= f.text_area :content,:rows=>"12",:placeholder=> "请填写内容",:required=>"required" + .modal-footer + .row + %div{:id=>"messageResult",:class=>"span6"}= "" + .pull-right + = submit_tag "发送",:class=>"btn primary" + =link_to "取消","#",:class=>"btn secondary",:onclick=>"closeMessageModal();return false;" + :javascript + function closeMessageModal(){ + $("#messageModal").modal("hide"); + $("#messageResult").html(""); + } + $(document).ready(function(){ + $("#messageModal form").bind("ajax:beforeSend",function(){ + $("#messageResult").html("正在发送,请稍后!"); + }).bind("ajax:success",function(event,data, status, xhr){ + $("#messageResult").html(data.info); + if(data.result){ + document.location.href=data.url; + }else{ + + } + }).bind("",function(event,xhr, status, error){ + $("#messageResult").html("发送错误,请重试!"); + }); + }); diff --git a/config/routes.rb b/config/routes.rb index 7e7546f..dcc4bc2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,7 +35,8 @@ match 'bookmarked/org/users'=>'org_users#bookmarked_users', :as=>"bookmarked_users_for_companies" match 'bookmarked/companies'=>'ind_users#bookmarked_companies', :as=>"bookmarked_companies" match 'bookmarked/jobs'=>'ind_users#bookmarked_jobs', :as=>"bookmarked_jobs" - + + match 'messages/users'=>'ind_users#messages_users', :as=>'messages_users' match 'org_users/:id/new/:info'=>'org_users#new',:as=>'org_user_new' match 'org_users/:id/edit/:info'=>'org_users#edit',:as=>'org_user_edit'