diu_ui-ORG.js 38 KB

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