1 /*jslint plusplus: true, sloppy: true, todo: true, vars: true, browser: true, devel: true, maxerr: 999 */
2 /*global $, tizen, app */
5 (function () { // strict mode wrapper
9 * Creates a new application object
13 App = function App() {};
19 requires: ['js/app.config.js',
23 'js/app.ui.templateManager.js',
24 'js/app.ui.events.js',
26 'js/app.client.model.js',
28 'js/app.server.model.js'
77 * Initialisation function
79 init: function App_init() {
80 this.config = new Config();
81 this.helpers = new Helpers();
82 this.model = new Model();
83 this.ui = new Ui(this.initModel.bind(this));
86 initModel: function App_initModel() {
87 this.model.init(this.checkPowerState.bind(this));
91 * exit application action
93 exit: function App_exit() {
94 tizen.application.getCurrentApplication().exit();
97 isConnection: function App_isConnection() {
98 return this.connection;
101 setConnection: function App_setConnection(boolean) {
102 this.connection = boolean;
105 getDoNotSendBye: function App_getDoNotSendBye() {
106 return this.doNotSendBye;
109 setDoNotSendBye: function App_setDoNotSendBye(boolean) {
110 this.doNotSendBye = boolean;
113 getCurrentName: function App_getCurrentName() {
114 return this.currentName;
117 getApplicationMode: function App_getApplicationMode() {
119 if (this.client !== null) {
121 } else if (this.server !== null) {
127 resetApplicationMode: function App_resetApplicationMode() {
132 checkPowerState: function App_checkPowerState() {
133 this.ui.setContentStartAttributes(
134 this.model.checkPowerState.bind(
135 this.model, this.ui.showPowerOnButton, this.ui.showStartButtons
140 powerOn: function App_powerOn() {
141 this.model.powerOn(this.ui.showStartButtons);
144 powerOff: function App_powerOff() {
145 this.model.powerOff(this.exit);
148 restartBluetooth: function App_restartBluetooth() {
149 this.model.restartBluetooth(this.powerOn.bind(this));
152 startServer: function App_startServer() {
153 this.server = new Server(this.model.adapter, this.model.serviceUUID);
154 this.showKeyboardPage();
157 startClient: function App_startClient() {
158 this.client = new Client(this.model.adapter, this.model.serviceUUID);
159 this.showKeyboardPage();
162 showKeyboardPage: function App_showKeyboardPage() {
163 this.ui.showKeyboardPage();
166 setUserName: function App_setUserName(value) {
167 this.currentName = value;
170 setAdapterName: function App_setAdapterName() {
171 var changeName = false, mode = this.getApplicationMode();
172 if (this.model.adapter.name !== this.currentName) {
175 if (mode === 'server') {
176 this.model.setAdapterName(changeName, this.server.registerServer.bind(this.server));
177 } else if (mode === 'client') {
178 this.model.setAdapterName(changeName, this.client.searchServer.bind(this.client));
182 clearListOfServers: function App_clearListOfServers() {
183 this.ui.clearListOfServers();
186 displaySentMessage: function App_displaySentMessage(message) {
187 this.ui.displaySentMessage(message);
190 sendMessage: function App_sendMessage(message) {
191 var mode = this.getApplicationMode();
192 if (mode === 'server') {
193 this.server.sendMessage(message, this.displaySentMessage.bind(this));
194 } else if (mode === 'client') {
195 this.client.sendMessage(message, this.displaySentMessage.bind(this));
199 sendBye: function App_sendBye() {
200 var mode = this.getApplicationMode();
201 if (mode === 'server') {
202 this.server.sendBye();
203 } else if (mode === 'client') {
204 this.client.sendBye();