Updated GhostCluster web sample from upstream
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / Modello_SDL / project / app / view / sdl / AlertManeuverPopUp.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.AlertManeuverPopUp
29  * @desc AlertManeuverPopUp module visual representation
30  * @category View
31  * @filesource app/view/sdl/AlertManeuverPopUp.js
32  * @version 1.0
33  */
34
35 SDL.AlertManeuverPopUp = Em.ContainerView.create( {
36
37     elementId: 'AlertManeuverPopUp',
38
39     classNames: 'AlertManeuverPopUp',
40
41     classNameBindings:
42         ['activate:AlertManeuverActive'
43         ],
44
45     childViews:
46         [
47             'applicationName',
48             // 'image',
49             // 'message1',
50             // 'message2',
51             // 'message3',
52             'softbuttons',
53             'closeButton'
54         ],
55
56     content1: 'Title',
57
58     content2: 'Text',
59
60     activate: false,
61
62     timer: null,
63
64     /**
65      * Wagning image on Alert Maneuver PopUp
66      */
67     image: Em.View.extend( {
68         elementId: 'alertManeuverPopUpImage',
69
70         classNames: 'alertManeuverPopUpImage'
71     } ),
72
73     applicationName: SDL.Label.extend( {
74
75         elementId: 'applicationName',
76
77         classNames: 'applicationName',
78
79         contentBinding: 'parentView.appName'
80     } ),
81
82     message1: SDL.Label.extend( {
83
84         elementId: 'message1',
85
86         classNames: 'message1',
87
88         contentBinding: 'parentView.content1'
89     } ),
90
91     message2: SDL.Label.extend( {
92
93         elementId: 'message2',
94
95         classNames: 'message2',
96
97         contentBinding: 'parentView.content2'
98     } ),
99
100     message3: SDL.Label.extend( {
101
102         elementId: 'message3',
103
104         classNames: 'message3',
105
106         contentBinding: 'parentView.content3'
107     } ),
108
109     /**
110      * Container for softbuttons
111      */
112     softbuttons: Em.ContainerView.extend( {
113         elementId: 'alertManeuverSoftButtons',
114
115         classNames: 'alertManeuverSoftButtons'
116     } ),
117
118     /**
119      * Close button
120      */
121     closeButton: SDL.Button.create( {
122         text: 'Close',
123         classNames: 'closeButton softButton',
124         action: 'closeAlertMeneuverPopUp',
125         target: 'SDL.SDLController',
126         templateName: 'text'
127     } ),
128
129     /**
130      * @desc Function creates Soft Buttons on AlertPoUp
131      * @param {Object} params
132      */
133     addSoftButtons: function( params ) {
134
135         var count = this.get( 'softbuttons' ).removeAllChildren();
136
137         if( params ){
138
139             var softButtonsClass;
140             switch( params.length ){
141                 case 1:
142                     softButtonsClass = 'one';
143                     break;
144                 case 2:
145                     softButtonsClass = 'two';
146                     break;
147                 case 3:
148                     softButtonsClass = 'three';
149                     break;
150                 case 4:
151                     softButtonsClass = 'four';
152                     break;
153             }
154
155             for( var i = 0; i < params.length; i++ ){
156                 this.get( 'softbuttons.childViews' ).pushObject( SDL.Button.create( SDL.PresetEventsCustom, {
157                     softButtonID: params[i].softButtonID,
158                     icon: params[i].image,
159                     text: params[i].text,
160                     classNames: 'list-item softButton ' + softButtonsClass,
161                     elementId: 'softButton' + i,
162                     templateName: params[i].image ? 'rightIcon' : 'text',
163                     systemAction: params[i].systemAction
164                 } ) );
165             }
166         }
167     },
168
169     AlertManeuverActive: function( message ) {
170         var self = this;
171
172         // play audio alert
173         if( message.playTone ){
174             SDL.Audio.play( 'audio/alert.wav' );
175         }
176
177         this.addSoftButtons( message.softButtons );
178         if( message.ttsChunks ){
179             SDL.SDLModel.onPrompt( message.ttsChunks.ttsChunks );
180         }
181
182         this.set( 'appName', SDL.SDLController.getApplicationModel( message.appId ).appName );
183
184         this.set( 'activate', true );
185
186         clearTimeout( this.timer );
187         this.timer = setTimeout( function() {
188             self.set( 'activate', false );
189         }, 5000 );
190     }
191 } );