1 /*global $, tizen, app, Config, Helpers, Model, Ui, Server, Client */
4 (function () { // strict mode wrapper
8 * Creates a new application object
12 App = function App() {};
18 requires: ['js/app.config.js',
22 'js/app.ui.templateManager.js',
23 'js/app.ui.events.js',
25 'js/app.client.model.js',
27 'js/app.server.model.js'
76 * Initialisation function
78 init: function App_init() {
79 this.config = new Config();
80 this.helpers = new Helpers();
81 this.model = new Model();
82 this.ui = new Ui(this.initModel.bind(this));
85 initModel: function App_initModel() {
86 this.model.init(this.checkPowerState.bind(this));
90 * exit application action
92 exit: function App_exit() {
93 tizen.application.getCurrentApplication().exit();
96 isConnection: function App_isConnection() {
97 return this.connection;
100 setConnection: function App_setConnection(bool) {
101 this.connection = bool;
104 getDoNotSendBye: function App_getDoNotSendBye() {
105 return this.doNotSendBye;
108 setDoNotSendBye: function App_setDoNotSendBye(bool) {
109 this.doNotSendBye = bool;
112 getCurrentName: function App_getCurrentName() {
113 return this.currentName;
116 getApplicationMode: function App_getApplicationMode() {
118 if (this.client !== null) {
120 } else if (this.server !== null) {
126 resetApplicationMode: function App_resetApplicationMode() {
131 checkPowerState: function App_checkPowerState() {
132 this.ui.setContentStartAttributes(
133 this.model.checkPowerState.bind(
135 this.ui.showPowerOnButton,
136 this.ui.showStartButtons
141 powerOn: function App_powerOn() {
142 this.model.powerOn(this.ui.showStartButtons);
145 powerOff: function App_powerOff() {
146 this.model.powerOff(this.exit);
149 restartBluetooth: function App_restartBluetooth() {
150 this.model.restartBluetooth(this.powerOn.bind(this));
153 startServer: function App_startServer() {
154 this.server = new Server(this.model.adapter, this.model.serviceUUID);
155 this.showKeyboardPage();
158 startClient: function App_startClient() {
159 this.client = new Client(this.model.adapter, this.model.serviceUUID);
160 this.showKeyboardPage();
163 showKeyboardPage: function App_showKeyboardPage() {
164 this.ui.showKeyboardPage();
167 setUserName: function App_setUserName(value) {
168 this.currentName = value;
171 setAdapterName: function App_setAdapterName() {
172 var changeName = false, mode = this.getApplicationMode();
173 if (this.model.adapter.name !== this.currentName) {
176 if (mode === 'server') {
177 this.model.setAdapterName(changeName, this.server.registerServer.bind(this.server));
178 } else if (mode === 'client') {
179 this.model.setAdapterName(changeName, this.client.searchServer.bind(this.client));
183 clearListOfServers: function App_clearListOfServers() {
184 this.ui.clearListOfServers();
187 displaySentMessage: function App_displaySentMessage(message) {
188 this.ui.displaySentMessage(message);
191 sendMessage: function App_sendMessage(message) {
192 var mode = this.getApplicationMode();
193 if (mode === 'server') {
194 this.server.sendMessage(message, this.displaySentMessage.bind(this));
195 } else if (mode === 'client') {
196 this.client.sendMessage(message, this.displaySentMessage.bind(this));
200 sendBye: function App_sendBye() {
201 var mode = this.getApplicationMode();
202 if (mode === 'server') {
203 this.server.sendBye();
204 } else if (mode === 'client') {
205 this.client.sendBye();