diff --git a/assets/scripts/app/components.coffee b/assets/scripts/app/components.coffee index da423edd..09a177fb 100644 --- a/assets/scripts/app/components.coffee +++ b/assets/scripts/app/components.coffee @@ -1,9 +1,19 @@ Travis.TravisSwitchComponent = Ember.Component.extend tagName: 'a' classNames: ['travis-switch'] - classNameBindings: ['active'] + classNameBindings: ['_active:active'] - activeBinding: 'target.active' + # TODO: how to handle overriding properties to + # avoid naming it _action? + _active: (-> + @get('target.active') || @get('active') + ).property('target.active', 'active') click: -> - @sendAction('action', @get('target')) + if target = @get('target') + @set('target.active', !@get('target.active')) + else + @set('active', !@get('active')) + # allow for bindings to propagate + Ember.run.next this, -> + @sendAction('action', target) diff --git a/assets/scripts/app/templates/components/travis-switch.hbs b/assets/scripts/app/templates/components/travis-switch.hbs index e7b20837..18617602 100644 --- a/assets/scripts/app/templates/components/travis-switch.hbs +++ b/assets/scripts/app/templates/components/travis-switch.hbs @@ -1,4 +1,4 @@ -{{#if active}} +{{#if _active}} ON {{else}} OFF