一部分ajax留言实现

This commit is contained in:
yanxd 2013-12-25 22:21:16 +08:00
parent c05dd4f900
commit 64d85a9ab2
5 changed files with 31 additions and 19 deletions

View File

@ -223,9 +223,8 @@ class UsersController < ApplicationController
# modified by fq # modified by fq
def user_newfeedback def user_newfeedback
@jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC') @jours = @user.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@jours.each do |jour| @jours.update_all(:is_readed => true, :status => false)
jour.update_attribute(:status, false)
end
@limit = 10 @limit = 10
@feedback_count = @jours.count @feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @feedback_pages = Paginator.new @feedback_count, @limit, params['page']

View File

@ -41,31 +41,34 @@ class WordsController < ApplicationController
end end
def create_reply def create_reply
@params = params user_id_str = request.headers["Referer"].match((%r|/[0-9]{1,}/|))[0]
user_id = user_id_str[1, user_id_str.size-2]
@user = User.find(user_id)
parent_id = params[:reference_id] parent_id = params[:reference_id]
author_id = User.current.id author_id = User.current.id
reply_user_id = params[:reference_user_id] reply_user_id = params[:reference_user_id]
reply_id = nil # 暂时不实现 reply_id = params[:reference_message_id] # 暂时不实现
content = params[:user_notes] content = params[:user_notes]
@params.merge!({flag:'====', parent_id: parent_id, author_id: author_id, reply_user_id: reply_user_id, content: content})
options = {:user_id => author_id, options = {:user_id => author_id,
:m_parent_id => parent_id, :m_parent_id => parent_id,
:m_reply_id => reply_id, :m_reply_id => reply_id,
:reply_id => reply_user_id, :reply_id => reply_user_id,
:notes => content, :notes => content,
:is_readed => false} :is_readed => false}
jfm = User.current.add_jour(nil, nil, nil, options) @jfm = @user.add_jour(nil, nil, nil, options)
respond_to do |format| respond_to do |format|
format.html { # format.html {
if jfm.errors.empty? # if @jfm.errors.empty?
flash.notice = l(:label_feedback_success) # flash.now.notice = l(:label_feedback_success)
else # else
flash.errors = l(:label_feedback_fail) # flash.now.errors = l(:label_feedback_fail)
end # end
render 'test/index' # render 'test/index'
# }
format.js{
@save_succ = true if @jfm.errors.empty?
} }
format.js
end end
end end

View File

@ -3,7 +3,7 @@
<%= image_tag url_to_avatar(reply.user), :class => "avatar-3" %> <%= image_tag url_to_avatar(reply.user), :class => "avatar-3" %>
</span> </span>
<span class="body"> <span class="body">
<% id = reply.id %> <% id = 'project_respond_form_'+ reply.id.to_s %>
<span style="color: green;"><%= link_to reply.user.name, user_path(reply.user) %>:&nbsp;</span> <span style="color: green;"><%= link_to reply.user.name, user_path(reply.user) %>:&nbsp;</span>
<span style="max-width: 80%; word-wrap: break-word;"> <%= reply.notes %></span> <span style="max-width: 80%; word-wrap: break-word;"> <%= reply.notes %></span>
<% ids = 'project_respond_form_'+ journal.id.to_s%> <% ids = 'project_respond_form_'+ journal.id.to_s%>
@ -13,7 +13,7 @@
<span style="float: right;"><%= toggle_link l(:label_projects_feedback_respond), id, {:focus => 'project_respond'} %></span> <span style="float: right;"><%= toggle_link l(:label_projects_feedback_respond), id, {:focus => 'project_respond'} %></span>
</p> </p>
</span> </span>
<div id=<%= id %> style="display: none;"> <div id='<%=id%>' style="display: none;">
<%= render :partial => "words/new_respond", :locals => {:journal => journal, :m_reply_id => m_reply_id} %> <%= render :partial => "words/new_respond", :locals => {:journal => journal, :m_reply_id => m_reply_id} %>
</div> </div>
<div style="clear: both;"></div> <div style="clear: both;"></div>

View File

@ -1,5 +1,4 @@
<%= form_tag({:controller => 'words', <%= form_tag({:controller => 'words', :action => 'create_reply'}, :remote => true) do %>
:action => 'create_reply'}) do %>
<%= text_area_tag 'user_notes', "", :class => 'noline', :style => "resize: none;", :rows => 4, :placeholder => l(:label_projects_feedback_respond_content) %> <%= text_area_tag 'user_notes', "", :class => 'noline', :style => "resize: none;", :rows => 4, :placeholder => l(:label_projects_feedback_respond_content) %>
<%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %> <%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %>

View File

@ -0,0 +1,11 @@
<% if @save_succ %>
$('#journal_reply_ul_<%=@jfm.m_parent_id%>').append(
'<%= j(
render :partial => "words/journal_reply_items",
:locals => {:reply => @jfm, :journal => @jfm.parent, :m_reply_id => @jfm.id}
) %>');
$('#project_respond_form_<%=@jfm.m_reply_id.to_s%> textarea').val('');
$('#project_respond_form_<%=@jfm.m_reply_id.to_s%>').hide();
<% else %>
alert("<%= l(:label_feedback_fail) %>");
<% end %>