PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/app/BluetoothChat/index.erb

https://github.com/koba290/rhodes-system-api-samples
Ruby HTML | 353 lines | 250 code | 103 blank | 0 comment | 38 complexity | d8cbb50933a88027ab512dfb483e2829 MD5 | raw file
  1. <div>
  2. <p>Bluetooth Chat</p>
  3. My Name:
  4. <input id="id_name" type="text" name="id_name" value="<%= $device_name %>" onChange="onDeviceNameChanged();"></input>
  5. <br>
  6. My Status:
  7. <input id="id_status" type="text" name="id_status" readonly value="<%= $current_status %>"></input>
  8. <br>
  9. <% if System::get_property('platform') != 'Blackberry' %>
  10. <% if not $connected_device_name.nil? %>
  11. <INPUT type="button" id="id_button1" value="Disconnect" name="id_button1" onClick="onDisconnect();">
  12. <INPUT type="button" id="id_button2" value="Disconnect" name="id_button2" onClick="onDisconnect();">
  13. <% else %>
  14. <INPUT type="button" id="id_button1" value="Connect as Server" name="id_button1" onClick="onConnectServer();">
  15. <INPUT type="button" id="id_button2" value="Connect as Client" name="id_button2" onClick="onConnectClient();">
  16. <% if System::get_property('platform') == 'APPLE' or System::get_property('platform') == 'ANDROID' %>
  17. <br>
  18. Custom Connection (without platform UI) : <br>
  19. <INPUT type="button" id="id_button3" value="Custom Server connect" name="id_button3" onClick="onConnectCustomServer();"><br>
  20. <INPUT type="button" id="id_button4" value="Connect to" name="id_button4" onClick="onConnectCustomClient();">
  21. <input id="id_server_name" type="text" name="id_server_name" value="<%= $server_name %>" onChange="onServerNameChanged();"></input>
  22. <% end %>
  23. <% end %>
  24. <% else %>
  25. <% if not $connected_device_name.nil? %>
  26. <%= link_to "[Disconnect]", :action => :on_disconnect %>
  27. <% else %>
  28. <%= link_to "[Connect as Server]", :action => :on_connect_server %>
  29. <%= link_to "[Connect as Client]", :action => :on_connect_client %>
  30. <% end %>
  31. <% end %>
  32. <br>
  33. History:<br>
  34. <% if System::get_property('platform') != 'Blackberry' %>
  35. <TEXTAREA id="id_history" ROWS="10" type="text" name="id_history" readonly value="<%= $history %>"></TEXTAREA>
  36. <% else %>
  37. <b>
  38. <pre>
  39. <%= $history %>
  40. </pre>
  41. </b>
  42. <% end %>
  43. <br>
  44. Message:<br>
  45. <% if System::get_property('platform') != 'Blackberry' %>
  46. <input id="id_message" type="text" name="id_message" value =""></input>
  47. <INPUT type="button" id="id_button_send" value="Send" name="id_button_send" onClick="onMessageSend();">
  48. <% else %>
  49. <form id="user_edit_form"
  50. method="POST"
  51. action="<%=url_for(:action => 'on_send')%>" selected="true">
  52. <input id="message" type="text" name="message" value =""></input>
  53. <a href="#" onclick="document.forms[0].submit(); return false;"><b>[SEND]</b></a>
  54. </form>
  55. <% end %>
  56. <br>
  57. <% if System::get_property('platform') == 'WINDOWS' %>
  58. <script type="text/javascript">
  59. var xmlHttpReq = null;
  60. function setTag(tag,value) {
  61. if (document.getElementsByTagName) {
  62. var el=document.getElementsByTagName(tag);
  63. for (i=0;i<el.length;i++) {
  64. el[i].innerText = value;
  65. }
  66. }
  67. }
  68. function ajaxCall(url)
  69. {
  70. //alert("ajaxCall() START");
  71. //Construct an XMLHTTP Object to handle our HTTP Request
  72. if (xmlHttpReq != null){
  73. xmlHttpReq = null;
  74. }
  75. if (xmlHttpReq == null) {
  76. try { xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); }
  77. catch(e) {}
  78. }
  79. if (xmlHttpReq == null) {
  80. try { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
  81. catch(e) {}
  82. }
  83. if (xmlHttpReq == null) {
  84. alert("Can't make the call - xmlHttpReq is not available");
  85. return;
  86. }
  87. //alert("about to open xmlHttpReq");
  88. xmlHttpReq.open("GET", url, true);
  89. //xmlHttpReq.onreadystatechange = doHttpReadyStateChange;
  90. //alert("about to send Req");
  91. xmlHttpReq.send();
  92. }
  93. function ajaxCallWithParam(url, param_name, param_value)
  94. {
  95. //alert("ajaxCallWithParam() START");
  96. //Construct an XMLHTTP Object to handle our HTTP Request
  97. if (xmlHttpReq != null){
  98. xmlHttpReq = null;
  99. }
  100. if (xmlHttpReq == null) {
  101. try { xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); }
  102. catch(e) {}
  103. }
  104. if (xmlHttpReq == null) {
  105. try { xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP"); }
  106. catch(e) {}
  107. }
  108. if (xmlHttpReq == null) {
  109. alert("Can't make the call - xmlHttpReq is not available");
  110. return;
  111. }
  112. //alert("ajaxCallWithParam() 2");
  113. //alert("about to open xmlHttpReq");
  114. var params = param_name+'=' + encodeURIComponent(param_value);
  115. //alert("ajaxCallWithParam() 3");
  116. xmlHttpReq.open("GET", url+'?&'+params, true);
  117. //alert("ajaxCallWithParam() 4");
  118. //xmlHttpReq.onreadystatechange = doHttpReadyStateChange;
  119. //alert("about to send Req");
  120. xmlHttpReq.send();
  121. //alert("ajaxCallWithParam() FINISH");
  122. }
  123. function onDeviceNameChanged() {
  124. ajaxCallWithParam('/app/BluetoothChat/on_change_name', 'device_name', document.getElementById("id_name").value);
  125. return false;
  126. }
  127. function onConnectServer() {
  128. ajaxCall('/app/BluetoothChat/on_connect_server');
  129. return false;
  130. }
  131. function onConnectClient() {
  132. ajaxCall("/app/BluetoothChat/on_connect_client");
  133. //ajaxCall('/app/BluetoothChat/on_connect_client');
  134. return false;
  135. }
  136. function onDisconnect() {
  137. ajaxCall('/app/BluetoothChat/on_disconnect');
  138. return false;
  139. }
  140. function onMessageSend() {
  141. //alert("onSend() START");
  142. var mmm = document.getElementById("id_message").value;
  143. //alert("onSend() 2");
  144. document.getElementById("id_message").value = "";
  145. //alert("onSend() 3");
  146. ajaxCallWithParam("/app/BluetoothChat/on_send", "message", mmm);
  147. //alert("onSend() FINISH");
  148. return false;
  149. }
  150. function setHistory(shistory) {
  151. //alert("setHistory() called");
  152. document.getElementById("id_history").value = shistory;
  153. }
  154. function setName(name) {
  155. document.getElementsById("id_name").value = name;
  156. }
  157. function setStatus(status) {
  158. document.getElementById("id_status").value = status;
  159. }
  160. function setButtonCaption(caption) {
  161. document.getElementById("id_button1").value = caption;
  162. document.getElementById("id_button2").value = caption;
  163. }
  164. function restoreButtonCaption() {
  165. document.getElementById("id_button1").value = "Connect as Server";
  166. document.getElementById("id_button2").value = "Connect as Client";
  167. }
  168. function onUnload() {
  169. ajaxCall('/app/BluetoothChat/on_close');
  170. return false;
  171. }
  172. </script>
  173. <% elsif System::get_property('platform') != 'Blackberry' %>
  174. <script type="text/javascript">
  175. function onDeviceNameChanged() {
  176. $.get('/app/BluetoothChat/on_change_name', { device_name: document.getElementById("id_name").value});
  177. return false;
  178. }
  179. function onConnectServer() {
  180. $.get('/app/BluetoothChat/on_connect_server', {});
  181. return false;
  182. }
  183. function onConnectClient() {
  184. $.get('/app/BluetoothChat/on_connect_client', {});
  185. return false;
  186. }
  187. function onConnectCustomServer() {
  188. $.get('/app/BluetoothChat/on_connect_custom_server', {});
  189. return false;
  190. }
  191. function onConnectCustomClient() {
  192. $.get('/app/BluetoothChat/on_connect_custom_client', {});
  193. return false;
  194. }
  195. function onServerNameChanged() {
  196. $.get('/app/BluetoothChat/on_change_server_name', { device_name: document.getElementById("id_server_name").value});
  197. return false;
  198. }
  199. function setServerName(name) {
  200. document.getElementById("id_server_name").value = name;
  201. }
  202. function onDisconnect() {
  203. $.get('/app/BluetoothChat/on_disconnect', {});
  204. return false;
  205. }
  206. function onMessageSend() {
  207. $.get('/app/BluetoothChat/on_send', { message: document.getElementById("id_message").value});
  208. document.getElementById("id_message").value = "";
  209. return false;
  210. }
  211. function setHistory(history) {
  212. document.getElementById("id_history").value = history;
  213. }
  214. function setName(name) {
  215. document.getElementById("id_name").value = name;
  216. }
  217. function setStatus(status) {
  218. document.getElementById("id_status").value = status;
  219. }
  220. function setDeviceName(name) {
  221. document.getElementById("id_name").value = name;
  222. }
  223. function setButtonCaption(caption) {
  224. document.getElementById("id_button1").value = caption;
  225. document.getElementById("id_button2").value = caption;
  226. }
  227. function restoreButtonCaption() {
  228. document.getElementById("id_button1").value = "Connect as Server";
  229. document.getElementById("id_button2").value = "Connect as Client";
  230. }
  231. function setCustomButtonCaption(caption) {
  232. document.getElementById("id_button3").value = caption;
  233. document.getElementById("id_button4").value = caption;
  234. }
  235. function restoreCustomButtonCaption() {
  236. document.getElementById("id_button3").value = "Custom Server connect";
  237. document.getElementById("id_button4").value = "Connect to";
  238. }
  239. function onUnload() {
  240. $.get('/app/BluetoothChat/on_close', {});
  241. return false;
  242. }
  243. </script>
  244. <% elsif System::get_property('platform') == 'Blackberry' %>
  245. <script type="text/javascript">
  246. function onUnload() {
  247. return false;
  248. }
  249. </script>
  250. <%end%>