解决删除项目主留言分页Url错误和页数错误的Bug

This commit is contained in:
linhk 2014-08-21 08:58:48 +08:00
parent cc08cdc140
commit 66dfa1ce4f
5 changed files with 107 additions and 10 deletions

View File

@ -403,17 +403,29 @@ class ProjectsController < ApplicationController
#Ended by young
def feedback
page = params[:page]
@page = params[:page]
@page = @page.to_i
# Find the page of the requested reply
@jours = @project.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@limit = 10
if params[:r] && page.nil?
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
page = 1 + offset / @limit
@limit = 3
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
page = 1 + offset / @limit
if params[:r] && @page.nil?
@page = page
end
puts @page
if @page < 0
@page = 1
end
if @page > page
@page = page
end
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, page
@feedback_pages = Paginator.new @feedback_count, @limit, @page
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@state = false

View File

@ -90,8 +90,37 @@ class WordsController < ApplicationController
end
def destroyJournal
@journalP=JournalsForMessage.find(params[:object_id])
@journalP.destroy
@page = params[:page]
@page = @page.to_i
@project = Project.find params[:project_id]
# Find the page of the requested reply
@jours = @project.journals_for_messages.where('m_parent_id IS NULL').order('created_on DESC')
@limit = 3
offset = @jours.count(:conditions => ["#{JournalsForMessage.table_name}.id > ?", params[:r].to_i])
page = 1 + offset / @limit
if params[:r] && @page.nil?
@page = page
end
if @page < 0
@page = 1
end
if @page > page
@page = page
end
@feedback_count = @jours.count
@feedback_pages = Paginator.new @feedback_count, @limit, @page
@offset ||= @feedback_pages.offset
@jour = @jours[@offset, @limit]
@state = false
@base_courses_tag = @project.project_type
respond_to do |format|
format.js
end

View File

@ -36,7 +36,8 @@ function checkMaxLength() {
</script>
<!-- fq -->
<% reply_allow = JournalsForMessage.create_by_user? User.current %>
<h3><%= l(:label_user_response) %></h3>
@ -59,6 +60,8 @@ function checkMaxLength() {
</div>
<% end %>
<div style="clear: both;"></div>
<div id="project_feedback">
<% reply_allow = JournalsForMessage.create_by_user? User.current %>
<% if @jour.size >0 %>
<ul class="message-for-user">
<% for journal in @jour%>
@ -81,7 +84,7 @@ function checkMaxLength() {
<% if User.current.logged? %>
<% if journal.user_id==User.current.id|| User.current.admin? %>
<%= link_to(l(:button_delete),{:controller => 'words', :action => 'destroyJournal', :object_id => journal.id},
<%= link_to(l(:button_delete),{:controller => 'words', :action => 'destroyJournal', :object_id => journal.id, :project_id=>@project.id, :page=>@page},
:remote => true, :title => l(:button_delete)) %>
<% end %>
<% end %>
@ -106,4 +109,5 @@ function checkMaxLength() {
<ul>
<%= pagination_links_full @feedback_pages %>
</ul>
</div>
</div>

View File

@ -0,0 +1,50 @@
<% reply_allow = JournalsForMessage.create_by_user? User.current %>
<% if @jour.size >0 %>
<ul class="message-for-user">
<% for journal in @jour%>
<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="body">
<span class="user"><%= link_to journal.user, user_path(journal.user)%></span>
<%= textilizable journal.notes%>
<span class="font_lighter"> <%= l :label_update_time %>: <%= format_time journal.created_on %></span>
<% id = 'project_respond_form_'+journal.id.to_s%>
<span>
<% if reply_allow %>
<%= link_to l(:label_projects_feedback_respond),'#',
{:focus => 'project_respond',
:onclick => "toggleAndSettingWordsVal($('##{id}'),
$('##{id} textarea'),
'#{l(:label_reply_plural)} #{journal.user.name}: ');
return false;"} %>
<% end %>
<% if User.current.logged? %>
<% if journal.user_id==User.current.id|| User.current.admin? %>
<%= link_to(l(:button_delete),{:controller => 'words', :action => 'destroyJournal', :object_id => journal.id, :project_id=>@project.id, :page=>@page},
:remote => true, :title => l(:button_delete)) %>
<% end %>
<% end %>
</span>
</span>
<div style="clear: both;"></div>
<% if reply_allow %>
<div id='<%= id %>' class="respond-form">
<%= render :partial => 'words/new_respond', :locals => {:journal => journal, :m_reply_id => journal} %>
</div>
<% end %>
<div style="clear: both;"></div>
<div>
<%= render :partial => "words/journal_reply", :locals => {:journal => journal } %>
</div>
</li>
<% end %>
</ul>
<% end %>
<div class="pagination" style="float:left;">
<ul>
<%= pagination_links_full(@feedback_pages,@feedback_count, :per_page_links => false){|text, parameters, options|
link_to text, project_feedback_path(@project,parameters.merge(:q => params[:q])) }%>
</ul>
</div>

View File

@ -1,3 +1,5 @@
<% if @journalP!=nil %>
$(".message-for-user").children("#word_li_<%=@journalP.id%>").remove();
//$(".message-for-user").children("#word_li_<%#=@journalP.id%>").remove();
$("#project_feedback").html("<%= escape_javascript(render :partial => 'words/feedback') %>");
<% end %>