2 * Copyright (c) 2013, Ford Motor Company All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * · Redistributions of source code must retain the above copyright notice,
7 * this list of conditions and the following disclaimer.
8 * · Redistributions in binary form must reproduce the above copyright notice,
9 * this list of conditions and the following disclaimer in the documentation
10 * and/or other materials provided with the distribution.
11 * · Neither the name of the Ford Motor Company nor the names of its
12 * contributors may be used to endorse or promote products derived from this
13 * software without specific prior written permission.
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
29 * @desc Universal button component with value indicator for SDL application
31 * @filesource app/controlls/Indicator.js
35 SDL.Indicator = Em.View.extend( Ember.TargetActionSupport, {
37 /** Content binding */
40 /** internal indicators array */
43 /** indicator active class */
46 /** indicator default class */
47 indDefaultClass: null,
49 /** Set active indicator from the start */
52 /** binding property to enable/disable indicators */
53 enabledBinding: 'content.enabled',
56 * Before rendering view handeler need to generate indicators array based on
57 * indicator range value
59 beforeRender: function() {
61 var length = this.content.range, view = this, i;
63 // generate indicators
66 for( i = 0; i < length; i++ ){
67 this.indicators.push( Em.Object.create( {
69 className: this.indDefaultClass
72 // apply indicator visualization rule
76 this.indicators[this.startFrom].set( 'className', this.indActiveClass );
79 // add observer to content record
80 this.addObserver( 'content', function() {
85 this.applyAttributesToBuffer( this.buffer );
88 actionDown: function() {
92 // change record binding
93 setRecord: function() {
97 if( this.content.observersForKey( 'value' ).length == 0 ){
99 this.content.addObserver( 'value', function() {
100 view.toggleIndicators();
105 this.toggleIndicators();
108 // Toggle indicator handeler
109 toggleIndicators: function() {
111 var length = this.indicators.length, i;
113 for( i = 0; i < length; i++ ){
114 if( i >= this.content.value ){
115 this.indicators[i].set( 'className', 'SDL_indicator ' + this.indDefaultClass );
117 this.indicators[i].set( 'className', 'SDL_indicator ' + this.indActiveClass );
122 /** Define indicator template */
123 template: Ember.Handlebars.compile( '{{#with view}}' + '{{#each indicators}}' + '<div {{bindAttr class="className view.enabled:show"}}></div>' + '{{/each}}' + '{{/with}}' )