aboutsummaryrefslogblamecommitdiffstats
path: root/data/lib/logging-front.js
blob: d186d7f873e051f6a1384348dc8821347ed4152f (plain) (tree)
1
2
3
4
5
6
7
8
9
10









                                                       
















                                                        
     


               




                          



                                                    
 


                                                                                     
 









                                                                                     
 




                                                                      
 



                                                            
 



                                                                  
 










                                                           

 
                                                        
                 
 
// 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 !== null) {
    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));
    }
    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";
  }
  */
}

if (window.location.hostname == "bugzilla.redhat.com") {
  setUpLogging();
}