this.initLoadMore();
},
+replace:
+ function(fid, lid, html) {
+ this.first_id = fid;
+ this.last_id = lid;
+ $("#notes-list").html(html);
+ this.initLoadMore();
+ },
+
+
prepend:
function(id, html) {
this.last_id = id;
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:
function() {
// init timer
- var int = setInterval("NoteList.getNew()", 20000);
+ var intNew = setInterval("NoteList.getNew()", 15000);
+ var intRefresh = setInterval("NoteList.refresh()", 90000);
},
initLoadMore:
cookies[:view_style] = ""
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
respond_to do |format|
format.html
- format.js do
- @notes = @notes.where("id > ?", params[:last_id]) if params[:last_id]
- @notes = @notes.where("id < ?", params[:first_id]) if params[:first_id]
- end
+ format.js { respond_with_notes }
end
end
end
respond_to do |format|
format.html
- format.js do
- @notes = @notes.where("id > ?", params[:last_id]) if params[:last_id]
- @notes = @notes.where("id < ?", params[:first_id]) if params[:first_id]
- end
+ format.js { respond_with_notes }
end
end
respond_to do |format|
format.html
- format.js do
- @notes = @notes.where("id > ?", params[:last_id]) if params[:last_id]
- @notes = @notes.where("id < ?", params[:first_id]) if params[:first_id]
- end
+ format.js { respond_with_notes }
end
end
- 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
NoteList.prepend(#{@notes.first.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}");
- - if params[:first_id]
+ - elsif params[:first_id]
:plain
NoteList.append(#{@notes.last.id}, "#{escape_javascript(render(:partial => 'notes/notes_list'))}");
+ - else
+ :plain