Code refactoring and cleanup
[profile/ivi/SettingsApp.git] / js / main.js
1 /*
2  * Copyright (c) 2013, Intel Corporation.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 (function() {
11
12     function connected() {
13         console.log('Settings daemon connected');
14     }
15
16     function disconnected(e) {
17         console.log('Settings daemon disconnected...');
18         showMsg('Error', e);
19     }
20
21     function init() {
22         console.log('Settings init...');
23         $('#quit').on('click', function() {
24             console.log('Settings exiting...');
25             tizen.application.getCurrentApplication().exit();
26         });
27
28         wsAPI.connect('ws://localhost:16000/', 'http-only', connected, disconnected);
29
30         try {
31             /* Settings Panel */
32             $('#main').on('pageshow', function(event, data) {
33                 /* TODO: unsubscribe events if neccessary */
34                 if (data.prevPage.attr('id') === 'page_bluetooth') console.log('Bluetooth settings exited');
35             });
36
37             /* Different sub panels */
38             bluetoothPanelInit();
39         } catch (e) {
40             showMsg('Error', 'Javascript Exception Caught: ' + e);
41         }
42     }
43
44     $(document).ready(function() {
45         init();
46     })
47 })();