Created
July 8, 2014 21:26
-
-
Save jeremyroman/7d80a25fac615f3435fa to your computer and use it in GitHub Desktop.
DAOListView + Array = wtf?
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
<!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