X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=js%2Ffunctions.js;h=7fbb4e75d59641ab0c83df45c5f63b2617ee3a1a;hb=0d27227359df5597d4dc3b646eaa63082f42e4f0;hp=63ff4121bb8c8fa56b326bd2794d5ebfb2aede20;hpb=fa287f6b116564f46aa20ee7da1a9d8aed311b97;p=tt-rss.git diff --git a/js/functions.js b/js/functions.js index 63ff4121..7fbb4e75 100755 --- a/js/functions.js +++ b/js/functions.js @@ -1,8 +1,9 @@ -var loading_progress = 0; -var sanity_check_done = false; -var init_params = {}; -var _label_base_index = -1024; -var notify_hide_timerid = false; +/* global dijit, __ */ + +let init_params = {}; +let _label_base_index = -1024; +let loading_progress = 0; +let notify_hide_timerid = false; Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( function (callOriginal, options) { @@ -22,72 +23,75 @@ Ajax.Base.prototype.initialize = Ajax.Base.prototype.initialize.wrap( } ); +/* xhr shorthand helpers */ + +function xhrPost(url, params, complete) { + console.log("xhrPost:", params); + new Ajax.Request(url, { + parameters: params, + onComplete: complete + }); +} + +function xhrJson(url, params, complete) { + xhrPost(url, params, (reply) => { + try { + const obj = JSON.parse(reply.responseText); + complete(obj); + } catch (e) { + console.error("xhrJson", e, reply); + complete(null); + } + + }) +} + /* add method to remove element from array */ Array.prototype.remove = function(s) { - for (var i=0; i < this.length; i++) { + for (let i=0; i < this.length; i++) { if (s == this[i]) this.splice(i, 1); } }; -/* create console.log if it doesn't exist */ - -if (!window.console) console = {}; -console.log = console.log || function(msg) { }; -console.warn = console.warn || function(msg) { }; -console.error = console.error || function(msg) { }; +function report_error(message, filename, lineno, colno, error) { + exception_error(error, null, filename, lineno); +} -function exception_error(location, e, ext_info) { - var msg = format_exception_error(location, e); +function exception_error(e, e_compat, filename, lineno, colno) { + if (typeof e == "string") e = e_compat; - if (!ext_info) ext_info = false; + if (!e) return; // no exception object, nothing to report. try { - - if (ext_info) - ext_info = JSON.stringify(ext_info); + console.error(e); + const msg = e.toString(); try { - new Ajax.Request("backend.php", { - parameters: {op: "rpc", method: "log", logmsg: msg}, - onComplete: function (transport) { - console.log(transport.responseText); - } }); + xhrPost("backend.php", + {op: "rpc", method: "log", + file: e.fileName ? e.fileName : filename, + line: e.lineNumber ? e.lineNumber : lineno, + msg: msg, context: e.stack}, + (transport) => { + console.warn(transport.responseText); + }); - } catch (eii) { - console.log("Exception while trying to log the error."); - console.log(eii); + } catch (e) { + console.error("Exception while trying to log the error.", e); } - msg += "
"+ __("The error will be reported to the configured log destination.") + - "
"; - - var content = "" + msg + ""; - - content += "