Permalink
Browse files

BarView: bind bar classes to status

  • Loading branch information...
1 parent 9d21187 commit 0df7aecf34b6bb267d426f503b41bed859748e79 James A. Rosen committed Sep 23, 2012
Showing with 13 additions and 2 deletions.
  1. +8 −2 lib/BarView.js
  2. +5 −0 spec/javascripts/BarView.spec.js
View
@@ -1,9 +1,10 @@
Ember.ProgressBars = Ember.ProgressBars || {};
Ember.ProgressBars.Bar = Ember.View.extend({
- template: Em.Handlebars.compile('<div class="bar"></div>'),
+ template: Em.Handlebars.compile('<div class="bar" {{bindAttr class="statusClass"}}></div>'),
percent: 0,
+ status: undefined,
init: function() {
var classNames = this.get('classNames') || [];
@@ -15,5 +16,10 @@ Ember.ProgressBars.Bar = Ember.View.extend({
onPercentChange: function() {
var percent = this.get('percent') || 0;
this.$('.bar').css('width', "%@%".fmt(percent) );
- }.observes('percent')
+ }.observes('percent'),
+
+ statusClass: Ember.computed(function() {
+ var status = this.get('status');
+ return status == null ? '' : 'bar-%@'.fmt(status);
+ }).property('status').cacheable()
});
@@ -39,6 +39,11 @@ describe('ProgressBars.Bar', function() {
it('accepts extra classes for the container', function() {
expect( bar.$().is('.progress.progress-striped.active') ).toBe(true);
});
+
+ it("accepts a status that is used as a class on the bar", function() {
+ Em.run(function() { bar.set('status', 'warning'); });
+ expect( bar.$('.bar').is('.bar-warning') ).toBe(true);
+ });
});
});

0 comments on commit 0df7aec

Please sign in to comment.