From 9cd931cb7ffbf87f4a2cc04221a266e27354394b Mon Sep 17 00:00:00 2001 From: yanxd Date: Mon, 30 Dec 2013 20:53:48 +0800 Subject: [PATCH] ajax --- app/controllers/projects_controller.rb | 3 +- app/views/projects/_new_respond.html.erb | 2 +- app/views/projects/feedback.html.erb | 37 +++++++++++++++++++++++ app/views/projects/project_respond.js.erb | 14 +++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 1a90efdb..7135610c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -311,11 +311,12 @@ class ProjectsController < ApplicationController :is_readed => false} @jfm = Project.add_new_jour(nil, nil, project_id, options) + @save_succ = @jfm.errors.empty? # flash[:notice]=l(:label_projects_feedback_respond_success) respond_to do |format| - format.html { redirect_to :back } + # format.html { redirect_to :back } format.js #format.api { render_api_ok } end diff --git a/app/views/projects/_new_respond.html.erb b/app/views/projects/_new_respond.html.erb index 511d90db..b7a58bf0 100644 --- a/app/views/projects/_new_respond.html.erb +++ b/app/views/projects/_new_respond.html.erb @@ -1,4 +1,4 @@ -<%= form_tag({:controller => 'projects', :action => 'project_respond'}) do %> +<%= form_tag({:controller => 'projects', :action => 'project_respond'}, :remote => true) do %> <%= text_area_tag 'project_respond', "", :class => 'noline', :required => true, :style => "resize: none;", :rows => 3, diff --git a/app/views/projects/feedback.html.erb b/app/views/projects/feedback.html.erb index a1d0c076..bdbcfd07 100644 --- a/app/views/projects/feedback.html.erb +++ b/app/views/projects/feedback.html.erb @@ -1,3 +1,40 @@ +

<%= l(:label_user_response) %>

diff --git a/app/views/projects/project_respond.js.erb b/app/views/projects/project_respond.js.erb index e69de29b..eb2ea736 100644 --- a/app/views/projects/project_respond.js.erb +++ b/app/views/projects/project_respond.js.erb @@ -0,0 +1,14 @@ +<% if @save_succ %> + var pre_append = $('<%= j( + render :partial => "words/journal_reply_items", + :locals => {:reply => @jfm, :journal => @jfm.parent, :m_reply_id => @jfm} + ) %>').hide(); + $('#journal_reply_ul_<%=@jfm.m_parent_id%>').append(pre_append); + pre_append.fadeIn(600); + var textarea = $('#project_respond_form_<%=@jfm.m_reply_id.to_s%> textarea'); + textarea.val(''); + $('#project_respond_form_<%=@jfm.m_reply_id.to_s%>').hide(); + setMaxLengthItem(pre_append.find('textarea')[0]); +<% else %> + alert("<%= l(:label_feedback_fail) %>"); +<% end %> \ No newline at end of file