diu_ui-ORG.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. /*
  2. * Copyright (c) 2019 Clementine Computing LLC.
  3. *
  4. * This file is part of PopuFare.
  5. *
  6. * PopuFare is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * PopuFare is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
  18. *
  19. */
  20. var _ADDRESS = "localhost";
  21. var _URL = "http://" + _ADDRESS;
  22. var _PORT = 60535;
  23. var _fqADDRESS = _ADDRESS + ":" + _PORT;
  24. var BG_COLOR = "#f7f7f7";
  25. var TEXT_COLOR = "#444444";
  26. var DIU_UI_VERSION = "0.1.8";
  27. var DIU_UI_VERSION_DATE = "2019-12-10";
  28. var g_snd = {
  29. "reject_fare" : "",
  30. "accept_fare" : "",
  31. "rule_error" : "",
  32. "button_press" : ""
  33. };
  34. function _beep_error() {
  35. g_snd.rule_error.currentTime=0;
  36. g_snd.rule_error.play();
  37. }
  38. function _beep_reject() {
  39. g_snd.reject_fare.currentTime=0;
  40. g_snd.reject_fare.play();
  41. }
  42. function _beep_accept() {
  43. g_snd.accept_fare.currentTime=0;
  44. g_snd.accept_fare.play();
  45. }
  46. function _beep() {
  47. g_snd.button_press.currentTime=0;
  48. g_snd.button_press.play();
  49. }
  50. var g_ctx = {
  51. "driver_login_state" : "driver",
  52. "driver" : "",
  53. "pin" : "",
  54. "paddle" : "",
  55. "eqnum" : "",
  56. "cur_eqnum" : "",
  57. "current_ui" : "ui_login",
  58. "ui_change_timeoutid": -1,
  59. "bulkfare" : "",
  60. "bulkfare_count" : "",
  61. "status_text": "",
  62. "status_text_w": 32,
  63. "status_text_h": 11,
  64. "status_html_text":"",
  65. "diu_status" : {},
  66. "x": ""
  67. };
  68. function _api_fail() {
  69. console.log(">>api fail");
  70. return true;
  71. }
  72. function _api_tick() { }
  73. function _api_request(action, param, cb_ok, cb_fail, cb_neterr) {
  74. var idx = 0;
  75. var param_name = [], param_val = [];
  76. var req = new XMLHttpRequest();
  77. // Firefox gets testy about parsing assumed XML
  78. //
  79. req.overrideMimeType("text/plain");
  80. var url = "/req";
  81. var varstr = "action=" + action;
  82. for (var x in param) {
  83. param_name.push(x);
  84. param_val.push(param[x]);
  85. }
  86. for (var ii=0; ii<param_name.length; ii++) {
  87. varstr += "&" + param_name[ii] + "=" + param_val[ii];
  88. }
  89. req.onreadystatechange = function() {
  90. if (req.readyState == 4) {
  91. if (req.status == 200) {
  92. var fulltxt = req.responseText;
  93. var resp = req.responseText.split(" ");
  94. if ((resp.length>=2) && (resp[0] == "ok")) {
  95. if (typeof cb_ok !== "undefined") {
  96. cb_ok(fulltxt);
  97. }
  98. return;
  99. }
  100. if (typeof cb_fail !== "undefined") {
  101. cb_fail(fulltxt);
  102. }
  103. }
  104. else if (typeof cb_fail !== "undefined") { cb_fail(); }
  105. }
  106. };
  107. req.addEventListener("error", _api_fail);
  108. req.addEventListener("abort", _api_fail);
  109. //req.addEventListener("load", _api_tick);
  110. //req.addEventListener("progress", _api_tick);
  111. req.onerror = function() { console.log("network error"); };
  112. try {
  113. //DEBUG
  114. console.log("req, varstr:", varstr);
  115. req.open("POST", url, true);
  116. req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  117. req.send(varstr);
  118. } catch (er) {
  119. console.log(">>>>>>ERROR", er);
  120. }
  121. }
  122. function _block_status_window(ui_id) {
  123. var ele = document.getElementById(ui_id + "_status");
  124. ele.ondragstart = function() { return false; }
  125. ele.onselectstart = function() { return false; }
  126. ele.onmousedown = function() { return false; }
  127. ele.ondragstart = function() { return false; }
  128. var rect = ele.getBoundingClientRect();
  129. var block_ele = document.getElementById(ui_id + "_blockwindow");
  130. block_ele.style.width = rect.width;
  131. block_ele.style.height = rect.height;
  132. block_ele.style.bottom = rect.bottom;
  133. block_ele.style.left = rect.left;
  134. block_ele.style.top = rect.top;
  135. block_ele.style.right = rect.right;
  136. block_ele.style.x = rect.x;
  137. block_ele.style.y = rect.y;
  138. }
  139. function _switch_ui(to) {
  140. var ele;
  141. console.log(">>>to", to);
  142. if (g_ctx.ui_change_timeoutid > 0) {
  143. window.clearTimeout(g_ctx.ui_change_timeoutid);
  144. g_ctx.ui_change_timeoutid = -1;
  145. }
  146. var from = g_ctx.current_ui;
  147. ele = document.getElementById(from);
  148. ele.style.display = "none";
  149. ele = document.getElementById(to);
  150. ele.style.display = "block";
  151. g_ctx.current_ui = to;
  152. if ((to == "ui_main") ||
  153. (to == "ui_login")) {
  154. _block_status_window(to);
  155. }
  156. }
  157. function _hide_ui(from) {
  158. var ele = document.getElementById(from);
  159. ele.style.display = "none";
  160. }
  161. function _hide_ui_element(from) {
  162. var ele = document.getElementById(from);
  163. ele.style.display = "none";
  164. }
  165. function _show_ui(to) {
  166. var ele = document.getElementById(to);
  167. ele.style.display = "block";
  168. g_ctx.current_ui = to;
  169. // put pane over status window to prevent highlights,
  170. // copy/pasting, etc.
  171. //
  172. if ((to == "ui_main") ||
  173. (to == "ui_login")) {
  174. _block_status_window(to);
  175. }
  176. }
  177. function _show_ui_element(to) {
  178. var ele = document.getElementById(to);
  179. ele.style.display = "block";
  180. }
  181. //------------
  182. // volume is from [0,1]
  183. //
  184. function _process_volume(vol) {
  185. var ele = document.getElementById("ui_configuration_displayvolume");
  186. ivol = Math.floor(vol*100.0);
  187. ele.innerHTML = "" + ivol + "%";
  188. }
  189. function _slider_change(name) {
  190. if (name == "configuration.volume") {
  191. var val = document.getElementById("ui_configuration_volume").value;
  192. _process_volume(val);
  193. ivol = Math.floor(val*100.0);
  194. _api_request("volume", {"volume":ivol},
  195. function(inp) { console.log("volume api set ok:", inp); },
  196. function(inp) { console.log("volume api set fail:", inp); });
  197. }
  198. }
  199. function _volume_test() {
  200. _api_request("say", {"message":"testing 1, 2, 3"},
  201. function(inp) { console.log("volume test ok:", inp); },
  202. function(inp) { console.log("volume test fail:", inp); });
  203. }
  204. //------------
  205. function _clear_ui_driver() {
  206. var ele;
  207. var u = ["driver", "pin"];
  208. for (var i=0; i<u.length; i++) {
  209. g_ctx[u[i]] = "";
  210. ele = document.getElementById("ui_driver_" + u[i]);
  211. ele.innerHTML = "";
  212. ele.style.background = "";
  213. }
  214. ele = document.getElementById("ui_driver_pin");
  215. ele.style.display = "none";
  216. ele = document.getElementById("ui_driver_pin_text");
  217. ele.style.display = "none";
  218. }
  219. function _clear_ui_paddle() {
  220. g_ctx.paddle = "";
  221. var ele = document.getElementById("ui_paddle_paddle");
  222. ele.innerHTML = "";
  223. }
  224. function _clear_ui_bulkaccept() {
  225. var ele;
  226. g_ctx.bulkfare = "";
  227. ele = document.getElementById("ui_bulkaccept_faretype");
  228. ele.innerHTML = "";
  229. g_ctx.bulkfare_count = "";
  230. ele = document.getElementById("ui_bulkaccept_count");
  231. ele.innerHTML = "";
  232. }
  233. function _login() {
  234. _switch_ui('ui_driver');
  235. g_ctx.driver_login_state = "driver";
  236. _clear_ui_driver();
  237. _clear_ui_paddle();
  238. }
  239. //------------
  240. function _verify_driver() {
  241. var driver = g_ctx.driver;
  242. var pin = g_ctx.pin;
  243. _api_request("driverlogin", {"driver":driver, "pin":pin}, _verify_driver_ok, _verify_driver_fail);
  244. return;
  245. }
  246. function _verify_driver_ok() { _switch_ui("ui_paddle"); }
  247. function _verify_driver_fail() { _switch_ui("ui_driverincorrect"); }
  248. function _driver_incorrect(inp) {
  249. _clear_ui_driver();
  250. _switch_ui("ui_driver");
  251. }
  252. //------------
  253. function _driver_login(inp) {
  254. var uvar = "";
  255. if (g_ctx.driver_login_state == "driver") { uvar = "driver"; }
  256. else if (g_ctx.driver_login_state == "pin") { uvar = "pin"; }
  257. else {
  258. console.log("_driver_login: ERROR: unknown driver state \"" + g_ctx.driver_login_state + "\"");
  259. return;
  260. }
  261. var n = g_ctx[uvar].length;
  262. //if (inp == 'cancel') { _switch_ui('ui_driver', 'ui_login'); }
  263. if (inp == 'cancel') { _switch_ui('ui_login'); }
  264. else if (inp == 'ok') {
  265. if (uvar == "driver") {
  266. g_ctx.driver_login_state = "pin";
  267. var ele;
  268. ele = document.getElementById("ui_driver_driver");
  269. ele.style.background = "#aaaaaa";
  270. ele = document.getElementById("ui_driver_pin");
  271. ele.style.display = "block";
  272. ele = document.getElementById("ui_driver_pin_text");
  273. ele.style.display = "block";
  274. }
  275. else if (uvar == "pin") {
  276. g_ctx.driver_login_state = "driver";
  277. _verify_driver();
  278. g_ctx.ui_change_timeoutid = window.setTimeout(function() {
  279. _switch_ui("ui_driververify");
  280. }, 150);
  281. return;
  282. }
  283. }
  284. // manage adding/subtracting/clearing relevant field
  285. //
  286. else if (inp == 'bksp') { g_ctx[uvar] = g_ctx[uvar].substr(0, n-1); }
  287. else if (inp == 'clr') { g_ctx[uvar]= ""; }
  288. else { g_ctx[uvar] += inp; }
  289. // Pin should not be displayed on screen.
  290. // Use '*' to hide it.
  291. //
  292. if (uvar == "pin") {
  293. var n = g_ctx[uvar].length;
  294. var x = "";
  295. for (i=0; i<n; i++) { x += "*"; }
  296. var ele = document.getElementById('ui_driver_' + uvar);
  297. ele.innerHTML = x;
  298. }
  299. // Otherwise update the displayed (driver number)
  300. //
  301. else {
  302. var ele = document.getElementById('ui_driver_' + uvar);
  303. ele.innerHTML = g_ctx[uvar];
  304. }
  305. }
  306. //------------
  307. //------------
  308. function _verify_paddle() {
  309. var paddle = g_ctx.paddle;
  310. _api_request("paddleinput", {"paddle":paddle}, _verify_paddle_ack, _verify_paddle_fail);
  311. return;
  312. }
  313. function _verify_paddle_ack() { console.log("got ack for push paddle message\n"); }
  314. function _verify_paddle_ok() { _switch_ui("ui_main"); }
  315. function _verify_paddle_fail() { _switch_ui("ui_paddleunknown"); }
  316. function _paddle_unknown(inp) {
  317. _clear_ui_paddle();
  318. _switch_ui("ui_paddle");
  319. }
  320. //------------
  321. function _paddle_input(inp) {
  322. var n = g_ctx.paddle.length;
  323. if (inp == 'cancel') { _switch_ui('ui_login'); }
  324. else if (inp == 'ok') {
  325. _verify_paddle();
  326. g_ctx.ui_change_timeoutid = window.setTimeout(function() {
  327. _switch_ui("ui_paddleverify");
  328. }, 150);
  329. return;
  330. }
  331. else if (inp == 'bksp') { g_ctx.paddle = g_ctx.paddle.substr(0, n-1); }
  332. else if (inp == 'clr') { g_ctx.paddle = ""; }
  333. else { g_ctx.paddle += inp; }
  334. // Otherwise update the displayed (driver number)
  335. //
  336. var ele = document.getElementById('ui_paddle_paddle');
  337. ele.innerHTML = g_ctx.paddle;
  338. }
  339. //-------------
  340. //-------------
  341. //-------------
  342. function _main_prv() {
  343. console.log("prv");
  344. _api_request("prevstop");
  345. }
  346. function _main_nxt() {
  347. console.log("nxt");
  348. _api_request("nextstop");
  349. }
  350. function _main_dim() {
  351. console.log("dim...");
  352. _api_request("dim");
  353. _switch_ui('ui_dim');
  354. }
  355. function _dim_wakeup() {
  356. console.log("waking up from dim");
  357. _switch_ui("ui_main");
  358. }
  359. function _fare_adult() {
  360. console.log("fare adult");
  361. _api_request("fare", {"rule":"CASH-ADULT", "param":"", "fare":"adult","count":1});
  362. }
  363. function _fare_youth() {
  364. console.log("fare youth");
  365. _api_request("fare", {"rule":"CASH-YOUTH", "param":"", "fare":"youth","count":1});
  366. }
  367. function _fare_half() {
  368. console.log("fare half");
  369. _api_request("fare", {"rule":"CASH-HALF", "param":"", "fare":"half","count":1});
  370. }
  371. function _fare_bike() {
  372. console.log("fare bike");
  373. _api_request("fare", {"rule":"MISC-BIKE", "param":"", "fare":"bike","count":1});
  374. }
  375. function _fare_wheelchair() {
  376. console.log("fare wheelchair");
  377. _api_request("fare", {"rule":"MISC-WHEELCHAIR", "param":"", "fare":"wheelchair","count":1});
  378. }
  379. function _fare_transfer() {
  380. console.log("fare transfer");
  381. _api_request("fare", {"rule":"MISC-TRANSFER", "param":"", "fare":"transfer","count":1});
  382. }
  383. //-------------
  384. //-------------
  385. //-------------
  386. function _main_bulk() {
  387. // reset tab to Misc. (first option) by default
  388. //
  389. ele = document.getElementById("ui_bulk_misc");
  390. ele.classList.remove("highlight");
  391. ele.classList.add("highlight");
  392. ele = document.getElementById("ui_bulk_passes");
  393. ele.classList.remove("highlight");
  394. _show_ui_element("ui_bulk_misc_tab");
  395. _hide_ui_element("ui_bulk_passes_tab");
  396. _switch_ui("ui_bulk");
  397. }
  398. function _main_menu() {
  399. // reset tab to Misc. (first option) by default
  400. //
  401. ele = document.getElementById("ui_fareoverride_misc");
  402. ele.classList.remove("highlight");
  403. ele.classList.add("highlight");
  404. ele = document.getElementById("ui_fareoverride_passes");
  405. ele.classList.remove("highlight");
  406. _show_ui_element("ui_fareoverride_misc_tab");
  407. _hide_ui_element("ui_fareoverride_passes_tab");
  408. _switch_ui("ui_fareoverride");
  409. }
  410. //-------------
  411. //-------------
  412. //-------------
  413. function _bulkaccept_ok() {
  414. console.log("bulkfare:", g_ctx.bulkfare, ", count:", g_ctx.bulkfare_count);
  415. _switch_ui("ui_main");
  416. _api_request("fare",{"rule":g_ctx.bulkfare, "param":g_ctx.bulkfare_count.toString(), "fare":g_ctx.bulkfare,"count":g_ctx.bulkfare_count});
  417. }
  418. function _bulkaccept_cancel() {
  419. _switch_ui("ui_main");
  420. }
  421. function _bulkaccept_input(inp) {
  422. var n = g_ctx.bulkfare_count.length;
  423. if (inp == 'cancel') { _switch_ui('ui_main'); }
  424. else if (inp == 'ok') { _bulkaccept_ok(); return; }
  425. else if (inp == 'bksp') { g_ctx.bulkfare_count = g_ctx.bulkfare_count.substr(0, n-1); }
  426. else if (inp == 'clr') { g_ctx.bulkfare_count = ""; }
  427. else { g_ctx.bulkfare_count += inp; }
  428. // Otherwise update the displayed (driver number)
  429. //
  430. var ele = document.getElementById('ui_bulkaccept_count');
  431. ele.innerHTML = g_ctx.bulkfare_count;
  432. }
  433. //-------------
  434. //-------------
  435. //-------------
  436. // space pad
  437. // default 10
  438. //
  439. function _sp(str, align, pad) {
  440. align = ((typeof align=="undefined") ? "left" : align);
  441. pad = ((typeof pad==="undefined") ? 10 : pad);
  442. var n = 0;
  443. n = pad - str.length;
  444. if (align == "left") {
  445. for (var i=0; i<n; i++) { str += " "; }
  446. }
  447. else if (align == "center") {
  448. var rem = n%2;
  449. var n2 = Math.floor(n/2);
  450. var pfx = "", sfx = "";
  451. for (var i=0; i<n2; i++) { pfx += " "; }
  452. for (var i=0; i<(n2+rem); i++) { sfx += " "; }
  453. str = pfx + str + sfx;
  454. }
  455. else if (align == "right") {
  456. var pfx = "";
  457. for (var i=0; i<n; i++) { pfx += " "; }
  458. str = pfx + str;
  459. }
  460. return str;
  461. }
  462. function _cb_status(inp) {
  463. var tok = inp.split(" ");
  464. if (tok.length < 2) { return; }
  465. if (tok[0]!="ok") { return; }
  466. valtok = tok.slice(1).join(" ").split("\n");
  467. if (valtok[0]!="msg=status") { return; }
  468. g_ctx.diu_status = {};
  469. var fields = valtok[1].split("|");
  470. for (var ii=0; ii<fields.length; ii++) {
  471. var kv = fields[ii].split("=");
  472. if (kv.length!=2) { continue; }
  473. g_ctx.diu_status[kv[0].trim()] = kv[1].trim();
  474. }
  475. if ("equipno" in g_ctx.diu_status) {
  476. g_ctx.cur_eqnum = g_ctx.diu_status["equipno"];
  477. }
  478. var m = g_ctx.diu_status;
  479. if (g_ctx.current_ui === "ui_login") {
  480. var has_tunn = ((m["tunnel"] == '1') ? 'YES' : 'NO');
  481. var has_gprs = ((m["gprs"] == '1') ? 'YES' : 'NO');
  482. var has_gps = ((m["gps"] == '1') ? 'YES' : 'NO');
  483. var lat = ((typeof m["gpslat"] !== "undefined") ? m["gpslat"] : "");
  484. var lon = ((typeof m["gpslon"] !== "undefined") ? m["gpslon"] : "");
  485. var gps_str = ( ((lat.length>0) && (lon.length>0)) ? (" (" + lat + "/" + lon + ")") : "" );
  486. var ele = document.getElementById("ui_login_status");
  487. var html_a = [];
  488. html_a.push("Tunnel: " + has_tunn + " GPRS: " + has_gprs + " Eq#: " + m["equipno"] + " #Msg: " + m["nmsg"]);
  489. html_a.push("Last Token Read (" + m["last_token"] + ")");
  490. html_a.push("GPS: " + has_gps + gps_str + "");
  491. html_a.push(" ");
  492. // some site specific fiddling to display package information
  493. //
  494. html_a.push(_sp("Package") + _sp("Version", "left", 18) + _sp("Installed", "right", 12));
  495. html_a.push(_sp("ui") + _sp(DIU_UI_VERSION, "left", 18) + _sp(DIU_UI_VERSION_DATE, "right", 12) + "");
  496. for (var _ii=0; _ii<3; _ii++) {
  497. var key = "pkg" + _ii;
  498. if (key in g_ctx.diu_status) {
  499. var aval = g_ctx.diu_status[key].split(" ");
  500. html_a.push(_sp(aval[0]) + _sp(aval[1], "left", 18) + _sp(aval[2], "right", 12));
  501. }
  502. }
  503. html_a.push(" ");
  504. if ("IMEI" in m) { html_a.push("IMEI = " + m["IMEI"] + ""); }
  505. if ("IMSI" in m) { html_a.push("IMSI = " + m["IMSI"] + ""); }
  506. if ("ETH0" in m) { html_a.push("ETH0 = " + m["ETH0"] + ""); }
  507. html_a.push(" ");
  508. for (var ii=0; ii<html_a.length; ii++) {
  509. html_a[ii] = html_a[ii].replace(/ /g, '&nbsp;');
  510. }
  511. var div_hdr = "<div class='textrow'>";
  512. var str = div_hdr + html_a.join("</div><br>" + div_hdr ) + "</div>";
  513. ele.innerHTML = str;
  514. }
  515. else if (g_ctx.current_ui === "ui_main") {
  516. var ele = document.getElementById("mainstatus");
  517. var str = "";
  518. str += "Rt " + m["route"] + " ";
  519. str += "Trip " + m["trip"] + " ";
  520. str += "Stop " + m["stop"] + " ";
  521. str += "GPS " + m["gps"] + " ";
  522. str += "Tun " + m["tunnel"] + ", ";
  523. str += m["date"];
  524. str += " " + moment().format("HH:mm");
  525. ele.innerHTML = str;
  526. }
  527. }
  528. function _cb_status_err(e) {
  529. console.log("ERROR: _cb_status_err:", e);
  530. }
  531. //-------------
  532. function _main_message_clear() {
  533. g_ctx.status_text = "";
  534. }
  535. function _main_message_replace(msg, bg_color, text_color) {
  536. var ele = document.getElementById("ui_main_status");
  537. bg_color = ((typeof bg_color === "undefined") ? BG_COLOR : bg_color);
  538. text_color = ((typeof text_color === "undefined") ? TEXT_COLOR : text_color);
  539. var lines = g_ctx.status_text.split("\n");
  540. if (lines.length > g_ctx.status_text_h) {
  541. var n = lines.length;
  542. lines = lines.slice(n - g_ctx.status_text_h);
  543. }
  544. for (var i=0; i<lines.length; i++) {
  545. lines[i] = lines[i].slice(0,g_ctx.status_text_w);
  546. }
  547. var idx = lines.length-1;
  548. if (idx<0) { idx = 0; }
  549. lines[idx] = msg;
  550. var html_lines = [];
  551. for (var i=0; i<lines.length; i++) {
  552. html_lines.push(lines[i].slice(0,g_ctx.status_text_w));
  553. if (html_lines[i].match(/ACCEPT/)) {
  554. html_lines[i] = "<div class='textrow accept'>" + html_lines[i] + "</div>";
  555. }
  556. else if (html_lines[i].match(/REJECT/)) {
  557. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  558. }
  559. else if (html_lines[i].match(/[Uu]nknown/)) {
  560. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  561. }
  562. else if (html_lines[i].match(/[Pp]assback/)) {
  563. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  564. }
  565. else if (html_lines[i].match(/Rule execution error/)) {
  566. html_lines[i] = "<div class='textrow error'>" + html_lines[i] + "</div>";
  567. }
  568. else {
  569. html_lines[i] = "<div class='textrow'>" + html_lines[i] + "</div>";
  570. }
  571. }
  572. g_ctx.status_text = lines.join("\n");
  573. g_ctx.status_text = lines.join("\n");
  574. g_ctx.status_html_text = html_lines.join("<br>");
  575. ele.innerHTML = g_ctx.status_html_text;
  576. // sounds
  577. //
  578. if (msg.match(/ACCEPT/)) {
  579. _beep_accept();
  580. }
  581. else if (msg.match(/REJECT/)) {
  582. _beep_reject();
  583. }
  584. else if (msg.match(/[Uu]nknown/)) {
  585. _beep_reject();
  586. }
  587. else if (msg.match(/[Pp]assback/)) {
  588. _beep_reject();
  589. }
  590. else if (msg.match(/Rule execution error/)) {
  591. _beep_error();
  592. }
  593. }
  594. function _main_message_add(msg, bg_color, text_color) {
  595. var ele = document.getElementById("ui_main_status");
  596. bg_color = ((typeof bg_color === "undefined") ? BG_COLOR : bg_color);
  597. text_color = ((typeof text_color === "undefined") ? TEXT_COLOR : text_color);
  598. var txt = g_ctx.status_text + "\n" + msg;
  599. var html_lines = [];
  600. var lines = txt.split("\n");
  601. if (lines.length > g_ctx.status_text_h) {
  602. var n = lines.length;
  603. lines = lines.slice(n - g_ctx.status_text_h);
  604. }
  605. for (var i=0; i<lines.length; i++) {
  606. html_lines.push(lines[i].slice(0,g_ctx.status_text_w));
  607. if (html_lines[i].match(/ACCEPT/)) {
  608. html_lines[i] = "<div class='textrow accept'>" + html_lines[i] + "</div>";
  609. }
  610. else if (html_lines[i].match(/REJECT/)) {
  611. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  612. }
  613. else if (html_lines[i].match(/[Uu]nknown/)) {
  614. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  615. }
  616. else if (html_lines[i].match(/[Pp]assback/)) {
  617. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  618. }
  619. else if (html_lines[i].match(/Rule execution error/)) {
  620. html_lines[i] = "<div class='textrow error'>" + html_lines[i] + "</div>";
  621. }
  622. else {
  623. html_lines[i] = "<div class='textrow'>" + html_lines[i] + "</div>";
  624. }
  625. }
  626. g_ctx.status_text = lines.join("\n");
  627. g_ctx.status_html_text = html_lines.join("<br>");
  628. ele.innerHTML = g_ctx.status_html_text;
  629. // sounds
  630. //
  631. if (msg.match(/ACCEPT/)) {
  632. _beep_accept();
  633. }
  634. else if (msg.match(/REJECT/)) {
  635. _beep_reject();
  636. }
  637. else if (msg.match(/[Uu]nknown/)) {
  638. _beep_reject();
  639. }
  640. else if (msg.match(/[Pp]assback/)) {
  641. _beep_reject();
  642. }
  643. else if (msg.match(/Rule execution error/)) {
  644. _beep_error();
  645. }
  646. }
  647. //-------------
  648. //-------------
  649. //-------------
  650. function _ws_process(dat) {
  651. var tok = dat.split(" ");
  652. if (tok.length < 2) { return; }
  653. if (tok[0] == "paddle") {
  654. if (tok[1] == "ok") { _verify_paddle_ok(); }
  655. else if (tok[1] == "fail") { _verify_paddle_fail(); }
  656. else { _verify_paddle_fail(); }
  657. }
  658. else if (tok[0] == "driver_notify") {
  659. if (tok.length < 5) {
  660. console.log("malformed message: ", dat);
  661. }
  662. else if (tok[1] == "replace") {
  663. _main_message_replace(tok.slice(4).join(" "));
  664. }
  665. else if (tok[1] == "ok") {
  666. _main_message_add(tok.slice(4).join(" "));
  667. }
  668. else {
  669. console.log("unknown message: ", dat);
  670. }
  671. }
  672. }
  673. function _init_websocket() {
  674. var sock = new WebSocket("ws://" + _fqADDRESS);
  675. sock.onopen = function(e) { console.log("open", e); }
  676. sock.onmessage = function(e) { _ws_process(e.data); }
  677. sock.onclose = function(e) { console.log("close", e); }
  678. sock.onerror = function(e) { console.log("error", e); }
  679. }
  680. //-------------
  681. var ui_pattern = {
  682. "state" : "idle",
  683. "lastX" : 0,
  684. "lastY" : 0,
  685. "curX" : 0,
  686. "curY" : 0
  687. };
  688. function ui_pattern_mousedown(ev) {
  689. var ele = document.getElementById("body");
  690. var rect = ele.getBoundingClientRect();
  691. var x = ev["x"];
  692. var y = ev["y"];
  693. var width = rect.width;
  694. var height = rect.height;
  695. if (ui_pattern.state == "idle") {
  696. if (y < (height/4)) {
  697. ui_pattern.state = "square_0";
  698. }
  699. else {
  700. ui_pattern.state = "idle"
  701. }
  702. }
  703. else if (ui_pattern.state == "square_0") {
  704. if (x > (3*width/4)) {
  705. ui_pattern.state = "square_1";
  706. }
  707. else {
  708. ui_pattern.state = "idle"
  709. }
  710. }
  711. else if (ui_pattern.state == "square_1") {
  712. if (y > (3*height/4)) {
  713. ui_pattern.state = "square_2";
  714. }
  715. else {
  716. ui_pattern.state = "idle"
  717. }
  718. }
  719. else if (ui_pattern.state == "square_2") {
  720. if (x < (width/4)) {
  721. ui_pattern.state = "square_3";
  722. }
  723. else {
  724. ui_pattern.state = "idle"
  725. }
  726. }
  727. else if (ui_pattern.state == "square_3") {
  728. if (y < (height/4)) {
  729. ui_pattern.state = "square_4";
  730. }
  731. else {
  732. ui_pattern.state = "idle"
  733. }
  734. }
  735. else if (ui_pattern.state == "square_4") {
  736. if (x > (3*width/4)) {
  737. ui_pattern.state = "square_5";
  738. }
  739. else {
  740. ui_pattern.state = "idle"
  741. }
  742. }
  743. else if (ui_pattern.state == "square_5") {
  744. if (y > (3*height/4)) {
  745. ui_pattern.state = "square_6";
  746. }
  747. else {
  748. ui_pattern.state = "idle"
  749. }
  750. }
  751. else if (ui_pattern.state == "square_6") {
  752. if (x < (width/4)) {
  753. _switch_ui("ui_diagnostic");
  754. }
  755. ui_pattern.state = "idle"
  756. }
  757. return false;
  758. }
  759. function ui_pattern_mouseup(ev) {
  760. return false;
  761. }
  762. //------------
  763. function _mainscreen() {
  764. _switch_ui('ui_login');
  765. g_ctx.driver_login_state = "driver";
  766. _clear_ui_driver();
  767. _clear_ui_paddle();
  768. }
  769. function _configuration() {
  770. _switch_ui('ui_configuration');
  771. g_ctx.driver_login_state = "driver";
  772. _clear_ui_driver();
  773. _clear_ui_paddle();
  774. }
  775. function _eqnum() {
  776. _switch_ui('ui_eqnum');
  777. g_ctx.driver_login_state = "driver";
  778. if (g_ctx.cur_eqnum.length > 0) {
  779. var ele = document.getElementById("ui_eqnum_eqnum");
  780. ele.innerHTML = g_ctx.cur_eqnum;
  781. g_ctx.eqnum = g_ctx.cur_eqnum;
  782. }
  783. _clear_ui_driver();
  784. _clear_ui_paddle();
  785. }
  786. function _reset() {
  787. _switch_ui('ui_login');
  788. g_ctx.driver_login_state = "driver";
  789. _clear_ui_driver();
  790. _clear_ui_paddle();
  791. location.reload(true);
  792. }
  793. function _reboot() {
  794. _switch_ui('ui_login');
  795. g_ctx.driver_login_state = "driver";
  796. _clear_ui_driver();
  797. _clear_ui_paddle();
  798. }
  799. function _custom0() {
  800. _api_request("interfaceupdown", {"interface":"eth0", "state":"up"}, function(inp) { console.log("custom0 ok:", inp); }, function(inp) { console.log("custom0 error:", inp); });
  801. }
  802. function _custom1() {
  803. _api_request("interfaceupdown", {"interface":"eth0", "state":"down"}, function(inp) { console.log("custom1 ok:", inp); }, function(inp) { console.log("custom1 error:", inp); });
  804. }
  805. function _update_diagnostic_window(_msg) {
  806. var ele = document.getElementById("ui_diagnostic_view");
  807. ele.innerHTML = _msg;
  808. }
  809. function _custom2() {
  810. _api_request("interfaceinfo", {"interface":"eth0"}, _update_diagnostic_window, function(inp) { console.log("custom2 error:", inp); });
  811. }
  812. function _custom3() {
  813. _api_request("say", {"message":"speech test"}, function(inp) { console.log("custom3 ok:", inp); }, function(inp) { console.log("custom3 error:", inp); });
  814. }
  815. function _custom4() {
  816. //_switch_ui('ui_login');
  817. //g_ctx.driver_login_state = "driver";
  818. //_clear_ui_driver();
  819. //_clear_ui_paddle();
  820. }
  821. function _custom5() {
  822. //_switch_ui('ui_login');
  823. //g_ctx.driver_login_state = "driver";
  824. //_clear_ui_driver();
  825. //_clear_ui_paddle();
  826. }
  827. //------------
  828. function _set_eqnum() {
  829. if (g_ctx.eqnum.length == 0) { return; }
  830. _api_request("eqnum", {"eqnum":g_ctx.eqnum}, function(inp) { console.log("eqnum ok:", inp); }, function(inp) { console.log("eqnum error:", inp); });
  831. }
  832. function _eqnum_input(inp) {
  833. var n = g_ctx.eqnum.length;
  834. if (inp == 'cancel') { _switch_ui('ui_login'); }
  835. else if (inp == 'ok') {
  836. _set_eqnum();
  837. _switch_ui('ui_login');
  838. return;
  839. }
  840. else if (inp == 'bksp') { g_ctx.eqnum = g_ctx.eqnum.substr(0, n-1); }
  841. else if (inp == 'clr') { g_ctx.eqnum = ""; }
  842. else { g_ctx.eqnum += inp; }
  843. // Otherwise update the displayed equipment number
  844. //
  845. var ele = document.getElementById('ui_eqnum_eqnum');
  846. ele.innerHTML = g_ctx.eqnum;
  847. }
  848. //-------------
  849. function init() {
  850. _init_websocket();
  851. // diagnostics
  852. //
  853. document.getElementById('ui_diagnostic_mainscreen').onclick = _mainscreen;
  854. document.getElementById('ui_diagnostic_reset').onclick = _reset;
  855. document.getElementById('ui_diagnostic_reboot').onclick = _reboot;
  856. document.getElementById('ui_diagnostic_custom0').onclick = _custom0;
  857. document.getElementById('ui_diagnostic_custom1').onclick = _custom1;
  858. document.getElementById('ui_diagnostic_custom2').onclick = _custom2;
  859. document.getElementById('ui_diagnostic_custom3').onclick = _custom3;
  860. document.getElementById('ui_diagnostic_custom4').onclick = _custom4;
  861. document.getElementById('ui_diagnostic_custom5').onclick = _custom5;
  862. // configuration
  863. //
  864. document.getElementById('ui_configuration_back').onclick = _mainscreen;
  865. document.getElementById('ui_configuration_volumetest').onclick = _volume_test;
  866. document.getElementById('ui_configuration_eqnum').onclick = _eqnum;
  867. // equipment number change
  868. //
  869. document.getElementById('ui_eqnum_cancel').onclick = _mainscreen;
  870. document.getElementById('ui_eqnum_ok').onclick = function() { console.log("eqnum change"); }
  871. // login
  872. //
  873. document.getElementById('ui_login_login').onclick = _login;
  874. document.getElementById('ui_login_configuration').onclick = _configuration;
  875. document.getElementById('ui_driverincorrect_btn').onclick = _driver_incorrect;
  876. document.getElementById('ui_paddleunknown_btn').onclick = _paddle_unknown;;
  877. // main menu buttons
  878. //
  879. document.getElementById('ui_main_prv').onclick = _main_prv;
  880. document.getElementById('ui_main_nxt').onclick = _main_nxt;
  881. document.getElementById('ui_main_bulk').onclick = _main_bulk;
  882. document.getElementById('ui_main_menu').onclick = _main_menu;
  883. document.getElementById('ui_main_dim').onclick = _main_dim;
  884. // dim
  885. //
  886. document.getElementById('ui_dim_btn').onclick = _dim_wakeup;
  887. var simple_fares = [ "adult", "youth", "half", "bike", "wheelchair", "transfer"];
  888. var simple_fares_f = [ _fare_adult, _fare_youth, _fare_half, _fare_bike, _fare_wheelchair, _fare_transfer];
  889. for (var ii=0; ii<simple_fares.length; ii++) {
  890. var fare = simple_fares[ii];
  891. document.getElementById('ui_main_' + fare).onclick = simple_fares_f[ii];
  892. }
  893. // bulk menu buttons
  894. //
  895. document.getElementById('ui_bulk_passes').onclick =
  896. function() {
  897. var ele;
  898. ele = document.getElementById("ui_bulk_misc");
  899. ele.classList.remove("highlight");
  900. ele = document.getElementById("ui_bulk_passes");
  901. ele.classList.add("highlight");
  902. _hide_ui_element("ui_bulk_misc_tab");
  903. _show_ui_element("ui_bulk_passes_tab");
  904. };
  905. document.getElementById('ui_bulk_misc').onclick =
  906. function() {
  907. var ele;
  908. ele = document.getElementById("ui_bulk_misc");
  909. ele.classList.add("highlight");
  910. ele = document.getElementById("ui_bulk_passes");
  911. ele.classList.remove("highlight");
  912. _show_ui_element("ui_bulk_misc_tab");
  913. _hide_ui_element("ui_bulk_passes_tab");
  914. };
  915. document.getElementById('ui_bulk_menu').onclick = function() { _switch_ui("ui_main"); }
  916. // Setup "Bulk" UI accept buttons to do proper screen switching and
  917. // other tasks.
  918. //
  919. var bulk_pass = ["adult", "youth", "half", "event", "transfer", "interline",
  920. "schoola", "schoolb", "schoolc", "orga", "orgb", "orgc"];
  921. var bulk_rule = ["BULK-CASH-ADULT", "BULK-CASH-YOUTH", "BULK-CASH-HALF",
  922. "BULK-MISC-EVENT", "BULK-MISC-TRANSFER", "BULK-MISC-INTERLINE",
  923. "BULK-OVR-SCHOOLA", "BULK-OVR-SCHOOLB", "BULK-OVR-SCHOOLC",
  924. "BULK-OVR-ORGA", "BULK-OVR-ORGB", "BULK-OVR-ORGC"];
  925. var bulk_pass_name = ["Adult Cash", "Youth Cash", "Half Cash", "Special Event", "Transfer", "Interline",
  926. "School A", "School B", "School C", "Org A", "Org B", "Org C"];
  927. // use site specific values if available, otherwise default to the above
  928. //
  929. if ((typeof BULK_PASS !== "undefined") && (BULK_PASS.length > 0)) {
  930. bulk_pass = BULK_PASS;
  931. }
  932. if ((typeof BULK_RULE !== "undefined") && (BULK_RULE.length > 0)) {
  933. bulk_rule= BULK_RULE;
  934. }
  935. if ((typeof BULK_PASS_NAME !== "undefined") && (BULK_PASS_NAME.length > 0)) {
  936. bulk_pass_name = BULK_PASS_NAME;
  937. }
  938. for (var i=0; i<bulk_pass.length; i++) {
  939. var p = bulk_pass[i];
  940. var u = bulk_pass_name[i];
  941. var r = bulk_rule[i];
  942. var ele = document.getElementById('ui_bulk_' + p);
  943. ele.onclick = (function(x,y) {
  944. return function() {
  945. _clear_ui_bulkaccept();
  946. g_ctx.bulkfare = x;
  947. _switch_ui("ui_bulkaccept");
  948. var ee = document.getElementById("ui_bulkaccept_faretype");
  949. ee.innerHTML = y;
  950. };
  951. })(r, u);
  952. }
  953. // bulk accept fares
  954. //
  955. document.getElementById('ui_bulkaccept_ok').onclick = _bulkaccept_ok;
  956. document.getElementById('ui_bulkaccept_cancel').onclick = _bulkaccept_cancel;
  957. // fareoverride menu buttons
  958. //
  959. document.getElementById('ui_fareoverride_passes').onclick =
  960. function() {
  961. var ele;
  962. ele = document.getElementById("ui_fareoverride_misc");
  963. ele.classList.remove("highlight");
  964. ele = document.getElementById("ui_fareoverride_passes");
  965. ele.classList.add("highlight");
  966. _hide_ui_element("ui_fareoverride_misc_tab");
  967. _show_ui_element("ui_fareoverride_passes_tab");
  968. };
  969. document.getElementById('ui_fareoverride_misc').onclick =
  970. function() {
  971. var ele;
  972. ele = document.getElementById("ui_fareoverride_misc");
  973. ele.classList.add("highlight");
  974. ele = document.getElementById("ui_fareoverride_passes");
  975. ele.classList.remove("highlight");
  976. _show_ui_element("ui_fareoverride_misc_tab");
  977. _hide_ui_element("ui_fareoverride_passes_tab");
  978. };
  979. document.getElementById('ui_fareoverride_menu').onclick = function() { _switch_ui("ui_main"); }
  980. document.getElementById('ui_fareoverride_logout').onclick =
  981. function() {
  982. _main_message_clear();
  983. _api_request("logout");
  984. _switch_ui("ui_login");
  985. }
  986. // default values for override passes
  987. //
  988. var override_pass = [ "adult", "youth", "half",
  989. "bike", "wheelchair", "transfer",
  990. "event", "interline",
  991. "schoola", "schoolb", "schoolc",
  992. "orga", "orgb", "orgc" ];
  993. var override_rule = [ "CASH-ADULT", "CASH-YOUTH", "CASH-HALF",
  994. "MISC-BIKE", "MISC-WHEELCHAIR", "MISC-TRANSFER",
  995. "MISC-EVENT", "MISC-INTERLINE",
  996. "OVR-SCHOOLA", "OVR-SCHOOLB", "OVR-SCHOOLC",
  997. "OVR-ORGA", "OVR-ORGB", "OVR-ORGC" ];
  998. // use site specific values if available, otherwise default to the above
  999. //
  1000. if ((typeof OVERRIDE_PASS !== "undefined") && (OVERRIDE_PASS.length > 0)) {
  1001. override_pass = OVERRIDE_PASS;
  1002. }
  1003. if ((typeof OVERRIDE_RULE !== "undefined") && (OVERRIDE_RULE.length > 0)) {
  1004. override_rule= OVERRIDE_RULE;
  1005. }
  1006. for (var i=0; i<override_pass.length; i++) {
  1007. var p = override_pass[i];
  1008. var r = override_rule[i];
  1009. var ele = document.getElementById("ui_fareoverride_" + p);
  1010. ele.onclick = (function(x,y) {
  1011. return function() { _api_request("fare", {"rule":x,"fare":y,"param":"","count":1}); };
  1012. })(r,p);
  1013. }
  1014. var ui_page = [ "driver", "paddle", "bulkaccept", "eqnum" ];
  1015. var ui_func = [ _driver_login, _paddle_input, _bulkaccept_input, _eqnum_input ];
  1016. for (var idx=0; idx<ui_page.length; idx++) {
  1017. var c = ui_page[idx];
  1018. var f = ui_func[idx];
  1019. for (var i=0; i<=9; i++) {
  1020. document.getElementById('ui_' + c + '_' + i).onclick =
  1021. (function(_f, x) { return function() { _f(x); } })(f, i);
  1022. }
  1023. document.getElementById('ui_' + c + '_' + 'bksp').onclick =
  1024. (function(_f,x) { return function() { _f(x); } })(f, 'bksp');
  1025. document.getElementById('ui_' + c + '_' + 'clr').onclick =
  1026. (function(_f,x) { return function() { _f(x); } })(f, 'clr');
  1027. document.getElementById('ui_' + c + '_' + 'ok').onclick =
  1028. (function(_f,x) { return function() { _f(x); } })(f, 'ok');
  1029. document.getElementById('ui_' + c + '_' + 'cancel').onclick =
  1030. (function(_f,x) { return function() { _f(x); } })(f, 'cancel');
  1031. }
  1032. // set interval to check status every 1 second
  1033. //
  1034. var x = window.setInterval(function() { _api_request("status", {}, _cb_status, _cb_status_err); }, 1000);
  1035. // try and reduce textarea highlighting, drag and drop/copy pasting,
  1036. // and other bad behavor.
  1037. //
  1038. var ele;
  1039. var block_ele;
  1040. var rect;
  1041. ele = document.getElementById("ui_login_status");
  1042. ele.ondragstart = function() { return false; }
  1043. ele.onselectstart = function() { return false; }
  1044. ele.onmousedown = function() { return false; }
  1045. ele.ondragstart = function() { return false; }
  1046. rect = ele.getBoundingClientRect();
  1047. block_ele = document.getElementById("ui_login_blockwindow");
  1048. block_ele.style.width = rect.width;
  1049. block_ele.style.height = rect.height;
  1050. block_ele.style.bottom = rect.bottom;
  1051. block_ele.style.left = rect.left;
  1052. block_ele.style.top = rect.top;
  1053. block_ele.style.right = rect.right;
  1054. block_ele.style.x = rect.x;
  1055. block_ele.style.y = rect.y;
  1056. ele = document.getElementById("ui_main_status");
  1057. ele.ondragstart = function() { return false; }
  1058. ele.onselectstart = function() { return false; }
  1059. ele.onmousedown = function() { return false; }
  1060. ele.ondragstart = function() { return false; }
  1061. rect = ele.getBoundingClientRect();
  1062. block_ele = document.getElementById("ui_main_blockwindow");
  1063. block_ele.style.width = rect.width;
  1064. block_ele.style.height = rect.height;
  1065. block_ele.style.bottom = rect.bottom;
  1066. block_ele.style.left = rect.left;
  1067. block_ele.style.top = rect.top;
  1068. block_ele.style.right = rect.right;
  1069. block_ele.style.x = rect.x;
  1070. block_ele.style.y = rect.y;
  1071. ele = document.getElementById("body");
  1072. // We're using jquery so we need to gracefully add callbacks
  1073. // for mouse events.
  1074. //
  1075. ele.addEventListener('mousedown', ui_pattern_mousedown);
  1076. ele.addEventListener('mouseup', ui_pattern_mouseup);
  1077. g_snd.button_press = new Audio("assets/459992_florianreichelt_beep_short.mp3");
  1078. g_snd.accept_fare = new Audio("assets/443026__qubodup__public-domain-beep-sound.mp3");
  1079. g_snd.reject_fare = new Audio("assets/368780__gurie__start-sound-beep.mp3");
  1080. g_snd.rule_error = new Audio("assets/363920__samsterbirdies__8-bit-error.mp3");
  1081. if (typeof PopufareSiteInit !== "undefined") {
  1082. PopufareSiteInit();
  1083. }
  1084. }
  1085. (function($) {
  1086. $(document).ready(function() {
  1087. init();
  1088. });
  1089. })(jQuery);