From ebc803a88a1a526899fbb1a61291dd0a75a6c5f6 Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 30 Dec 2013 17:13:44 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E7=95=99=E8=A8=80.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 3 -- app/controllers/words_controller.rb | 41 +++++++++++++--------- app/views/projects/feedback.html.erb | 42 +++++++++++------------ app/views/projects/project_respond.js.erb | 0 app/views/words/destroy.js.erb | 2 +- 5 files changed, 47 insertions(+), 41 deletions(-) create mode 100644 app/views/projects/project_respond.js.erb diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 6dbcc2178..1a90efdbf 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -181,9 +181,7 @@ class ProjectsController < ApplicationController @s_type = 2 end else - logger.debug("-------------------------------------------------") @projects = Project.visible.where("project_type = ?", 1).order("created_on desc").offset(@project_pages.offset).limit(@limit).all - logger.debug("-------------------------------------------------") @s_type = 0 end respond_to do |format| @@ -316,7 +314,6 @@ class ProjectsController < ApplicationController # flash[:notice]=l(:label_projects_feedback_respond_success) - respond_to do |format| format.html { redirect_to :back } format.js diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index ce4523b2f..224d44050 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -39,11 +39,10 @@ class WordsController < ApplicationController #format.api { render_api_ok } end end + def create_reply # deny api. api useless - user_id = request.headers["Referer"].match((%r|/([0-9]{1,})/|))[1] - @user = User.find(user_id) parent_id = params[:reference_id] author_id = User.current.id reply_user_id = params[:reference_user_id] @@ -55,7 +54,8 @@ class WordsController < ApplicationController :reply_id => reply_user_id, :notes => content, :is_readed => false} - @jfm = @user.add_jour(nil, nil, nil, options) + @obj = obj_distinguish_url_origin + @jfm = add_reply_adapter @obj, options respond_to do |format| # format.html { @@ -74,21 +74,8 @@ class WordsController < ApplicationController def destroy @journal_destroyed = JournalsForMessage.delete_message(params[:object_id]) - @jours = @user.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'] - @offset ||= @feedback_pages.offset - @jour = @jours[@offset, @limit] - # if a_message.size > 5 - # @message = a_message[-5, 5] - # else - # @message = a_message - # end - # @message_count = a_message.count respond_to do |format| - format.html { redirect_to :back } format.js #format.api { render_api_ok } end @@ -187,5 +174,27 @@ class WordsController < ApplicationController render_404 end + def obj_distinguish_url_origin + referer = request.headers["Referer"] + obj_id = referer.match((%r|/([0-9]{1,})/|))[1] + if referer.match(/project/) + obj = Project.find_by_id(obj_id) + elsif referer.match(/user/) + obj = User.find_by_id(obj_id) + else + raise 'create reply obj unknow type.' + end + obj + end + + def add_reply_adapter obj, options + if obj.kind_of? User + obj.add_jour(nil, nil, nil, options) + elsif obj.kind_of? Project + Project.add_new_jour(nil, nil, obj.id, options) + else + raise 'create reply obj unknow type.' + end + end #######end of message end \ No newline at end of file diff --git a/app/views/projects/feedback.html.erb b/app/views/projects/feedback.html.erb index ec630aee2..a1d0c0763 100644 --- a/app/views/projects/feedback.html.erb +++ b/app/views/projects/feedback.html.erb @@ -14,32 +14,32 @@ <% if @jour.size >0 %> <% end %> diff --git a/app/views/projects/project_respond.js.erb b/app/views/projects/project_respond.js.erb new file mode 100644 index 000000000..e69de29bb diff --git a/app/views/words/destroy.js.erb b/app/views/words/destroy.js.erb index 6b582f804..d12041f1f 100644 --- a/app/views/words/destroy.js.erb +++ b/app/views/words/destroy.js.erb @@ -1,6 +1,6 @@ <% if @journal_destroyed.nil? %> alert('<%=l(:notice_failed_delete)%>'); -<% elsif (@journal_destroyed.jour_type == 'Principal')%> +<% elsif (['Principal','Project'].include? @journal_destroyed.jour_type)%> var destroyedItem = $('#word_li_<%=@journal_destroyed.id%>') destroyedItem.fadeOut(600,function(){ destroyedItem.remove();