From 1d962b98d38a3d0b6ad007a780a317037d862a66 Mon Sep 17 00:00:00 2001 From: yanxd Date: Sun, 29 Dec 2013 19:35:52 +0800 Subject: [PATCH 01/18] 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 From 4c4e725b5cbd34c24997912d401379734a1274bf Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 30 Dec 2013 08:47:45 +0800 Subject: [PATCH 02/18] project leave message. --- app/controllers/projects_controller.rb | 5 +++-- app/views/projects/_new_respond.html.erb | 2 ++ app/views/projects/feedback.html.erb | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index eb41db700..97d84d6a6 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -299,7 +299,7 @@ class ProjectsController < ApplicationController 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) + # @project = Project.find_by_id(project_id) parent_id = params[:reference_id] author_id = User.current.id reply_user_id = params[:reference_user_id] @@ -312,13 +312,14 @@ class ProjectsController < ApplicationController :notes => content, :is_readed => false} - @jfm = @project.add_new_jour(nil, nil, nil, options) + @jfm = Project.add_new_jour(nil, nil, project_id, options) # flash[:notice]=l(:label_projects_feedback_respond_success) respond_to do |format| format.html { redirect_to :back } + format.js #format.api { render_api_ok } end end diff --git a/app/views/projects/_new_respond.html.erb b/app/views/projects/_new_respond.html.erb index da9185d0c..a8a3e3a6f 100644 --- a/app/views/projects/_new_respond.html.erb +++ b/app/views/projects/_new_respond.html.erb @@ -6,6 +6,8 @@ :maxlength => 250 %> <%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %> +<%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => m_reply_id.user.id %> +<%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => m_reply_id.id %> <%= submit_tag l(:button_projects_feedback_respond), :name => nil , :class => "bid_btn"%> <%end%> diff --git a/app/views/projects/feedback.html.erb b/app/views/projects/feedback.html.erb index b5588ee0f..e32d75670 100644 --- a/app/views/projects/feedback.html.erb +++ b/app/views/projects/feedback.html.erb @@ -44,7 +44,7 @@
style="display: none"> - <%= render :partial => 'new_respond', :locals => {:journal => journal} %> + <%= render :partial => 'new_respond', :locals => {:journal => journal, :m_reply_id => journal} %>
From 36289eba41f52600d4b04e4b8c2026d0f6dbbaea Mon Sep 17 00:00:00 2001 From: nieguanghui Date: Mon, 30 Dec 2013 16:03:28 +0800 Subject: [PATCH 03/18] modified projects --- app/controllers/projects_controller.rb | 2 +- app/views/projects/_new_respond.html.erb | 4 +- app/views/projects/feedback.html.erb | 86 +++++++++++------------- 3 files changed, 41 insertions(+), 51 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 97d84d6a6..6dbcc2178 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -80,7 +80,7 @@ class ProjectsController < ApplicationController helper :documents helper :watchers # helper :watcherlist - + helper :words ### added by william include ActsAsTaggableOn::TagsHelper diff --git a/app/views/projects/_new_respond.html.erb b/app/views/projects/_new_respond.html.erb index a8a3e3a6f..511d90db6 100644 --- a/app/views/projects/_new_respond.html.erb +++ b/app/views/projects/_new_respond.html.erb @@ -1,13 +1,13 @@ <%= form_tag({:controller => 'projects', :action => 'project_respond'}) do %> <%= text_area_tag 'project_respond', "", :class => 'noline', :required => true, - :style => "resize: none;", :rows => 6, + :style => "resize: none;", :rows => 3, :placeholder => l(:label_projects_feedback_respond_content), :maxlength => 250 %> <%= hidden_field_tag 'reference_id', params[:reference_id], :value => journal.id %> <%= hidden_field_tag 'reference_user_id', params[:reference_user_id], :value => m_reply_id.user.id %> <%= hidden_field_tag 'reference_message_id', params[:reference_message_id], :value => m_reply_id.id %> -<%= submit_tag l(:button_projects_feedback_respond), :name => nil , :class => "bid_btn"%> +<%= submit_tag l(:button_projects_feedback_respond), :name => nil , :class => "enterprise"%> <%end%> diff --git a/app/views/projects/feedback.html.erb b/app/views/projects/feedback.html.erb index e32d75670..ec630aee2 100644 --- a/app/views/projects/feedback.html.erb +++ b/app/views/projects/feedback.html.erb @@ -1,57 +1,47 @@

<%= l(:label_user_response) %>

- +
<%= form_for('new_form', :method => :post, :url => {:controller => 'words', :action => 'leave_project_message'}) do |f|%> - - - - - -
<%= f.text_area 'project_message', :rows => 3, :cols => 65, :placeholder => "#{l(:label_welcome_my_respond)}", :style => "resize: none;", :class => 'noline'%>
- - - - -
- <%= submit_tag l(:button_leave_meassge), :name => nil , :class => "bid_btn" %> -
+ <%= f.text_area 'project_message', :rows => 3, :cols => 65, + :placeholder => "#{l(:label_welcome_my_respond)}", + :style => "resize: none; width: 98%", + :class => 'noline'%> + <%= submit_tag l(:button_leave_meassge), :name => nil , :class => "enterprise" , :style => "display: block; float: right; margin-right: 1%; margin-top: 1px;"%> <% end %> - +
+
<% if @jour.size >0 %> - -<% for journal in @jour%> - - - - - -
<%= image_tag(url_to_avatar(journal.user), :class => "avatar") %> - - - - - - - - - - - - - - -
<%= link_to journal.user, user_path(journal.user)%><%= l(:label_projects_feedback) %>
-
- <%= textilizable journal.notes%> -
<%= l :label_update_time %>: <%= format_time journal.created_on %> - <% ids = 'project_respond_form_'+journal.id.to_s%> - <%= toggle_link l(:label_projects_feedback_respond), ids, {:focus => 'project_respond'} %>
-
style="display: none"> - <%= render :partial => 'new_respond', :locals => {:journal => journal, :m_reply_id => journal} %> -
-
-<% end %> +
    + <% for journal in @jour%> +
  • + <%= image_tag(url_to_avatar(journal.user), :class => "avatar") %> + + <%= link_to journal.user, user_path(journal.user)%> + <%= l(:label_projects_feedback) %> +

    + <%= textilizable journal.notes%> +

    + <%= l :label_update_time %>: <%= format_time journal.created_on %> + <% id = 'project_respond_form_'+journal.id.to_s%> + <%= link_to l(:label_projects_feedback_respond),'', + {:focus => 'project_respond', + :onclick => "toggleAndSettingWordsVal($('##{id}'), + $('##{id} textarea'), + '#{l(:label_reply_plural)} #{m_reply_id.user.show_name}: '); + return false;"} %> +
    +
    +
    + <%= render :partial => 'new_respond', :locals => {:journal => journal, :m_reply_id => journal} %> +
    +
    +
    + <%= render :partial => "words/journal_reply", :locals => {:journal => journal } %> +
    +
  • + <% end %> +
<% end %>