aboutsummaryrefslogtreecommitdiffstats
path: root/data/lib/logging-front.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-03-02 16:23:39 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-03-02 16:23:39 +0100
commitea71f2b3c7d6b7e8a2a63669aa818d79ad85ffa0 (patch)
tree0eb77d02fef588fdc9a52db656a8b5bd453f3eb2 /data/lib/logging-front.js
parent40a7136e0946f1f9d938fd65e0f416cd3455413f (diff)
downloadbugzilla-triage-ea71f2b3c7d6b7e8a2a63669aa818d79ad85ffa0.tar.gz
Separate logging front-end into special content script.
Diffstat (limited to 'data/lib/logging-front.js')
-rw-r--r--data/lib/logging-front.js88
1 files changed, 88 insertions, 0 deletions
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();