var _ADDRESS = "192.168.0.110"; //var _URL = "http://localhost"; var _URL = "http://" + _ADDRESS; var _PORT = 60535; var _fqADDRESS = _ADDRESS + ":" + _PORT; var BG_COLOR = "#f7f7f7"; var TEXT_COLOR = "#444444"; var g_ctx = { "driver_login_state" : "driver", "driver" : "", "pin" : "", "paddle" : "", "current_ui" : "ui_login", "ui_change_timeoutid": -1, "bulkfare" : "", "bulkfare_count" : "", "status_text": "", "status_text_w": 0, "status_text_h": 0, /* "rule" : { "adult":"CASH-ADULT", "youth":"CASH-YOUTH", "half":"CASH-HALF", "bike":"MISC-BIKE", "wheelchair":"MISC-WHEELCHAIR", "transfer":"MISC-TRANSFER", "interline":"MISC-INTERLINE", "event":"MISC-EVENT", "schoola":"OVR-SCHOOLA", "schoolb":"OVR-SCHOOLB", "schoolc":"OVR-SCHOOLC", "orga":"OVR-ORGA", "orgb":"OVR-ORGB", "orgc":"OVR-ORGC", }, */ "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(); //var url = _URL + ":" + _PORT + "/req"; 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=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 _switch_ui(to) { var ele; console.log(">>>to", to); 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") || (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 _clear_ui_driver() { var ele; var u = ["driver", "pin"]; for (var i=0; i>\n", inp); var fields = inp.substr(3).split(";"); var fv = {}; for (var ii=0; ii g_ctx.status_text_h) { var n = lines.length; lines = lines.slice(n - g_ctx.status_text_h); } for (var i=0; i>replace:", msg); } function _main_message_add(msg, bg_color, text_color) { var ele = document.getElementById("ui_main_status"); g_ctx.status_text_w = ele.cols; g_ctx.status_text_h = ele.rows; bg_color = ((typeof bg_color === "undeinfed") ? BG_COLOR : bg_color); text_color = ((typeof text_color === "undefined") ? TEXT_COLOR : text_color); var txt = g_ctx.status_text + "\n" + msg; 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>add:", msg); } //------------- //------------- //------------- function _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); } sock.onerror = function(e) { console.log("error", e); } } //------------- function init() { _init_websocket(); // login // document.getElementById('ui_login_login').onclick = _login; 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; 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>>", x); // 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; } init();