diu_ui-ORG.js 38 KB

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