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 General list component for SDL application
31 * @filesource app/controlls/List.js
35 SDL.List = Em.ContainerView.extend( {
39 /** flag for scrollbar */
40 disableScrollbar: true,
42 /** Set count of items at one time */
45 /** Speed of scrolling in milliseconds */
48 /** Number of columns on page */
53 /** Current scroll page */
56 /** Css style of list */
57 listScrollingAttributes: '',
59 /** Count of items in menu */
61 * listCount: function(){ if( this.items ) { return this.items.length; }
62 * }.property('items.@each.type'),
64 listCount: function() {
65 // console.log(this.get('this.list.childViews.length'));
66 return this.get( 'this.list.childViews.length' );
67 }.property( 'this.list.childViews.length' ),
70 pageCount: function() {
71 return Math.ceil( this.get( 'listCount' ) / this.get( 'columnsNumber' ) / this.get( 'itemsOnPage' ) );
72 }.property( 'listCount', 'itemsOnPage' ),
74 listHeight: function() {
75 return this.itemsOnPage * this.itemheight;
76 }.property( 'itemsOnPage' ),
78 /** Action of element "sb-top" which show previous list page */
80 if( this.get( 'currentPage' ) > 0 ){
81 this.set( 'currentPage', this.get( 'currentPage' ) - 1 );
85 /** Action of element "sb-bottom" which show previous list page */
87 if( this.get( 'currentPage' ) < this.get( 'pageCount' ) - 1 ){
88 this.set( 'currentPage', this.get( 'currentPage' ) + 1 );
92 /** Scroll content according to current page */
93 onCurrentPageChange: function() {
94 this.set( 'listScrollingAttributes', 'margin-top: ' + ( this.get( 'currentPage' ) * this.itemsOnPage * ( -50 ) ) + 'px' );
95 }.observes( 'currentPage' ),
97 /** Method for delete certain item from list */
98 deleteItem: function( id ) {
99 this.items.splice( id, 1 );
103 /** List components */
111 list: Em.ContainerView.extend( {
113 classNames: 'list-content',
115 listStyleBinding: 'parentView.listScrollingAttributes',
122 refresh: function() {
124 }.observes( '_parentView.items.@each.type' ),
126 afterRender: function() {
127 var items = this._parentView.items, element, i, key, binding;
129 for( i = 0; i < items.length; i++ ){
131 element = items[i].type.create( {
133 elementId: this._parentView.elementId + '_item' + i,
135 // list item css class
136 classNames: 'list-item',
143 // Dynamic property set
145 for( key in items[i].params ){
146 if( key.match( 'Binding' ) != null ){
147 binding = Ember.Binding.from( items[i].params[key] ).to( key.replace( 'Binding', '' ) );
148 binding.connect( this );
149 // Set one way binding
152 this.set( key, items[i].params[key] );
156 // synchronize bindings
161 // Push element to list
162 this.get( 'childViews' ).pushObject( element );
167 /** Scrollbar view */
168 scrollbar: SDL.ScrollBar.extend( {
169 currentPageBinding: 'parentView.currentPage',
170 pageCountBinding: 'parentView.pageCount',
171 listHeightBinding: 'parentView.listHeight',
172 scrollBarIsDisabledBinding: 'parentView.disableScrollbar'