[jslint] Enable js lint and fix the errors.
[platform/framework/web/tizen-extensions-crosswalk.git] / demos / system_info / js / system_info.js
1 // Copyright (c) 2013 Intel Corporation. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 function BatteryInfo() {
6   this.level = $('<p></p>').addClass('center');
7   this.charging = $('<p></p>').addClass('center');
8   $('#battery_data').append(this.level, this.charging);
9
10   this.draw_graph = function draw_graph(BATDATA) {
11     $('#battery_container div span').css('width', BATDATA.level * 100 + '%');
12     if (BATDATA.isCharging) {
13       $('#battery_container div').addClass('shine');
14     } else {
15       $('#battery_container div').removeClass('shine');
16     }
17   };
18
19   this.getInfo = function getInfo(BATTERY) {
20     tizen.systeminfo.getPropertyValue(
21         'BATTERY',
22         function(battery) {
23           BATTERY.draw_graph(battery);
24           BATTERY.charging.text(battery.isCharging ? 'Charging' : 'No Charging');
25           BATTERY.level.text(battery.level * 100 + '%');
26         },
27         null);
28     tizen.systeminfo.addPropertyValueChangeListener(
29         'BATTERY',
30         function(battery) {
31           BATTERY.draw_graph(battery);
32           BATTERY.charging.text(battery.isCharging ? 'Charging' : 'No Charging');
33           BATTERY.level.text(battery.level * 100 + '%');
34         });
35   };
36 }
37
38 function BuildInfo() {
39   this.model = $('<p></p>').addClass('center');
40   this.manufacturer = $('<p></p>').addClass('center');
41   this.build_version = $('<p></p>').addClass('center');
42   $('#build').append(this.model, this.manufacturer, this.build_version);
43
44   this.getInfo = function getInfo(BUILD) {
45     tizen.systeminfo.getPropertyValue(
46         'BUILD',
47         function(build) {
48           BUILD.model.text('MODEL: ' + build.model);
49           BUILD.manufacturer.text('MANUFACTURE: ' + build.manufacturer);
50           BUILD.build_version.text('BUILDVERSION: ' + build.buildVersion);
51         },
52         null);
53     tizen.systeminfo.addPropertyValueChangeListener(
54         'BUILD',
55         function(build) {
56           BUILD.model.text('MODEL: ' + build.model);
57           BUILD.manufacturer.text('MANUFACTURE: ' + build.manufacturer);
58           BUILD.build_version.text('BUILDVERSION: ' + build.buildVersion);
59         });
60   };
61 }
62
63 function CellularNetworkInfo() {
64   this.status = $('<p></p>').text('CELLULAR is OFF');
65   this.apn_imei = $('<p></p>');
66   this.ip_address = $('<p></p>');
67   this.ipv6_address = $('<p></p>');
68   this.short_info = $('<p></p>');
69   this.bool_info = $('<p></p>');
70   $('#cellular_network_info').append(this.status, this.apn_imei,
71                                      this.ip_address, this.ipv6_address,
72                                      this.short_info, this.bool_info);
73
74   this.change_cellular = function change_cellular(cellular) {
75     if (cellular.status == 'ON') {
76       this.status.text('CELLULAR: ' + cellular.status);
77       this.apn_imei.text('APN: ' + cellular.apn + '  ' +
78                          'IMEI: ' + cellular.imei);
79       this.ip_address.text('IP ADDRESS: ' + cellular.ipAddress);
80       this.ipv6_address.text('IPV6 ADDRESS: ' + cellular.ipv6Address);
81       this.short_info.text('MCC: ' + cellular.mcc + '  ' +
82                            'MNC: ' + cellular.mnc + '  ' +
83                            'CELLID: ' + cellular.cellId + '  ' +
84                            'LAC: ' + cellular.lac);
85       this.bool_info.text(cellular.isRoaming ? 'Roaming' : 'NoRoaming' +
86                           cellular.isFlightMode ? 'Flight' : 'NoFlight');
87     } else {
88       this.status.text('CELLULAR IS OFF!');
89     }
90   };
91
92   this.getInfo = function getInfo(CELLULAR) {
93     tizen.systeminfo.getPropertyValue(
94         'CELLULAR_NETWORK',
95         function(cellular) {
96           CELLULAR.change_cellular(cellular);
97         },
98         null);
99     tizen.systeminfo.addPropertyValueChangeListener(
100         'CELLULAR_NETWORK',
101         function(cellular) {
102           CELLULAR.change_cellular(cellular);
103         });
104   };
105 }
106
107
108 function CPUInfo() {
109   this.cpu_container = document.getElementById('cpu_container');
110   this.cpu_data = [];
111   this.cpu_data_size = 200;
112   this.cpu_graph = null;
113   this.graph_lines = {
114     data: [],
115     label: 'CPU',
116     lines: {
117       show: true,
118       fill: true,
119       fillColor: {
120         colors: ['#f00', '#fdd'],
121         getInfo: 'top',
122         end: 'bottom'
123       },
124       fillOpacity: 1
125     }
126   };
127   this.graph_yaxis = {
128     title: 'USAGE',
129     noTicks: 6,
130     tickFormatter: function(n) {return n + '%';},
131     max: 100,
132     min: -5,
133     color: '#fff',
134     autoScale: true
135   };
136   this.graph_xaxis = {
137     title: 'TIME',
138     noTicks: true,
139     ticks: [[0, 'PAST'], [200, 'FUTURE']],
140     max: 200,
141     min: 0
142   };
143   this.graph_grid = {
144     backgroundColor: {
145       colors: [[0, '#fff'], [1, '#bbb']],
146       getInfo: 'top',
147       end: 'bottom'
148     }
149   };
150
151   this.cpu_animate = function cpu_animate(CPU, length) {
152     if (CPU.cpu_data.length <= CPU.cpu_data_size) {
153       CPU.cpu_data.push(CPU.cpu_data[length - 1]);
154     } else {
155       CPU.cpu_data.push(CPU.cpu_data[length - 1]);
156       CPU.cpu_data.shift();
157     }
158
159     CPU.graph_lines.data = [];
160     for (var i = 0; i < CPU.cpu_data.length; ++i) {
161       CPU.graph_lines.data.push([i, CPU.cpu_data[i]]);
162     }
163
164     while (CPU.cpu_data[length - 1] > CPU.graph_yaxis.max) {
165       CPU.graph_yaxis.max += 50;
166     }
167
168     CPU.cpu_graph = Flotr.draw(CPU.cpu_container,
169         [CPU.graph_lines], {
170           title: CPU.cpu_data[length - 1] + '%',
171           yaxis: CPU.graph_yaxis,
172           xaxis: CPU.graph_xaxis,
173           grid: CPU.graph_grid,
174           legend: {position: 'nw'}
175         }
176         );
177
178     setTimeout(function() {
179       CPU.cpu_animate(CPU, CPU.cpu_data.length);
180     }, 50);
181   };
182
183   this.getInfo = function getInfo(CPU) {
184     tizen.systeminfo.getPropertyValue(
185         'CPU',
186         function(cpu) {
187           CPU.cpu_data.push((cpu.load * 100).toFixed(1));
188         },
189         null);
190     CPU.cpu_animate(CPU, CPU.cpu_data.length);
191     tizen.systeminfo.addPropertyValueChangeListener(
192         'CPU',
193         function(cpu) {
194           if (CPU.cpu_data.length < CPU.cpu_data_size) {
195             CPU.cpu_data.push((cpu.load * 100).toFixed(1));
196           } else {
197             CPU.cpu_data.shift();
198             CPU.cpu_data.push((cpu.load * 100).toFixed(1));
199           }
200         });
201   };
202 }
203
204 function DeviceOrientationInfo() {
205   this.status = $('<p></p>');
206   this.auto_rotation = $('<p></p>');
207   $('#deviceorientation').append(this.status, this.auto_rotation);
208
209   this.change_status = function change_status(status) {
210     switch (status) {
211       case 'PORTRAIT_PRIMARY':
212         $('#ball').css('-webkit-animation', 'jump-pp 1s infinite');
213         $('#ball').css('animation', 'jump-pp 1.5s infinite');
214         $('#ball').removeClass();
215         $('#ball').addClass('ball-top');
216         break;
217       case 'PORTRAIT_SECONDARY':
218         $('#ball').css('-webkit-animation', 'jump-ps 1s infinite');
219         $('#ball').css('animation', 'jump-ps 1.5s infinite');
220         $('#ball').removeClass();
221         $('#ball').addClass('ball-bottom');
222         break;
223       case 'LANDSCAPE_PRIMARY':
224         $('#ball').css('-webkit-animation', 'jump-lp 1s infinite');
225         $('#ball').css('animation', 'jump-lp 1.5s infinite');
226         $('#ball').removeClass();
227         $('#ball').addClass('ball-left');
228         break;
229       case 'LANDSCAPE_SECONDARY':
230         $('#ball').css('-webkit-animation', 'jump-ls 1s infinite');
231         $('#ball').css('animation', 'jump-ls 1.5s infinite');
232         $('#ball').removeClass();
233         $('#ball').addClass('ball-right');
234         break;
235       default:
236         $('#ball').css('-webkit-animation', 'jump-no 1s infinite');
237         $('#ball').css('animation', 'jump-no 1.5s infinite');
238         $('#ball').removeClass();
239     }
240   };
241
242   this.getInfo = function getInfo(DEVICEORIENTATION) {
243     tizen.systeminfo.getPropertyValue(
244         'DEVICE_ORIENTATION',
245         function(deviceorientation) {
246           DEVICEORIENTATION.change_status(deviceorientation.status);
247           DEVICEORIENTATION.status.text('STATUS: ' + deviceorientation.status);
248           DEVICEORIENTATION.auto_rotation.text(deviceorientation.isAutoRotation ?
249               'AUTOROTATION' : 'NO AUTOROTATION');
250         },
251         null);
252     tizen.systeminfo.addPropertyValueChangeListener(
253         'DEVICE_ORIENTATION',
254         function(deviceorientation) {
255           DEVICEORIENTATION.change_status(deviceorientation.status);
256           DEVICEORIENTATION.status.text('STATUS: ' + deviceorientation.status);
257           DEVICEORIENTATION.auto_rotation.text(deviceorientation.isAutoRotation ?
258               'AUTOROTATION' : 'NO AUTOROTATION');
259         });
260   };
261 }
262
263 function DisplayInfo() {
264   this.dots_perinch_width = $('<p></p>').addClass('center');
265   this.dots_perinch_height = $('<p></p>').addClass('center');
266   this.screen = $('<p></p>').addClass('center');
267   this.physical = $('<p></p>').addClass('center');
268   this.brightness = $('<p></p>').addClass('center');
269   $('#display_status').append(this.dots_perinch_width, this.dots_perinch_height,
270                               this.screen, this.physical, this.brightness);
271
272   this.change_display = function change_display(display) {
273     this.dots_perinch_width.text('DOS PER INCH WIDTH: ' +
274         display.dotsPerInchWidth.toFixed(2));
275     this.dots_perinch_height.text('DOS PER INCH HEIGTH: ' +
276         display.dotsPerInchHeight.toFixed(2));
277     this.screen.text('SCREEN: WIDTH(' + display.resolutionWidth +
278         ') HEIGHT(' + display.resolutionHeight + ')');
279     this.physical.text('PHYSICAL: WIDTH(' + display.physicalWidth +
280         ') HEIGHT(' + display.physicalHeight + ')');
281     this.brightness.text('BRIGHTNESS: ' + display.brightness);
282     var physicalTotal = display.physicalWidth + display.physicalHeight;
283     var screenTotal = display.resolutionWidth + display.resolutionHeight;
284     $('#display_physical').width(500 * display.physicalWidth /
285         physicalTotal + 'px');
286     $('#display_physical').height(500 * display.physicalHeight /
287         physicalTotal + 'px');
288     $('#display_screen').width(380 * display.resolutionWidth /
289         screenTotal + 'px');
290     $('#display_screen').height(380 * display.resolutionHeight /
291         screenTotal + 'px');
292     $('#display_screen').css('opacity', display.brightness);
293   };
294
295   this.getInfo = function getInfo(DISPLAY) {
296     tizen.systeminfo.getPropertyValue(
297         'DISPLAY',
298         function(display) {
299           DISPLAY.change_display(display);
300         },
301         null);
302     tizen.systeminfo.addPropertyValueChangeListener(
303         'DISPLAY',
304         function(display) {
305           DISPLAY.change_display(display);
306         });
307   };
308 }
309
310 function LocaleInfo() {
311   this.language = $('<p></p>').addClass('center');
312   this.country = $('<p></p>').addClass('center');
313   $('#locale').append(this.language, this.country);
314
315   this.getInfo = function getInfo(LOCALE) {
316     tizen.systeminfo.getPropertyValue(
317         'LOCALE',
318         function(locale) {
319           LOCALE.language.text('LANGUAGE: ' + locale.language);
320           LOCALE.country.text('COUNTRY: ' + locale.country);
321         },
322         null);
323     tizen.systeminfo.addPropertyValueChangeListener(
324         'LOCALE',
325         function(locale) {
326           LOCALE.language.text('LANGUAGE: ' + locale.language);
327           LOCALE.country.text('COUNTRY: ' + locale.country);
328         });
329   };
330 }
331
332 function NetworkInfo() {
333   this.network_type = $('#network_type');
334
335   this.getInfo = function getInfo(NETWORK) {
336     tizen.systeminfo.getPropertyValue(
337         'NETWORK',
338         function(network) {
339           NETWORK.network_type.text('TYPE: ' + network.type);
340         },
341         null);
342     tizen.systeminfo.addPropertyValueChangeListener(
343         'NETWORK',
344         function(network) {
345           NETWORK.network_type.text('TYPE: ' + network.type);
346         });
347   };
348 }
349
350 function PeripheralInfo() {
351   this.video_output = $('<p></p>');
352   $('#peripheral').append(this.video_output);
353
354   this.getInfo = function getInfo(PERIPHERAL) {
355     tizen.systeminfo.getPropertyValue(
356         'PERIPHERAL',
357         function(peripheral) {
358           PERIPHERAL.video_output.text(peripheral.isVideoOutputOn ?
359               'VIDEOOUTPUT: ON' : 'VIDEOOUTPUT: OFF');
360         },
361         null);
362     tizen.systeminfo.addPropertyValueChangeListener(
363         'PERIPHERAL',
364         function(peripheral) {
365           PERIPHERAL.video_output.text(peripheral.isVideoOutputOn ?
366               'VIDEOOUTPUT: ON' : 'VIDEOOUTPUT: OFF');
367         });
368   };
369 }
370
371 function SimInfo() {
372   this.state = $('<p></p>');
373   this.operator_name = $('<p></p>');
374   this.msisdn_iccid = $('<p></p>');
375   this.short_info = $('<p></p>');
376   this.msin_spn = $('<p></p>');
377   $('#sim_container').append(this.state, this.operator_name, this.msisdn_iccid,
378                              this.short_info, this.msin_spn);
379
380   this.change_sim = function change_sim(sim) {
381     this.state.text('STATE: ' + sim.state);
382     this.operator_name.text('OPERATOR NAME: ' + sim.operatorName);
383     this.msisdn_iccid.text('MSISDN: ' + sim.msisdn + '  ' +
384         'ICCID: ' + sim.iccid);
385     this.short_info.text('MCC: ' + sim.mcc + '  ' +
386         'MNC: ' + sim.mnc);
387     this.msin_spn.text('MSIN: ' + sim.msin + '  ' +
388         'SPN: ' + sim.spn);
389   };
390
391   this.getInfo = function getInfo(SIM) {
392     tizen.systeminfo.getPropertyValue(
393         'SIM',
394         function(sim) {
395           SIM.change_sim(sim);
396         },
397         null);
398     tizen.systeminfo.addPropertyValueChangeListener(
399         'SIM',
400         function(sim) {
401           SIM.change_sim(sim);
402         });
403   };
404 }
405
406 function StorageInfo() {
407   this.draw_graph = function draw_graph(UNITS) {
408     $('#storage_container').empty();
409     for (var i = 0; i < UNITS.length; ++i) {
410       var unit = $('<div></div>').attr('id', 'unit' + i);
411       unit.width('75%');
412       unit.height(85 / UNITS.length + '%');
413       unit.css('margin', '0 auto');
414       unit.css('padding', '10px');
415       $('#storage_container').css('position', 'relative');
416       $('#storage_container').append(unit);
417       var data1 = [0, UNITS[i].capacity - UNITS[i].availableCapacity];
418       var data2 = [0, UNITS[i].availableCapacity];
419       var containner = document.getElementById('unit' + i);
420       Flotr.draw(containner, [
421         {data: [data1], label: 'used'},
422         {data: [data2], label: 'available'}
423       ], {
424         HtmlText: false,
425         title: 'TYPE:' + UNITS[i].type,
426         grid: {
427           verticalLines: false,
428           horizontalLines: false,
429           circular: true
430         },
431         xaxis: {showLabels: false},
432         yaxis: {showLabels: false},
433         pie: {
434           show: true,
435           explode: 6
436         },
437         mouse: {track: true},
438         legend: {
439           position: 'se',
440           backgroundColor: '#D2E8FF'
441         }
442       });
443     }
444   };
445
446   this.getInfo = function getInfo(STORAGE) {
447     tizen.systeminfo.getPropertyValue(
448         'STORAGE',
449         function(storage) {
450           STORAGE.draw_graph(storage.units);
451         },
452         null);
453     tizen.systeminfo.addPropertyValueChangeListener(
454         'STORAGE',
455         function(storage) {
456           STORAGE.draw_graph(storage.units);
457         });
458   };
459 }
460
461 function WifiNetworkInfo() {
462   this.status = $('<p></p>').text('WIFI IS OFF!');
463   this.ssid = $('<p></p>');
464   this.ip_address = $('<p></p>');
465   this.ipv6_address = $('<p></p>');
466   this.signal_strength = $('<p></p>');
467   $('#wifi_network_info').append(this.status, this.ssid, this.ip_address,
468                                  this.ipv6_address, this.signal_strength);
469
470   this.change_wifi = function change_wifi(wifi) {
471     if (wifi.status == 'ON') {
472       this.status.text('WIFI: ' + wifi.status);
473       this.ssid.text('WIFI SSID: ' + wifi.ssid);
474       this.ip_address.text('WIFI IP ADDRESS: ' + wifi.ipAddress);
475       this.ipv6_address.text('WIFI IPV6 ADDRESS: ' + wifi.ipv6Address);
476       this.signal_strength.text('WIFI SIGNAL STRENGTH: ' +
477                                 wifi.signalStrength);
478     } else {
479       this.status.text('WIFI IS OFF!');
480     }
481   };
482
483   this.getInfo = function getInfo(WIFI) {
484     tizen.systeminfo.getPropertyValue(
485         'WIFI_NETWORK',
486         function(wifi) {
487           WIFI.change_wifi(wifi);
488         },
489         null);
490     tizen.systeminfo.addPropertyValueChangeListener(
491         'WIFI_NETWORK',
492         function(wifi) {
493           WIFI.change_wifi(wifi);
494         });
495   };
496 }