From 49fd7407187f5f08b74dc4aca15557c43ba8e6c6 Mon Sep 17 00:00:00 2001 From: Sean Devine Date: Fri, 18 Dec 2015 10:27:06 -0500 Subject: [PATCH] add level button with initial behavior --- app/controllers/application.js | 3 ++- app/routes/application.js | 22 +++++++++++++++++++--- app/templates/application.hbs | 5 +++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/app/controllers/application.js b/app/controllers/application.js index 489f8e5..2e52b90 100644 --- a/app/controllers/application.js +++ b/app/controllers/application.js @@ -1,5 +1,6 @@ import Ember from 'ember'; export default Ember.Controller.extend({ - isOn: null + isOn: null, + level: null }); diff --git a/app/routes/application.js b/app/routes/application.js index f7d88d7..820816e 100644 --- a/app/routes/application.js +++ b/app/routes/application.js @@ -1,16 +1,32 @@ import Ember from 'ember'; export default Ember.Route.extend({ + levels: [1,2,3,4], + setupController(controller) { controller.set('isOn', false); }, + actions: { turnOn() { - this.controllerFor('application').set('isOn', true); - this.set('isOn', true); + const c = this.controllerFor('application'); + c.set('isOn', true); + c.set('level', this.get('levels').objectAt(0)); }, turnOff() { - this.controllerFor('application').set('isOn', false); + const c = this.controllerFor('application'); + c.set('isOn', false); + }, + nextLevel() { + if (this.controllerFor('application').get('isOn')) { + const c = this.controllerFor('application'); + const level = c.get('level'); + const levelIndex = this.get('levels').indexOf(level); + const nextLevel = this.get('levels').objectAt( + (levelIndex + 1) % this.get('levels').length + ); + c.set('level', nextLevel); + } } } }); diff --git a/app/templates/application.hbs b/app/templates/application.hbs index fc9fa4b..75606c4 100644 --- a/app/templates/application.hbs +++ b/app/templates/application.hbs @@ -1,6 +1,7 @@
{{#if isOn}} ON + {{level}} {{else}} OFF {{/if}} @@ -13,3 +14,7 @@ + +