1 /* global loadScript, Themes, Wifi, Bluetooth, ko, loadTemplate, $ */
4 * Settings class provides list view of available Settings options.
6 * This class requires following components:
8 * * {{#crossLink "BoxCaption"}}{{/crossLink}} component
9 * * {{#crossLink "Tabs"}}{{/crossLink}} component
10 * * {{#crossLink "Themes"}}{{/crossLink}} component
11 * * {{#crossLink "Wifi"}}{{/crossLink}} component
12 * * {{#crossLink "Bluetooth"}}{{/crossLink}} component
18 var Settings = (function() {
25 console.info("Starting up service Settings");
30 * Shows a given Settings option.
33 * @param setting {Object} Object representing Setting option to be showed.
35 this.openSetting = function(setting) {
36 self.selectedSetting = null;
37 if (!!setting && !self.locked) {
39 self.selectedSetting = setting;
42 loadScript(self.SETTINGS_JS_PATH + "themes.js", function(path, status) {
43 if (status === "ok") {
45 self.Theme = new Themes();
53 loadScript(self.SETTINGS_JS_PATH + "wifi.js", function(path, status) {
54 if (status === "ok") {
56 self.Wifi = new Wifi();
57 self.Wifi.init(function(err) {
62 self.Wifi.showNetworks();
67 self.Wifi.showNetworks();
76 loadScript(self.SETTINGS_JS_PATH + "wifi.js", function(path, status) {
77 if (status === "ok") {
79 self.Wifi = new Wifi();
80 self.Wifi.init(function(err) {
85 self.Wifi.showWifiTethering();
90 self.Wifi.showWifiTethering();
99 loadScript(self.SETTINGS_JS_PATH + "bluetooth.js", function(path, status) {
100 if (status === "ok") {
101 if (!self.Bluetooth) {
102 self.Bluetooth = new Bluetooth();
104 self.Bluetooth.show();
118 * Defines base path to Settings resources.
120 * @property SETTINGS_BASEPATH
123 * @default ./css/car/components/settings/
125 Settings.prototype.SETTINGS_BASEPATH = "./css/car/components/settings/";
127 * Defines path to Settings templates.
129 * @property SETTINGS_TEMPLATES_PATH
132 * @default ./css/car/components/settings/templates/
134 Settings.prototype.SETTINGS_TEMPLATES_PATH = "./css/car/components/settings/templates/";
136 * Defines path to Settings javascript files.
138 * @property SETTINGS_JS_PATH
141 * @default ./css/car/components/settings/js/
143 Settings.prototype.SETTINGS_JS_PATH = "./css/car/components/settings/js/";
145 * Holds the git revision number.
147 * @property SETTINGS_REVISION
151 Settings.prototype.SETTINGS_REVISION = "@revision@";
153 * Instance of Theme class.
159 Settings.prototype.Theme = null;
161 * Instance of Wifi class.
167 Settings.prototype.Wifi = null;
169 * Instance of Bluetooth class.
171 * @property Bluetooth
175 Settings.prototype.Bluetooth = null;
177 * jQuery representation of Settings Tabs component.
179 * @property domElement
183 Settings.prototype.domElement = null;
185 * Prevents opening of clicked Settings option more times.
192 Settings.prototype.locked = false;
195 * Contains array of Settings options.
197 * @property settingsModel
200 Settings.prototype.settingsModel = ko.observableArray([ {
205 name : "Wifi networks"
207 id : "wifitethering",
208 name : "Wifi tethering"
214 * Represents opened Settings option.
216 * @property selectedSetting
221 Settings.prototype.selectedSetting = null;
224 * Loads all the javascript and style files, initializes UI components that Settings list view depends on.
228 Settings.prototype.init = function() {
230 loadScript('./css/car/components/boxCaption/boxCaption.js', function(path, status) {
231 if (status === "ok") {
232 loadScript('./css/car/components/tabs/tabs.js', function(path, status) {
233 if (status === "ok") {
234 $("head").append($("<link rel='stylesheet' href='./css/car/components/boxCaption/boxCaption.css' />"));
235 $("head").append($("<link rel='stylesheet' href='./css/car/components/tabs/tabs.css' />"));
236 $("head").append($("<link rel='stylesheet' href='" + self.SETTINGS_BASEPATH + "/css/settings.css' />"));
238 if (!$("#settingsTabs").length) {
239 var settings = '<div id="settingsTabs" class="tabs pageBgColorNormalTransparent"></div>';
240 $(settings).appendTo("body");
241 self.domElement = $("#settingsTabs");
244 self.domElement.bind('eventClick_menuItemBtn', function() {
245 self.renderSettingsView();
248 self.domElement.tabs("setSectionTitle", "APPS");
249 var version = typeof tizen === 'undefined' ? "" : tizen.application.getCurrentApplication().appInfo.version;
250 self.domElement.tabs("setSectionHint", "v. " + version + " rev. " + self.SETTINGS_REVISION);
251 self.domElement.tabs("init");
260 self.domElement.tabs("tabMenuTemplateCompile", tabMenuModel, function() {
261 self.renderSettingsView(function() {
272 * Fades in the Settings.
276 Settings.prototype.show = function() {
278 self.domElement.tabs("showPage");
282 * Shows list view of available Settings options.
284 * @method renderSettingsView
285 * @param successCallback {Function()} Callback function to be invoked when the rendering ends.
287 Settings.prototype.renderSettingsView = function(successCallback) {
289 var settingsContent = "settingsContent";
290 var templateName = "template-settings";
291 self.domElement.tabs('closeSubpanel');
292 self.domElement.tabs("clearContent");
293 self.domElement.tabs("changeContentClass", settingsContent);
294 loadTemplate(self.SETTINGS_TEMPLATES_PATH, templateName, function() {
295 if (!$("#settingsList").length) {
296 var settingsList = '<div id="settingsList" data-bind="template: { name: \'';
297 settingsList += templateName;
298 settingsList += '\', foreach: Settings.settingsModel }"></div>';
299 $(settingsList).appendTo($('.' + settingsContent));
300 ko.applyBindings(window.Settings);
302 if (!!successCallback) {
306 if (self.domElement.find(".bluetoothPINCode").length) {
307 self.domElement.find(".bluetoothPINCode").remove();
311 window.__settings = undefined === window.__settings ? new Settings() : window.__settings;
313 return window.__settings;