diu_ui-ORG.js 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  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.9";
  27. var DIU_UI_VERSION_DATE = "2020-01-30";
  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() { console.log("driver ok"); _switch_ui("ui_paddle"); }
  247. function _verify_driver_fail() { console.log("driver fail"); _switch_ui("ui_driverincorrect"); }
  248. function _driver_incorrect(inp) {
  249. console.log("driver incorrect");
  250. _clear_ui_driver();
  251. _switch_ui("ui_driver");
  252. }
  253. //------------
  254. function _driver_login(inp) {
  255. var uvar = "";
  256. if (g_ctx.driver_login_state == "driver") { uvar = "driver"; }
  257. else if (g_ctx.driver_login_state == "pin") { uvar = "pin"; }
  258. else {
  259. console.log("_driver_login: ERROR: unknown driver state \"" + g_ctx.driver_login_state + "\"");
  260. return;
  261. }
  262. var n = g_ctx[uvar].length;
  263. //if (inp == 'cancel') { _switch_ui('ui_driver', 'ui_login'); }
  264. if (inp == 'cancel') { _switch_ui('ui_login'); }
  265. else if (inp == 'ok') {
  266. if (uvar == "driver") {
  267. g_ctx.driver_login_state = "pin";
  268. var ele;
  269. ele = document.getElementById("ui_driver_driver");
  270. ele.style.background = "#aaaaaa";
  271. ele = document.getElementById("ui_driver_pin");
  272. ele.style.display = "block";
  273. ele = document.getElementById("ui_driver_pin_text");
  274. ele.style.display = "block";
  275. }
  276. else if (uvar == "pin") {
  277. g_ctx.driver_login_state = "driver";
  278. _verify_driver();
  279. g_ctx.ui_change_timeoutid = window.setTimeout(function() {
  280. _switch_ui("ui_driververify");
  281. }, 150);
  282. return;
  283. }
  284. }
  285. // manage adding/subtracting/clearing relevant field
  286. //
  287. else if (inp == 'bksp') { g_ctx[uvar] = g_ctx[uvar].substr(0, n-1); }
  288. else if (inp == 'clr') { g_ctx[uvar]= ""; }
  289. else { g_ctx[uvar] += inp; }
  290. // Pin should not be displayed on screen.
  291. // Use '*' to hide it.
  292. //
  293. if (uvar == "pin") {
  294. var n = g_ctx[uvar].length;
  295. var x = "";
  296. for (i=0; i<n; i++) { x += "*"; }
  297. var ele = document.getElementById('ui_driver_' + uvar);
  298. ele.innerHTML = x;
  299. }
  300. // Otherwise update the displayed (driver number)
  301. //
  302. else {
  303. var ele = document.getElementById('ui_driver_' + uvar);
  304. ele.innerHTML = g_ctx[uvar];
  305. }
  306. }
  307. //------------
  308. //------------
  309. function _verify_paddle() {
  310. var paddle = g_ctx.paddle;
  311. _api_request("paddleinput", {"paddle":paddle}, _verify_paddle_ack, _verify_paddle_fail);
  312. return;
  313. }
  314. function _verify_paddle_ack() { console.log("got ack for push paddle message\n"); }
  315. function _verify_paddle_ok() { console.log("verify paddle ok"); _switch_ui("ui_main"); }
  316. function _verify_paddle_fail() { console.log("verify paddle fail"); _switch_ui("ui_paddleunknown"); }
  317. function _paddle_unknown(inp) {
  318. console.log("paddle unknown...");
  319. _clear_ui_paddle();
  320. _switch_ui("ui_paddle");
  321. }
  322. //------------
  323. function _paddle_input(inp) {
  324. var n = g_ctx.paddle.length;
  325. if (inp == 'cancel') { _switch_ui('ui_login'); }
  326. else if (inp == 'ok') {
  327. _verify_paddle();
  328. g_ctx.ui_change_timeoutid = window.setTimeout(function() {
  329. _switch_ui("ui_paddleverify");
  330. }, 150);
  331. return;
  332. }
  333. else if (inp == 'bksp') { g_ctx.paddle = g_ctx.paddle.substr(0, n-1); }
  334. else if (inp == 'clr') { g_ctx.paddle = ""; }
  335. else { g_ctx.paddle += inp; }
  336. // Otherwise update the displayed (driver number)
  337. //
  338. var ele = document.getElementById('ui_paddle_paddle');
  339. ele.innerHTML = g_ctx.paddle;
  340. }
  341. //-------------
  342. //-------------
  343. //-------------
  344. function _main_prv() {
  345. console.log("prv");
  346. _api_request("prevstop");
  347. }
  348. function _main_nxt() {
  349. console.log("nxt");
  350. _api_request("nextstop");
  351. }
  352. function _main_dim() {
  353. console.log("dim...");
  354. _api_request("dim");
  355. _switch_ui('ui_dim');
  356. }
  357. function _dim_wakeup() {
  358. console.log("waking up from dim");
  359. _switch_ui("ui_main");
  360. }
  361. function _fare_adult() {
  362. console.log("fare adult");
  363. _api_request("fare", {"rule":"CASH-ADULT", "param":"", "fare":"adult","count":1});
  364. }
  365. function _fare_youth() {
  366. console.log("fare youth");
  367. _api_request("fare", {"rule":"CASH-YOUTH", "param":"", "fare":"youth","count":1});
  368. }
  369. function _fare_half() {
  370. console.log("fare half");
  371. _api_request("fare", {"rule":"CASH-HALF", "param":"", "fare":"half","count":1});
  372. }
  373. function _fare_bike() {
  374. console.log("fare bike");
  375. _api_request("fare", {"rule":"MISC-BIKE", "param":"", "fare":"bike","count":1});
  376. }
  377. function _fare_wheelchair() {
  378. console.log("fare wheelchair");
  379. _api_request("fare", {"rule":"MISC-WHEELCHAIR", "param":"", "fare":"wheelchair","count":1});
  380. }
  381. function _fare_transfer() {
  382. console.log("fare transfer");
  383. _api_request("fare", {"rule":"MISC-TRANSFER", "param":"", "fare":"transfer","count":1});
  384. }
  385. //-------------
  386. //-------------
  387. //-------------
  388. function _main_bulk() {
  389. // reset tab to Misc. (first option) by default
  390. //
  391. ele = document.getElementById("ui_bulk_misc");
  392. ele.classList.remove("highlight");
  393. ele.classList.add("highlight");
  394. ele = document.getElementById("ui_bulk_passes");
  395. ele.classList.remove("highlight");
  396. _show_ui_element("ui_bulk_misc_tab");
  397. _hide_ui_element("ui_bulk_passes_tab");
  398. _switch_ui("ui_bulk");
  399. }
  400. function _main_menu() {
  401. // reset tab to Misc. (first option) by default
  402. //
  403. ele = document.getElementById("ui_fareoverride_misc");
  404. ele.classList.remove("highlight");
  405. ele.classList.add("highlight");
  406. ele = document.getElementById("ui_fareoverride_passes");
  407. ele.classList.remove("highlight");
  408. _show_ui_element("ui_fareoverride_misc_tab");
  409. _hide_ui_element("ui_fareoverride_passes_tab");
  410. _switch_ui("ui_fareoverride");
  411. }
  412. //-------------
  413. //-------------
  414. //-------------
  415. function _bulkaccept_ok() {
  416. console.log("bulkfare:", g_ctx.bulkfare, ", count:", g_ctx.bulkfare_count);
  417. _switch_ui("ui_main");
  418. _api_request("fare",{"rule":g_ctx.bulkfare, "param":g_ctx.bulkfare_count.toString(), "fare":g_ctx.bulkfare,"count":g_ctx.bulkfare_count});
  419. }
  420. function _bulkaccept_cancel() {
  421. _switch_ui("ui_main");
  422. }
  423. function _bulkaccept_input(inp) {
  424. var n = g_ctx.bulkfare_count.length;
  425. if (inp == 'cancel') { _switch_ui('ui_main'); }
  426. else if (inp == 'ok') { _bulkaccept_ok(); return; }
  427. else if (inp == 'bksp') { g_ctx.bulkfare_count = g_ctx.bulkfare_count.substr(0, n-1); }
  428. else if (inp == 'clr') { g_ctx.bulkfare_count = ""; }
  429. else { g_ctx.bulkfare_count += inp; }
  430. // Otherwise update the displayed (driver number)
  431. //
  432. var ele = document.getElementById('ui_bulkaccept_count');
  433. ele.innerHTML = g_ctx.bulkfare_count;
  434. }
  435. //-------------
  436. //-------------
  437. //-------------
  438. // space pad
  439. // default 10
  440. //
  441. function _sp(str, align, pad) {
  442. align = ((typeof align=="undefined") ? "left" : align);
  443. pad = ((typeof pad==="undefined") ? 10 : pad);
  444. var n = 0;
  445. n = pad - str.length;
  446. if (align == "left") {
  447. for (var i=0; i<n; i++) { str += " "; }
  448. }
  449. else if (align == "center") {
  450. var rem = n%2;
  451. var n2 = Math.floor(n/2);
  452. var pfx = "", sfx = "";
  453. for (var i=0; i<n2; i++) { pfx += " "; }
  454. for (var i=0; i<(n2+rem); i++) { sfx += " "; }
  455. str = pfx + str + sfx;
  456. }
  457. else if (align == "right") {
  458. var pfx = "";
  459. for (var i=0; i<n; i++) { pfx += " "; }
  460. str = pfx + str;
  461. }
  462. return str;
  463. }
  464. function _cb_status(inp) {
  465. var tok = inp.split(" ");
  466. if (tok.length < 2) { return; }
  467. if (tok[0]!="ok") { return; }
  468. valtok = tok.slice(1).join(" ").split("\n");
  469. if (valtok[0]!="msg=status") { return; }
  470. g_ctx.diu_status = {};
  471. var fields = valtok[1].split("|");
  472. for (var ii=0; ii<fields.length; ii++) {
  473. var kv = fields[ii].split("=");
  474. if (kv.length!=2) { continue; }
  475. g_ctx.diu_status[kv[0].trim()] = kv[1].trim();
  476. }
  477. if ("equipno" in g_ctx.diu_status) {
  478. g_ctx.cur_eqnum = g_ctx.diu_status["equipno"];
  479. }
  480. var m = g_ctx.diu_status;
  481. if (g_ctx.current_ui === "ui_login") {
  482. var has_tunn = ((m["tunnel"] == '1') ? 'YES' : 'NO');
  483. var has_gprs = ((m["gprs"] == '1') ? 'YES' : 'NO');
  484. var has_gps = ((m["gps"] == '1') ? 'YES' : 'NO');
  485. var lat = ((typeof m["gpslat"] !== "undefined") ? m["gpslat"] : "");
  486. var lon = ((typeof m["gpslon"] !== "undefined") ? m["gpslon"] : "");
  487. var gps_str = ( ((lat.length>0) && (lon.length>0)) ? (" (" + lat + "/" + lon + ")") : "" );
  488. var ele = document.getElementById("ui_login_status");
  489. var html_a = [];
  490. html_a.push("Tunnel: " + has_tunn + " GPRS: " + has_gprs + " Eq#: " + m["equipno"] + " #Msg: " + m["nmsg"]);
  491. html_a.push("Last Token Read (" + m["last_token"] + ")");
  492. html_a.push("GPS: " + has_gps + gps_str + "");
  493. html_a.push(" ");
  494. // some site specific fiddling to display package information
  495. //
  496. html_a.push(_sp("Package") + _sp("Version", "left", 18) + _sp("Installed", "right", 12));
  497. html_a.push(_sp("ui") + _sp(DIU_UI_VERSION, "left", 18) + _sp(DIU_UI_VERSION_DATE, "right", 12) + "");
  498. for (var _ii=0; _ii<3; _ii++) {
  499. var key = "pkg" + _ii;
  500. if (key in g_ctx.diu_status) {
  501. var aval = g_ctx.diu_status[key].split(" ");
  502. html_a.push(_sp(aval[0]) + _sp(aval[1], "left", 18) + _sp(aval[2], "right", 12));
  503. }
  504. }
  505. html_a.push(" ");
  506. if ("IMEI" in m) { html_a.push("IMEI = " + m["IMEI"] + ""); }
  507. if ("IMSI" in m) { html_a.push("IMSI = " + m["IMSI"] + ""); }
  508. if ("ETH0" in m) { html_a.push("ETH0 = " + m["ETH0"] + ""); }
  509. html_a.push(" ");
  510. for (var ii=0; ii<html_a.length; ii++) {
  511. html_a[ii] = html_a[ii].replace(/ /g, '&nbsp;');
  512. }
  513. var div_hdr = "<div class='textrow'>";
  514. var str = div_hdr + html_a.join("</div><br>" + div_hdr ) + "</div>";
  515. ele.innerHTML = str;
  516. }
  517. else if (g_ctx.current_ui === "ui_main") {
  518. var ele = document.getElementById("mainstatus");
  519. var str = "";
  520. str += "Rt " + m["route"] + " ";
  521. str += "Trip " + m["trip"] + " ";
  522. str += "Stop " + m["stop"] + " ";
  523. str += "GPS " + m["gps"] + " ";
  524. str += "Tun " + m["tunnel"] + ", ";
  525. str += m["date"];
  526. str += " " + moment().format("HH:mm");
  527. ele.innerHTML = str;
  528. }
  529. }
  530. function _cb_status_err(e) {
  531. console.log("ERROR: _cb_status_err:", e);
  532. }
  533. //-------------
  534. function _main_message_clear() {
  535. g_ctx.status_text = "";
  536. }
  537. function _main_message_replace(msg, bg_color, text_color) {
  538. var ele = document.getElementById("ui_main_status");
  539. bg_color = ((typeof bg_color === "undefined") ? BG_COLOR : bg_color);
  540. text_color = ((typeof text_color === "undefined") ? TEXT_COLOR : text_color);
  541. var lines = g_ctx.status_text.split("\n");
  542. if (lines.length > g_ctx.status_text_h) {
  543. var n = lines.length;
  544. lines = lines.slice(n - g_ctx.status_text_h);
  545. }
  546. for (var i=0; i<lines.length; i++) {
  547. lines[i] = lines[i].slice(0,g_ctx.status_text_w);
  548. }
  549. var idx = lines.length-1;
  550. if (idx<0) { idx = 0; }
  551. lines[idx] = msg;
  552. var html_lines = [];
  553. for (var i=0; i<lines.length; i++) {
  554. html_lines.push(lines[i].slice(0,g_ctx.status_text_w));
  555. if (html_lines[i].match(/ACCEPT/)) {
  556. html_lines[i] = "<div class='textrow accept'>" + html_lines[i] + "</div>";
  557. }
  558. else if (html_lines[i].match(/REJECT/)) {
  559. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  560. }
  561. else if (html_lines[i].match(/[Uu]nknown/)) {
  562. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  563. }
  564. else if (html_lines[i].match(/[Pp]assback/)) {
  565. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  566. }
  567. else if (html_lines[i].match(/Rule execution error/)) {
  568. html_lines[i] = "<div class='textrow error'>" + html_lines[i] + "</div>";
  569. }
  570. else {
  571. html_lines[i] = "<div class='textrow'>" + html_lines[i] + "</div>";
  572. }
  573. }
  574. g_ctx.status_text = lines.join("\n");
  575. g_ctx.status_text = lines.join("\n");
  576. g_ctx.status_html_text = html_lines.join("<br>");
  577. ele.innerHTML = g_ctx.status_html_text;
  578. // sounds
  579. //
  580. if (msg.match(/ACCEPT/)) {
  581. _beep_accept();
  582. }
  583. else if (msg.match(/REJECT/)) {
  584. _beep_reject();
  585. }
  586. else if (msg.match(/[Uu]nknown/)) {
  587. _beep_reject();
  588. }
  589. else if (msg.match(/[Pp]assback/)) {
  590. _beep_reject();
  591. }
  592. else if (msg.match(/Rule execution error/)) {
  593. _beep_error();
  594. }
  595. }
  596. function _main_message_add(msg, bg_color, text_color) {
  597. var ele = document.getElementById("ui_main_status");
  598. bg_color = ((typeof bg_color === "undefined") ? BG_COLOR : bg_color);
  599. text_color = ((typeof text_color === "undefined") ? TEXT_COLOR : text_color);
  600. var txt = g_ctx.status_text + "\n" + msg;
  601. var html_lines = [];
  602. var lines = txt.split("\n");
  603. if (lines.length > g_ctx.status_text_h) {
  604. var n = lines.length;
  605. lines = lines.slice(n - g_ctx.status_text_h);
  606. }
  607. for (var i=0; i<lines.length; i++) {
  608. html_lines.push(lines[i].slice(0,g_ctx.status_text_w));
  609. if (html_lines[i].match(/ACCEPT/)) {
  610. html_lines[i] = "<div class='textrow accept'>" + html_lines[i] + "</div>";
  611. }
  612. else if (html_lines[i].match(/REJECT/)) {
  613. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  614. }
  615. else if (html_lines[i].match(/[Uu]nknown/)) {
  616. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  617. }
  618. else if (html_lines[i].match(/[Pp]assback/)) {
  619. html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
  620. }
  621. else if (html_lines[i].match(/Rule execution error/)) {
  622. html_lines[i] = "<div class='textrow error'>" + html_lines[i] + "</div>";
  623. }
  624. else {
  625. html_lines[i] = "<div class='textrow'>" + html_lines[i] + "</div>";
  626. }
  627. }
  628. g_ctx.status_text = lines.join("\n");
  629. g_ctx.status_html_text = html_lines.join("<br>");
  630. ele.innerHTML = g_ctx.status_html_text;
  631. // sounds
  632. //
  633. if (msg.match(/ACCEPT/)) {
  634. _beep_accept();
  635. }
  636. else if (msg.match(/REJECT/)) {
  637. _beep_reject();
  638. }
  639. else if (msg.match(/[Uu]nknown/)) {
  640. _beep_reject();
  641. }
  642. else if (msg.match(/[Pp]assback/)) {
  643. _beep_reject();
  644. }
  645. else if (msg.match(/Rule execution error/)) {
  646. _beep_error();
  647. }
  648. }
  649. //-------------
  650. //-------------
  651. //-------------
  652. function _ws_process(dat) {
  653. console.log("_ws_process:", dat);
  654. var tok = dat.split(" ");
  655. if (tok.length < 2) { return; }
  656. if (tok[0] == "paddle") {
  657. if (tok[1] == "ok") { _verify_paddle_ok(); }
  658. else if (tok[1] == "fail") { _verify_paddle_fail(); }
  659. else { _verify_paddle_fail(); }
  660. }
  661. else if (tok[0] == "driver_notify") {
  662. if (tok.length < 5) {
  663. console.log("malformed message: ", dat);
  664. }
  665. else if (tok[1] == "replace") {
  666. _main_message_replace(tok.slice(4).join(" "));
  667. }
  668. else if (tok[1] == "ok") {
  669. _main_message_add(tok.slice(4).join(" "));
  670. }
  671. else {
  672. console.log("unknown message: ", dat);
  673. }
  674. }
  675. }
  676. function _init_websocket() {
  677. var sock = new WebSocket("ws://" + _fqADDRESS);
  678. sock.onopen = function(e) { console.log("open", e); }
  679. sock.onmessage = function(e) { _ws_process(e.data); }
  680. sock.onclose = function(e) {
  681. console.log("close", e);
  682. setTimeout( function() { _init_websocket(); }, 1000);
  683. }
  684. sock.onerror = function(e) {
  685. console.log("error", e);
  686. }
  687. }
  688. //-------------
  689. var ui_pattern = {
  690. "state" : "idle",
  691. "lastX" : 0,
  692. "lastY" : 0,
  693. "curX" : 0,
  694. "curY" : 0
  695. };
  696. function ui_pattern_mousedown(ev) {
  697. var ele = document.getElementById("body");
  698. var rect = ele.getBoundingClientRect();
  699. var x = ev["x"];
  700. var y = ev["y"];
  701. var width = rect.width;
  702. var height = rect.height;
  703. if (ui_pattern.state == "idle") {
  704. if (y < (height/4)) {
  705. ui_pattern.state = "square_0";
  706. }
  707. else {
  708. ui_pattern.state = "idle"
  709. }
  710. }
  711. else if (ui_pattern.state == "square_0") {
  712. if (x > (3*width/4)) {
  713. ui_pattern.state = "square_1";
  714. }
  715. else {
  716. ui_pattern.state = "idle"
  717. }
  718. }
  719. else if (ui_pattern.state == "square_1") {
  720. if (y > (3*height/4)) {
  721. ui_pattern.state = "square_2";
  722. }
  723. else {
  724. ui_pattern.state = "idle"
  725. }
  726. }
  727. else if (ui_pattern.state == "square_2") {
  728. if (x < (width/4)) {
  729. ui_pattern.state = "square_3";
  730. }
  731. else {
  732. ui_pattern.state = "idle"
  733. }
  734. }
  735. else if (ui_pattern.state == "square_3") {
  736. if (y < (height/4)) {
  737. ui_pattern.state = "square_4";
  738. }
  739. else {
  740. ui_pattern.state = "idle"
  741. }
  742. }
  743. else if (ui_pattern.state == "square_4") {
  744. if (x > (3*width/4)) {
  745. ui_pattern.state = "square_5";
  746. }
  747. else {
  748. ui_pattern.state = "idle"
  749. }
  750. }
  751. else if (ui_pattern.state == "square_5") {
  752. if (y > (3*height/4)) {
  753. ui_pattern.state = "square_6";
  754. }
  755. else {
  756. ui_pattern.state = "idle"
  757. }
  758. }
  759. else if (ui_pattern.state == "square_6") {
  760. if (x < (width/4)) {
  761. _switch_ui("ui_diagnostic");
  762. }
  763. ui_pattern.state = "idle"
  764. }
  765. return false;
  766. }
  767. function ui_pattern_mouseup(ev) {
  768. return false;
  769. }
  770. //------------
  771. function _mainscreen() {
  772. _switch_ui('ui_login');
  773. g_ctx.driver_login_state = "driver";
  774. _clear_ui_driver();
  775. _clear_ui_paddle();
  776. }
  777. function _configuration() {
  778. _switch_ui('ui_configuration');
  779. g_ctx.driver_login_state = "driver";
  780. _clear_ui_driver();
  781. _clear_ui_paddle();
  782. }
  783. function _eqnum() {
  784. _switch_ui('ui_eqnum');
  785. g_ctx.driver_login_state = "driver";
  786. if (g_ctx.cur_eqnum.length > 0) {
  787. var ele = document.getElementById("ui_eqnum_eqnum");
  788. ele.innerHTML = g_ctx.cur_eqnum;
  789. g_ctx.eqnum = g_ctx.cur_eqnum;
  790. }
  791. _clear_ui_driver();
  792. _clear_ui_paddle();
  793. }
  794. function _reset() {
  795. _switch_ui('ui_login');
  796. g_ctx.driver_login_state = "driver";
  797. _clear_ui_driver();
  798. _clear_ui_paddle();
  799. location.reload(true);
  800. }
  801. function _reboot() {
  802. _switch_ui('ui_login');
  803. g_ctx.driver_login_state = "driver";
  804. _clear_ui_driver();
  805. _clear_ui_paddle();
  806. }
  807. function _custom0() {
  808. _api_request("interfaceupdown", {"interface":"eth0", "state":"up"}, function(inp) { console.log("custom0 ok:", inp); }, function(inp) { console.log("custom0 error:", inp); });
  809. }
  810. function _custom1() {
  811. _api_request("interfaceupdown", {"interface":"eth0", "state":"down"}, function(inp) { console.log("custom1 ok:", inp); }, function(inp) { console.log("custom1 error:", inp); });
  812. }
  813. function _update_diagnostic_window(_msg) {
  814. var ele = document.getElementById("ui_diagnostic_view");
  815. ele.innerHTML = _msg;
  816. }
  817. function _custom2() {
  818. _api_request("interfaceinfo", {"interface":"eth0"}, _update_diagnostic_window, function(inp) { console.log("custom2 error:", inp); });
  819. }
  820. function _custom3() {
  821. _api_request("say", {"message":"speech test"}, function(inp) { console.log("custom3 ok:", inp); }, function(inp) { console.log("custom3 error:", inp); });
  822. }
  823. function _custom4() {
  824. //_switch_ui('ui_login');
  825. //g_ctx.driver_login_state = "driver";
  826. //_clear_ui_driver();
  827. //_clear_ui_paddle();
  828. }
  829. function _custom5() {
  830. //_switch_ui('ui_login');
  831. //g_ctx.driver_login_state = "driver";
  832. //_clear_ui_driver();
  833. //_clear_ui_paddle();
  834. }
  835. //------------
  836. function _set_eqnum() {
  837. if (g_ctx.eqnum.length == 0) { return; }
  838. _api_request("eqnum", {"eqnum":g_ctx.eqnum}, function(inp) { console.log("eqnum ok:", inp); }, function(inp) { console.log("eqnum error:", inp); });
  839. }
  840. function _eqnum_input(inp) {
  841. var n = g_ctx.eqnum.length;
  842. if (inp == 'cancel') { _switch_ui('ui_login'); }
  843. else if (inp == 'ok') {
  844. _set_eqnum();
  845. _switch_ui('ui_login');
  846. return;
  847. }
  848. else if (inp == 'bksp') { g_ctx.eqnum = g_ctx.eqnum.substr(0, n-1); }
  849. else if (inp == 'clr') { g_ctx.eqnum = ""; }
  850. else { g_ctx.eqnum += inp; }
  851. // Otherwise update the displayed equipment number
  852. //
  853. var ele = document.getElementById('ui_eqnum_eqnum');
  854. ele.innerHTML = g_ctx.eqnum;
  855. }
  856. //-------------
  857. function init() {
  858. _init_websocket();
  859. // diagnostics
  860. //
  861. document.getElementById('ui_diagnostic_mainscreen').onclick = _mainscreen;
  862. document.getElementById('ui_diagnostic_reset').onclick = _reset;
  863. document.getElementById('ui_diagnostic_reboot').onclick = _reboot;
  864. document.getElementById('ui_diagnostic_custom0').onclick = _custom0;
  865. document.getElementById('ui_diagnostic_custom1').onclick = _custom1;
  866. document.getElementById('ui_diagnostic_custom2').onclick = _custom2;
  867. document.getElementById('ui_diagnostic_custom3').onclick = _custom3;
  868. document.getElementById('ui_diagnostic_custom4').onclick = _custom4;
  869. document.getElementById('ui_diagnostic_custom5').onclick = _custom5;
  870. // configuration
  871. //
  872. document.getElementById('ui_configuration_back').onclick = _mainscreen;
  873. document.getElementById('ui_configuration_volumetest').onclick = _volume_test;
  874. document.getElementById('ui_configuration_eqnum').onclick = _eqnum;
  875. // equipment number change
  876. //
  877. document.getElementById('ui_eqnum_cancel').onclick = _mainscreen;
  878. document.getElementById('ui_eqnum_ok').onclick = function() { console.log("eqnum change"); }
  879. // login
  880. //
  881. document.getElementById('ui_login_login').onclick = _login;
  882. document.getElementById('ui_login_configuration').onclick = _configuration;
  883. document.getElementById('ui_driverincorrect_btn').onclick = _driver_incorrect;
  884. document.getElementById('ui_paddleunknown_btn').onclick = _paddle_unknown;
  885. // main menu buttons
  886. //
  887. document.getElementById('ui_main_prv').onclick = _main_prv;
  888. document.getElementById('ui_main_nxt').onclick = _main_nxt;
  889. document.getElementById('ui_main_bulk').onclick = _main_bulk;
  890. document.getElementById('ui_main_menu').onclick = _main_menu;
  891. document.getElementById('ui_main_dim').onclick = _main_dim;
  892. // dim
  893. //
  894. document.getElementById('ui_dim_btn').onclick = _dim_wakeup;
  895. var simple_fares = [ "adult", "youth", "half", "bike", "wheelchair", "transfer"];
  896. var simple_fares_f = [ _fare_adult, _fare_youth, _fare_half, _fare_bike, _fare_wheelchair, _fare_transfer];
  897. for (var ii=0; ii<simple_fares.length; ii++) {
  898. var fare = simple_fares[ii];
  899. document.getElementById('ui_main_' + fare).onclick = simple_fares_f[ii];
  900. }
  901. // bulk menu buttons
  902. //
  903. document.getElementById('ui_bulk_passes').onclick =
  904. function() {
  905. var ele;
  906. ele = document.getElementById("ui_bulk_misc");
  907. ele.classList.remove("highlight");
  908. ele = document.getElementById("ui_bulk_passes");
  909. ele.classList.add("highlight");
  910. _hide_ui_element("ui_bulk_misc_tab");
  911. _show_ui_element("ui_bulk_passes_tab");
  912. };
  913. document.getElementById('ui_bulk_misc').onclick =
  914. function() {
  915. var ele;
  916. ele = document.getElementById("ui_bulk_misc");
  917. ele.classList.add("highlight");
  918. ele = document.getElementById("ui_bulk_passes");
  919. ele.classList.remove("highlight");
  920. _show_ui_element("ui_bulk_misc_tab");
  921. _hide_ui_element("ui_bulk_passes_tab");
  922. };
  923. document.getElementById('ui_bulk_menu').onclick = function() { _switch_ui("ui_main"); }
  924. // Setup "Bulk" UI accept buttons to do proper screen switching and
  925. // other tasks.
  926. //
  927. var bulk_pass = ["adult", "youth", "half", "event", "transfer", "interline",
  928. "schoola", "schoolb", "schoolc", "orga", "orgb", "orgc"];
  929. var bulk_rule = ["BULK-CASH-ADULT", "BULK-CASH-YOUTH", "BULK-CASH-HALF",
  930. "BULK-MISC-EVENT", "BULK-MISC-TRANSFER", "BULK-MISC-INTERLINE",
  931. "BULK-OVR-SCHOOLA", "BULK-OVR-SCHOOLB", "BULK-OVR-SCHOOLC",
  932. "BULK-OVR-ORGA", "BULK-OVR-ORGB", "BULK-OVR-ORGC"];
  933. var bulk_pass_name = ["Adult Cash", "Youth Cash", "Half Cash", "Special Event", "Transfer", "Interline",
  934. "School A", "School B", "School C", "Org A", "Org B", "Org C"];
  935. // use site specific values if available, otherwise default to the above
  936. //
  937. if ((typeof BULK_PASS !== "undefined") && (BULK_PASS.length > 0)) {
  938. bulk_pass = BULK_PASS;
  939. }
  940. if ((typeof BULK_RULE !== "undefined") && (BULK_RULE.length > 0)) {
  941. bulk_rule= BULK_RULE;
  942. }
  943. if ((typeof BULK_PASS_NAME !== "undefined") && (BULK_PASS_NAME.length > 0)) {
  944. bulk_pass_name = BULK_PASS_NAME;
  945. }
  946. for (var i=0; i<bulk_pass.length; i++) {
  947. var p = bulk_pass[i];
  948. var u = bulk_pass_name[i];
  949. var r = bulk_rule[i];
  950. var ele = document.getElementById('ui_bulk_' + p);
  951. ele.onclick = (function(x,y) {
  952. return function() {
  953. _clear_ui_bulkaccept();
  954. g_ctx.bulkfare = x;
  955. _switch_ui("ui_bulkaccept");
  956. var ee = document.getElementById("ui_bulkaccept_faretype");
  957. ee.innerHTML = y;
  958. };
  959. })(r, u);
  960. }
  961. // bulk accept fares
  962. //
  963. document.getElementById('ui_bulkaccept_ok').onclick = _bulkaccept_ok;
  964. document.getElementById('ui_bulkaccept_cancel').onclick = _bulkaccept_cancel;
  965. // fareoverride menu buttons
  966. //
  967. document.getElementById('ui_fareoverride_passes').onclick =
  968. function() {
  969. var ele;
  970. ele = document.getElementById("ui_fareoverride_misc");
  971. ele.classList.remove("highlight");
  972. ele = document.getElementById("ui_fareoverride_passes");
  973. ele.classList.add("highlight");
  974. _hide_ui_element("ui_fareoverride_misc_tab");
  975. _show_ui_element("ui_fareoverride_passes_tab");
  976. };
  977. document.getElementById('ui_fareoverride_misc').onclick =
  978. function() {
  979. var ele;
  980. ele = document.getElementById("ui_fareoverride_misc");
  981. ele.classList.add("highlight");
  982. ele = document.getElementById("ui_fareoverride_passes");
  983. ele.classList.remove("highlight");
  984. _show_ui_element("ui_fareoverride_misc_tab");
  985. _hide_ui_element("ui_fareoverride_passes_tab");
  986. };
  987. document.getElementById('ui_fareoverride_menu').onclick = function() { _switch_ui("ui_main"); }
  988. document.getElementById('ui_fareoverride_logout').onclick =
  989. function() {
  990. _main_message_clear();
  991. _api_request("logout");
  992. _switch_ui("ui_login");
  993. }
  994. // default values for override passes
  995. //
  996. var override_pass = [ "adult", "youth", "half",
  997. "bike", "wheelchair", "transfer",
  998. "event", "interline",
  999. "schoola", "schoolb", "schoolc",
  1000. "orga", "orgb", "orgc" ];
  1001. var override_rule = [ "CASH-ADULT", "CASH-YOUTH", "CASH-HALF",
  1002. "MISC-BIKE", "MISC-WHEELCHAIR", "MISC-TRANSFER",
  1003. "MISC-EVENT", "MISC-INTERLINE",
  1004. "OVR-SCHOOLA", "OVR-SCHOOLB", "OVR-SCHOOLC",
  1005. "OVR-ORGA", "OVR-ORGB", "OVR-ORGC" ];
  1006. // use site specific values if available, otherwise default to the above
  1007. //
  1008. if ((typeof OVERRIDE_PASS !== "undefined") && (OVERRIDE_PASS.length > 0)) {
  1009. override_pass = OVERRIDE_PASS;
  1010. }
  1011. if ((typeof OVERRIDE_RULE !== "undefined") && (OVERRIDE_RULE.length > 0)) {
  1012. override_rule= OVERRIDE_RULE;
  1013. }
  1014. for (var i=0; i<override_pass.length; i++) {
  1015. var p = override_pass[i];
  1016. var r = override_rule[i];
  1017. var ele = document.getElementById("ui_fareoverride_" + p);
  1018. ele.onclick = (function(x,y) {
  1019. return function() { _api_request("fare", {"rule":x,"fare":y,"param":"","count":1}); };
  1020. })(r,p);
  1021. }
  1022. var ui_page = [ "driver", "paddle", "bulkaccept", "eqnum" ];
  1023. var ui_func = [ _driver_login, _paddle_input, _bulkaccept_input, _eqnum_input ];
  1024. for (var idx=0; idx<ui_page.length; idx++) {
  1025. var c = ui_page[idx];
  1026. var f = ui_func[idx];
  1027. for (var i=0; i<=9; i++) {
  1028. document.getElementById('ui_' + c + '_' + i).onclick =
  1029. (function(_f, x) { return function() { _f(x); } })(f, i);
  1030. }
  1031. document.getElementById('ui_' + c + '_' + 'bksp').onclick =
  1032. (function(_f,x) { return function() { _f(x); } })(f, 'bksp');
  1033. document.getElementById('ui_' + c + '_' + 'clr').onclick =
  1034. (function(_f,x) { return function() { _f(x); } })(f, 'clr');
  1035. document.getElementById('ui_' + c + '_' + 'ok').onclick =
  1036. (function(_f,x) { return function() { _f(x); } })(f, 'ok');
  1037. document.getElementById('ui_' + c + '_' + 'cancel').onclick =
  1038. (function(_f,x) { return function() { _f(x); } })(f, 'cancel');
  1039. }
  1040. // set interval to check status every 1 second
  1041. //
  1042. var x = window.setInterval(function() { _api_request("status", {}, _cb_status, _cb_status_err); }, 1000);
  1043. // try and reduce textarea highlighting, drag and drop/copy pasting,
  1044. // and other bad behavor.
  1045. //
  1046. var ele;
  1047. var block_ele;
  1048. var rect;
  1049. ele = document.getElementById("ui_login_status");
  1050. ele.ondragstart = function() { return false; }
  1051. ele.onselectstart = function() { return false; }
  1052. ele.onmousedown = function() { return false; }
  1053. ele.ondragstart = function() { return false; }
  1054. rect = ele.getBoundingClientRect();
  1055. block_ele = document.getElementById("ui_login_blockwindow");
  1056. block_ele.style.width = rect.width;
  1057. block_ele.style.height = rect.height;
  1058. block_ele.style.bottom = rect.bottom;
  1059. block_ele.style.left = rect.left;
  1060. block_ele.style.top = rect.top;
  1061. block_ele.style.right = rect.right;
  1062. block_ele.style.x = rect.x;
  1063. block_ele.style.y = rect.y;
  1064. ele = document.getElementById("ui_main_status");
  1065. ele.ondragstart = function() { return false; }
  1066. ele.onselectstart = function() { return false; }
  1067. ele.onmousedown = function() { return false; }
  1068. ele.ondragstart = function() { return false; }
  1069. rect = ele.getBoundingClientRect();
  1070. block_ele = document.getElementById("ui_main_blockwindow");
  1071. block_ele.style.width = rect.width;
  1072. block_ele.style.height = rect.height;
  1073. block_ele.style.bottom = rect.bottom;
  1074. block_ele.style.left = rect.left;
  1075. block_ele.style.top = rect.top;
  1076. block_ele.style.right = rect.right;
  1077. block_ele.style.x = rect.x;
  1078. block_ele.style.y = rect.y;
  1079. ele = document.getElementById("body");
  1080. // We're using jquery so we need to gracefully add callbacks
  1081. // for mouse events.
  1082. //
  1083. ele.addEventListener('mousedown', ui_pattern_mousedown);
  1084. ele.addEventListener('mouseup', ui_pattern_mouseup);
  1085. g_snd.button_press = new Audio("assets/459992_florianreichelt_beep_short.mp3");
  1086. g_snd.accept_fare = new Audio("assets/443026__qubodup__public-domain-beep-sound.mp3");
  1087. g_snd.reject_fare = new Audio("assets/368780__gurie__start-sound-beep.mp3");
  1088. g_snd.rule_error = new Audio("assets/363920__samsterbirdies__8-bit-error.mp3");
  1089. if (typeof PopufareSiteInit !== "undefined") {
  1090. PopufareSiteInit();
  1091. }
  1092. }
  1093. (function($) {
  1094. $(document).ready(function() {
  1095. init();
  1096. });
  1097. })(jQuery);