aboutsummaryrefslogtreecommitdiffstats
path: root/lib/bzpage.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/bzpage.js')
-rw-r--r--lib/bzpage.js162
1 files changed, 83 insertions, 79 deletions
diff --git a/lib/bzpage.js b/lib/bzpage.js
index 59790fb..79f6d64 100644
--- a/lib/bzpage.js
+++ b/lib/bzpage.js
@@ -5,6 +5,7 @@
"use strict";
var util = require("util");
var simpleStorage = require("simple-storage");
+var Color = require("color").Color;
var TriagedDistro = 13;
var NumberOfFrames = 7;
@@ -14,7 +15,7 @@ var bugURL = "https://bugzilla.redhat.com/show_bug.cgi?id=";
// ====================================================================================
// BZPage's methods
-exports.BZPage = function BZPage(doc, config) {
+var BZPage = exports.BZPage = function BZPage(doc, config) {
// constants
this.SalmonPink = new Color(255, 224, 176); // RGB 255, 224, 176; HSL 36, 2,
// 85
@@ -22,6 +23,7 @@ exports.BZPage = function BZPage(doc, config) {
// 83
// initialize dynamic properties
this.doc = doc;
+ console.log("this.doc = " + this.doc);
this.packages = this.getInstalledPackages();
if ("commentStrings" in config.gJSONData) {
this.commentStrings = config.gJSONData.commentStrings;
@@ -55,20 +57,20 @@ exports.BZPage = function BZPage(doc, config) {
this.CCList = this.getCCList();
this.generateButtons();
-}
+};
/**
*
*/
BZPage.prototype.getInstalledPackages = function() {
- let installedPackages = {};
+ var installedPackages = {};
if (config.gJSONData && ("commentPackages" in config.gJSONData)) {
- let enabledPackages = jetpack.storage.settings.enabledPacks.split(/[, ]/);
- for each (let pkg in enabledPackages) {
+ var enabledPackages = jetpack.storage.settings.enabledPacks.split(/[, ]/);
+ enabledPackages.forEach(function (pkg, idx, arr) {
if (pkg in config.gJSONData.commentPackages) {
installedPackages[pkg] = config.gJSONData.commentPackages[pkg];
}
- }
+ });
}
return installedPackages;
};
@@ -141,13 +143,13 @@ BZPage.prototype.centralCommandDispatch = function (cmdLabel, cmdParams) {
break;
case "removeBlocks":
this.clickMouse("blocked_edit_action");
- this.removeStuffFromTextBox("blocked", cmdParams)
+ this.removeStuffFromTextBox("blocked", cmdParams);
break;
case "comment":
this.addStuffToTextBox("comment", cmdParams);
break;
case "commentIdx":
- let commentText = this.commentStrings[cmdParams];
+ var commentText = this.commentStrings[cmdParams];
this.addStuffToTextBox("comment", commentText);
break;
case "setNeedinfo":
@@ -178,10 +180,10 @@ BZPage.prototype.centralCommandDispatch = function (cmdLabel, cmdParams) {
* this.centralCommandDispatch to execute them.
*/
BZPage.prototype.executeCommand = function(cmd) {
- let [pkg, id] = cmd.split("//");
- let commentObj = this.packages[pkg][id];
+ var cmdArr = cmd.split("//");
+ var commentObj = this.packages[cmdArr[0]][cmdArr[1]];
- for (let key in commentObj) {
+ for (var key in commentObj) {
this.centralCommandDispatch(key,commentObj[key]);
}
};
@@ -193,7 +195,7 @@ BZPage.prototype.executeCommand = function(cmd) {
* @return none
*/
BZPage.prototype.changeAssignee = function(newAssignee) {
- let defAssigneeButton = null;
+ var defAssigneeButton = null;
this.addToCCList(this.owner);
if (newAssignee === null) {
this.doc.getElementById("set_default_assignee").removeAttribute(
@@ -202,8 +204,8 @@ BZPage.prototype.changeAssignee = function(newAssignee) {
}
if (this.getDefaultAssignee) {
- if (newAssignee == "default") {
- let defAss = this.getDefaultAssignee();
+ if (newAssignee === "default") {
+ var defAss = this.getDefaultAssignee();
if (defAss) {
newAssignee = defAss;
} else {
@@ -216,8 +218,8 @@ BZPage.prototype.changeAssignee = function(newAssignee) {
this.clickMouse("bz_assignee_edit_action");
this.doc.getElementById("assigned_to").value = newAssignee;
this.doc.getElementById("set_default_assignee").checked = false;
- if (defAssigneeButton = this.doc
- .getElementById("setDefaultAssignee_btn")) {
+ defAssigneeButton = this.doc.getElementById("setDefaultAssignee_btn");
+ if (defAssigneeButton) {
defAssigneeButton.style.display = "none";
}
}
@@ -232,9 +234,9 @@ BZPage.prototype.changeAssignee = function(newAssignee) {
* function will set up new one.
*/
BZPage.prototype.addToCommentsDropdown = function(pkg, cmd) {
- let select = this.doc.getElementById("comment_action");
+ var select = this.doc.getElementById("comment_action");
if (!select) {
- let that = this;
+ var that = this;
this.doc.getElementById("comments").innerHTML +=
"<div id='make_bugzilla_comment_action'>" +
" <label for='comment_action'>Add Comment: </label>" +
@@ -243,9 +245,10 @@ BZPage.prototype.addToCommentsDropdown = function(pkg, cmd) {
"</div>";
select = this.doc.getElementById("comment_action");
select.addEventListener("change", function () {
- let valueElement = that.doc.getElementById("comment_action");
+ var value = "";
+ var valueElement = that.doc.getElementById("comment_action");
if (valueElement) {
- let value = valueElement.getAttribute("value");
+ value = valueElement.getAttribute("value");
} else {
return;
}
@@ -253,7 +256,7 @@ BZPage.prototype.addToCommentsDropdown = function(pkg, cmd) {
}, false);
}
- let opt = that.doc.createElement("option");
+ var opt = this.doc.createElement("option");
opt.value = pkg + "//" + cmd;
opt.textContent = this.packages[pkg][cmd].name;
select.appendChild(opt);
@@ -270,10 +273,10 @@ BZPage.prototype.addToCommentsDropdown = function(pkg, cmd) {
* @return none
*/
BZPage.prototype.createNewButton = function(location, after, pkg, id) {
- let that = this;
- let cmdObj = this.packages[pkg][id];
- let newId = id + "_btn";
- let label = cmdObj["name"];
+ var that = this;
+ var cmdObj = this.packages[pkg][id];
+ var newId = id + "_btn";
+ var label = cmdObj.name;
// protection against double-firings
if (this.doc.getElementById(newId)) {
@@ -283,12 +286,12 @@ BZPage.prototype.createNewButton = function(location, after, pkg, id) {
// creation of button might be conditional on existence of data in constantData
if ("ifExist" in cmdObj) {
- if (!(cmdObj["ifExist"] in this.constantData)) {
+ if (!(cmdObj.ifExist in this.constantData)) {
return ;
}
}
- let newButton = this.doc.createElement("input");
+ var newButton = this.doc.createElement("input");
newButton.setAttribute("id", newId);
newButton.setAttribute("type", "button");
newButton.value = label;
@@ -296,7 +299,7 @@ BZPage.prototype.createNewButton = function(location, after, pkg, id) {
that.executeCommand(pkg + "//" + id);
}, false);
- let originalLocation = this.doc.getElementById(location);
+ var originalLocation = this.doc.getElementById(location);
if (after) {
originalLocation.parentNode.insertBefore(newButton,
@@ -314,19 +317,19 @@ BZPage.prototype.createNewButton = function(location, after, pkg, id) {
*
*/
BZPage.prototype.generateButtons = function() {
- let topRowPosition = "topRowPositionID";
- let bottomRowPosition = "commit";
+ var topRowPosition = "topRowPositionID";
+ var bottomRowPosition = "commit";
// create anchor for the top toolbar
- let commentBox = this.doc.getElementById("comment");
- let brElement = this.doc.createElement("br");
+ var commentBox = this.doc.getElementById("comment");
+ var brElement = this.doc.createElement("br");
brElement.setAttribute("id",topRowPosition);
commentBox.parentNode.normalize();
commentBox.parentNode.insertBefore(brElement, commentBox);
- for (let pkg in this.packages) {
- for (let cmdIdx in this.packages[pkg]) {
- let cmdObj = this.packages[pkg][cmdIdx];
+ for (var pkg in this.packages) {
+ for (var cmdIdx in this.packages[pkg]) {
+ var cmdObj = this.packages[pkg][cmdIdx];
switch (cmdObj.position) {
case "topRow":
this.createNewButton(topRowPosition, false, pkg, cmdIdx);
@@ -338,9 +341,9 @@ BZPage.prototype.generateButtons = function() {
this.addToCommentsDropdown(pkg,cmdIdx);
break;
default: // [+-]ID
- let firstChr = cmdObj.position.charAt(0);
- let newId = cmdObj.position.substr(1);
- this.createNewButton(newId, firstChr == "+", pkg, cmdIdx);
+ var firstChr = cmdObj.position.charAt(0);
+ var newId = cmdObj.position.substr(1);
+ this.createNewButton(newId, firstChr === "+", pkg, cmdIdx);
break;
}
}
@@ -364,8 +367,8 @@ BZPage.prototype.getReporter = function() {
* @return string (integer for released Fedora, float for RHEL, rawhide)
*/
BZPage.prototype.getVersion = function() {
- let verStr = this.getOptionValue("version").toLowerCase();
- let verNo = 0;
+ var verStr = this.getOptionValue("version").toLowerCase();
+ var verNo = 0;
if (/rawhide/.test(verStr)) {
verNo = 999;
} else {
@@ -375,7 +378,7 @@ BZPage.prototype.getVersion = function() {
};
BZPage.prototype.commentsWalker = function(fce) {
- let comments = this.doc.getElementById("comments").getElementsByClassName(
+ var comments = this.doc.getElementById("comments").getElementsByClassName(
"bz_comment");
Array.forEach(comments, function(item) {
fce(item);
@@ -387,9 +390,9 @@ BZPage.prototype.commentsWalker = function(fce) {
*
*/
BZPage.prototype.checkComments = function() {
- let that = this;
+ var that = this;
this.commentsWalker(function(x) {
- let email = x.getElementsByClassName("vcard")[0]
+ var email = x.getElementsByClassName("vcard")[0]
.getElementsByTagName("a")[0].textContent;
if (new RegExp(that.reporter).test(email)) {
x.style.backgroundColor = that.ReporterColor.toString();
@@ -398,7 +401,7 @@ BZPage.prototype.checkComments = function() {
};
BZPage.prototype.collectComments = function() {
- let outStr = "";
+ var outStr = "";
this.commentsWalker(function(x) {
outStr += x.getElementsByTagName("pre")[0].textContent + "\n";
});
@@ -417,13 +420,13 @@ BZPage.prototype.collectComments = function() {
*
* FIXME bugzilla-comments version has this signature:
* selectOption = function selectOption(select, value) {
- let doc = select[0].ownerDocument;
+ var doc = select[0].ownerDocument;
select.val(value);
*/
BZPage.prototype.selectOption = function(id, label) {
- let sel = this.doc.getElementById(id);
+ var sel = this.doc.getElementById(id);
sel.value = label;
- let intEvent = this.doc.createEvent("HTMLEvents");
+ var intEvent = this.doc.createEvent("HTMLEvents");
intEvent.initEvent("change", true, true);
sel.dispatchEvent(intEvent);
};
@@ -435,7 +438,7 @@ BZPage.prototype.selectOption = function(id, label) {
* @return None
*/
BZPage.prototype.clickMouse = function(targetID) {
- let localEvent = this.doc.createEvent("MouseEvents");
+ var localEvent = this.doc.createEvent("MouseEvents");
localEvent.initMouseEvent("click", true, true, this.doc.defaultView, 0, 0,
0, 0, 0, false, false, false, false, 0, null);
this.doc.getElementById(targetID).dispatchEvent(localEvent);
@@ -450,7 +453,7 @@ BZPage.prototype.clickMouse = function(targetID) {
* @return none
*/
BZPage.prototype.addStuffToTextBox = function(id, stuff) {
- let textBox = this.doc.getElementById(id);
+ var textBox = this.doc.getElementById(id);
if (textBox.tagName.toLowerCase() === "textarea") {
stuff = textBox.value ? "\n\n" + stuff : stuff;
textBox.value += stuff;
@@ -466,9 +469,9 @@ BZPage.prototype.addStuffToTextBox = function(id, stuff) {
* @param stuff String/Array with keyword(s) to be removed
*/
BZPage.prototype.removeStuffFromTextBox = function(id, stuff) {
- let changedElement = this.getElementById(id);
+ var changedElement = this.getElementById(id);
changedElement.value = util.removeCSVValue(changedElement.value,stuff);
-}
+};
/**
* generalized hasKeyword ... search in the value of the box with given id
@@ -478,13 +481,14 @@ BZPage.prototype.removeStuffFromTextBox = function(id, stuff) {
* @return Boolean found?
*/
BZPage.prototype.idContainsWord = function(id, str) {
+ var kwd = "";
try {
- var kwd = this.doc.getElementById(id).value;
+ kwd = this.doc.getElementById(id).value;
} catch (e) {
// For those who don't have particular element at all or if it is empty
return false;
}
- return (kwd.trim().indexOf(str) != -1);
+ return (kwd.trim().indexOf(str) !== -1);
};
/**
@@ -502,7 +506,7 @@ BZPage.prototype.hasKeyword = function(str) {
*/
BZPage.prototype.getOptionValue = function(id) {
// Some special bugs don't have version for example
- let element = this.doc.getElementById(id);
+ var element = this.doc.getElementById(id);
if (element) {
return element.value;
} else {
@@ -528,11 +532,11 @@ BZPage.prototype.setNeedinfoReporter = function() {
*
*/
BZPage.prototype.getOwner = function() {
- let priorityParent = this.doc.querySelector("label[for~='target_milestone']")
+ var priorityParent = this.doc.querySelector("label[for~='target_milestone']")
.parentNode.parentNode.parentNode;
- let assigneeAElement = priorityParent.querySelector("tr:nth-of-type(1) a.email");
- let assgineeHref = decodeURI(assigneeAElement.getAttribute("href"));
- let email = assgineeHref.split(":")[1];
+ var assigneeAElement = priorityParent.querySelector("tr:nth-of-type(1) a.email");
+ var assgineeHref = decodeURI(assigneeAElement.getAttribute("href"));
+ var email = assgineeHref.split(":")[1];
return email;
};
@@ -542,9 +546,9 @@ BZPage.prototype.getOwner = function() {
* @return String with the login name of the currently logged-in user
*/
BZPage.prototype.getLogin = function () {
- let lastLIElement = this.doc.querySelector("#header ul.links li:last-of-type");
- let loginArr = lastLIElement.textContent.split("\n");
- let loginStr = loginArr[loginArr.length - 1].trim();
+ var lastLIElement = this.doc.querySelector("#header ul.links li:last-of-type");
+ var loginArr = lastLIElement.textContent.split("\n");
+ var loginStr = loginArr[loginArr.length - 1].trim();
return loginStr;
};
@@ -555,9 +559,9 @@ BZPage.prototype.getLogin = function () {
* @return String with the maintainer's email address
*/
BZPage.prototype.getDefaultBugzillaMaintainer = function(component) {
- let address = util.filterByRegexp(this.defBugzillaMaintainerArr, component);
+ var address = util.filterByRegexp(this.defBugzillaMaintainerArr, component);
return address;
-}
+};
/**
* collect the list of attachments in a structured format
@@ -568,10 +572,10 @@ BZPage.prototype.getDefaultBugzillaMaintainer = function(component) {
* element itself
*/
BZPage.prototype.getAttachments = function() {
- let outAtts = [];
- let atts = this.doc.getElementById("attachment_table")
+ var outAtts = [];
+ var atts = this.doc.getElementById("attachment_table")
.getElementsByTagName("tr");
- for ( let i = 1, ii = atts.length - 1; i < ii; i++) {
+ for ( var i = 1, ii = atts.length - 1; i < ii; i++) {
outAtts.push(this.parseAttachmentLine(atts[i]));
}
return outAtts;
@@ -587,21 +591,21 @@ BZPage.prototype.getPassword = function() {
if (jetpack.storage.settings.BZpassword) {
return jetpack.storage.settings.BZpassword;
} else {
- let prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
+ var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
- let password = {
+ var password = {
value : ""
}; // default the password to pass
- let check = {
+ var check = {
value : true
}; // default the checkbox to true
- let result = prompts.promptPassword(null, "Title", "Enter password:",
+ var result = prompts.promptPassword(null, "Title", "Enter password:",
password, null, check);
// result is true if OK was pressed, false if cancel was pressed.
// password.value is
// set if OK was pressed. The checkbox is not displayed.
if (result) {
- let passwordText = password.value;
+ var passwordText = password.value;
jetpack.storage.settings.BZpassword = passwordText;
jetpack.storage.simple.sync();
return passwordText;
@@ -615,8 +619,8 @@ BZPage.prototype.getPassword = function() {
*/
BZPage.prototype.setUpLogging = function() {
// For adding additional buttons to the top toolbar
- let additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions");
- let that = this;
+ var additionalButtons = this.doc.querySelector("#bugzilla-body *.related_actions");
+ var that = this;
// logging all submits for timesheet
// FIXME we should merge in functionality of RHBugzillaPage.submitCallback
@@ -626,7 +630,7 @@ BZPage.prototype.setUpLogging = function() {
console.log("Installing submit callback!");
this.doc.forms.namedItem("changeform").addEventListener("submit",function (evt) {
console.log("Submit callback!");
- let resp = that.log.addLogRecord(that);
+ var resp = that.log.addLogRecord(that);
console.log("resp = " + resp);
if (resp === null) {
console.log("Avoiding submitting!");
@@ -638,7 +642,7 @@ BZPage.prototype.setUpLogging = function() {
this.submitHandlerInstalled = true;
}
- let generateTimeSheetUI = this.doc.createElement("li");
+ var generateTimeSheetUI = this.doc.createElement("li");
generateTimeSheetUI.innerHTML = "\u00A0-\u00A0<a href='#' id='generateTSButton'>"
+ "Generate timesheet</a>";
additionalButtons.appendChild(generateTimeSheetUI);
@@ -651,11 +655,11 @@ BZPage.prototype.setUpLogging = function() {
evt.preventDefault();
}, false);
- let clearLogsUI = this.doc.createElement("li");
+ var clearLogsUI = this.doc.createElement("li");
clearLogsUI.innerHTML = "\u00A0-\u00A0<a href='#' id='clearLogs'>"
+ "Clear logs</a>";
additionalButtons.appendChild(clearLogsUI);
- let clearLogAElem = this.doc.getElementById("clearLogs");
+ var clearLogAElem = this.doc.getElementById("clearLogs");
clearLogAElem.addEventListener("click", function() {
that.log.store = {};
jetpack.storage.simple.sync();
@@ -688,7 +692,7 @@ BZPage.prototype.addToCCList = function(who) {
if (!who) {
return ;
}
- if (who == "self") {
+ if (who === "self") {
this.doc.getElementById("addselfcc").checked = true;
} else {
this.clickMouse("cc_edit_area_showhide");
@@ -704,7 +708,7 @@ BZPage.prototype.addToCCList = function(who) {
* @return Array with email addresses as Strings.
*/
BZPage.prototype.getCCList = function() {
- let CCListSelect = this.doc.getElementById("cc");
+ var CCListSelect = this.doc.getElementById("cc");
outCCList = [];
if (CCListSelect) {
outCCList = Array.map(CCListSelect.options, function(item) {