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 var contentHeight = screen.availHeight - $('div[data-role="header"]').outerHeight() - $('div[data-role="footer"]').outerHeight();
81 $('div[data-role="content"]').css('height',contentHeight);
83 this.config = new Config();
84 this.helpers = new Helpers();
85 this.model = new Model();
86 this.ui = new Ui(this.initModel.bind(this));
89 initModel: function App_initModel() {
90 this.model.init(this.checkPowerState.bind(this));
94 * exit application action
96 exit: function App_exit() {
97 tizen.application.getCurrentApplication().exit();
100 isConnection: function App_isConnection() {
101 return this.connection;
104 setConnection: function App_setConnection(boolean) {
105 this.connection = boolean;
108 getDoNotSendBye: function App_getDoNotSendBye() {
109 return this.doNotSendBye;
112 setDoNotSendBye: function App_setDoNotSendBye(boolean) {
113 this.doNotSendBye = boolean;
116 getCurrentName: function App_getCurrentName() {
117 return this.currentName;
120 getApplicationMode: function App_getApplicationMode() {
122 if (this.client !== null) {
124 } else if (this.server !== null) {
130 resetApplicationMode: function App_resetApplicationMode() {
135 checkPowerState: function App_checkPowerState() {
136 this.ui.setContentStartAttributes(
137 this.model.checkPowerState.bind(
138 this.model, this.ui.showPowerOnButton, this.ui.showStartButtons
143 powerOn: function App_powerOn() {
144 this.model.powerOn(this.ui.showStartButtons);
147 powerOff: function App_powerOff() {
148 this.model.powerOff(this.exit);
151 restartBluetooth: function App_restartBluetooth() {
152 this.model.restartBluetooth(this.powerOn.bind(this));
155 startServer: function App_startServer() {
156 this.server = new Server(this.model.adapter, this.model.serviceUUID);
157 this.showKeyboardPage();
160 startClient: function App_startClient() {
161 this.client = new Client(this.model.adapter, this.model.serviceUUID);
162 this.showKeyboardPage();
165 showKeyboardPage: function App_showKeyboardPage() {
166 this.ui.showKeyboardPage();
169 setUserName: function App_setUserName(value) {
170 this.currentName = value;
173 setAdapterName: function App_setAdapterName() {
174 var changeName = false, mode = this.getApplicationMode();
175 if (this.model.adapter.name !== this.currentName) {
178 if (mode === 'server') {
179 this.model.setAdapterName(changeName, this.server.registerServer.bind(this.server));
180 } else if (mode === 'client') {
181 this.model.setAdapterName(changeName, this.client.searchServer.bind(this.client));
185 clearListOfServers: function App_clearListOfServers() {
186 this.ui.clearListOfServers();
189 displaySentMessage: function App_displaySentMessage(message) {
190 this.ui.displaySentMessage(message);
193 sendMessage: function App_sendMessage(message) {
194 var mode = this.getApplicationMode();
195 if (mode === 'server') {
196 this.server.sendMessage(message, this.displaySentMessage.bind(this));
197 } else if (mode === 'client') {
198 this.client.sendMessage(message, this.displaySentMessage.bind(this));
202 sendBye: function App_sendBye() {
203 var mode = this.getApplicationMode();
204 if (mode === 'server') {
205 this.server.sendBye();
206 } else if (mode === 'client') {
207 this.client.sendBye();