From 1d962b98d38a3d0b6ad007a780a317037d862a66 Mon Sep 17 00:00:00 2001 From: yanxd Date: Sun, 29 Dec 2013 19:35:52 +0800 Subject: [PATCH] model project leave message --- app/controllers/projects_controller.rb | 45 +++++++++++--------------- app/models/project.rb | 9 ++++-- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 736842107..eb41db700 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -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{
((.|\s)*?)
}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 diff --git a/app/models/project.rb b/app/models/project.rb index d198d38c0..e106ac0c0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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