Modifying spec file to rely on Common module, and copying the code from it once insta...
[profile/ivi/html5_UI_Dashboard.git] / js / dashboardControler.js
1 /**
2  * @module DashboardApplication
3  */
4
5 /**
6  * Class which provides methods to fill content of dashboard's UI.
7  * @class dashBoardControler
8  * @static
9  */
10
11 var dashBoardControler = function() {
12         "use strict";
13         this.initInfos();
14 };
15
16 /**
17  * Method handles click event on rear left indicator.
18  * @method onRearLDisplayClick
19  */
20 dashBoardControler.prototype.onRearLDisplayClick = function() {
21         "use strict";
22         if (this.RearLDispaly) {
23                 $('#rearLButtonText').removeClass("fontColorSelected");
24                 $('#rearLButtonText').addClass("fontColorNormal");
25                 $('#rearLButtonText').empty();
26                 $('#rearLButtonText').append("OFF");
27                 this.RearLDispaly = false;
28         } else {
29                 $('#rearLButtonText').removeClass("fontColorNormal");
30                 $('#rearLButtonText').addClass("fontColorSelected");
31                 $('#rearLButtonText').empty();
32                 $('#rearLButtonText').append("ON");
33                 this.RearLDispaly = true;
34         }
35 };
36
37 /**
38  * Method handles click event on rear right indicator.
39  * @method onRearRDisplayClick
40  */
41 dashBoardControler.prototype.onRearRDisplayClick = function() {
42         "use strict";
43         if (this.RearRDispaly) {
44                 $('#rearRButtonText').removeClass("fontColorSelected");
45                 $('#rearRButtonText').addClass("fontColorNormal");
46                 $('#rearRButtonText').empty();
47                 $('#rearRButtonText').append("OFF");
48                 this.RearRDispaly = false;
49         } else {
50                 $('#rearRButtonText').removeClass("fontColorNormal");
51                 $('#rearRButtonText').addClass("fontColorSelected");
52                 $('#rearRButtonText').empty();
53                 $('#rearRButtonText').append("ON");
54                 this.RearRDispaly = true;
55         }
56 };
57
58 /**
59  * Method is setting status of child lock.
60  * @method onChildLockChanged
61  * @param newStatus {Boolean} New status of child lock of the car.
62  */
63 dashBoardControler.prototype.onChildLockChanged = function(newStatus) {
64         "use strict";
65         if (newStatus === false || newStatus === "false") {
66                 $('#leftPadlock').removeClass("padlocActive");
67                 $('#leftPadlock').addClass("padlocInactive");
68                 $('#rightPadlock').removeClass("padlocActive");
69                 $('#rightPadlock').addClass("padlocInactive");
70                 $('#childLockText').removeClass("fontColorSelected");
71                 $('#childLockText').addClass("fontColorNormal");
72                 $('#childLockText').empty();
73                 $('#childLockText').append("CHILD LOCK DEACTIVATED");
74         } else {
75                 $('#leftPadlock').removeClass("padlocInactive");
76                 $('#leftPadlock').addClass("padlocActive");
77                 $('#rightPadlock').removeClass("padlocInactive");
78                 $('#rightPadlock').addClass("padlocActive");
79                 $('#childLockText').removeClass("fontColorNormal");
80                 $('#childLockText').addClass("fontColorSelected");
81                 $('#childLockText').empty();
82                 $('#childLockText').append("CHILD LOCK ACTIVATED");
83         }
84 };
85
86 /**
87  * Method is setting status of front lights of the car.
88  * @method onFrontLightsChanged
89  * @param newStatus {Boolean} New status of front lights of car.
90  */
91 dashBoardControler.prototype.onFrontLightsChanged = function(newStatus) {
92         "use strict";
93         if (newStatus === false || newStatus === "false") {
94                 $('#frontLightsButton').css("opacity", "0");
95                 $("#frontLightsImage").css("opacity", "0");
96         } else {
97                 $('#frontLightsButton').css("opacity", "1");
98                 $("#frontLightsImage").css("opacity", "1");
99         }
100 };
101
102 /**
103  * Method is setting value of trasmission gear of the car.
104  * @method onGearChanged
105  * @param newStatus {String} New status value for trasmission gear.
106  */
107 dashBoardControler.prototype.onGearChanged = function(newStatus) {
108         "use strict";
109         $("#engineStatus #gearboxStatus").text(newStatus);
110 };
111
112 /**
113  * Method is setting value of speed of the car.
114  * @method onSpeedChanged
115  * @param newStatus {Number} New value for the speed.
116  */
117 dashBoardControler.prototype.onSpeedChanged = function(newStatus) {
118         "use strict";
119         $("#engineStatus #textIndicator").text(newStatus + " mph");
120 };
121
122 /**
123  * Method is setting value of odometer of the car.
124  * @method onOdoMeterChanged
125  * @param newStatus {Number} New value for the odoMeter.
126  */
127 dashBoardControler.prototype.onOdoMeterChanged = function(newStatus) {
128         "use strict";
129         $("#engineStatus #statusIndicator").text(newStatus + " mi");
130 };
131
132 /**
133  * Method  is setting status of rear lights of the car.
134  * @method onRearLightsChanged
135  * @param newStatus {Boolean} New status of rear lights of car.
136  */
137 dashBoardControler.prototype.onRearLightsChanged = function(newStatus) {
138         "use strict";
139         if (newStatus === false || newStatus === "false") {
140                 $('#rearLightsButton').css("opacity", "0");
141                 $("#rearLightsImage").css("opacity", "0");
142         } else {
143                 $('#rearLightsButton').css("opacity", "1");
144                 $("#rearLightsImage").css("opacity", "1");
145         }
146 };
147 /**
148  * Method  is setting status of break lights of the car.
149  * @method onBreakLightsChanged
150  * @param newStatus {Boolean} New status of break lights of car.
151  */
152 dashBoardControler.prototype.onBreakLightsChanged = function(newStatus) {
153         "use strict";
154         if (newStatus === false || newStatus === "false") {
155                 $("#breakLightsImage").css("opacity", "0");
156         } else {
157                 $("#breakLightsImage").css("opacity", "1");
158         }
159 };
160 /**
161  * Method  is setting status of fan in the car.
162  * @method onFanChanged
163  * @param newStatus {Boolean} New status of fan in the car.
164  */
165 dashBoardControler.prototype.onFanChanged = function(newStatus) {
166         "use strict";
167         if (newStatus === false || newStatus === "false") {
168                 $('#fanCircle').css("opacity", "0");
169                 $("#fanIcon").css("opacity", "0");
170                 $("#fanIcon").css("-webkit-transform", "rotate(0deg)");
171                 $("#fanIcon").css("-moz-transform", "rotate(0deg)");
172                 $("#fanIcon").css("-ms-transform", "rotate(0deg)");
173                 $("#fanIcon").css("-o-transform", "rotate(0deg)");
174                 $('#fanStatus').removeClass("fontColorSelected");
175                 $('#fanStatus').addClass("fontColorNormal");
176         } else {
177                 $('#fanCircle').css("opacity", "1");
178                 $("#fanIcon").css("opacity", "1");
179                 $("#fanIcon").css("-webkit-transform", "rotate(720deg)");
180                 $("#fanIcon").css("-moz-transform", "rotate(720deg)");
181                 $("#fanIcon").css("-ms-transform", "rotate(720deg)");
182                 $("#fanIcon").css("-o-transform", "rotate(720deg)");
183                 $('#fanStatus').removeClass("fontColorNormal");
184                 $('#fanStatus').addClass("fontColorSelected");
185         }
186 };
187
188 /**
189  * Method is setting status of exterior brightness .
190  * @method onExteriorBrightnessChanged
191  * @param newStatus {Boolean} New exterior brightness value.
192  */
193 dashBoardControler.prototype.onExteriorBrightnessChanged = function(newValue) {
194         "use strict";
195         var newValueP = (Math.abs(newValue) / 5000) * 100;
196         if (newValueP > 100) {
197                 newValueP = 100;
198         }
199         $("#exteriorBrightnessProgressBar").progressBarPlugin('setPosition', newValueP);
200 };
201
202 /**
203  * Method is setting new value of battery status.
204  * @method onBatteryStatusChanged
205  * @param newValue {Integer} New battery status value.
206  * @param status {bootstrap.carIndicator.status} Current status object.
207  */
208 dashBoardControler.prototype.onBatteryStatusChanged = function(newValue, status) {
209         "use strict";
210         $("#batteryProgressBar").progressBarPlugin('setPosition', newValue);
211         var newBatteryStatus = newValue.toString() + "%";
212         $('#batteryStatus').empty();
213         $('#batteryStatus').append(newBatteryStatus);
214         var newBatteryRange = "~" + Math.round(((newValue / 100) * status.fullBatteryRange)).toString() + " MI";
215         $('#batteryRange').empty();
216         $('#batteryRange').append(newBatteryRange);
217 };
218
219 /**
220  * Method is setting new value of full battery range.
221  * @method onBatteryRangeChanged
222  * @param newValue {Integer} New full battery range value.
223  * @param status {bootstrap.carIndicator.status} Current status object.
224  */
225 dashBoardControler.prototype.onBatteryRangeChanged = function(newValue, status) {
226         "use strict";
227         var self = this;
228
229         $('#batteryStatus').empty();
230
231         $('#batteryStatus').append(newValue);
232         var newBatteryRange = "~" + Math.round(((status.batteryStatus / 100) * newValue)).toString() + " MI";
233         $('#batteryRange').empty();
234         $('#batteryRange').append(newBatteryRange);
235 };
236
237 /**
238  * Method is setting new value of outside temperature.
239  * @method onOutsiteTempChanged
240  * @param newValue {Number} New outside temperature status value.
241  */
242 dashBoardControler.prototype.onOutsiteTempChanged = function(newValue) {
243         "use strict";
244         var newOutsiteTemp = newValue + "°C";
245         $("#weatherStatus").empty();
246         $("#weatherStatus").append(newOutsiteTemp);
247 };
248
249 /**
250  * Method is setting new value of Avg KW.
251  * @method onAvgKWChanged
252  * @param newValue {Number} New Avg KW status value.
253  */
254 dashBoardControler.prototype.onAvgKWChanged = function(newValue) {
255         "use strict";
256         var newAvgKW = newValue + " KW-H / MI";
257         $("#avgConsumptionCaption").empty();
258         $("#avgConsumptionCaption").append(newAvgKW);
259 };
260
261 /**
262  * Method is setting new value of night mode indicator .
263  * @method onNightModeChanged
264  * @param newValue {Boolean} New value of day/night mode .
265  */
266 dashBoardControler.prototype.onNightModeChanged = function(newValue) {
267         "use strict";
268         if (newValue) {
269                 $("#dayNight").removeClass("dashboardSunElement");
270                 $("#dayNight").addClass("dashboardMoonElement");
271         } else {
272                 $("#dayNight").removeClass("dashboardMoonElement");
273                 $("#dayNight").addClass("dashboardSunElement");
274         }
275
276 };
277
278 /**
279  * Method is setting new value of inside temperature.
280  * @method onInsideTempChanged
281  * @param newValue {Number} New inside temperature status value.
282  */
283 dashBoardControler.prototype.onInsideTempChanged = function(newValue) {
284         "use strict";
285         var newInsiteTemp = newValue + "°F";
286         $("#fanStatus").empty();
287         $("#fanStatus").append(newInsiteTemp);
288 };
289
290 /**
291  * Method is setting new value of weather. Weather is coded to following values:
292  *
293  * * 1 - Cloudy weather
294  * * 2 - Sunny weather
295  * * 3 - Stormy weather
296  *
297  * @method onWeatherChanged
298  * @param newWeater {Integer} New weather status value.
299  */
300 dashBoardControler.prototype.onWeatherChanged = function(newValue) {
301         "use strict";
302         if (newValue === 1) {
303                 $("#dashBoardWeatherIcon").removeClass("dashBoardWeatherSun");
304                 $("#dashBoardWeatherIcon").removeClass("dashBoardWeatherCloudy");
305                 $("#dashBoardWeatherIcon").removeClass("dashBoardWeatherThunder");
306                 $("#dashBoardWeatherIcon").addClass("dashBoardWeatherCloudy");
307
308         } else if (newValue === 2) {
309                 $("#dashBoardWeatherIcon").removeClass("dashBoardWeatherSun");
310                 $("#dashBoardWeatherIcon").removeClass("dashBoardWeatherCloudy");
311                 $("#dashBoardWeatherIcon").removeClass("dashBoardWeatherThunder");
312                 $("#dashBoardWeatherIcon").addClass("dashBoardWeatherSun");
313
314         } else {
315                 $("#dashBoardWeatherIcon").removeClass("dashBoardWeatherSun");
316                 $("#dashBoardWeatherIcon").removeClass("dashBoardWeatherCloudy");
317                 $("#dashBoardWeatherIcon").removeClass("dashBoardWeatherThunder");
318                 $("#dashBoardWeatherIcon").addClass("dashBoardWeatherThunder");
319         }
320 };
321
322 /**
323  * Method is setting new value of angle of front wheels.
324  * @method onWheelAngleChanged
325  * @param newAngle {Integer} New angle status value for wheels.
326  */
327 dashBoardControler.prototype.onWheelAngleChanged = function(newAngle) {
328         "use strict";
329         var maxAngle = 30;
330         if (newAngle > 30) {
331                 newAngle = (-1 * (360 - newAngle));
332         }
333         if (newAngle > maxAngle) {
334                 newAngle = maxAngle;
335         } else if (newAngle < (-maxAngle)) {
336                 newAngle = -maxAngle;
337         } else if (newAngle === "") {
338                 newAngle = 0;
339         }
340
341         var newDuration = Math.round(Math.abs(newAngle) / 10);
342         if (newDuration === 0) {
343                 newDuration = 0.1;
344         }
345         newDuration = 0;
346         $("#leftWhell").css("-webkit-transition", newDuration + "s");
347         $("#leftWhell").css("-webkit-transform", "rotate(" + newAngle + "deg)");
348         $("#rightWhell").css("-webkit-transition", newDuration + "s");
349         $("#rightWhell").css("-webkit-transform", "rotate(" + newAngle + "deg)");
350
351         $("#leftWhell").css("-moz-transition", newDuration + "s");
352         $("#leftWhell").css("-moz-transform", "rotate(" + newAngle + "deg)");
353         $("#rightWhell").css("-moz-transition", newDuration + "s");
354         $("#rightWhell").css("-moz-transform", "rotate(" + newAngle + "deg)");
355
356         $("#leftWhell").css("-ms-transition", newDuration + "s");
357         $("#leftWhell").css("-ms-transform", "rotate(" + newAngle + "deg)");
358         $("#rightWhell").css("-ms-transition", newDuration + "s");
359         $("#rightWhell").css("-ms-transform", "rotate(" + newAngle + "deg)");
360
361         $("#leftWhell").css("-o-transition", newDuration + "s");
362         $("#leftWhell").css("-o-transform", "rotate(" + newAngle + "deg)");
363         $("#rightWhell").css("-o-transition", newDuration + "s");
364         $("#rightWhell").css("-o-transform", "rotate(" + newAngle + "deg)");
365 };
366
367 /**
368  * Method is setting new value of randomizer.
369  * @method onRandomizerChanged
370  * @param newStatus {Boolean} New randomizer status.
371  */
372 dashBoardControler.prototype.onRandomizerChanged = function(newStatus) {
373         "use strict";
374         if (newStatus === false || newStatus === "false") {
375                 $('#randomizer').css("opacity", "0");
376                 $("#randomizer").css("opacity", "0");
377         } else {
378                 $('#randomizer').css("opacity", "1");
379                 $("#randomizer").css("opacity", "1");
380         }
381 };
382
383 /**
384  * Method initialize info status on HTML and jQuery plugins.
385  * @method initInfos
386  */
387 dashBoardControler.prototype.initInfos = function() {
388         "use strict";
389         $("#weatherCaption").boxCaptionPlugin('init', 'weather');
390
391         $("#exteriorBrightnessCaption").boxCaptionPlugin('init', 'Exterior Brightness');
392
393         $("#exteriorBrightnessProgressBar").progressBarPlugin('init', 'progressBar');
394         $("#exteriorBrightnessProgressBar").progressBarPlugin('setPosition', 30);
395
396         $("#batteryLevelCaption").boxCaptionPlugin('init', 'Battery level');
397
398         $("#batteryProgressBar").progressBarPlugin('init', 'progressBar');
399         $("#batteryProgressBar").progressBarPlugin('setPosition', 82);
400
401         $("#avgEConsumption").boxCaptionPlugin('init', 'avg e-consumtion');
402         $("#rearLDisplay").boxCaptionPlugin('init', 'Rear l Display');
403         $("#rearRDisplay").boxCaptionPlugin('init', 'Rear r Display');
404
405         $('#bottomPanel').bottomPanel('init');
406
407         $("#leftFrontPressure").statusBoxPlugin('init', 'PRESSSURE LEVEL', 'L FRONT TIRE', 'OK');
408         $("#rightFrontPressure").statusBoxPlugin('init', 'PRESSSURE LEVEL', 'R FRONT TIRE', 'ok');
409
410         $("#leftRearPressure").statusBoxPlugin('init', 'PRESSSURE LEVEL', 'L Rear TIRE', 'OK');
411         $("#rightRearPressure").statusBoxPlugin('init', 'PRESSSURE LEVEL', 'R Rear TIRE', 'ok');
412
413 };
414 /**
415  * Method is setting new value of left front tire pressure.
416  * @method onTirePressureLeftFrontChanged
417  * @param newValue {FLoat} new tire pressure status. If is status between 1.8 and 2.2 new status value is string "OK".
418  */
419 dashBoardControler.prototype.onTirePressureLeftFrontChanged = function(newValue) {
420         "use strict";
421         $("#leftFrontPressure").statusBoxPlugin('init', 'PRESSSURE LEVEL', 'L FRONT TIRE', newValue);
422 };
423 /**
424  * Method is setting new value of right front tire pressure.
425  * @method onTirePressureRightFrontChanged
426  * @param newValue {FLoat} new tire pressure status. If is status between 1.8 and 2.2 new status value is string "OK".
427  */
428 dashBoardControler.prototype.onTirePressureRightFrontChanged = function(newValue) {
429         "use strict";
430         $("#rightFrontPressure").statusBoxPlugin('init', 'PRESSSURE LEVEL', 'R FRONT TIRE', newValue);
431 };
432 /**
433  * Method is setting new value of left rear tire pressure.
434  * @method onTirePressureLeftRearChanged
435  * @param newValue {FLoat} new tire pressure status. If is status between 1.8 and 2.2 new status value is string "OK".
436  */
437 dashBoardControler.prototype.onTirePressureLeftRearChanged = function(newValue) {
438         "use strict";
439         $("#leftRearPressure").statusBoxPlugin('init', 'PRESSSURE LEVEL', 'L Rear TIRE', newValue);
440 };
441 /**
442  * Method is setting new value of right rear tire pressure.
443  * @method onTirePressureRightRearChanged
444  * @param newValue {FLoat} new tire pressure status. If is status between 1.8 and 2.2 new status value is string "OK".
445  */
446 dashBoardControler.prototype.onTirePressureRightRearChanged = function(newValue) {
447         "use strict";
448         $("#rightRearPressure").statusBoxPlugin('init', 'PRESSSURE LEVEL', 'R Rear TIRE', newValue);
449 };