model project leave message
This commit is contained in:
parent
42fa7eb4c1
commit
1d962b98d3
|
@ -282,7 +282,7 @@ class ProjectsController < ApplicationController
|
|||
#Ended by young
|
||||
|
||||
def feedback
|
||||
@jours = @project.journals_for_messages.reverse
|
||||
@jours = @project.journals_for_messages.where('m_parent_id IS NULL').reverse
|
||||
@limit = 10
|
||||
@feedback_count = @jours.count
|
||||
@feedback_pages = Paginator.new @feedback_count, @limit, params['page']
|
||||
|
@ -297,39 +297,30 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
|
||||
def project_respond
|
||||
# will_reply = JournalsForMessage.find(params[:reference_id]) if params[:reference_id]
|
||||
project_id = request.headers["Referer"].match((%r|/([0-9]{1,})/|))[1]
|
||||
@project = Project.find(project_id)
|
||||
parent_id = params[:reference_id]
|
||||
author_id = User.current.id
|
||||
reply_user_id = params[:reference_user_id]
|
||||
reply_id = params[:reference_message_id]
|
||||
content = params[:project_respond]
|
||||
options = {:user_id => author_id,
|
||||
:m_parent_id => parent_id,
|
||||
:m_reply_id => reply_id,
|
||||
:reply_id => reply_user_id,
|
||||
:notes => content,
|
||||
:is_readed => false}
|
||||
|
||||
if params[:project_respond].size>0
|
||||
jour = JournalsForMessage.find(params[:reference_id]) if params[:reference_id]
|
||||
if jour
|
||||
user = jour.user
|
||||
text = jour.notes
|
||||
else
|
||||
user = User.current
|
||||
text = []
|
||||
end
|
||||
# Replaces pre blocks with [...]
|
||||
text = text.to_s.strip.gsub(%r{<pre>((.|\s)*?)</pre>}m, '[...]')
|
||||
reference_content = "> #{ll(Setting.default_language, :text_user_wrote, user)}\n> "
|
||||
reference_content << text.gsub(/(\r?\n|\r\n?)/, "\n> ") + "\n\n"
|
||||
# reference_message = JournalForMessage.find(params[:reference_id])
|
||||
message = params[:project_respond] + "\n" + reference_content
|
||||
@jfm = @project.add_new_jour(nil, nil, nil, options)
|
||||
|
||||
# flash[:notice]=l(:label_projects_feedback_respond_success)
|
||||
|
||||
|
||||
user.add_jour(User.current, message, user.id)
|
||||
flash[:notice]=l(:label_projects_feedback_respond_success)
|
||||
# if a_message.size > 5
|
||||
# @message = a_message[-5, 5]
|
||||
# else
|
||||
# @message = a_message
|
||||
# end
|
||||
# @message_count = a_message.count
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to :back }
|
||||
#format.api { render_api_ok }
|
||||
end
|
||||
# redirect_to project_feedback_path(@project)
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
|
@ -166,10 +166,13 @@ class Project < ActiveRecord::Base
|
|||
pjfm
|
||||
end
|
||||
|
||||
def self.add_new_jour(user, notes, id)
|
||||
def self.add_new_jour(user, notes, id, options={})
|
||||
project = Project.find(id)
|
||||
# project.journals_for_messages << JournalsForMessage.new(:user_id => user.id, :notes => notes, :reply_id => 0)
|
||||
pjfm = project.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0)
|
||||
if options.count == 0
|
||||
pjfm = project.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0)
|
||||
else
|
||||
pjfm = project.journals_for_messages.build(options)
|
||||
end
|
||||
pjfm.save
|
||||
pjfm
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue