fixed notes loading/paging

This commit is contained in:
Dmitriy Zaporozhets 2011-11-05 13:59:43 +02:00
parent 0b0e0225ad
commit 586c53ea05
6 changed files with 47 additions and 15 deletions

View file

@ -31,6 +31,15 @@ append:
this.initLoadMore(); this.initLoadMore();
}, },
replace:
function(fid, lid, html) {
this.first_id = fid;
this.last_id = lid;
$("#notes-list").html(html);
this.initLoadMore();
},
prepend: prepend:
function(id, html) { function(id, html) {
this.last_id = id; this.last_id = id;
@ -47,10 +56,23 @@ getNew:
dataType: "script"}); dataType: "script"});
}, },
refresh:
function() {
// refersh notes list
$.ajax({
type: "GET",
url: location.href,
data: "first_id=" + this.first_id + "&last_id=" + this.last_id,
dataType: "script"});
},
initRefresh: initRefresh:
function() { function() {
// init timer // init timer
var int = setInterval("NoteList.getNew()", 20000); var intNew = setInterval("NoteList.getNew()", 15000);
var intRefresh = setInterval("NoteList.refresh()", 90000);
}, },
initLoadMore: initLoadMore:

View file

@ -83,4 +83,16 @@ class ApplicationController < ActionController::Base
cookies[:view_style] = "" cookies[:view_style] = ""
end end
end end
def respond_with_notes
if params[:last_id] && params[:first_id]
@notes = @notes.where("id >= ?", params[:first_id])
elsif params[:last_id]
@notes = @notes.where("id > ?", params[:last_id])
elsif params[:first_id]
@notes = @notes.where("id < ?", params[:first_id])
else
nil
end
end
end end

View file

@ -33,10 +33,7 @@ class CommitsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js do format.js { respond_with_notes }
@notes = @notes.where("id > ?", params[:last_id]) if params[:last_id]
@notes = @notes.where("id < ?", params[:first_id]) if params[:first_id]
end
end end
end end
end end

View file

@ -40,10 +40,7 @@ class IssuesController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js do format.js { respond_with_notes }
@notes = @notes.where("id > ?", params[:last_id]) if params[:last_id]
@notes = @notes.where("id < ?", params[:first_id]) if params[:first_id]
end
end end
end end

View file

@ -90,10 +90,7 @@ class ProjectsController < ApplicationController
respond_to do |format| respond_to do |format|
format.html format.html
format.js do format.js { respond_with_notes }
@notes = @notes.where("id > ?", params[:last_id]) if params[:last_id]
@notes = @notes.where("id < ?", params[:first_id]) if params[:first_id]
end
end end
end end

View file

@ -1,10 +1,17 @@
- unless @notes.blank? - unless @notes.blank?
- if params[:last_id] - if params[:last_id] && params[:first_id]
:plain
NoteList.replace(#{@notes.last.id}, #{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}");
- elsif params[:last_id]
:plain :plain
NoteList.prepend(#{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); NoteList.prepend(#{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}");
- if params[:first_id] - elsif params[:first_id]
:plain :plain
NoteList.append(#{@notes.last.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}"); NoteList.append(#{@notes.last.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}");
- else
:plain