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.
28 * @name SDL.ScrollableText
29 * @desc General ScrollableText component
31 * @filesource app/controlls/scrollableText.js
35 SDL.ScrollableText = Em.ContainerView.extend( {
37 classNames: 'scrollableText',
39 /** flag for scrollbar */
40 disableScrollbar: false,
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 scrollableText */
57 scrollableTextScrollingAttributes: '',
59 /** Css style of line-height of rows */
66 scrollableTextCount: function() {
67 if( $( '#' + this.get( 'childViews' )[1].elementId ) ){
68 $( '#' + this.get( 'childViews' )[1].elementId ).removeAttr( 'style' );
69 this.set( 'scrollHeight', $( '#' + this.get( 'childViews' )[1].elementId )[0].scrollHeight );
70 $( '#' + this.get( 'childViews' )[1].elementId ).height( this.scrollHeight );
71 this.set( 'linesCount', $( '#' + this.get( 'childViews' )[1].elementId )[0].scrollHeight / this.linesHeght );
76 pageCount: function() {
77 return Math.ceil( this.get( 'linesCount' ) / this.get( 'itemsOnPage' ) );
78 }.property( 'linesCount', 'itemsOnPage' ),
80 scrollableTextHeight: function() {
81 return this.itemsOnPage * this.itemheight;
82 }.property( 'itemsOnPage' ),
84 /** Action of element "sb-top" which show previous scrollableText page */
86 if( this.get( 'currentPage' ) > 0 ){
87 this.set( 'currentPage', this.get( 'currentPage' ) - 1 );
91 /** Action of element "sb-bottom" which show previous scrollableText page */
93 if( this.get( 'currentPage' ) < this.get( 'pageCount' ) - 1 ){
94 this.set( 'currentPage', this.get( 'currentPage' ) + 1 );
98 /** Scroll content according to current page */
99 onCurrentPageChange: function() {
100 this.set( 'scrollableTextScrollingAttributes', 'height: ' + this.scrollHeight + 'px; top: ' + ( this.get( 'currentPage' ) * this.itemsOnPage * ( -23 ) ) + 'px' );
101 }.observes( 'currentPage' ),
103 /** Method for delete certain item from scrollableText */
104 deleteItem: function( id ) {
105 this.items.splice( id, 1 );
106 this.scrollableText.refresh();
109 /** scrollableText components */
116 refreshTextArea: function() {
117 if( this.get( 'childViews' )[1] ){
118 this.get( 'childViews' ).removeObject( this.get( 'childViews' )[1] );
121 $( '#scrollableTextArea' ).height( 23 );
122 this.set( 'scrollHeight', 23 );
123 this.set( 'linesCount', 1 );
124 this.set( 'currentPage', 0 );
126 this.get( 'childViews' ).pushObject( Ember.TextArea.create( {
128 classNames: 'scrollableTextArea',
130 elementId: 'scrollableTextArea',
132 scrollableTextStyleBinding: 'parentView.scrollableTextScrollingAttributes',
136 'scrollableTextStyle:style'
139 valueBinding: 'this.parentView.items',
141 actionDown: function() {
145 didInsertElement: function() {
146 this.get( 'parentView' ).scrollableTextCount();
149 }.observes( 'items' ),
151 /** scrollableText view */
152 scrollableText: Ember.TextArea.extend( {
154 classNames: 'scrollableTextArea',
156 elementId: 'scrollableTextArea',
158 scrollableTextStyleBinding: 'parentView.scrollableTextScrollingAttributes',
162 'scrollableTextStyle:style'
165 valueBinding: 'this.parentView.items',
167 actionDown: function() {
171 didInsertElement: function() {
172 this._parentView.scrollableTextCount();
175 refresh: function() {
177 }.observes( '_parentView.items' )
181 /** Scrollbar view */
182 scrollbar: SDL.ScrollBar.extend( {
183 currentPageBinding: 'parentView.currentPage',
184 pageCountBinding: 'parentView.pageCount',
185 scrollableTextHeightBinding: 'parentView.scrollableTextHeight',
186 scrollBarIsDisabledBinding: 'parentView.disableScrollbar'