public
Created

Spine Post & Messages, Chat Display.

  • Download Gist
message.jeco
1 2 3
<li class='item'>
<%= @body %>
</li>
post.main.coffee
CoffeeScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
Spine = require('spine')
$ = Spine.$
 
# Models
Post = require('models/post')
Session = require('models/session')
Message = require('models/message')
 
class Show extends Spine.Controller
className: 'show content-area'
 
events:
'submit form': 'submit'
 
elements:
'.messages' : 'messages'
constructor: ->
super
@html require('views/posts/show')
@active @change
 
@list = new Spine.List
el: @messages
template: require('views/messages/message')
selectFirst: true
 
@list.bind 'change', @render
 
Post.bind 'refresh', @render
Message.bind 'create', @change
render: =>
return if !@postId
@post = Post.exists(@postId)
 
if @post
messages = @post.messages
@list.render(messages)
 
@html require('views/posts/show')(@post)
change: (params) =>
if params.id != @postId
@postId = params.id
if Session.first()
Post.fetch
id: @postId
 
@render()
 
submit: (e) =>
e.preventDefault()
message = Message.fromForm(e.target)
message.save()
 
 
class Main extends Spine.Stack
className: 'main stack'
controllers:
show: Show
module.exports = Main
show.eco
1 2 3 4 5 6 7 8 9
<ul class='messages'></ul>
 
<div class='footer'>
<form class='new-message'>
<input type="hidden" name="post_id" value="<%= @id %>">
<textarea name='body' placeholder='Type your message hereā€¦' autofocus='autofocus'></textarea>
<input type='submit' value='Send'>
</form>
</div>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.