From 4ffd6b9e6b61c9eaa323e4f4d537db5d1a36872d Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Fri, 24 Sep 2010 12:28:11 +0200 Subject: Fix Logger object to be self contained and use storage properly * there is really no other way than using module.storage directly Sucks! * all logger-related logic should go to the module and not be flying around (import TS, clear, isEmpty) --- lib/bzpage.js | 50 +++++++++++++++++--------------------------------- 1 file changed, 17 insertions(+), 33 deletions(-) (limited to 'lib/bzpage.js') diff --git a/lib/bzpage.js b/lib/bzpage.js index 269f4fa..2aeaf51 100644 --- a/lib/bzpage.js +++ b/lib/bzpage.js @@ -7,7 +7,6 @@ var passUtils = require("passwords"); var apiUtils = require("api-utils"); var selfMod = require("self"); var clip = require("clipboard"); -var fileMod = require("file"); var simpleStorage = require("simple-storage"); var preferences = require("preferences-service"); var selection = require("selection"); @@ -945,6 +944,18 @@ BZPage.prototype.setUpLogging = function setUpLogging () { evt.preventDefault(); }, false); + var clearLogsUI = this.doc.createElement("li"); + clearLogsUI.innerHTML = "\u00A0-\u00A0" + + "Clear TS"; + additionalButtons.appendChild(clearLogsUI); + var clearLogAElem = this.doc.getElementById("clearLogs"); + clearLogAElem.addEventListener("click", function(evt) { + that.log.clearStore(this); + console.log("this.store wiped out!"); + evt.stopPropagation(); + evt.preventDefault(); + }, false); + var ImportTimeSheetUI = this.doc.createElement("li"); ImportTimeSheetUI.innerHTML = "\u00A0-\u00A0" + "Import TS"; @@ -952,45 +963,18 @@ BZPage.prototype.setUpLogging = function setUpLogging () { this.doc.getElementById("importTSButton").addEventListener( "click", function(evt) { - var otherTS = {}, thisTS = that.log.store; - jsonPaths = prompts.promptFileOpenPicker(that.win); - if (fileMod.exists(jsonPaths)) { - otherTS = JSON.parse(fileMod.read(jsonPaths)); - if (otherTS.logs) { - for (var rec in otherTS.logs) { - thisTS[rec] = otherTS.logs[rec]; - } - } else { - console.error("This is not a log file!"); - } - } else { - console.error("File " + jsonPaths + " doesn't exist!"); - } + that.log.importOtherStore(jsonPaths, clearLogAElem); evt.stopPropagation(); evt.preventDefault(); }, false); - var clearLogsUI = this.doc.createElement("li"); - clearLogsUI.innerHTML = "\u00A0-\u00A0" - + "Clear TS"; - additionalButtons.appendChild(clearLogsUI); - var clearLogAElem = this.doc.getElementById("clearLogs"); - clearLogAElem.addEventListener("click", function() { - that.log.store = {}; - this.style.color = that.log.EmptyLogsColor; - this.style.fontWeight = "normal"; - console.log("this.store wiped out!"); - evt.stopPropagation(); - evt.preventDefault(); - }, false); - - if (this.log.store.length > 0) { - clearLogAElem.style.color = this.log.FullLogsColor; - clearLogAElem.style.fontWeight = "bolder"; - } else { + if (this.log.isEmpty()) { clearLogAElem.style.color = this.log.EmptyLogsColor; clearLogAElem.style.fontWeight = "normal"; + } else { + clearLogAElem.style.color = this.log.FullLogsColor; + clearLogAElem.style.fontWeight = "bolder"; } }; -- cgit