1 /*jslint devel: true */
2 /*global $, tizen, app, UiEvents, TemplateManager, document, window, setTimeout */
7 function Ui(callback) {
12 (function () { // strict mode wrapper
16 templateManager: null,
19 * UI object for UI events
24 * UI module initialisation
26 init: function Ui_init(callback) {
27 this.templateManager = new TemplateManager();
28 this.uiEvents = new UiEvents(this);
29 $.mobile.tizen.disableSelection(document);
31 $(document).ready(this.domInit.bind(this, callback));
35 * When DOM is ready, initialise it (bind events)
37 domInit: function Ui_domInit(callback) {
38 var templates = ['keyboard_page',
48 this.templateManager.loadToCache(templates, this.initPages.bind(this, callback));
51 initPages: function Ui_initPages(callback) {
52 var pages = [], body = $('body');
54 body.append(this.templateManager.get('bye_popup')).append(this.templateManager.get('visibility_popup')).trigger('create');
56 pages.push(this.templateManager.get('keyboard_page'));
57 pages.push(this.templateManager.get('chat_page'));
58 pages.push(this.templateManager.get('choose_page'));
59 body.append(pages.join(''));
66 setContentStartAttributes: function Ui_setContentStartAttributes(callback) {
67 var contentStart, contentStartHeight;
68 contentStart = $('#start-content');
69 if (contentStart.height() > $(window).height()) {
70 contentStartHeight = $(window).height() - $('#start-header').height()
71 - parseInt(contentStart.css('padding-top'), 10) - parseInt(contentStart.css('padding-bottom'), 10);
73 contentStartHeight = contentStart.height();
75 setTimeout(function () { // workaround (setTimeout with 0 delay)
77 .css('height', contentStartHeight + 'px')
78 .css('min-height', 'auto')
79 .css('width', contentStart.width() + 'px');
80 $('#start').css('min-height', 'auto');
85 showChatPage: function Ui_showChatPage(serverName) {
86 if (serverName !== undefined) {
87 $('#chat').data('serverName', serverName);
89 $.mobile.changePage('#chat');
92 showKeyboardPage: function Ui_showKeyboardPage() {
93 $.mobile.changePage('#keyboard');
96 clearChatDialog: function Ui_clearChatDialog() {
97 $('#chat-content .ui-listview').empty();
100 showPowerOnButton: function Ui_showPowerOnButton() {
101 $('#start-monit').hide();
102 $('#serverButton').hide();
103 $('#clientButton').hide();
104 $('#turnOnButton').show();
107 showStartButtons: function Ui_showStartButtons() {
108 $('#start-monit').hide();
109 $('#turnOnButton').hide();
110 $('#serverButton').show();
111 $('#clientButton').show();
114 hideStartButtons: function Ui_hideStartButtons() {
115 $('#serverButton').hide();
116 $('#clientButton').hide();
117 $('#turnOnButton').hide();
118 $('#start-monit').show();
121 addDeviceToList: function Ui_addDeviceToList(device) {
122 var listElement, address, sub2, ul = $('#choose-content ul.ui-listview');
124 listElement = this.templateManager.get('server_row', {
125 'deviceAddress': device.address,
126 'deviceName': device.name
129 ul.append(listElement);
130 ul.listview('refresh');
133 clearListOfServers: function Ui_clearListOfServers() {
134 $('#choose-content ul.ui-listview').empty();
137 showByePopup: function Ui_showByePopup(name) {
138 var mode = app.getApplicationMode(), message = $('#byeMessage');
139 if (mode === 'server') {
140 message.html('Client name "' + name + '" is unavailable.\nYour bluetooth device will be automatically restarted.');
141 } else if (mode === 'client') {
142 message.html('Server name "' + name + '" is unavailable.\nYour bluetooth device will be automatically restarted.');
144 $('#byePopup').popup('open', {'positionTo': 'window'});
147 hideByePopup: function Ui_hideByePopup() {
148 $('#byePopup').popup('close');
151 showVisibilityPopup: function Ui_showVisibilityPopup() {
152 $('#visibilityPopup').popup('open', {'positionTo': 'window'});
155 hideVisibilityPopup: function Ui_hideVisibilityPopup() {
156 $('#visibilityPopup').popup('close');
159 displayReceivedMessage: function Ui_displayReceivedMessage(name, text, ping, bye) {
160 var listElement, span, ul;
161 text = decodeURIComponent(text);
162 name = decodeURIComponent(name);
164 this.showByePopup(name);
166 app.setConnection(true);
167 $('#chat-header-type').append(' - connected with ' + name);
168 this.checkSendButtonState();
170 listElement = this.templateManager.get('left_bubble', {
173 ul = $('#chat-content > .ui-scrollview-view > ul');
174 ul.append(listElement);
175 ul.listview('refresh');
179 enableSendButton: function Ui_enableSendButton() {
181 .css({'pointer-events': 'auto', 'color': '#000'})
182 .removeClass('ui-disabled');
185 disableSendButton: function Ui_disableSendButton() {
187 .css({'pointer-events': 'none', 'color': '#bbb'})
188 .removeClass('ui-btn-down-s')
189 .addClass('ui-disabled');
192 checkSendButtonState: function Ui_checkSendButtonState() {
193 if (app.helpers.checkStringLength($('#text').val().trim()) && app.isConnection()) {
194 this.enableSendButton();
196 this.disableSendButton();
200 moveMessagesListDown: function Ui_moveMessagesListDown(content, listHeight) {
201 var delta = content.height() - listHeight;
203 content.scrollview('scrollTo', 0, delta, 500);
207 displaySentMessage: function Ui_displaySentMessage(message) {
208 var listElement, span, ul, content, self = this;
209 message = decodeURIComponent(message);
210 listElement = this.templateManager.get('right_bubble', {
213 content = $('#chat-content');
214 ul = content.find('ul');
215 ul.append(listElement);
216 ul.listview('refresh');
217 setTimeout(function () { self.moveMessagesListDown(content, ul.height()) }, 200);
220 setDiscoveringProgress: function Ui_setDiscoveringProgress(boolean) {
221 $('#discovering').progress('hide', !boolean).progress('running', boolean);