Created
June 25, 2012 15:25
-
-
Save michaelgodshall/2989243 to your computer and use it in GitHub Desktop.
Spine.js List
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
require('lib/setup') | |
Spine = require('spine') | |
Stages = require('controllers/main') | |
Stage = require('models/stage') | |
class App extends Spine.Controller | |
constructor: -> | |
super | |
@stage = new Stages | |
@append @stage.active() | |
Spine.Route.setup() | |
module.exports = App |
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
<div class="item"> | |
<%= @name %> | |
<% for question in @questions().all(): %> | |
<%= question.question %> ### EMPTY | |
<% end %> | |
</div> |
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
class StagesList extends Spine.Controller | |
elements: | |
'.stages': 'items' | |
constructor: -> | |
super | |
@html require('views/stages/list')() | |
@list = new List | |
el: @items, | |
template: require('views/stages/item') | |
#selectFirst: true | |
@list.bind 'change', @change | |
@active (params) -> | |
@list.change(Stage.find(params.id)) | |
Stage.bind('refresh change', @render) | |
render: => | |
stages = Stage.all() | |
for stage in stages | |
console.log stage.questions().all() ### EMPTY | |
@list.render(stages) | |
change: (item) => | |
@navigate '/stages', item.id | |
module.exports = StagesList |
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.$ | |
Stage = require('models/stage') | |
StagesStack = require('controllers/stages/stack') | |
StagesList = require('controllers/stages/list') | |
Question = require('models/question') | |
class Stages extends Spine.Controller | |
className: 'stages' | |
constructor: -> | |
super | |
@list = new StagesList | |
@stack = new StagesStack | |
@routes | |
'/stages/:id': (params) -> | |
@stack.show.active(params) | |
'/stages/:id/complete': (params) -> | |
@stack.complete.active(params) | |
'/questions/:id': (params) -> | |
@stack.questions.active(params) | |
@append @list, @stack | |
Question.fetch() | |
Stage.fetch() | |
module.exports = Stages |
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') | |
class Question extends Spine.Model | |
@configure 'Question', 'id', 'question', 'stage', 'stage_order', 'level', 'question_type', 'clue', 'clue_link', 'is_daily_double', 'image', 'completed' | |
@extend Spine.Model.Ajax | |
@url: '/questions/' | |
@belongsTo 'parent_stage', 'models/stage', 'stage' | |
module.exports = Question |
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') | |
class Stage extends Spine.Model | |
@configure 'Stage', 'id', 'name', 'description', 'slug', 'is_active', 'created_at' | |
@extend Spine.Model.Ajax | |
@url: '/stages/' | |
@hasMany 'questions', 'models/question', 'stage' | |
module.exports = Stage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment