fixed notes logic
This commit is contained in:
parent
f0f14c8eab
commit
1e689bfba3
6 changed files with 109 additions and 79 deletions
|
@ -13,46 +13,54 @@ init:
|
|||
this.notes_path = path + ".js";
|
||||
this.target_id = tid;
|
||||
this.target_type = tt;
|
||||
this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id
|
||||
this.refresh();
|
||||
this.target_params = "&target_type=" + this.target_type + "&target_id=" + this.target_id;
|
||||
|
||||
// get notes
|
||||
this.getContent();
|
||||
|
||||
// get new notes every n seconds
|
||||
this.initRefresh();
|
||||
this.initLoadMore();
|
||||
|
||||
$('.delete-note').live('ajax:success', function() {
|
||||
$(this).closest('li').fadeOut(); });
|
||||
|
||||
$("#new_note").live("ajax:before", function(){
|
||||
$("#submit_note").attr("disabled", "disabled");
|
||||
})
|
||||
|
||||
$("#new_note").live("ajax:complete", function(){
|
||||
$("#submit_note").removeAttr("disabled");
|
||||
})
|
||||
|
||||
$("#note_note").live("click", function(){
|
||||
$(this).css("height", "100px");
|
||||
$('.attach_holder').show();
|
||||
});
|
||||
|
||||
},
|
||||
|
||||
getOld:
|
||||
|
||||
/**
|
||||
* Load new notes to fresh list called 'new_notes_list':
|
||||
* - Replace 'new_notes_list' with new list every n seconds
|
||||
* - Append new notes to this list after submit
|
||||
*/
|
||||
|
||||
initRefresh:
|
||||
function() {
|
||||
$('.loading').show();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: this.notes_path,
|
||||
data: "first_id=" + this.first_id + this.target_params,
|
||||
complete: function(){ $('.loading').hide()},
|
||||
dataType: "script"});
|
||||
},
|
||||
|
||||
append:
|
||||
function(id, html) {
|
||||
if(this.first_id == id) {
|
||||
this.disable = true;
|
||||
} else {
|
||||
this.first_id = id;
|
||||
$("#notes-list").append(html);
|
||||
}
|
||||
// init timer
|
||||
var intNew = setInterval("NoteList.getNew()", 10000);
|
||||
},
|
||||
|
||||
replace:
|
||||
function(fid, lid, html) {
|
||||
this.first_id = fid;
|
||||
this.last_id = lid;
|
||||
$("#notes-list").html(html);
|
||||
this.initLoadMore();
|
||||
function(html) {
|
||||
$("#new_notes_list").html(html);
|
||||
},
|
||||
|
||||
prepend:
|
||||
function(id, html) {
|
||||
if(id != this.last_id) {
|
||||
this.last_id = id;
|
||||
$("#notes-list").prepend(html);
|
||||
$("#new_notes_list").prepend(html);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -76,13 +84,66 @@ refresh:
|
|||
dataType: "script"});
|
||||
},
|
||||
|
||||
initRefresh:
|
||||
function() {
|
||||
// init timer
|
||||
var intNew = setInterval("NoteList.getNew()", 15000);
|
||||
var intRefresh = setInterval("NoteList.refresh()", 90000);
|
||||
|
||||
/**
|
||||
* Init load of notes:
|
||||
* 1. Get content with ajax call
|
||||
* 2. Set content of notes list with loaded one
|
||||
*/
|
||||
|
||||
|
||||
getContent:
|
||||
function() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: this.notes_path,
|
||||
data: "?" + this.target_params,
|
||||
dataType: "script"});
|
||||
},
|
||||
|
||||
setContent:
|
||||
function(fid, lid, html) {
|
||||
this.last_id = lid;
|
||||
this.first_id = fid;
|
||||
$("#notes-list").html(html);
|
||||
|
||||
// Init infinite scrolling
|
||||
this.initLoadMore();
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Paging for old notes when scroll to bottom:
|
||||
* 1. Init scroll events with 'initLoadMore'
|
||||
* 2. Load onlder notes with 'getOld' method
|
||||
* 3. append old notes to bottom of list with 'append'
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
getOld:
|
||||
function() {
|
||||
$('.loading').show();
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: this.notes_path,
|
||||
data: "first_id=" + this.first_id + this.target_params,
|
||||
complete: function(){ $('.status').removeClass("loading")},
|
||||
beforeSend: function() { $('.status').addClass("loading") },
|
||||
dataType: "script"});
|
||||
},
|
||||
|
||||
append:
|
||||
function(id, html) {
|
||||
if(this.first_id == id) {
|
||||
this.disable = true;
|
||||
} else {
|
||||
this.first_id = id;
|
||||
$("#notes-list").append(html);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
initLoadMore:
|
||||
function() {
|
||||
$(document).endlessScroll({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue