Created
October 8, 2013 07:30
-
-
Save peteroome/6880967 to your computer and use it in GitHub Desktop.
Spine Post & Messages, Chat Display.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<li class='item'> | |
<%= @body %> | |
</li> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment