Add Modello web sample applications; version up
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / Modello_SDL / project / app / controlls / ScrollableText.js
1 /*
2  * Copyright (c) 2013, Ford Motor Company All rights reserved.
3  *
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.
14  *
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.
26  */
27 /**
28  * @name SDL.ScrollableText
29  * @desc General ScrollableText component
30  * @category Controlls
31  * @filesource app/controlls/scrollableText.js
32  * @version 1.0
33  */
34
35 SDL.ScrollableText = Em.ContainerView.extend( {
36
37     classNames: 'scrollableText',
38
39     /** flag for scrollbar */
40     disableScrollbar: false,
41
42     /** Set count of items at one time */
43     itemsOnPage: 0,
44
45     /** Speed of scrolling in milliseconds */
46     scrollBarSpeed: 200,
47
48     /** Number of columns on page */
49     columnsNumber: 1,
50
51     itemheight: 50,
52
53     /** Current scroll page */
54     currentPage: 0,
55
56     /** Css style of scrollableText */
57     scrollableTextScrollingAttributes: '',
58
59     /** Css style of line-height of rows */
60     linesHeght: 23,
61
62     linesCount: 1,
63
64     scrollHeight: null,
65
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 );
72         }
73     },
74
75     /** Pages count */
76     pageCount: function() {
77         return Math.ceil( this.get( 'linesCount' ) / this.get( 'itemsOnPage' ) );
78     }.property( 'linesCount', 'itemsOnPage' ),
79
80     scrollableTextHeight: function() {
81         return this.itemsOnPage * this.itemheight;
82     }.property( 'itemsOnPage' ),
83
84     /** Action of element "sb-top" which show previous scrollableText page */
85     sbUp: function() {
86         if( this.get( 'currentPage' ) > 0 ){
87             this.set( 'currentPage', this.get( 'currentPage' ) - 1 );
88         }
89     },
90
91     /** Action of element "sb-bottom" which show previous scrollableText page */
92     sbDown: function() {
93         if( this.get( 'currentPage' ) < this.get( 'pageCount' ) - 1 ){
94             this.set( 'currentPage', this.get( 'currentPage' ) + 1 );
95         }
96     },
97
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' ),
102
103     /** Method for delete certain item from scrollableText */
104     deleteItem: function( id ) {
105         this.items.splice( id, 1 );
106         this.scrollableText.refresh();
107     },
108
109     /** scrollableText components */
110     childViews:
111         [
112             'scrollbar',
113         // 'scrollableText'
114         ],
115
116     refreshTextArea: function() {
117         if( this.get( 'childViews' )[1] ){
118             this.get( 'childViews' ).removeObject( this.get( 'childViews' )[1] );
119         }
120
121         $( '#scrollableTextArea' ).height( 23 );
122         this.set( 'scrollHeight', 23 );
123         this.set( 'linesCount', 1 );
124         this.set( 'currentPage', 0 );
125
126         this.get( 'childViews' ).pushObject( Ember.TextArea.create( {
127
128             classNames: 'scrollableTextArea',
129
130             elementId: 'scrollableTextArea',
131
132             scrollableTextStyleBinding: 'parentView.scrollableTextScrollingAttributes',
133
134             attributeBindings:
135                 [
136                     'scrollableTextStyle:style'
137                 ],
138
139             valueBinding: 'this.parentView.items',
140
141             actionDown: function() {
142                 return false;
143             },
144
145             didInsertElement: function() {
146                 this.get( 'parentView' ).scrollableTextCount();
147             }
148         } ) );
149     }.observes( 'items' ),
150
151     /** scrollableText view */
152     scrollableText: Ember.TextArea.extend( {
153
154         classNames: 'scrollableTextArea',
155
156         elementId: 'scrollableTextArea',
157
158         scrollableTextStyleBinding: 'parentView.scrollableTextScrollingAttributes',
159
160         attributeBindings:
161             [
162                 'scrollableTextStyle:style'
163             ],
164
165         valueBinding: 'this.parentView.items',
166
167         actionDown: function() {
168             return false;
169         },
170
171         didInsertElement: function() {
172             this._parentView.scrollableTextCount();
173         },
174
175         refresh: function() {
176             this.rerender();
177         }.observes( '_parentView.items' )
178
179     } ),
180
181     /** Scrollbar view */
182     scrollbar: SDL.ScrollBar.extend( {
183         currentPageBinding: 'parentView.currentPage',
184         pageCountBinding: 'parentView.pageCount',
185         scrollableTextHeightBinding: 'parentView.scrollableTextHeight',
186         scrollBarIsDisabledBinding: 'parentView.disableScrollbar'
187     } )
188 } );