2013-05-02 07:36:53 -04:00
|
|
|
class Wall
|
|
|
|
constructor: (project_id) ->
|
|
|
|
@project_id = project_id
|
|
|
|
@note_ids = []
|
|
|
|
@getContent()
|
|
|
|
@initRefresh()
|
|
|
|
@initForm()
|
2013-03-19 06:35:55 -04:00
|
|
|
|
|
|
|
#
|
|
|
|
# Gets an initial set of notes.
|
|
|
|
#
|
|
|
|
getContent: ->
|
2013-05-02 07:36:53 -04:00
|
|
|
Api.notes @project_id, (notes) =>
|
|
|
|
$.each notes, (i, note) =>
|
2013-03-20 15:55:25 -04:00
|
|
|
# render note if it not present in loaded list
|
|
|
|
# or skip if rendered
|
2013-05-02 07:36:53 -04:00
|
|
|
if $.inArray(note.id, @note_ids) == -1
|
|
|
|
@note_ids.push(note.id)
|
|
|
|
@renderNote(note)
|
|
|
|
@scrollDown()
|
2013-03-20 15:55:25 -04:00
|
|
|
$("abbr.timeago").timeago()
|
2013-03-19 06:35:55 -04:00
|
|
|
|
|
|
|
initRefresh: ->
|
2013-05-02 07:36:53 -04:00
|
|
|
setInterval =>
|
|
|
|
@refresh()
|
|
|
|
, 10000
|
2013-03-19 06:35:55 -04:00
|
|
|
|
|
|
|
refresh: ->
|
2013-05-02 07:36:53 -04:00
|
|
|
@getContent()
|
2013-03-19 07:28:29 -04:00
|
|
|
|
|
|
|
scrollDown: ->
|
|
|
|
notes = $('ul.notes')
|
2013-03-19 09:04:58 -04:00
|
|
|
$('body, html').scrollTop(notes.height())
|
2013-03-19 07:28:29 -04:00
|
|
|
|
|
|
|
initForm: ->
|
2013-03-19 08:39:32 -04:00
|
|
|
form = $('.wall-note-form')
|
2013-03-19 07:28:29 -04:00
|
|
|
form.find("#target_type").val('wall')
|
|
|
|
|
2013-05-02 07:36:53 -04:00
|
|
|
form.on 'ajax:success', =>
|
|
|
|
@refresh()
|
2013-03-19 07:28:29 -04:00
|
|
|
form.find(".js-note-text").val("").trigger("input")
|
|
|
|
|
|
|
|
form.on 'ajax:complete', ->
|
|
|
|
form.find(".js-comment-button").removeAttr('disabled')
|
|
|
|
form.find(".js-comment-button").removeClass('disabled')
|
|
|
|
|
|
|
|
form.on "click", ".js-choose-note-attachment-button", ->
|
|
|
|
form.find(".js-note-attachment-input").click()
|
|
|
|
|
|
|
|
form.on "change", ".js-note-attachment-input", ->
|
|
|
|
filename = $(this).val().replace(/^.*[\\\/]/, '')
|
|
|
|
form.find(".js-attachment-filename").text(filename)
|
|
|
|
|
2013-03-20 03:53:39 -04:00
|
|
|
form.find('.note_text').keydown (e) ->
|
|
|
|
if e.ctrlKey && e.keyCode == 13
|
|
|
|
form.find('.js-comment-button').submit()
|
|
|
|
|
2013-03-19 07:28:29 -04:00
|
|
|
form.show()
|
2013-03-19 08:39:32 -04:00
|
|
|
|
|
|
|
renderNote: (note) ->
|
2013-05-02 07:36:53 -04:00
|
|
|
template = @noteTemplate()
|
2013-03-28 10:41:29 -04:00
|
|
|
template = template.replace('{{author_name}}', note.author.name)
|
2013-05-22 09:12:30 -04:00
|
|
|
template = template.replace(/{{created_at}}/g, note.created_at)
|
2013-05-24 02:49:49 -04:00
|
|
|
template = template.replace('{{text}}', simpleFormat(note.body))
|
2013-03-19 08:39:32 -04:00
|
|
|
|
|
|
|
if note.attachment
|
2013-07-30 10:48:00 -04:00
|
|
|
file = '<i class="icon-paper-clip"/><a href="' + gon.relative_url_root + '/files/note/' + note.id + '/' + note.attachment + '">' + note.attachment + '</a>'
|
2013-03-28 10:41:29 -04:00
|
|
|
else
|
|
|
|
file = ''
|
|
|
|
template = template.replace('{{file}}', file)
|
|
|
|
|
|
|
|
|
|
|
|
$('ul.notes').append(template)
|
2013-03-19 08:39:32 -04:00
|
|
|
|
2013-03-28 10:41:29 -04:00
|
|
|
noteTemplate: ->
|
|
|
|
return '<li>
|
|
|
|
<strong class="wall-author">{{author_name}}</strong>
|
|
|
|
<span class="wall-text">
|
|
|
|
{{text}}
|
|
|
|
<span class="wall-file">{{file}}</span>
|
|
|
|
</span>
|
|
|
|
<abbr class="timeago" title="{{created_at}}">{{created_at}}</abbr>
|
|
|
|
</li>'
|
2013-05-02 07:36:53 -04:00
|
|
|
|
|
|
|
@Wall = Wall
|