Created
November 3, 2017 01:00
-
-
Save RickButler/a0a1137e4dea01a2dbef4a37853ceb8f 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
var app = require('ampersand-app'); | |
var baseView = require('../_core/base'); | |
var CollectionView = require('ampersand-collection-view') | |
var collectionView = require('../gameobject/recipe-view'); | |
var GameObjectMenu = require('../gameobjects/gameobjectmenu-view'); | |
var templates = require('../../templates'); | |
module.exports = baseView.extend({ | |
pageTitle: 'Recipes', | |
template: templates.pages.gameobjects.recipes, | |
session: { | |
isCollectionReady: 'boolean', | |
isItemClassesReady: 'boolean', | |
}, | |
derived: { | |
isRecipeListReady: { | |
deps: ['isCollectionReady', 'isItemClassesReady'], | |
fn: function () { | |
return this.isCollectionReady && this.isItemClassesReady; | |
} | |
} | |
}, | |
events: { 'click [data-hook~=fetch]': 'fetchCollection' }, | |
render: function () { | |
var self = this; | |
if (!app.itemclasses.length) { | |
app.itemclasses.fetch({ | |
success: function () { | |
self.isItemClassesReady = true; | |
} | |
}); | |
} else { | |
this.isItemClassesReady = true; | |
} | |
this.renderWithTemplate(); | |
if (!this.collection.length) { | |
this.fetchCollection({ | |
success: function () { | |
self.isCollectionReady = true; | |
} | |
}); | |
} else { | |
self.isCollectionReady = true; | |
} | |
}, | |
fetchCollection: function () { | |
this.collection.fetch({ | |
success: function () { | |
this.collectionReady = true; | |
} | |
}); | |
return false; | |
}, | |
subviews: { | |
div: { | |
hook: 'game-object-menu', | |
prepareView: function (el) { | |
return new GameObjectMenu({ | |
el: el, | |
parent: this | |
}); | |
} | |
}, | |
recipeList: { | |
hook: 'recipe-list', | |
waitFor: 'isRecipeListReady', | |
prepareView: function (el) { | |
return new CollectionView({ | |
collection: this.collection, | |
el: el, | |
view: collectionView, | |
parent: this, | |
viewOptions: { | |
parent: this | |
} | |
}); | |
} | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment