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/controllers.coffee b/assets/scripts/app/controllers.coffee index 5a267beb..84fa90e7 100644 --- a/assets/scripts/app/controllers.coffee +++ b/assets/scripts/app/controllers.coffee @@ -54,7 +54,7 @@ Travis.RepoSettingsController = Em.ObjectController.extend tab: Ember.computed.alias('controllers.repoSettingsTab.model.tab') settings: Ember.computed.alias('model.settings') - submit: -> + save: -> @set('saving', true) self = this @get('model').saveSettings(@get('settings')).then -> 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 diff --git a/assets/scripts/app/templates/repo/settings.hbs b/assets/scripts/app/templates/repo/settings.hbs index 80737cf4..db445f93 100644 --- a/assets/scripts/app/templates/repo/settings.hbs +++ b/assets/scripts/app/templates/repo/settings.hbs @@ -5,26 +5,18 @@ {{#travis-tab "general" "General Settings"}} {{#settings-form}}

- {{settings-input checked=builds_only_with_travis_yml type="checkbox" id="builds-only-with-travis-yml"}} - + {{travis-switch action="save" active=settings.builds_only_with_travis_yml}} + Build only commits with .travis.yml file

- {{settings-input checked=build_pushes type="checkbox" id="build-pushes"}} - + {{travis-switch action="save" active=settings.build_pushes}} + Build pushes

- {{settings-input checked=build_pull_requests type="checkbox" id="build-pull-requests"}} - -

- -

- {{#if saving}} - Saving - {{else}} - - {{/if}} + {{travis-switch action="save" active=settings.build_pull_requests}} + Build pull requests

{{/settings-form}} {{/travis-tab}}