diu_ui-ORG.js 38 KB

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