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 class Notes
@interval: null
constructor: (notes_url, note_ids) -> constructor: (notes_url, note_ids) ->
@notes_url = notes_url @notes_url = notes_url
@notes_url = gon.relative_url_root + @notes_url if gon.relative_url_root? @notes_url = gon.relative_url_root + @notes_url if gon.relative_url_root?
...@@ -60,7 +62,8 @@ class Notes ...@@ -60,7 +62,8 @@ class Notes
initRefresh: -> initRefresh: ->
setInterval => clearInterval(Notes.interval)
Notes.interval = setInterval =>
@refresh() @refresh()
, 15000 , 15000
...@@ -74,10 +77,6 @@ class Notes ...@@ -74,10 +77,6 @@ class Notes
success: (data) => success: (data) =>
notes = data.notes notes = data.notes
$.each notes, (i, note) => $.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) @renderNote(note)
...@@ -87,14 +86,27 @@ class Notes ...@@ -87,14 +86,27 @@ class Notes
Note: for rendering inline notes use renderDiscussionNote Note: for rendering inline notes use renderDiscussionNote
### ###
renderNote: (note) -> 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) $('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. Render note in discussion area.
Note: for rendering inline notes use renderDiscussionNote Note: for rendering inline notes use renderDiscussionNote
### ###
renderDiscussionNote: (note) -> renderDiscussionNote: (note) ->
@note_ids.push(note.id)
form = $("form[rel='" + note.discussion_id + "']") form = $("form[rel='" + note.discussion_id + "']")
row = form.closest("tr") row = form.closest("tr")
...@@ -219,7 +231,6 @@ class Notes ...@@ -219,7 +231,6 @@ class Notes
Adds new note to list. Adds new note to list.
### ###
addNote: (xhr, note, status) => addNote: (xhr, note, status) =>
@note_ids.push(note.id)
@renderNote(note) @renderNote(note)
### ###
...@@ -228,7 +239,6 @@ class Notes ...@@ -228,7 +239,6 @@ class Notes
Adds new note to list. Adds new note to list.
### ###
addDiscussionNote: (xhr, note, status) => addDiscussionNote: (xhr, note, status) =>
@note_ids.push(note.id)
@renderDiscussionNote(note) @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