Created
September 26, 2012 06:29
-
-
Save maedi/3786443 to your computer and use it in GitHub Desktop.
Ember.js, document collection and polling...written in CoffeeScript
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
- 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}} |
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
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