删除留言操作

This commit is contained in:
yanxd 2013-12-26 19:28:18 +08:00
parent 7197e3d90c
commit 8a1316cf8f
11 changed files with 42 additions and 30 deletions

View File

@ -73,10 +73,10 @@ class WordsController < ApplicationController
end end
def destroy def destroy
if User.current.admin? || User.current.id == @user.id if User.current.admin? || @user.id == User.current.id || User.current.id == JournalsForMessage.find(params[:object_id]).jour_id
JournalsForMessage.delete_message(params[:object_id]) @journal_destroyed = JournalsForMessage.delete_message(params[:object_id])
end end
@jours = @user.journals_for_messages.reverse @jours = @user.journals_for_messages.where('m_parent_id IS NULL').reverse
@limit = 10 @limit = 10
@feedback_count = @jours.count @feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, params['page'] @feedback_pages = Paginator.new @feedback_count, @limit, params['page']

View File

@ -20,7 +20,6 @@ class JournalsForMessage < ActiveRecord::Base
belongs_to :at_user, :class_name => "User", :foreign_key => 'reply_id' belongs_to :at_user, :class_name => "User", :foreign_key => 'reply_id'
has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy
has_many :reply_for_journals, :dependent => :destroy
validates :notes, presence: true validates :notes, presence: true
after_create :act_as_activity #huang after_create :act_as_activity #huang
@ -30,7 +29,8 @@ class JournalsForMessage < ActiveRecord::Base
# default_scope { where('m_parent_id IS NULL') } # default_scope { where('m_parent_id IS NULL') }
def self.delete_message(message_id) def self.delete_message(message_id)
self.delete_all "id = #{message_id}" self.find(message_id).destroy
# self.destroy_all "id = #{message_id}"
end end
def reference_user def reference_user

View File

@ -1,6 +1,6 @@
<% id = "journal_reply_ul_" + journal.id.to_s%> <% id = "journal_reply_ul_" + journal.id.to_s%>
<ul class="messages-for-user-reply" id = <%= id %> > <ul class="messages-for-user-reply" id = '<%= id %>' >
<% fetch_user_leaveWord_reply(journal).each do |reply|%> <% fetch_user_leaveWord_reply(journal).each do |reply|%>
<%= render :partial => "words/journal_reply_items", :locals => {:reply => reply, :journal => journal, :m_reply_id => reply.id} %> <%= render :partial => "words/journal_reply_items", :locals => {:reply => reply, :journal => journal, :m_reply_id => reply.id} %>
<% end %> <% end %>

View File

@ -1,5 +1,5 @@
<% ids_r = 'reply_respond_form_'+ reply.id.to_s %> <% ids_r = 'reply_respond_form_'+ reply.id.to_s %>
<li onmouseover="$('#<%= ids_r %>').show()" onmouseout="$('#<%= ids_r %>').hide()"> <li id='word_li_<%=reply.id.to_s%>' onmouseover="$('#<%= ids_r %>').show()" onmouseout="$('#<%= ids_r %>').hide()">
<span class="portrait"> <span class="portrait">
<%= image_tag url_to_avatar(reply.user), :class => "avatar-3" %> <%= image_tag url_to_avatar(reply.user), :class => "avatar-3" %>
</span> </span>
@ -7,17 +7,17 @@
<% id = 'project_respond_form_'+ reply.id.to_s %> <% id = 'project_respond_form_'+ reply.id.to_s %>
<span><%= link_to reply.user.name, user_path(reply.user) %>:&nbsp;</span> <span><%= link_to reply.user.name, user_path(reply.user) %>:&nbsp;</span>
<span class="message-notes"> <%= reply.notes %></span> <span class="message-notes"> <%= reply.notes %></span>
<% ids = 'project_respond_form_'+ journal.id.to_s%> <%# ids = 'project_respond_form_'+ journal.id.to_s%>
<p> <p>
<span class="time"><%= format_time reply.created_on %></span> <span class="time"><%= format_time reply.created_on %></span>
<span style="display: none; margin-left: 4px;" id=<%= ids_r %>> <span style="display: none; margin-left: 4px;" id='<%=ids_r%>' >
<%= link_to l(:label_projects_feedback_respond),'', <%= link_to l(:label_projects_feedback_respond),'',
{:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), '#{l(:label_reply_plural)} #{journal.user.show_name}:'); return false;"} {:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{id}'), $('##{id} textarea'), '#{l(:label_reply_plural)} #{journal.user.show_name}: '); return false;"}
%> %>
<% if @user == User.current %> <% if @user == User.current %>
<%= link_to(l(:label_newfeedback_delete), {:controller => 'words', :action => 'destroy', :object_id => journal, :user_id => reply.user}, <%= link_to(l(:label_newfeedback_delete), {:controller => 'words', :action => 'destroy', :object_id => reply, :user_id => reply.user},
:remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) if (User.current.id == reply.user_id) || journal.jour_id == User.current.id %></td> :remote => true, :confirm => l(:text_are_you_sure), :method => 'delete', :class => "delete", :title => l(:button_delete)) if (User.current.id == reply.user_id) || journal.jour_id == User.current.id %></td>
<% end %> <% end %>
</span> </span>

View File

@ -3,7 +3,7 @@
<% remove_allowed = (User.current.id == jour.first.user_id) %> <% remove_allowed = (User.current.id == jour.first.user_id) %>
<ul class="message-for-user"> <ul class="message-for-user">
<% for journal in jour%> <% for journal in jour%>
<li class="outer-message-for-user"> <li id='word_li_<%=journal.id.to_s%>' class="outer-message-for-user">
<span class="portrait"><%= image_tag(url_to_avatar(journal.user), :class => "avatar") %></span> <span class="portrait"><%= image_tag(url_to_avatar(journal.user), :class => "avatar") %></span>
<span class="body"> <span class="body">
<span class="user"><%= link_to journal.user, user_path(journal.user)%></span> <span class="user"><%= link_to journal.user, user_path(journal.user)%></span>
@ -19,7 +19,7 @@
<% ids = 'project_respond_form_'+ journal.id.to_s%> <% ids = 'project_respond_form_'+ journal.id.to_s%>
<span> <span>
<%= link_to l(:label_projects_feedback_respond),'', <%= link_to l(:label_projects_feedback_respond),'',
{:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), '#{l(:label_reply_plural)} #{journal.user.show_name}:'); return false;"} {:focus => 'project_respond', :onclick => "toggleAndSettingWordsVal($('##{ids}'), $('##{ids} textarea'), '#{l(:label_reply_plural)} #{journal.user.show_name}: '); $('##{ids} textarea') ;return false;"}
%> %>
<% if @user == User.current %> <% if @user == User.current %>
@ -29,7 +29,7 @@
</span> </span>
</span> </span>
<div style="clear: both;"></div> <div style="clear: both;"></div>
<div id=<%= ids %> class="respond-form"> <div id='<%= ids %>' class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => journal, :m_reply_id => journal.id} %> <%= render :partial => 'words/new_respond', :locals => {:journal => journal, :m_reply_id => journal.id} %>
</div> </div>
<div> <div>

View File

@ -1,9 +1,10 @@
<% if @save_succ %> <% if @save_succ %>
$('#journal_reply_ul_<%=@jfm.m_parent_id%>').append( var pre_append = $('<%= j(
'<%= j(
render :partial => "words/journal_reply_items", render :partial => "words/journal_reply_items",
:locals => {:reply => @jfm, :journal => @jfm.parent, :m_reply_id => @jfm.id} :locals => {:reply => @jfm, :journal => @jfm.parent, :m_reply_id => @jfm.id}
) %>'); ) %>').hide();
$('#journal_reply_ul_<%=@jfm.m_parent_id%>').append(pre_append);
pre_append.fadeIn(600);
$('#project_respond_form_<%=@jfm.m_reply_id.to_s%> textarea').val(''); $('#project_respond_form_<%=@jfm.m_reply_id.to_s%> textarea').val('');
$('#project_respond_form_<%=@jfm.m_reply_id.to_s%>').hide(); $('#project_respond_form_<%=@jfm.m_reply_id.to_s%>').hide();
<% else %> <% else %>

View File

@ -1,2 +1,11 @@
<% if @journal_destroyed.nil? %>
alert('<%=l(:notice_failed_delete)%>');
<% elsif (@journal_destroyed.jour_type == 'Principal')%>
var destroyedItem = $('#word_li_<%=@journal_destroyed.id%>')
destroyedItem.fadeOut(600,function(){
destroyedItem.remove();
});
<% else %>
$('#message').html('<%= escape_javascript(render(:partial => 'words/message', :locals => {:jour => @jour, :state => false, :user => @user, :feedback_pages => @feedback_pages})) %>'); $('#message').html('<%= escape_javascript(render(:partial => 'words/message', :locals => {:jour => @jour, :state => false, :user => @user, :feedback_pages => @feedback_pages})) %>');
$('#new_form_reference_user_id').val(""); $('#new_form_reference_user_id').val("");
<% end %>

View File

@ -155,6 +155,7 @@ en:
notice_successful_create: Successful creation. notice_successful_create: Successful creation.
notice_successful_update: Successful update. notice_successful_update: Successful update.
notice_successful_delete: Successful deletion. notice_successful_delete: Successful deletion.
notice_failed_delete: Successful failure.
notice_successful_connection: Successful connection. notice_successful_connection: Successful connection.
notice_file_not_found: The page you were trying to access doesn't exist or has been removed. notice_file_not_found: The page you were trying to access doesn't exist or has been removed.
notice_locking_conflict: Data has been updated by another user. notice_locking_conflict: Data has been updated by another user.

View File

@ -164,6 +164,7 @@ zh:
notice_successful_create: 创建成功 notice_successful_create: 创建成功
notice_successful_update: 更新成功 notice_successful_update: 更新成功
notice_successful_delete: 删除成功 notice_successful_delete: 删除成功
notice_failed_delete: 删除失败
notice_successful_connection: 连接成功 notice_successful_connection: 连接成功
notice_file_not_found: 您访问的页面不存在或已被删除。 notice_file_not_found: 您访问的页面不存在或已被删除。
notice_locking_conflict: 数据已被另一位用户更新 notice_locking_conflict: 数据已被另一位用户更新

View File

@ -592,7 +592,7 @@ function blockEventPropagation(event) {
function toggleAndSettingWordsVal(parent_widget, text_widget, value){ function toggleAndSettingWordsVal(parent_widget, text_widget, value){
text_widget.val(value) text_widget.val(value)
parent_widget.toggle(400) parent_widget.slideToggle(400)
} }
$(document).ready(setupAjaxIndicator); $(document).ready(setupAjaxIndicator);

View File

@ -2123,7 +2123,7 @@ ul.messages-for-user-reply li {
.respond-form{ .respond-form{
display: none; display: none;
width: 100%; width: 87%;
margin: auto; margin: auto;
clear:both; clear:both;
} }