Skip to content

Instantly share code, notes, and snippets.

@maedi
Forked from timgremore/index.html.haml
Created September 26, 2012 06:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maedi/3786443 to your computer and use it in GitHub Desktop.
Save maedi/3786443 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