Skip to content

Instantly share code, notes, and snippets.

@timgremore
Created January 3, 2012 21:13
Show Gist options
  • Save timgremore/1556963 to your computer and use it in GitHub Desktop.
Save timgremore/1556963 to your computer and use it in GitHub Desktop.
Ember.js, document collection and polling...written in CoffeeScript
- title "#{@game.name}"
%h1= yield(:title)
#documents
= form_tag(assessment_game_documents_path(@game)) do
%ul
%script{ type: "text/x-handlebars" }
{{#collection Game.DocumentsCollectionView contentBinding="Game.documentsController"}}
%li {{content.name}}
{{/collection}}
window.Game ||= Ember.Application.create
ready: () ->
setInterval(() ->
Game.documentsController.refresh()
, 10000)
this._super()
Game.Document = Ember.Object.extend
name: null,
description: null
Game.documentsController = Ember.ArrayController.create
content: [],
createDocument: (name, description) ->
document = Game.Document.create
name: name,
description: description
this.pushObject(document)
refresh: () ->
$.getJSON("index.json", (data) ->
for item in data
Game.documentsController.createDocument item["document"]["name"], item["document"]["description"]
)
Game.DocumentsCollectionView = Ember.CollectionView.extend
itemView: Ember.View.extend
mouseDown: (evt) ->
alert "You clicked on " + this.get('content')
Game.documentsController.refresh()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment