You can do it setting an attribute on your widget's Coffescript starting it with false
and bind a toggle function using data-event-click
on your view. That will toggle the value of your attribute.
Them, you put what you want to show and hide on two containers and bind that attribute on them, using data-hideif='attributeName'
on the container you want to hide when raise a click event on your widget and using data-showif='attributeName'
on the container you want to show when raise the click event.
So, your coffescript would become something like:
class Dashing.ToggleableWidget extends Dashing.Widget
toggleDetails: ->
@set('showDetails', !@showDetails)
# you could still use accessor with:
# @accessor 'toggleDetails',
# get: -> @set('showDetails', !@showDetails)
# cache: false
#
# ... but it is not necessary, and using a normal function will solve your problem
ready: ->
@showDetails = false
And your view would become something like:
<div class="status-accounts" data-event-click="toggleDetails">
<div class="summary" data-hideif="showDetails" data-bind="summary"></div>
<div class="details" data-showif="showDetails">
<div class="account" data-foreach-account='accounts' data-bind-title='account.status'>
<span class="name" data-bind="account.account_name | append ' - '"></span>
<span class="status" data-bind="account.status | truncate 3, ''"></span>
</div>
</div>
</div>
With that, when your widget be rendered (or re-rendered after changing data), it will show your summary container, and if you click, it will show your details container.