Created
July 17, 2012 22:17
-
-
Save crtr0/3132522 to your computer and use it in GitHub Desktop.
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
Application = Thorax.Application.create() | |
# convenience for debugging | |
window.Application = Application | |
# main view controller | |
Application.ViewController.create | |
parent: Application | |
routes: | |
'': 'index' | |
'edit/:id': 'edit' | |
'create' : 'create' | |
index: -> | |
eventsView = EventsView.create | |
eventsCollection: Events.instance() | |
@setView eventsView | |
edit: (id) -> | |
events = Events.instance() | |
event = events.find (event) -> | |
event.get('id') is id | |
@setView EditView.create model: event | |
create: -> | |
@setView CreateView.create model: new Event() | |
Event = Application.model 'event' | |
urlRoot: '/events' | |
defaults: { | |
name: "" | |
} | |
Events = Application.collection 'events' | |
model: Event | |
url: '/events' | |
EventsView = Application.view 'events' | |
edit: (event) -> | |
model = $(event.target).model() | |
Backbone.history.navigate 'edit/' + model.get('id'), trigger: true | |
create: -> | |
model = new Event() | |
Backbone.history.navigate 'create', trigger: true | |
template: """ | |
<h1>Event List</h1> | |
{{#collection eventsCollection tag="ul"}} | |
<li>{{#button "edit" class="btn"}}Edit{{/button}} {{name}}</li> | |
{{/collection}} | |
{{#button "create" class="btn"}}New{{/button}} | |
""" | |
EditView = Application.view 'edit' | |
events: -> | |
'submit form': (event) -> | |
@serialize event, (attributes, release) => | |
console.log(@model) | |
#@model.save() | |
release() | |
template: """ | |
<h1>Editing {{name}}</h1> | |
<form> | |
{{input name="name"}} | |
<input type="submit"> | |
</form> | |
{{#link ""}}Go Back{{/link}} | |
""" | |
CreateView = Application.view 'create' | |
events: -> | |
'submit form': (event) -> | |
@serialize event, (attributes, release) => | |
console.log(@model) | |
#@model.save() | |
release() | |
template: """ | |
<h1>New Event</h1> | |
<form> | |
{{input name="name"}} | |
<input type="submit" class="btn btn-primary"> | |
</form> | |
{{#link ""}}Go Back{{/link}} | |
""" | |
# spin until data loaded | |
$ -> | |
document.body.appendChild(Application.el) | |
Application.setView Application.View.create | |
template: "Loading" | |
Events.instance().fetch success: -> | |
Application.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment