Commit 32c7310f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Clear refresh interval for notes. Fixes duplicate note rendering

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 5b1984ce
class Notes
@interval: null
constructor: (notes_url, note_ids) ->
@notes_url = notes_url
@notes_url = gon.relative_url_root + @notes_url if gon.relative_url_root?
......@@ -60,7 +62,8 @@ class Notes
initRefresh: ->
setInterval =>
clearInterval(Notes.interval)
Notes.interval = setInterval =>
@refresh()
, 15000
......@@ -74,10 +77,6 @@ class Notes
success: (data) =>
notes = data.notes
$.each notes, (i, note) =>
# render note if it not present in loaded list
# or skip if rendered
if $.inArray(note.id, @note_ids) == -1
@note_ids.push(note.id)
@renderNote(note)
......@@ -87,14 +86,27 @@ class Notes
Note: for rendering inline notes use renderDiscussionNote
###
renderNote: (note) ->
# render note if it not present in loaded list
# or skip if rendered
if @isNewNote(note)
@note_ids.push(note.id)
$('ul.main-notes-list').append(note.html)
###
Check if note does not exists on page
###
isNewNote: (note) ->
$.inArray(note.id, @note_ids) == -1
###
Render note in discussion area.
Note: for rendering inline notes use renderDiscussionNote
###
renderDiscussionNote: (note) ->
@note_ids.push(note.id)
form = $("form[rel='" + note.discussion_id + "']")
row = form.closest("tr")
......@@ -219,7 +231,6 @@ class Notes
Adds new note to list.
###
addNote: (xhr, note, status) =>
@note_ids.push(note.id)
@renderNote(note)
###
......@@ -228,7 +239,6 @@ class Notes
Adds new note to list.
###
addDiscussionNote: (xhr, note, status) =>
@note_ids.push(note.id)
@renderDiscussionNote(note)
###
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment