/app/BluetoothChat/index.erb
Ruby HTML | 353 lines | 250 code | 103 blank | 0 comment | 38 complexity | d8cbb50933a88027ab512dfb483e2829 MD5 | raw file
- <div>
- <p>Bluetooth Chat</p>
- My Name:
- <input id="id_name" type="text" name="id_name" value="<%= $device_name %>" onChange="onDeviceNameChanged();"></input>
- <br>
- My Status:
- <input id="id_status" type="text" name="id_status" readonly value="<%= $current_status %>"></input>
- <br>
- <% if System::get_property('platform') != 'Blackberry' %>
- <% if not $connected_device_name.nil? %>
- <INPUT type="button" id="id_button1" value="Disconnect" name="id_button1" onClick="onDisconnect();">
- <INPUT type="button" id="id_button2" value="Disconnect" name="id_button2" onClick="onDisconnect();">
- <% else %>
- <INPUT type="button" id="id_button1" value="Connect as Server" name="id_button1" onClick="onConnectServer();">
- <INPUT type="button" id="id_button2" value="Connect as Client" name="id_button2" onClick="onConnectClient();">
- <% if System::get_property('platform') == 'APPLE' or System::get_property('platform') == 'ANDROID' %>
- <br>
- Custom Connection (without platform UI) : <br>
- <INPUT type="button" id="id_button3" value="Custom Server connect" name="id_button3" onClick="onConnectCustomServer();"><br>
- <INPUT type="button" id="id_button4" value="Connect to" name="id_button4" onClick="onConnectCustomClient();">
- <input id="id_server_name" type="text" name="id_server_name" value="<%= $server_name %>" onChange="onServerNameChanged();"></input>
- <% end %>
- <% end %>
- <% else %>
- <% if not $connected_device_name.nil? %>
- <%= link_to "[Disconnect]", :action => :on_disconnect %>
- <% else %>
- <%= link_to "[Connect as Server]", :action => :on_connect_server %>
- <%= link_to "[Connect as Client]", :action => :on_connect_client %>
- <% end %>
- <% end %>
- <br>
- History:<br>
- <% if System::get_property('platform') != 'Blackberry' %>
- <TEXTAREA id="id_history" ROWS="10" type="text" name="id_history" readonly value="<%= $history %>"></TEXTAREA>
- <% else %>
- <b>
- <pre>
- <%= $history %>
- </pre>
- </b>
- <% end %>
- <br>
- Message:<br>
- <% if System::get_property('platform') != 'Blackberry' %>
- <input id="id_message" type="text" name="id_message" value =""></input>
- <INPUT type="button" id="id_button_send" value="Send" name="id_button_send" onClick="onMessageSend();">
- <% else %>
- <form id="user_edit_form"
- method="POST"
- action="<%=url_for(:action => 'on_send')%>" selected="true">
- <input id="message" type="text" name="message" value =""></input>
- <a href="#" onclick="document.forms[0].submit(); return false;"><b>[SEND]</b></a>
- </form>
- <% end %>
- <br>
- <% if System::get_property('platform') == 'WINDOWS' %>
- <script type="text/javascript">
- var xmlHttpReq = null;
- function setTag(tag,value) {
- if (document.getElementsByTagName) {
- var el=document.getElementsByTagName(tag);
- for (i=0;i<el.length;i++) {
- el[i].innerText = value;
- }
- }
- }
- function ajaxCall(url)
- {
- //alert("ajaxCall() START");
- //Construct an XMLHTTP Object to handle our HTTP Request
- if (xmlHttpReq != null){
- xmlHttpReq = null;
- }
- if (xmlHttpReq == null) {
- try { xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); }
- catch(e) {}
- }
- if (xmlHttpReq == null) {
- try { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
- catch(e) {}
- }
- if (xmlHttpReq == null) {
- alert("Can't make the call - xmlHttpReq is not available");
- return;
- }
- //alert("about to open xmlHttpReq");
- xmlHttpReq.open("GET", url, true);
- //xmlHttpReq.onreadystatechange = doHttpReadyStateChange;
- //alert("about to send Req");
- xmlHttpReq.send();
- }
- function ajaxCallWithParam(url, param_name, param_value)
- {
- //alert("ajaxCallWithParam() START");
- //Construct an XMLHTTP Object to handle our HTTP Request
- if (xmlHttpReq != null){
- xmlHttpReq = null;
- }
- if (xmlHttpReq == null) {
- try { xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); }
- catch(e) {}
- }
- if (xmlHttpReq == null) {
- try { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
- catch(e) {}
- }
- if (xmlHttpReq == null) {
- alert("Can't make the call - xmlHttpReq is not available");
- return;
- }
- //alert("ajaxCallWithParam() 2");
- //alert("about to open xmlHttpReq");
- var params = param_name+'=' + encodeURIComponent(param_value);
- //alert("ajaxCallWithParam() 3");
- xmlHttpReq.open("GET", url+'?&'+params, true);
- //alert("ajaxCallWithParam() 4");
- //xmlHttpReq.onreadystatechange = doHttpReadyStateChange;
- //alert("about to send Req");
- xmlHttpReq.send();
- //alert("ajaxCallWithParam() FINISH");
- }
- function onDeviceNameChanged() {
- ajaxCallWithParam('/app/BluetoothChat/on_change_name', 'device_name', document.getElementById("id_name").value);
- return false;
- }
- function onConnectServer() {
- ajaxCall('/app/BluetoothChat/on_connect_server');
- return false;
- }
- function onConnectClient() {
- ajaxCall("/app/BluetoothChat/on_connect_client");
- //ajaxCall('/app/BluetoothChat/on_connect_client');
- return false;
- }
- function onDisconnect() {
- ajaxCall('/app/BluetoothChat/on_disconnect');
- return false;
- }
- function onMessageSend() {
- //alert("onSend() START");
- var mmm = document.getElementById("id_message").value;
- //alert("onSend() 2");
- document.getElementById("id_message").value = "";
- //alert("onSend() 3");
- ajaxCallWithParam("/app/BluetoothChat/on_send", "message", mmm);
- //alert("onSend() FINISH");
- return false;
- }
- function setHistory(shistory) {
- //alert("setHistory() called");
- document.getElementById("id_history").value = shistory;
- }
- function setName(name) {
- document.getElementsById("id_name").value = name;
- }
- function setStatus(status) {
- document.getElementById("id_status").value = status;
- }
- function setButtonCaption(caption) {
- document.getElementById("id_button1").value = caption;
- document.getElementById("id_button2").value = caption;
- }
- function restoreButtonCaption() {
- document.getElementById("id_button1").value = "Connect as Server";
- document.getElementById("id_button2").value = "Connect as Client";
- }
- function onUnload() {
- ajaxCall('/app/BluetoothChat/on_close');
- return false;
- }
- </script>
- <% elsif System::get_property('platform') != 'Blackberry' %>
- <script type="text/javascript">
- function onDeviceNameChanged() {
- $.get('/app/BluetoothChat/on_change_name', { device_name: document.getElementById("id_name").value});
- return false;
- }
- function onConnectServer() {
- $.get('/app/BluetoothChat/on_connect_server', {});
- return false;
- }
- function onConnectClient() {
- $.get('/app/BluetoothChat/on_connect_client', {});
- return false;
- }
- function onConnectCustomServer() {
- $.get('/app/BluetoothChat/on_connect_custom_server', {});
- return false;
- }
- function onConnectCustomClient() {
- $.get('/app/BluetoothChat/on_connect_custom_client', {});
- return false;
- }
- function onServerNameChanged() {
- $.get('/app/BluetoothChat/on_change_server_name', { device_name: document.getElementById("id_server_name").value});
- return false;
- }
- function setServerName(name) {
- document.getElementById("id_server_name").value = name;
- }
- function onDisconnect() {
- $.get('/app/BluetoothChat/on_disconnect', {});
- return false;
- }
- function onMessageSend() {
- $.get('/app/BluetoothChat/on_send', { message: document.getElementById("id_message").value});
- document.getElementById("id_message").value = "";
- return false;
- }
- function setHistory(history) {
- document.getElementById("id_history").value = history;
- }
- function setName(name) {
- document.getElementById("id_name").value = name;
- }
- function setStatus(status) {
- document.getElementById("id_status").value = status;
- }
- function setDeviceName(name) {
- document.getElementById("id_name").value = name;
- }
- function setButtonCaption(caption) {
- document.getElementById("id_button1").value = caption;
- document.getElementById("id_button2").value = caption;
- }
- function restoreButtonCaption() {
- document.getElementById("id_button1").value = "Connect as Server";
- document.getElementById("id_button2").value = "Connect as Client";
- }
- function setCustomButtonCaption(caption) {
- document.getElementById("id_button3").value = caption;
- document.getElementById("id_button4").value = caption;
- }
- function restoreCustomButtonCaption() {
- document.getElementById("id_button3").value = "Custom Server connect";
- document.getElementById("id_button4").value = "Connect to";
- }
- function onUnload() {
- $.get('/app/BluetoothChat/on_close', {});
- return false;
- }
- </script>
- <% elsif System::get_property('platform') == 'Blackberry' %>
- <script type="text/javascript">
- function onUnload() {
- return false;
- }
- </script>
- <%end%>