Skip to content

Instantly share code, notes, and snippets.

@RickButler
Created November 3, 2017 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickButler/a0a1137e4dea01a2dbef4a37853ceb8f to your computer and use it in GitHub Desktop.
Save RickButler/a0a1137e4dea01a2dbef4a37853ceb8f to your computer and use it in GitHub Desktop.
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