Skip to content

Instantly share code, notes, and snippets.

@jeremyroman
Created July 8, 2014 21:26
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 jeremyroman/7d80a25fac615f3435fa to your computer and use it in GitHub Desktop.
Save jeremyroman/7d80a25fac615f3435fa to your computer and use it in GitHub Desktop.
DAOListView + Array = wtf?
<!DOCTYPE html>
<script src="foam/core/bootFOAM.js"></script>
<link rel="stylesheet" href="foam/core/foam.css">
<script>
MODEL({
name: 'Widget',
properties: ['gizmo'],
});
MODEL({
name: 'WidgetController',
properties: [
{
name: 'widgetCount',
defaultValue: 0,
view: { model_: 'TextFieldView', mode: 'read-only' },
},
{
name: 'widgets',
defaultValue: [],
view: { model_: 'DAOListView', mode: 'read-only' }
},
{
name: 'proxiedWidgets',
model_: 'DAOProperty',
dynamicValue: function() { return this.widgets; },
view: { model_: 'DAOListView', mode: 'read-only' }
}
],
actions: [
{
name: 'newWidget',
help: 'Add another widget',
isAvailable: function() { return true; },
isEnabled: function() { return true; },
action: function() {
if (typeof this.widgets === 'string') console.log('wtf a string?');
this.widgets.put(Widget.create({ gizmo: 'Whiz-Bang 3000' }));
this.widgetCount = this.widgets.length;
}
}
]
});
MODEL({
name: 'WidgetControllerView',
extendsModel: 'DetailView',
templates: [
function toHTML() {/*
<div>
<%= ActionButton.create({ action: this.model.NEW_WIDGET, value: SimpleValue.create(this.data) }) %>
</div>
<p>$$widgetCount{mode: 'read-only'}</p>
$$widgets
*/}
]
});
</script>
<foam model="WidgetController" view="WidgetControllerView"></foam>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment