Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.