| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641 |
- /*
- * Copyright (c) 2019 Clementine Computing LLC.
- *
- * This file is part of PopuFare.
- *
- * PopuFare is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * PopuFare is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with PopuFare. If not, see <https://www.gnu.org/licenses/>.
- *
- */
- var _ADDRESS = "localhost";
- var _URL = "http://" + _ADDRESS;
- var _PORT = 60535;
- var _fqADDRESS = _ADDRESS + ":" + _PORT;
- var BG_COLOR = "#f7f7f7";
- var TEXT_COLOR = "#444444";
- var DIU_UI_VERSION = "0.1.10";
- var DIU_UI_VERSION_DATE = "2020-02-10";
- var g_snd = {
- "reject_fare" : "",
- "accept_fare" : "",
- "rule_error" : "",
- "button_press" : ""
- };
- function _beep_error() {
- g_snd.rule_error.currentTime=0;
- g_snd.rule_error.play();
- }
- function _beep_reject() {
- g_snd.reject_fare.currentTime=0;
- g_snd.reject_fare.play();
- }
- function _beep_accept() {
- g_snd.accept_fare.currentTime=0;
- g_snd.accept_fare.play();
- }
- function _beep() {
- g_snd.button_press.currentTime=0;
- g_snd.button_press.play();
- }
- var g_ctx = {
- "driver_login_state" : "driver",
- "driver" : "",
- "pin" : "",
- "paddle" : "",
- "eqnum" : "",
- "cur_eqnum" : "",
- "current_ui" : "ui_login",
- "ui_stack" : [],
- "ui_change_timeoutid": -1,
- "ui_watchdog_timeoutid": -1,
- "bulkfare" : "",
- "bulkfare_count" : "",
- "status_text": "",
- "status_text_w": 32,
- "status_text_h": 11,
- "status_html_text":"",
- "diu_status" : {},
- "x": ""
- };
- function _api_fail() {
- console.log(">>api fail");
- return true;
- }
- function _api_tick() { }
- function _api_request(action, param, cb_ok, cb_fail, cb_neterr) {
- var idx = 0;
- var param_name = [], param_val = [];
- var req = new XMLHttpRequest();
- // Firefox gets testy about parsing assumed XML
- //
- req.overrideMimeType("text/plain");
- var url = "/req";
- var varstr = "action=" + action;
- for (var x in param) {
- param_name.push(x);
- param_val.push(param[x]);
- }
- for (var ii=0; ii<param_name.length; ii++) {
- varstr += "&" + param_name[ii] + "=" + param_val[ii];
- }
- req.onreadystatechange = function() {
- if (req.readyState == 4) {
- if (req.status == 200) {
- var fulltxt = req.responseText;
- var resp = req.responseText.split(" ");
- if ((resp.length>=2) && (resp[0] == "ok")) {
- if (typeof cb_ok !== "undefined") {
- cb_ok(fulltxt);
- }
- return;
- }
- if (typeof cb_fail !== "undefined") {
- cb_fail(fulltxt);
- }
- }
- else if (typeof cb_fail !== "undefined") { cb_fail(); }
- }
- };
- req.addEventListener("error", _api_fail);
- req.addEventListener("abort", _api_fail);
- //req.addEventListener("load", _api_tick);
- //req.addEventListener("progress", _api_tick);
- req.onerror = function() { console.log("network error"); };
- try {
- //DEBUG
- console.log("req, varstr:", varstr);
- req.open("POST", url, true);
- req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
- req.send(varstr);
- } catch (er) {
- console.log(">>>>>>ERROR", er);
- }
- }
- function _block_status_window(ui_id) {
- var ele = document.getElementById(ui_id + "_status");
- ele.ondragstart = function() { return false; }
- ele.onselectstart = function() { return false; }
- ele.onmousedown = function() { return false; }
- ele.ondragstart = function() { return false; }
- var rect = ele.getBoundingClientRect();
- var block_ele = document.getElementById(ui_id + "_blockwindow");
- block_ele.style.width = rect.width;
- block_ele.style.height = rect.height;
- block_ele.style.bottom = rect.bottom;
- block_ele.style.left = rect.left;
- block_ele.style.top = rect.top;
- block_ele.style.right = rect.right;
- block_ele.style.x = rect.x;
- block_ele.style.y = rect.y;
- }
- function _clear_ui_watchdog() {
- if (g_ctx.ui_watchdog_timeoutid >= 0) {
- window.clearTimeout(g_ctx.ui_watchdog_timeoutid);
- }
- }
- function _set_ui_watchdog(failsafe_ui, _dt) {
- // default to 'ui_watchdog' and 5s
- //
- failsafe_ui = (( typeof failsafe_ui === "undefined") ? "ui_watchdog" : failsafe_ui);
- _dt = (( typeof _dt === "undefined") ? 5000 : _dt);
- _clear_ui_watchdog();
- g_ctx.ui_watchdog_timeoutid = window.setTimeout(
- (function(_fsui) {
- return function() { console.log("???", _fsui); _switch_ui(_fsui); };
- })(failsafe_ui),
- _dt);
- }
- function _switch_ui(to) {
- var ele;
- if (g_ctx.ui_change_timeoutid > 0) {
- window.clearTimeout(g_ctx.ui_change_timeoutid);
- g_ctx.ui_change_timeoutid = -1;
- }
- var from = g_ctx.current_ui;
- ele = document.getElementById(from);
- ele.style.display = "none";
- ele = document.getElementById(to);
- ele.style.display = "block";
- g_ctx.current_ui = to;
- if (to == "ui_main") {
- var _x = _calculate_ui_main_status_width_height();
- g_ctx.status_text_h = _x.n_height;
- g_ctx.status_text_w = _x.n_width;
- }
- if ((to == "ui_main") ||
- (to == "ui_login")) {
- _block_status_window(to);
- }
- }
- function _hide_ui(from) {
- var ele = document.getElementById(from);
- ele.style.display = "none";
- }
- function _hide_ui_element(from) {
- var ele = document.getElementById(from);
- ele.style.display = "none";
- }
- function _show_ui(to) {
- var ele = document.getElementById(to);
- ele.style.display = "block";
- g_ctx.current_ui = to;
- // put pane over status window to prevent highlights,
- // copy/pasting, etc.
- //
- if ((to == "ui_main") ||
- (to == "ui_login")) {
- _block_status_window(to);
- }
- }
- function _show_ui_element(to) {
- var ele = document.getElementById(to);
- ele.style.display = "block";
- }
- //------------
- function _get_now_HH_MM() {
- var _dt = new Date();
- var _sep = ":";
- if ( (_dt.getSeconds() % 2) == 0) {
- _sep = " ";
- }
- var _hr = _dt.getHours();
- var _min = _dt.getMinutes();
- var _hr_str = _hr.toString();
- var _min_str = _min.toString();
- if (_hr < 10) { _hr_str = "0" + _hr_str; }
- if (_min < 10) { _min_str = "0" + _min_str; }
- var _time_str = _hr_str + _sep + _min_str;
- return _time_str;
- }
- function _update_display_time() {
- var ele = document.getElementById("ui_main_time");
- if (typeof ele === "undefined") { return; }
- /*
- var _dt = new Date();
- var _sep = ":";
- if ( (_dt.getSeconds() % 2) == 0) { _sep = " "; }
- var _hr = _dt.getHours();
- var _min = _dt.getMinutes();
- var _hr_str = _hr.toString();
- var _min_str = _min.toString();
- if (_hr < 10) { _hr_str = "0" + _hr_str; }
- if (_min < 10) { _min_str = "0" + _min_str; }
- var _time_str = _hr_str + _sep + _min_str;
- */
- var _time_str = _get_now_HH_MM();
- ele.innerHTML = "<span style='white-space:nowrap;'>" + _time_str + "</span>";
- }
- //------------
- function _update_login_time() {
- var ele = document.getElementById("ui_login_time");
- if (typeof ele === "undefined") { return; }
- var _time_str = _get_now_HH_MM();
- ele.innerHTML = "<span style='white-space:nowrap;'>" + _time_str + "</span>";
- }
- //------------
- // value is from [0,1]
- //
- function _process_brightness(brightness) {
- // 0 opacity is completely clear, so (1.0) brightness (100% brightness).
- //
- var f_brightness = parseFloat(brightness);
- var opacity = 1.0 - f_brightness;
- // fail
- //
- if ((opacity < 0.0) || (opacity > 1.0)) { return {"type":"error", "msg":"opacity out of range"}; }
- var ele = document.getElementById("dim_overlay");
- ele.style.opacity = opacity;
- ele = document.getElementById("ui_configuration_displaybrightness");
- ival = Math.floor(f_brightness*100.0);
- ele.innerHTML = "" + ival + "%";
- }
- //------------
- // volume is from [0,1]
- //
- function _process_volume(vol) {
- var ele = document.getElementById("ui_configuration_displayvolume");
- ivol = Math.floor(vol*100.0);
- ele.innerHTML = "" + ivol + "%";
- }
- function _slider_change(name) {
- if (name == "configuration.volume") {
- var val = document.getElementById("ui_configuration_volume").value;
- _process_volume(val);
- ivol = Math.floor(val*100.0);
- _api_request("custom", {"function":"volume", "parameter":ivol});
- }
- else if (name == "configuration.brightness") {
- var val = document.getElementById("ui_configuration_brightness").value;
- _process_brightness(val);
- }
- }
- function _volume_test() {
- _api_request("custom", {"function":"say", "parameter":"testing 1, 2, 3"});
- }
- //------------
- function _clear_ui_driver() {
- var ele;
- var u = ["driver", "pin"];
- for (var i=0; i<u.length; i++) {
- g_ctx[u[i]] = "";
- ele = document.getElementById("ui_driver_" + u[i]);
- ele.innerHTML = "";
- ele.style.background = "";
- }
- ele = document.getElementById("ui_driver_pin");
- ele.style.display = "none";
- ele = document.getElementById("ui_driver_pin_text");
- ele.style.display = "none";
- }
- function _clear_ui_paddle() {
- g_ctx.paddle = "";
- var ele = document.getElementById("ui_paddle_paddle");
- ele.innerHTML = "";
- }
- function _clear_ui_bulkaccept() {
- var ele;
- g_ctx.bulkfare = "";
- ele = document.getElementById("ui_bulkaccept_faretype");
- ele.innerHTML = "";
- g_ctx.bulkfare_count = "";
- ele = document.getElementById("ui_bulkaccept_count");
- ele.innerHTML = "";
- }
- function _login() {
- _switch_ui('ui_driver');
- g_ctx.driver_login_state = "driver";
- _clear_ui_driver();
- _clear_ui_paddle();
- }
- //------------
- function _verify_driver() {
- var driver = g_ctx.driver;
- var pin = g_ctx.pin;
- // have a fail safe for the verification
- //
- _set_ui_watchdog();
- _api_request("driverlogin", {"driver":driver, "pin":pin}, _verify_driver_ok, _verify_driver_fail);
- return;
- }
- function _verify_driver_ok() {
- console.log("driver ok");
- _clear_ui_watchdog();
- _switch_ui("ui_paddle");
- }
- function _verify_driver_fail() {
- console.log("driver fail");
- _clear_ui_watchdog();
- _switch_ui("ui_driverincorrect");
- }
- function _driver_incorrect(inp) {
- console.log("driver incorrect");
- _clear_ui_watchdog();
- _clear_ui_driver();
- _switch_ui("ui_driver");
- }
- //------------
- function _driver_login(inp) {
- var uvar = "";
- if (g_ctx.driver_login_state == "driver") { uvar = "driver"; }
- else if (g_ctx.driver_login_state == "pin") { uvar = "pin"; }
- else {
- console.log("_driver_login: ERROR: unknown driver state \"" + g_ctx.driver_login_state + "\"");
- return;
- }
- var n = g_ctx[uvar].length;
- if (inp == 'cancel') { _switch_ui('ui_login'); }
- else if (inp == 'ok') {
- if (uvar == "driver") {
- g_ctx.driver_login_state = "pin";
- var ele;
- ele = document.getElementById("ui_driver_driver");
- ele.style.background = "#aaaaaa";
- // Show 'pin' box now that the 'driver' box has been filled
- //
- ele = document.getElementById("ui_driver_pin");
- ele.style.display = "block";
- ele = document.getElementById("ui_driver_pin_text");
- ele.style.display = "block";
- }
- else if (uvar == "pin") {
- g_ctx.driver_login_state = "driver";
- _verify_driver();
- g_ctx.ui_change_timeoutid = window.setTimeout(function() {
- _switch_ui("ui_driververify");
- }, 150);
- return;
- }
- }
- // manage adding/subtracting/clearing relevant field
- //
- else if (inp == 'bksp') { g_ctx[uvar] = g_ctx[uvar].substr(0, n-1); }
- else if (inp == 'clr') { g_ctx[uvar]= ""; }
- else { g_ctx[uvar] += inp; }
- // Pin should not be displayed on screen.
- // Use '*' to hide it.
- //
- if (uvar == "pin") {
- var n = g_ctx[uvar].length;
- var x = "";
- for (i=0; i<n; i++) { x += "*"; }
- var ele = document.getElementById('ui_driver_' + uvar);
- ele.innerHTML = x;
- }
- // Otherwise update the displayed (driver number)
- //
- else {
- var ele = document.getElementById('ui_driver_' + uvar);
- ele.innerHTML = g_ctx[uvar];
- }
- }
- //------------
- //------------
- function _verify_paddle() {
- var paddle = g_ctx.paddle;
- // have a fail safe for the verification
- //
- _set_ui_watchdog();
- _api_request("paddleinput", {"paddle":paddle}, _verify_paddle_ack, _verify_paddle_fail);
- return;
- }
- function _verify_paddle_ack() {
- console.log("got ack for push paddle message\n");
- }
- function _verify_paddle_ok() {
- console.log("verify paddle ok");
- _clear_ui_watchdog();
- _switch_ui("ui_main");
- }
- function _verify_paddle_fail() {
- console.log("verify paddle fail");
- _clear_ui_watchdog();
- _switch_ui("ui_paddleunknown");
- }
- function _paddle_unknown(inp) {
- console.log("paddle unknown...");
- _clear_ui_watchdog();
- _clear_ui_paddle();
- _switch_ui("ui_paddle");
- }
- function _watchdog_tripped(inp) {
- console.log("watchdog UI expired!...");
- _reset();
- }
- //------------
- function _paddle_input(inp) {
- var n = g_ctx.paddle.length;
- if (inp == 'cancel') { _switch_ui('ui_login'); }
- else if (inp == 'ok') {
- _verify_paddle();
- g_ctx.ui_change_timeoutid = window.setTimeout(function() {
- _switch_ui("ui_paddleverify");
- }, 150);
- return;
- }
- else if (inp == 'bksp') { g_ctx.paddle = g_ctx.paddle.substr(0, n-1); }
- else if (inp == 'clr') { g_ctx.paddle = ""; }
- else { g_ctx.paddle += inp; }
- // Otherwise update the displayed (driver number)
- //
- var ele = document.getElementById('ui_paddle_paddle');
- ele.innerHTML = g_ctx.paddle;
- }
- //-------------
- //-------------
- //-------------
- function _main_prv() {
- console.log("prv");
- _api_request("prevstop");
- }
- function _main_nxt() {
- console.log("nxt");
- _api_request("nextstop");
- }
- function _main_dim() {
- console.log("dim...");
- //_api_request("dim");
- _api_request("custom", {"function":"dim"});
- _switch_ui('ui_dim');
- }
- function _dim_wakeup() {
- console.log("waking up from dim");
- _api_request("custom", {"function": "undim" });
- _switch_ui("ui_main");
- }
- function _fare_adult() {
- console.log("fare adult");
- _api_request("fare", {"rule":"CASH-ADULT", "param":"", "fare":"adult","count":1});
- }
- function _fare_youth() {
- console.log("fare youth");
- _api_request("fare", {"rule":"CASH-YOUTH", "param":"", "fare":"youth","count":1});
- }
- function _fare_half() {
- console.log("fare half");
- _api_request("fare", {"rule":"CASH-HALF", "param":"", "fare":"half","count":1});
- }
- function _fare_bike() {
- console.log("fare bike");
- _api_request("fare", {"rule":"MISC-BIKE", "param":"", "fare":"bike","count":1});
- }
- function _fare_wheelchair() {
- console.log("fare wheelchair");
- _api_request("fare", {"rule":"MISC-WHEELCHAIR", "param":"", "fare":"wheelchair","count":1});
- }
- function _fare_transfer() {
- console.log("fare transfer");
- _api_request("fare", {"rule":"MISC-TRANSFER", "param":"", "fare":"transfer","count":1});
- }
- //-------------
- //-------------
- //-------------
- function _main_bulk() {
- // reset tab to Misc. (first option) by default
- //
- ele = document.getElementById("ui_bulk_misc");
- ele.classList.remove("highlight");
- ele.classList.add("highlight");
- ele = document.getElementById("ui_bulk_passes");
- ele.classList.remove("highlight");
- _show_ui_element("ui_bulk_misc_tab");
- _hide_ui_element("ui_bulk_passes_tab");
- _switch_ui("ui_bulk");
- }
- function _main_menu() {
- // reset tab to Misc. (first option) by default
- //
- ele = document.getElementById("ui_fareoverride_misc");
- ele.classList.remove("highlight");
- ele.classList.add("highlight");
- ele = document.getElementById("ui_fareoverride_passes");
- ele.classList.remove("highlight");
- ele = document.getElementById("ui_fareoverride_options");
- ele.classList.remove("highlight");
- _show_ui_element("ui_fareoverride_misc_tab");
- _hide_ui_element("ui_fareoverride_passes_tab");
- _hide_ui_element("ui_fareoverride_options_tab");
- _switch_ui("ui_fareoverride");
- }
- //-------------
- //-------------
- //-------------
- function _bulkaccept_ok() {
- console.log("bulkfare:", g_ctx.bulkfare, ", count:", g_ctx.bulkfare_count);
- _switch_ui("ui_main");
- _api_request("fare",{"rule":g_ctx.bulkfare, "param":g_ctx.bulkfare_count.toString(), "fare":g_ctx.bulkfare,"count":g_ctx.bulkfare_count});
- }
- function _bulkaccept_cancel() {
- _switch_ui("ui_main");
- }
- function _bulkaccept_input(inp) {
- var n = g_ctx.bulkfare_count.length;
- if (inp == 'cancel') { _switch_ui('ui_main'); }
- else if (inp == 'ok') { _bulkaccept_ok(); return; }
- else if (inp == 'bksp') { g_ctx.bulkfare_count = g_ctx.bulkfare_count.substr(0, n-1); }
- else if (inp == 'clr') { g_ctx.bulkfare_count = ""; }
- else { g_ctx.bulkfare_count += inp; }
- // Otherwise update the displayed (driver number)
- //
- var ele = document.getElementById('ui_bulkaccept_count');
- ele.innerHTML = g_ctx.bulkfare_count;
- }
- //-------------
- //-------------
- //-------------
- // space pad
- // default 10
- //
- function _sp(str, align, pad) {
- align = ((typeof align=="undefined") ? "left" : align);
- pad = ((typeof pad==="undefined") ? 10 : pad);
- var n = 0;
- n = pad - str.length;
- if (align == "left") {
- for (var i=0; i<n; i++) { str += " "; }
- }
- else if (align == "center") {
- var rem = n%2;
- var n2 = Math.floor(n/2);
- var pfx = "", sfx = "";
- for (var i=0; i<n2; i++) { pfx += " "; }
- for (var i=0; i<(n2+rem); i++) { sfx += " "; }
- str = pfx + str + sfx;
- }
- else if (align == "right") {
- var pfx = "";
- for (var i=0; i<n; i++) { pfx += " "; }
- str = pfx + str;
- }
- return str;
- }
- function _cb_status(inp) {
- var tok = inp.split(" ");
- if (tok.length < 2) { return; }
- if (tok[0]!="ok") { return; }
- valtok = tok.slice(1).join(" ").split("\n");
- if (valtok[0]!="msg=status") { return; }
- g_ctx.diu_status = {};
- var fields = valtok[1].split("|");
- for (var ii=0; ii<fields.length; ii++) {
- var kv = fields[ii].split("=");
- if (kv.length!=2) { continue; }
- g_ctx.diu_status[kv[0].trim()] = kv[1].trim();
- }
- if ("equipno" in g_ctx.diu_status) {
- g_ctx.cur_eqnum = g_ctx.diu_status["equipno"];
- }
- var m = g_ctx.diu_status;
- if (g_ctx.current_ui === "ui_login") {
- var has_tunn = ((m["tunnel"] == '1') ? 'YES' : 'NO');
- var has_gprs = ((m["gprs"] == '1') ? 'YES' : 'NO');
- var has_gps = ((m["gps"] == '1') ? 'YES' : 'NO');
- var lat = ((typeof m["gpslat"] !== "undefined") ? m["gpslat"] : "");
- var lon = ((typeof m["gpslon"] !== "undefined") ? m["gpslon"] : "");
- var gps_str = ( ((lat.length>0) && (lon.length>0)) ? (" (" + lat + "/" + lon + ")") : "" );
- var ele = document.getElementById("ui_login_status");
- var html_a = [];
- html_a.push("Tunnel: " + has_tunn + " GPRS: " + has_gprs + " Eq#: " + m["equipno"] + " #Msg: " + m["nmsg"]);
- html_a.push("Last Token Read (" + m["last_token"] + ")");
- html_a.push("GPS: " + has_gps + gps_str + "");
- html_a.push(" ");
- // some site specific fiddling to display package information
- //
- html_a.push(_sp("Package") + _sp("Version", "left", 18) + _sp("Installed", "right", 12));
- html_a.push(_sp("ui") + _sp(DIU_UI_VERSION, "left", 18) + _sp(DIU_UI_VERSION_DATE, "right", 12) + "");
- for (var _ii=0; _ii<3; _ii++) {
- var key = "pkg" + _ii;
- if (key in g_ctx.diu_status) {
- var aval = g_ctx.diu_status[key].split(" ");
- html_a.push(_sp(aval[0]) + _sp(aval[1], "left", 18) + _sp(aval[2], "right", 12));
- }
- }
- html_a.push(" ");
- if ("IMEI" in m) { html_a.push("IMEI = " + m["IMEI"] + ""); }
- if ("IMSI" in m) { html_a.push("IMSI = " + m["IMSI"] + ""); }
- if ("ETH0" in m) { html_a.push("ETH0 = " + m["ETH0"] + ""); }
- html_a.push(" ");
- for (var ii=0; ii<html_a.length; ii++) {
- html_a[ii] = html_a[ii].replace(/ /g, ' ');
- }
- var div_hdr = "<div class='textrow'>";
- var str = div_hdr + html_a.join("</div><br>" + div_hdr ) + "</div>";
- ele.innerHTML = str;
- }
- else if (g_ctx.current_ui === "ui_main") {
- var ele = document.getElementById("mainstatus");
- var str = "";
- str += "Rt " + m["route"] + " ";
- str += "Trip " + m["trip"] + " ";
- str += "Stop " + m["stop"] + " ";
- str += "GPS " + m["gps"] + " ";
- str += "Tun " + m["tunnel"] + ", ";
- str += m["date"];
- str += " " + moment().format("HH:mm");
- ele.innerHTML = str;
- }
- }
- function _cb_status_err(e) {
- console.log("ERROR: _cb_status_err:", e);
- }
- //-------------
- function _main_message_clear() {
- g_ctx.status_text = "";
- }
- function _main_message_replace(msg, bg_color, text_color) {
- var ele = document.getElementById("ui_main_status");
- bg_color = ((typeof bg_color === "undefined") ? BG_COLOR : bg_color);
- text_color = ((typeof text_color === "undefined") ? TEXT_COLOR : text_color);
- var lines = g_ctx.status_text.split("\n");
- if (lines.length > g_ctx.status_text_h) {
- var n = lines.length;
- lines = lines.slice(n - g_ctx.status_text_h);
- }
- for (var i=0; i<lines.length; i++) {
- lines[i] = lines[i].slice(0,g_ctx.status_text_w-1);
- }
- var idx = lines.length-1;
- if (idx<0) { idx = 0; }
- lines[idx] = msg;
- var html_lines = [];
- for (var i=0; i<lines.length; i++) {
- html_lines.push(lines[i].slice(0,g_ctx.status_text_w-1));
- if (html_lines[i].match(/ACCEPT/)) {
- html_lines[i] = "<div class='textrow accept'>" + html_lines[i] + "</div>";
- }
- else if (html_lines[i].match(/REJECT/)) {
- html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
- }
- else if (html_lines[i].match(/[Uu]nknown/)) {
- html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
- }
- else if (html_lines[i].match(/[Pp]assback/)) {
- html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
- }
- else if (html_lines[i].match(/Rule execution error/)) {
- html_lines[i] = "<div class='textrow error'>" + html_lines[i] + "</div>";
- }
- else {
- html_lines[i] = "<div class='textrow'>" + html_lines[i] + "</div>";
- }
- }
- g_ctx.status_text = lines.join("\n");
- g_ctx.status_html_text = html_lines.join("<br>");
- ele.innerHTML = g_ctx.status_html_text;
- // sounds
- //
- if (msg.match(/ACCEPT/)) {
- _beep_accept();
- }
- else if (msg.match(/REJECT/)) {
- _beep_reject();
- }
- else if (msg.match(/[Uu]nknown/)) {
- _beep_reject();
- }
- else if (msg.match(/[Pp]assback/)) {
- _beep_reject();
- }
- else if (msg.match(/Rule execution error/)) {
- _beep_error();
- }
- }
- function _main_message_add(msg, bg_color, text_color) {
- var ele = document.getElementById("ui_main_status");
- bg_color = ((typeof bg_color === "undefined") ? BG_COLOR : bg_color);
- text_color = ((typeof text_color === "undefined") ? TEXT_COLOR : text_color);
- var txt = g_ctx.status_text + "\n" + msg;
- var html_lines = [];
- var lines = txt.split("\n");
- if (lines.length > g_ctx.status_text_h) {
- var n = lines.length;
- lines = lines.slice(n - g_ctx.status_text_h);
- }
- for (var i=0; i<lines.length; i++) {
- lines[i] = lines[i].slice(0,g_ctx.status_text_w-1);
- }
- for (var i=0; i<lines.length; i++) {
- html_lines.push(lines[i].slice(0,g_ctx.status_text_w-1));
- if (html_lines[i].match(/ACCEPT/)) {
- html_lines[i] = "<div class='textrow accept'>" + html_lines[i] + "</div>";
- }
- else if (html_lines[i].match(/REJECT/)) {
- html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
- }
- else if (html_lines[i].match(/[Uu]nknown/)) {
- html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
- }
- else if (html_lines[i].match(/[Pp]assback/)) {
- html_lines[i] = "<div class='textrow reject'>" + html_lines[i] + "</div>";
- }
- else if (html_lines[i].match(/Rule execution error/)) {
- html_lines[i] = "<div class='textrow error'>" + html_lines[i] + "</div>";
- }
- else {
- html_lines[i] = "<div class='textrow'>" + html_lines[i] + "</div>";
- }
- }
- g_ctx.status_text = lines.join("\n");
- g_ctx.status_html_text = html_lines.join("<br>");
- ele.innerHTML = g_ctx.status_html_text;
- // sounds
- //
- if (msg.match(/ACCEPT/)) {
- _beep_accept();
- }
- else if (msg.match(/REJECT/)) {
- _beep_reject();
- }
- else if (msg.match(/[Uu]nknown/)) {
- _beep_reject();
- }
- else if (msg.match(/[Pp]assback/)) {
- _beep_reject();
- }
- else if (msg.match(/Rule execution error/)) {
- _beep_error();
- }
- }
- //-------------
- //-------------
- //-------------
- function _ws_process(dat) {
- console.log("_ws_process:", dat);
- var tok = dat.split(" ");
- if (tok.length < 2) { return; }
- if (tok[0] == "paddle") {
- if (tok[1] == "ok") { _verify_paddle_ok(); }
- else if (tok[1] == "fail") { _verify_paddle_fail(); }
- else { _verify_paddle_fail(); }
- }
- else if (tok[0] == "driver_notify") {
- if (tok.length < 5) {
- console.log("malformed message: ", dat);
- }
- else if (tok[1] == "replace") {
- _main_message_replace(tok.slice(4).join(" "));
- }
- else if (tok[1] == "ok") {
- _main_message_add(tok.slice(4).join(" "));
- }
- else {
- console.log("unknown message: ", dat);
- }
- }
- }
- function _init_websocket() {
- var sock = new WebSocket("ws://" + _fqADDRESS);
- sock.onopen = function(e) { console.log("open", e); }
- sock.onmessage = function(e) { _ws_process(e.data); }
- sock.onclose = function(e) {
- console.log("close", e);
- setTimeout( function() { _init_websocket(); }, 1000);
- }
- sock.onerror = function(e) {
- console.log("error", e);
- }
- }
- //-------------
- var ui_pattern = {
- "state" : "idle",
- "lastX" : 0,
- "lastY" : 0,
- "curX" : 0,
- "curY" : 0
- };
- function ui_pattern_mousedown(ev) {
- var ele = document.getElementById("body");
- var rect = ele.getBoundingClientRect();
- var x = ev["x"];
- var y = ev["y"];
- var width = rect.width;
- var height = rect.height;
- if (ui_pattern.state == "idle") {
- if (y < (height/4)) {
- ui_pattern.state = "square_0";
- }
- else {
- ui_pattern.state = "idle"
- }
- }
- else if (ui_pattern.state == "square_0") {
- if (x > (3*width/4)) {
- ui_pattern.state = "square_1";
- }
- else {
- ui_pattern.state = "idle"
- }
- }
- else if (ui_pattern.state == "square_1") {
- if (y > (3*height/4)) {
- ui_pattern.state = "square_2";
- }
- else {
- ui_pattern.state = "idle"
- }
- }
- else if (ui_pattern.state == "square_2") {
- if (x < (width/4)) {
- ui_pattern.state = "square_3";
- }
- else {
- ui_pattern.state = "idle"
- }
- }
- else if (ui_pattern.state == "square_3") {
- if (y < (height/4)) {
- ui_pattern.state = "square_4";
- }
- else {
- ui_pattern.state = "idle"
- }
- }
- else if (ui_pattern.state == "square_4") {
- if (x > (3*width/4)) {
- ui_pattern.state = "square_5";
- }
- else {
- ui_pattern.state = "idle"
- }
- }
- else if (ui_pattern.state == "square_5") {
- if (y > (3*height/4)) {
- ui_pattern.state = "square_6";
- }
- else {
- ui_pattern.state = "idle"
- }
- }
- else if (ui_pattern.state == "square_6") {
- if (x < (width/4)) {
- _switch_ui("ui_diagnostic");
- }
- ui_pattern.state = "idle"
- }
- return false;
- }
- function ui_pattern_mouseup(ev) {
- return false;
- }
- //------------
- function _mainscreen() {
- _switch_ui('ui_login');
- g_ctx.driver_login_state = "driver";
- _clear_ui_driver();
- _clear_ui_paddle();
- }
- function _configuration() {
- _switch_ui('ui_configuration');
- g_ctx.driver_login_state = "driver";
- _clear_ui_driver();
- _clear_ui_paddle();
- }
- function _configuration_back() {
- var ui_prev = "ui_login";
- if (g_ctx.ui_stack.length > 0) {
- ui_prev = g_ctx.ui_stack.pop();
- }
- _switch_ui(ui_prev);
- if (ui_prev == "ui_login") {
- g_ctx.driver_login_state = "driver";
- _clear_ui_driver();
- _clear_ui_paddle();
- }
- }
- function _eqnum() {
- _switch_ui('ui_eqnum');
- g_ctx.driver_login_state = "driver";
- if (g_ctx.cur_eqnum.length > 0) {
- var ele = document.getElementById("ui_eqnum_eqnum");
- ele.innerHTML = g_ctx.cur_eqnum;
- g_ctx.eqnum = g_ctx.cur_eqnum;
- }
- _clear_ui_driver();
- _clear_ui_paddle();
- }
- function _reset() {
- _switch_ui('ui_login');
- g_ctx.driver_login_state = "driver";
- _clear_ui_driver();
- _clear_ui_paddle();
- location.reload(true);
- }
- function _reboot() {
- _api_request("custom", {"function":"reboot"});
- _switch_ui('ui_login');
- g_ctx.driver_login_state = "driver";
- _clear_ui_driver();
- _clear_ui_paddle();
- }
- function _custom0() {
- _api_request("interfaceupdown", {"interface":"eth0", "state":"up"});
- }
- function _custom1() {
- _api_request("interfaceupdown", {"interface":"eth0", "state":"down"});
- }
- function _update_diagnostic_window(_msg) {
- var ele = document.getElementById("ui_diagnostic_view");
- ele.innerHTML = _msg;
- }
- function _custom2() {
- _api_request("interfaceinfo", {"interface":"eth0"}, _update_diagnostic_window);
- }
- function _custom3() {
- _api_request("say", {"message":"speech test"});
- }
- function _custom4() {
- }
- function _custom5() {
- }
- //------------
- function _set_eqnum() {
- if (g_ctx.eqnum.length == 0) { return; }
- _api_request("eqnum", {"eqnum":g_ctx.eqnum}, function(inp) { console.log("eqnum ok:", inp); }, function(inp) { console.log("eqnum error:", inp); });
- }
- function _eqnum_input(inp) {
- var n = g_ctx.eqnum.length;
- if (inp == 'cancel') { _switch_ui('ui_login'); }
- else if (inp == 'ok') {
- _set_eqnum();
- _switch_ui('ui_login');
- return;
- }
- else if (inp == 'bksp') { g_ctx.eqnum = g_ctx.eqnum.substr(0, n-1); }
- else if (inp == 'clr') { g_ctx.eqnum = ""; }
- else { g_ctx.eqnum += inp; }
- // Otherwise update the displayed equipment number
- //
- var ele = document.getElementById('ui_eqnum_eqnum');
- ele.innerHTML = g_ctx.eqnum;
- }
- //-------------
- function _text_width_height() {
- var _t = document.getElementById("ui_test");
- console.log(">>>", _t.clientHeight, _t.clientWidth);
- }
- function _calculate_ui_main_status_width_height() {
- var _t = document.getElementById("ui_test");
- var ch_w = _t.clientWidth;
- var ch_h = _t.clientHeight;
- var _w = document.getElementById("ui_main_status");
- var win_w = _w.clientWidth;
- var win_h = _w.clientHeight;
- var n_w = Math.floor(win_w / ch_w);
- var n_h = Math.floor(win_h / ch_h);
- return {"n_width": n_w, "n_height":n_h};
- }
- function _init_dim_overlay() {
- var ele = document.getElementById("ui_dim_overlay");
- }
- function init() {
- _init_websocket();
- _init_dim_overlay();
- window.setInterval(_update_display_time, 200);
- window.setInterval(_update_login_time, 200);
- // watchdog
- //
- document.getElementById('ui_watchdog_btn').onclick = _watchdog_tripped;
- // diagnostics
- //
- document.getElementById('ui_diagnostic_mainscreen').onclick = _mainscreen;
- document.getElementById('ui_diagnostic_reset').onclick = _reset;
- document.getElementById('ui_diagnostic_reboot').onclick = _reboot;
- document.getElementById('ui_diagnostic_custom0').onclick = _custom0;
- document.getElementById('ui_diagnostic_custom1').onclick = _custom1;
- document.getElementById('ui_diagnostic_custom2').onclick = _custom2;
- document.getElementById('ui_diagnostic_custom3').onclick = _custom3;
- document.getElementById('ui_diagnostic_custom4').onclick = _custom4;
- document.getElementById('ui_diagnostic_custom5').onclick = _custom5;
- // configuration
- //
- //document.getElementById('ui_configuration_back').onclick = _mainscreen;
- document.getElementById('ui_configuration_back').onclick = _configuration_back;
- document.getElementById('ui_configuration_volumetest').onclick = _volume_test;
- document.getElementById('ui_configuration_eqnum').onclick = _eqnum;
- // equipment number change
- //
- document.getElementById('ui_eqnum_cancel').onclick = _mainscreen;
- document.getElementById('ui_eqnum_ok').onclick = function() { console.log("eqnum change"); }
- // login
- //
- document.getElementById('ui_login_login').onclick = _login;
- document.getElementById('ui_login_configuration').onclick = _configuration;
- document.getElementById('ui_driverincorrect_btn').onclick = _driver_incorrect;
- document.getElementById('ui_paddleunknown_btn').onclick = _paddle_unknown;
- // main menu buttons
- //
- document.getElementById('ui_main_prv').onclick = _main_prv;
- document.getElementById('ui_main_nxt').onclick = _main_nxt;
- document.getElementById('ui_main_bulk').onclick = _main_bulk;
- document.getElementById('ui_main_menu').onclick = _main_menu;
- document.getElementById('ui_main_dim').onclick = _main_dim;
- // dim
- //
- document.getElementById('ui_dim_btn').onclick = _dim_wakeup;
- var simple_fares = [ "adult", "youth", "half", "bike", "wheelchair", "transfer"];
- var simple_fares_f = [ _fare_adult, _fare_youth, _fare_half, _fare_bike, _fare_wheelchair, _fare_transfer];
- for (var ii=0; ii<simple_fares.length; ii++) {
- var fare = simple_fares[ii];
- document.getElementById('ui_main_' + fare).onclick = simple_fares_f[ii];
- }
- // bulk menu buttons
- //
- document.getElementById('ui_bulk_passes').onclick =
- function() {
- var ele;
- ele = document.getElementById("ui_bulk_misc");
- ele.classList.remove("highlight");
- ele = document.getElementById("ui_bulk_passes");
- ele.classList.add("highlight");
- _hide_ui_element("ui_bulk_misc_tab");
- _show_ui_element("ui_bulk_passes_tab");
- };
- document.getElementById('ui_bulk_misc').onclick =
- function() {
- var ele;
- ele = document.getElementById("ui_bulk_misc");
- ele.classList.add("highlight");
- ele = document.getElementById("ui_bulk_passes");
- ele.classList.remove("highlight");
- _show_ui_element("ui_bulk_misc_tab");
- _hide_ui_element("ui_bulk_passes_tab");
- };
- document.getElementById('ui_bulk_menu').onclick = function() { _switch_ui("ui_main"); }
- // Setup "Bulk" UI accept buttons to do proper screen switching and
- // other tasks.
- //
- var bulk_pass = ["adult", "youth", "half", "event", "transfer", "interline",
- "schoola", "schoolb", "schoolc", "orga", "orgb", "orgc"];
- var bulk_rule = ["BULK-CASH-ADULT", "BULK-CASH-YOUTH", "BULK-CASH-HALF",
- "BULK-MISC-EVENT", "BULK-MISC-TRANSFER", "BULK-MISC-INTERLINE",
- "BULK-OVR-SCHOOLA", "BULK-OVR-SCHOOLB", "BULK-OVR-SCHOOLC",
- "BULK-OVR-ORGA", "BULK-OVR-ORGB", "BULK-OVR-ORGC"];
- var bulk_pass_name = ["Adult Cash", "Youth Cash", "Half Cash", "Special Event", "Transfer", "Interline",
- "School A", "School B", "School C", "Org A", "Org B", "Org C"];
- // use site specific values if available, otherwise default to the above
- //
- if ((typeof BULK_PASS !== "undefined") && (BULK_PASS.length > 0)) {
- bulk_pass = BULK_PASS;
- }
- if ((typeof BULK_RULE !== "undefined") && (BULK_RULE.length > 0)) {
- bulk_rule= BULK_RULE;
- }
- if ((typeof BULK_PASS_NAME !== "undefined") && (BULK_PASS_NAME.length > 0)) {
- bulk_pass_name = BULK_PASS_NAME;
- }
- for (var i=0; i<bulk_pass.length; i++) {
- var p = bulk_pass[i];
- var u = bulk_pass_name[i];
- var r = bulk_rule[i];
- var ele = document.getElementById('ui_bulk_' + p);
- ele.onclick = (function(x,y) {
- return function() {
- _clear_ui_bulkaccept();
- g_ctx.bulkfare = x;
- _switch_ui("ui_bulkaccept");
- var ee = document.getElementById("ui_bulkaccept_faretype");
- ee.innerHTML = y;
- };
- })(r, u);
- }
- // bulk accept fares
- //
- document.getElementById('ui_bulkaccept_ok').onclick = _bulkaccept_ok;
- document.getElementById('ui_bulkaccept_cancel').onclick = _bulkaccept_cancel;
- // fareoverride menu buttons
- //
- document.getElementById('ui_fareoverride_misc').onclick =
- function() {
- var ele;
- ele = document.getElementById("ui_fareoverride_misc");
- ele.classList.add("highlight");
- ele = document.getElementById("ui_fareoverride_passes");
- ele.classList.remove("highlight");
- ele = document.getElementById("ui_fareoverride_options");
- ele.classList.remove("highlight");
- _show_ui_element("ui_fareoverride_misc_tab");
- _hide_ui_element("ui_fareoverride_passes_tab");
- _hide_ui_element("ui_fareoverride_options_tab");
- };
- document.getElementById('ui_fareoverride_passes').onclick =
- function() {
- var ele;
- ele = document.getElementById("ui_fareoverride_misc");
- ele.classList.remove("highlight");
- ele = document.getElementById("ui_fareoverride_passes");
- ele.classList.add("highlight");
- ele = document.getElementById("ui_fareoverride_options");
- ele.classList.remove("highlight");
- _hide_ui_element("ui_fareoverride_misc_tab");
- _show_ui_element("ui_fareoverride_passes_tab");
- _hide_ui_element("ui_fareoverride_options_tab");
- };
- document.getElementById('ui_fareoverride_options').onclick =
- function() {
- var ele;
- ele = document.getElementById("ui_fareoverride_misc");
- ele.classList.remove("highlight");
- ele = document.getElementById("ui_fareoverride_passes");
- ele.classList.remove("highlight");
- ele = document.getElementById("ui_fareoverride_options");
- ele.classList.add("highlight");
- _hide_ui_element("ui_fareoverride_misc_tab");
- _hide_ui_element("ui_fareoverride_passes_tab");
- _show_ui_element("ui_fareoverride_options_tab");
- };
- document.getElementById('ui_fareoverride_menu').onclick = function() { _switch_ui("ui_main"); };
- document.getElementById('ui_fareoverride_config').onclick =
- function() {
- g_ctx.ui_stack.push("ui_fareoverride");
- _switch_ui("ui_configuration");
- };
- document.getElementById('ui_fareoverride_logout').onclick =
- function() {
- _main_message_clear();
- _api_request("logout");
- _switch_ui("ui_login");
- };
- // default values for override passes
- //
- var override_pass = [ "adult", "youth", "half",
- "bike", "wheelchair", "transfer",
- "event", "interline",
- "schoola", "schoolb", "schoolc",
- "orga", "orgb", "orgc" ];
- var override_rule = [ "CASH-ADULT", "CASH-YOUTH", "CASH-HALF",
- "MISC-BIKE", "MISC-WHEELCHAIR", "MISC-TRANSFER",
- "MISC-EVENT", "MISC-INTERLINE",
- "OVR-SCHOOLA", "OVR-SCHOOLB", "OVR-SCHOOLC",
- "OVR-ORGA", "OVR-ORGB", "OVR-ORGC" ];
- // use site specific values if available, otherwise default to the above
- //
- if ((typeof OVERRIDE_PASS !== "undefined") && (OVERRIDE_PASS.length > 0)) {
- override_pass = OVERRIDE_PASS;
- }
- if ((typeof OVERRIDE_RULE !== "undefined") && (OVERRIDE_RULE.length > 0)) {
- override_rule= OVERRIDE_RULE;
- }
- for (var i=0; i<override_pass.length; i++) {
- var p = override_pass[i];
- var r = override_rule[i];
- var ele = document.getElementById("ui_fareoverride_" + p);
- ele.onclick = (function(x,y) {
- return function() { _api_request("fare", {"rule":x,"fare":y,"param":"","count":1}); };
- })(r,p);
- }
- var ui_page = [ "driver", "paddle", "bulkaccept", "eqnum" ];
- var ui_func = [ _driver_login, _paddle_input, _bulkaccept_input, _eqnum_input ];
- for (var idx=0; idx<ui_page.length; idx++) {
- var c = ui_page[idx];
- var f = ui_func[idx];
- for (var i=0; i<=9; i++) {
- document.getElementById('ui_' + c + '_' + i).onclick =
- (function(_f, x) { return function() { _f(x); } })(f, i);
- }
- document.getElementById('ui_' + c + '_' + 'bksp').onclick =
- (function(_f,x) { return function() { _f(x); } })(f, 'bksp');
- document.getElementById('ui_' + c + '_' + 'clr').onclick =
- (function(_f,x) { return function() { _f(x); } })(f, 'clr');
- document.getElementById('ui_' + c + '_' + 'ok').onclick =
- (function(_f,x) { return function() { _f(x); } })(f, 'ok');
- document.getElementById('ui_' + c + '_' + 'cancel').onclick =
- (function(_f,x) { return function() { _f(x); } })(f, 'cancel');
- }
- // set interval to check status every 1 second
- //
- var x = window.setInterval(function() { _api_request("status", {}, _cb_status, _cb_status_err); }, 1000);
- // try and reduce textarea highlighting, drag and drop/copy pasting,
- // and other bad behavor.
- //
- var ele;
- var block_ele;
- var rect;
- ele = document.getElementById("ui_login_status");
- ele.ondragstart = function() { return false; }
- ele.onselectstart = function() { return false; }
- ele.onmousedown = function() { return false; }
- ele.ondragstart = function() { return false; }
- rect = ele.getBoundingClientRect();
- block_ele = document.getElementById("ui_login_blockwindow");
- block_ele.style.width = rect.width;
- block_ele.style.height = rect.height;
- block_ele.style.bottom = rect.bottom;
- block_ele.style.left = rect.left;
- block_ele.style.top = rect.top;
- block_ele.style.right = rect.right;
- block_ele.style.x = rect.x;
- block_ele.style.y = rect.y;
- ele = document.getElementById("ui_main_status");
- ele.ondragstart = function() { return false; }
- ele.onselectstart = function() { return false; }
- ele.onmousedown = function() { return false; }
- ele.ondragstart = function() { return false; }
- rect = ele.getBoundingClientRect();
- block_ele = document.getElementById("ui_main_blockwindow");
- block_ele.style.width = rect.width;
- block_ele.style.height = rect.height;
- block_ele.style.bottom = rect.bottom;
- block_ele.style.left = rect.left;
- block_ele.style.top = rect.top;
- block_ele.style.right = rect.right;
- block_ele.style.x = rect.x;
- block_ele.style.y = rect.y;
- ele = document.getElementById("body");
- // We're using jquery so we need to gracefully add callbacks
- // for mouse events.
- //
- ele.addEventListener('mousedown', ui_pattern_mousedown);
- ele.addEventListener('mouseup', ui_pattern_mouseup);
- g_snd.button_press = new Audio("assets/459992_florianreichelt_beep_short.mp3");
- //g_snd.accept_fare = new Audio("assets/443026__qubodup__public-domain-beep-sound.mp3");
- g_snd.accept_fare = new Audio("assets/389214__joe-anderson22__microwave-beeps.mp3");
- g_snd.reject_fare = new Audio("assets/368780__gurie__start-sound-beep.mp3");
- g_snd.rule_error = new Audio("assets/363920__samsterbirdies__8-bit-error.mp3");
- if (typeof PopufareSiteInit !== "undefined") {
- PopufareSiteInit();
- }
- }
- (function($) {
- $(document).ready(function() {
- init();
- });
- })(jQuery);
|