diff options
author | Matěj Cepl <mcepl@redhat.com> | 2011-03-02 16:23:39 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2011-03-02 16:23:39 +0100 |
commit | ea71f2b3c7d6b7e8a2a63669aa818d79ad85ffa0 (patch) | |
tree | 0eb77d02fef588fdc9a52db656a8b5bd453f3eb2 | |
parent | 40a7136e0946f1f9d938fd65e0f416cd3455413f (diff) | |
download | bugzilla-triage-ea71f2b3c7d6b7e8a2a63669aa818d79ad85ffa0.tar.gz |
Separate logging front-end into special content script.
-rw-r--r-- | data/lib/bzpage.js | 134 | ||||
-rw-r--r-- | data/lib/logging-front.js | 88 | ||||
-rw-r--r-- | data/lib/util.js | 50 | ||||
-rw-r--r-- | lib/main.js | 1 |
4 files changed, 139 insertions, 134 deletions
diff --git a/data/lib/bzpage.js b/data/lib/bzpage.js index aa81370..bd8e6ce 100644 --- a/data/lib/bzpage.js +++ b/data/lib/bzpage.js @@ -12,14 +12,11 @@ var SalmonPink = new Color(255, 224, 176); // RGB 255, 224, 176; HSL 36, 2, // 85 var ReporterColor = new Color(255, 255, 166); // RGB 255, 255, 166; HSL 60, 2, // 83 -var EmptyLogsColor = new Color(0, 255, 0); -var FullLogsColor = new Color(0, 40, 103); // global variables var config = {}; var constantData = {}; // This should be probably eliminated ASAP or // or done by other means. TODO -var submitHandlerInstalled = false; // for setUpLogging /** * central handler processing messages from the main script. */ @@ -272,57 +269,6 @@ function addToCommentsDropdown (cmdObj) { } /** - * Create a A element leadink nowhere, but with listener running a callback on the click - * - * @param id String with a id to be added to the element - * @param text String with a string to be added as a textContent of the element - * @param parent Node which is a parent of the object - * @param callback Function to be called after clicking on the link - * @param params Array with parameters of the callback - * @param Boolean before if there should be a <br> element before. - * @return none - */ -function createDeadLink (id, text, parent, callback, params, before, covered, accesskey) { - params = valToArray(params); - var locParent = {}; - - // Yes, I want != here, not !== - if (covered != null) { - locParent = document.createElement(covered); - parent.appendChild(locParent); - } else { - locParent = parent; - } - - var newAElem = document.createElement("a"); - newAElem.setAttribute("id", id); - if (accesskey) { - newAElem.setAttribute("accesskey", accesskey); - } - newAElem.textContent = text; - - if (typeof callback === "string") { - newAElem.setAttribute("href", callback); - } else { - newAElem.setAttribute("href", ""); - newAElem.addEventListener("click", function(evt) { - callback.apply(null, params); - evt.stopPropagation(); - evt.preventDefault(); - }, false); - } - - if ((before === "br") || (before === true)) { - locParent.appendChild(document.createElement("br")); - } else if (before === "dash") { - locParent.appendChild(document.createTextNode("\u00A0-\u00A0")); - } - - locParent.appendChild(newAElem); -} - - -/** * Generic function to add new button to the page. Actually copies new button * from the old one (in order to have the same look-and-feel, etc. * @@ -384,8 +330,6 @@ function generateButtons (pkgs, kNodes) { var topRowPosition = "topRowPositionID"; var bottomRowPosition = "commit"; - setUpLogging(); - // ========================================================= if (kNodes && window.location.hostname in kNodes) { var killConf = killNodes[window.location.hostname]; @@ -757,84 +701,6 @@ function getLogin () { return loginStr; } -function addLogRecord() { - var rec = {}; - rec.date = new Date(); - rec.url = document.location.toString(); - rec.title = document.title; - var comment = window.prompt( - "Enter comments for this comment"); - if (comment) { - comment = comment.trim(); - if (comment.length > 0) { - comment = comment.trim(); - rec.comment = comment; - var dateStr = getISODate(rec.date); - var urlStr = window.location.hostname; - var bugNo = getBugNoFromURL(window.location.href); - rec.key = dateStr + "+" + - urlStr + "+" + bugNo; - postMessage(new Message("AddLogRecord", rec)); - } else { - console.log("Empty string!"); - } - console.log("addLogRecord : rec = " + rec.toSource()); - return rec; - } - return null; -} - -/** - */ -function setUpLogging () { - // Protection against double-call - if (document.getElementById("generateTSButton")) { - return ; - } - - // For adding additional buttons to the top toolbar - var additionalButtons = document.querySelector("#bugzilla-body *.related_actions"); - var that = this; - - // logging all submits for timesheet - if (!submitHandlerInstalled) { - document.forms.namedItem("changeform").addEventListener("submit",function (evt) { - if (addLogRecord() === null) { - evt.stopPropagation(); - evt.preventDefault(); - } - }, false); - submitHandlerInstalled = true; - } - - // (id, text, parent, callback, params, before, covered, accesskey) - createDeadLink("generateTSButton", "Generate TS", additionalButtons, - function(evt) { - postMessage(new Message("GenerateTS")); - }, [], "dash", "li"); - - createDeadLink("clearLogs", "Clear TS", additionalButtons, - function(evt) { - postMessage(new Message("ClearTS")); - }, [], "dash", "li"); - - createDeadLink("importTSButton", "Import TS", additionalButtons, - function(evt) { - postMessage(new Message("ImportTS")); - }, [], "dash", "li"); - - /* TODO - var clearLogAElem = document.getElementById("clearLogs"); - 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"; - } - */ -} - function getSelection () { var text = ""; var selectionObject = window.getSelection(); diff --git a/data/lib/logging-front.js b/data/lib/logging-front.js new file mode 100644 index 0000000..4b0a3f9 --- /dev/null +++ b/data/lib/logging-front.js @@ -0,0 +1,88 @@ +// Released under the MIT/X11 license +// http://www.opensource.org/licenses/mit-license.php +"use strict"; + +var EmptyLogsColor = new Color(0, 255, 0); +var FullLogsColor = new Color(0, 40, 103); + +var submitHandlerInstalled = false; // for setUpLogging + +function addLogRecord() { + var rec = {}; + rec.date = new Date(); + rec.url = document.location.toString(); + rec.title = document.title; + var comment = window.prompt( + "Enter comments for this comment"); + if (comment) { + comment = comment.trim(); + if (comment.length > 0) { + comment = comment.trim(); + rec.comment = comment; + var dateStr = getISODate(rec.date); + var urlStr = window.location.hostname; + var bugNo = getBugNoFromURL(window.location.href); + rec.key = dateStr + "+" + + urlStr + "+" + bugNo; + postMessage(new Message("AddLogRecord", rec)); + } else { + console.log("Empty string!"); + } + console.log("addLogRecord : rec = " + rec.toSource()); + return rec; + } + return null; +} + +/** + */ +function setUpLogging () { + // Protection against double-call + if (document.getElementById("generateTSButton")) { + return ; + } + + // For adding additional buttons to the top toolbar + var additionalButtons = document.querySelector("#bugzilla-body *.related_actions"); + var that = this; + + // logging all submits for timesheet + if (!submitHandlerInstalled) { + document.forms.namedItem("changeform").addEventListener("submit",function (evt) { + if (addLogRecord() === null) { + evt.stopPropagation(); + evt.preventDefault(); + } + }, false); + submitHandlerInstalled = true; + } + + // (id, text, parent, callback, params, before, covered, accesskey) + createDeadLink("generateTSButton", "Generate TS", additionalButtons, + function(evt) { + postMessage(new Message("GenerateTS")); + }, [], "dash", "li"); + + createDeadLink("clearLogs", "Clear TS", additionalButtons, + function(evt) { + postMessage(new Message("ClearTS")); + }, [], "dash", "li"); + + createDeadLink("importTSButton", "Import TS", additionalButtons, + function(evt) { + postMessage(new Message("ImportTS")); + }, [], "dash", "li"); + + /* TODO + var clearLogAElem = document.getElementById("clearLogs"); + 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"; + } + */ +} + +setUpLogging(); diff --git a/data/lib/util.js b/data/lib/util.js index 6c204ff..0ecc318 100644 --- a/data/lib/util.js +++ b/data/lib/util.js @@ -80,6 +80,56 @@ function getBugNoFromURL(url) { } } +/** + * Create a A element leadink nowhere, but with listener running a callback on the click + * + * @param id String with a id to be added to the element + * @param text String with a string to be added as a textContent of the element + * @param parent Node which is a parent of the object + * @param callback Function to be called after clicking on the link + * @param params Array with parameters of the callback + * @param Boolean before if there should be a <br> element before. + * @return none + */ +function createDeadLink (id, text, parent, callback, params, before, covered, accesskey) { + params = valToArray(params); + var locParent = {}; + + // Yes, I want != here, not !== + if (covered != null) { + locParent = document.createElement(covered); + parent.appendChild(locParent); + } else { + locParent = parent; + } + + var newAElem = document.createElement("a"); + newAElem.setAttribute("id", id); + if (accesskey) { + newAElem.setAttribute("accesskey", accesskey); + } + newAElem.textContent = text; + + if (typeof callback === "string") { + newAElem.setAttribute("href", callback); + } else { + newAElem.setAttribute("href", ""); + newAElem.addEventListener("click", function(evt) { + callback.apply(null, params); + evt.stopPropagation(); + evt.preventDefault(); + }, false); + } + + if ((before === "br") || (before === true)) { + locParent.appendChild(document.createElement("br")); + } else if (before === "dash") { + locParent.appendChild(document.createTextNode("\u00A0-\u00A0")); + } + + locParent.appendChild(newAElem); +} + /* * From <a> element diggs out just plain email address * Note that bugzilla.gnome.org doesn't have mailto: url but diff --git a/lib/main.js b/lib/main.js index 191391f..fe97964 100644 --- a/lib/main.js +++ b/lib/main.js @@ -115,6 +115,7 @@ var contentScriptLibraries = { "bugzilla.redhat.com": [ self.data.url("lib/util.js"), self.data.url("lib/color.js"), + self.data.url("lib/logging-front.js"), self.data.url("lib/rhbzpage.js"), self.data.url("lib/bzpage.js") ] |