Updated GhostCluster web sample from upstream
[profile/ivi/sdk/web-sample-build.git] / samples / web / Sample / Tizen / Web App / Modello_SDL / project / app / model / sdl / AppModel.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.SDLAppModel
29  * @desc Abstarct model for SDL applications
30  * @category Model
31  * @filesource app/model/sdl/AppModel.js
32  * @version 1.0
33  */
34
35 SDL.SDLAppModel = Em.Object.extend( {
36
37     /**
38      * Application Id
39      *
40      * @type {Number}
41      */
42     appId: null,
43
44     /**
45      * Application name
46      *
47      * @type {String}
48      */
49     appName: '',
50
51     /**
52      * Chosen device name
53      *
54      * @type {String}
55      */
56     deviceName: '',
57
58     /**
59      * Statusbar text
60      *
61      * @type {String}
62      */
63     statusText: '',
64
65     /**
66      * Info data
67      *
68      * @type: {Em.Object}
69      */
70     appInfo: null,
71
72     /**
73      * Current language of applications UI component
74      *
75      * @type {String}
76      */
77     UILanguage: 'EN-US',
78
79     /**
80      * Current language of applications TTS and applications VR component
81      *
82      * @type {String}
83      */
84     TTSVRLanguage: 'EN-US',
85
86     /**
87      * Array of Soft Buttons
88      *
89      * @type {Array}
90      */
91     softButtons: [],
92
93     /**
94      * Array of Objects for TBTTurnList
95      *
96      * @type {Array}
97      */
98     turnList: [],
99
100     /**
101      * URL to application Icon
102      *
103      * @type {String}
104      */
105     appIcon: 'images/info/info_leftMenu_apps_ico.png',
106
107     /**
108      * Application commands list
109      *
110      * @type {Array}
111      */
112     commandsList: [],
113
114     /**
115      * Return current menu commands
116      *
117      * @return {Array}
118      */
119     currentCommandsList: function() {
120         return this.get( 'commandsList' ).filterProperty( 'parent', this.get( 'currentSubMenuId' ) );
121     }.property( 'this.commandsList.@each', 'this.currentSubMenuId' ),
122
123     /**
124      * Current command submenu identificator
125      *
126      * @type {Number}
127      */
128     currentSubMenuId: 0,
129
130     /**
131      * Return current submenu name
132      *
133      * @return {String}
134      */
135     currentSubMenuLabel: function() {
136         var submenu = this.get( 'commandsList' ).filterProperty( 'menuId', this.get( 'currentSubMenuId' ) );
137         return submenu.length ? submenu[0].name : 'Options';
138     }.property( 'this.currentSubMenuId' ),
139
140     /**
141      * Interaction chooses data
142      *
143      * @type {Object}
144      */
145     interactionChoices: {},
146
147     /**
148      * Update Soft Buttons will handle on command Show
149      *
150      * @param {Array}
151      */
152     updateSoftButtons: function( buttons ) {
153         // delete existing buttons from array
154         this.softButtons.splice( 0 );
155
156         // push new buttons to array
157         this.get( 'softButtons' ).pushObjects( buttons );
158     },
159
160     /**
161      * Add command to list
162      *
163      * @param {Object}
164      */
165     addCommand: function( params ) {
166
167         this.get( 'commandsList' ).pushObject( {
168             commandId: params.cmdId,
169             name: params.menuParams.menuName,
170             parent: params.menuParams.parentID ? params.menuParams.parentID : 0,
171             position: params.menuParams.position,
172             icon: params.cmdIcon ? params.cmdIcon.value : null
173         } );
174     },
175
176     /**
177      * Delete command from list
178      *
179      * @param {Number}
180      */
181     deleteCommand: function( commandId ) {
182
183         this.get( 'commandsList' ).removeObjects( this.get( 'commandsList' ).filterProperty( 'commandId', commandId ) );
184     },
185
186     /**
187      * Add submenu to commands list
188      *
189      * @param {Object}
190      */
191     addSubMenu: function( params ) {
192
193         this.get( 'commandsList' ).pushObject( {
194             menuId: params.menuId,
195             name: params.menuName,
196             parent: 0,
197             position: params.position
198         } );
199     },
200
201     /**
202      * Delete submenu and related commands from list
203      *
204      * @param {Number}
205      */
206     deleteSubMenu: function( menuId ) {
207
208         // don't delete if current submenu active
209         if( this.get( 'currentSubMenuId' ) == menuId ){
210             return 'IN_USE';
211             // SDL.SDLAppController.onSubMenu(0);
212         }
213
214         // remove submenu
215         this.get( 'commandsList' ).removeObjects( this.get( 'commandsList' ).filterProperty( 'menuId', menuId ) );
216
217         // remove commands from deleted submenu
218         this.get( 'commandsList' ).removeObjects( this.get( 'commandsList' ).filterProperty( 'parent', menuId ) );
219
220         return 'SUCCESS';
221     },
222
223     /**
224      * SDL UI PreformInteraction response handeler open Perform Interaction
225      * screen and show choices
226      *
227      * @param {Object} message
228      * @param {Number} performInteractionRequestId
229      */
230     onPreformInteraction: function( message, performInteractionRequestId ) {
231
232         var i = 0, length = message.interactionChoiceSetIDList.length;
233
234         SDL.InteractionChoicesView.clean();
235
236         for( i = 0; i < length; i++ ){
237             var choiceSetId = message.interactionChoiceSetIDList[i];
238             SDL.InteractionChoicesView.preformChoices( this.interactionChoices[choiceSetId], performInteractionRequestId, message.timeout );
239
240             SDL.VRPopUp.CreateInteractionChoise( this.interactionChoices[choiceSetId], performInteractionRequestId );
241         }
242
243         SDL.InteractionChoicesView.activate( message.initialText );
244
245         // Show Initial prompt
246         SDL.SDLModel.onPrompt( message.initialPrompt );
247     },
248
249     /**
250      * SDL UI CreateInteraction response handeler push set of commands to voice
251      * recognition list
252      *
253      * @param {Object}
254      */
255     onCreateInteraction: function( message ) {
256
257         this.interactionChoices[message.interactionChoiceSetID] = message.choiceSet;
258
259     },
260
261     /**
262      * SDL UI DeleteInteraction response handeler close current interaction set
263      * window (if opened) and delete current set commands from voice recognition
264      * list
265      *
266      * @param {Object}
267      */
268     onDeleteInteraction: function( message ) {
269         delete this.interactionChoices[message.interactionChoiceSetID];
270     },
271
272     /**
273      * SDL UI Slider response handeler open Slider window with received
274      * parameters
275      *
276      * @param {Object}
277      */
278     onSlider: function( message ) {
279
280         SDL.SliderView.loadData( message );
281
282         SDL.SliderView.activate( this.appName );
283
284         setTimeout( function() {
285             if( SDL.SliderView.active ){
286                 SDL.SliderView.deactivate();
287             }
288         }, message.params.timeout );
289     }
290 } );