From d818b656fb0db9a5edd8c9bdf756fc007ba4f8fe Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Wed, 12 May 2010 01:08:30 +0200 Subject: Add getInstalledPackages, initCommentsDropdown, onCommentsDropdownChange with a rough transcription into plain Javascript (no JQuery), not functional yet. Reformat deformations in Javadocs Finally remove heir() function forever. --- bugzillaBugTriage.js | 372 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 220 insertions(+), 152 deletions(-) diff --git a/bugzillaBugTriage.js b/bugzillaBugTriage.js index 8a4f5f0..35d4132 100644 --- a/bugzillaBugTriage.js +++ b/bugzillaBugTriage.js @@ -265,19 +265,6 @@ XMLRPCMessage.prototype.getParamXML = function(type, data) { return xml; }; -///* -// * Create and return an object that has p as its prototype -// * -// * @param p parent Object -// * @return child Object -// */ -//heir = function (o) { -// function F() {}; -// F.prototype = o; -// delete F.prototype.create; -// return new F(); -//}; - // ============================================================== var hlpr = function () { }; @@ -292,15 +279,30 @@ hlpr.valToArray = function valToArray(val) { return arr; }; +/** + * Merges two comma separated string as a list and returns new string + * + * @param str String with one values + * @param value String with other values + * @return String with merged lists + */ hlpr.addCSVValue = function addCSVValue(str, value) { let parts = (str.trim().length > 0 ? str.split(",") : []); + // FIXME isn't this wrong? In if conditions it treats value as a + // string, but then uses hlpr.valToArray on it ??? if (parts.indexOf(value) < 0) { parts.concat(hlpr.valToArray(value)); } return parts.join(","); }; -// FIXME rewrite so that it doesn't break Eclipse +/** + * Treats comma separated string as a list and removes one item from it + * + * @param str String treated as a list + * @param value String with the value to be removed from str + * @return String with the resulting list comma separated + */ hlpr.removeCSVValue = function removeCSVValue(str, value) { str = str.trim(); // we want it trimmed without any questions anyway let parts = str ? str.split(",") : []; @@ -312,10 +314,8 @@ hlpr.removeCSVValue = function removeCSVValue(str, value) { * Check whether an item is member of the list. Idea is just to make long if * commands slightly more readable. * - * @param mbr - * string to be searched in the list - * @param list - * list + * @param mbr string to be searched in the list + * @param list list * @return position of the string in the list, or -1 if none found. */ hlpr.isInList = function(mbr, list) { @@ -463,12 +463,9 @@ Color.prototype.toString = function() { * http://en.wikipedia.org/wiki/HSL_color_space. Assumes r, g, and b are * contained in the set [0, 255] and returns h, s, and l in the set [0, 1].4343 * - * @param Number - * r The red color value - * @param Number - * g The green color value - * @param Number - * b The blue color value + * @param Number r The red color value + * @param Number g The green color value + * @param Number b The blue color value * @return Array The HSL representation */ Color.prototype.hsl = function() { @@ -505,12 +502,9 @@ Color.prototype.hsl = function() { * http://en.wikipedia.org/wiki/HSL_color_space. Assumes h, s, and l are * contained in the set [0, 1] and returns r, g, and b in the set [0, 255]. * - * @param Number - * h The hue - * @param Number - * s The saturation - * @param Number - * l The lightness + * @param Number h The hue + * @param Number s The saturation + * @param Number l The lightness * @return Array The RGB representation */ Color.prototype.hslToRgb = function(h, s, l) { @@ -553,12 +547,9 @@ Color.prototype.hslToRgb = function(h, s, l) { * http://en.wikipedia.org/wiki/HSV_color_space. Assumes r, g, and b are * contained in the set [0, 255] and returns h, s, and v in the set [0, 1]. * - * @param Number - * r The red color value - * @param Number - * g The green color value - * @param Number - * b The blue color value + * @param Number r The red color value + * @param Number g The green color value + * @param Number b The blue color value * @return Array The HSV representation */ Color.prototype.hsv = function() { @@ -596,12 +587,9 @@ Color.prototype.hsv = function() { * http://en.wikipedia.org/wiki/HSV_color_space. Assumes h, s, and v are * contained in the set [0, 1] and returns r, g, and b in the set [0, 255]. * - * @param Number - * h The hue - * @param Number - * s The saturation - * @param Number - * v The value + * @param Number h The hue + * @param Number s The saturation + * @param Number v The value * @return Array The RGB representation */ Color.prototype.hsvToRgb = function(h, s, v) { @@ -665,9 +653,139 @@ Color.prototype.lightColor = function() { // BZPage's methods function BZPage(doc) { - +// this.initCommentsDropdown(); } +/** + * + */ +BZPage.prototype.getInstalledPackages = function() { + let installedPackages = {}; + if (gJSONData && ("commentPackages" in gJSONData)) { + let enabledPackages = jetpack.storage.settings.enabledPacks.split(/[, ]/); + for each (let pkg in enabledPackages) { + if (pkg in gJSONData.commentPackages) { + installedPackages[pkg] = gJSONData.commentPackages[pkg]; + } + } + } + return installedPackages; +}; + +/** + * + */ +BZPage.prototype.initCommentsDropdown = function() { + let that = this; + this.doc.getElementById("comments").innerHTML += + "
" + + " " + + " element with given id. * @@ -699,21 +817,14 @@ BZPage.prototype.selectOption = function(id, label) { /** * Send mouse click to the specified element * - * @param element - * where to send mouseclick to + * @param String ID of the element to send mouseclick to * @return None - * - * FIXME depreceated version from bugzilla-comments - hlpr.clickElement = function clickElement(element) { - let doc = element[0].ownerDocument; - ... - element[0].dispatchEvent(e); */ -BZPage.prototype.clickMouse = function(target) { +BZPage.prototype.clickMouse = function(targetID) { 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); - target.dispatchEvent(localEvent); + this.doc.getElementById(targetID).dispatchEvent(localEvent); }; /** @@ -735,11 +846,9 @@ BZPage.prototype.getISODate = function (dateStr) { * select element of the array where regexp in the first element matches second * parameter of this function * - * @param list - * array with regexps and return values - * @param chosingMark - * string by which the element of array is to be matched - * @return string chosen element + * @param list Array with regexps and return values + * @param chosingMark String by which the element of array is to be matched + * @return String chosen element */ BZPage.prototype.filterByRegexp = function(list, chosingMark) { var chosenPair = []; @@ -758,10 +867,8 @@ BZPage.prototype.filterByRegexp = function(list, chosingMark) { /** * Add text to the text box (comment box or status whiteboard) * - * @param id - * string with the id of the element - * @param string2BAdded - * string to be added to the comment box + * @param id String with the id of the element + * @param string2BAdded String to be added to the comment box * * @return none */ @@ -788,8 +895,7 @@ BZPage.prototype.addTextToTextBox = function(id, string2BAdded) { /** * Add new keyword among the keywords. * - * @param str - * string with the new keyword + * @param str String with the new keyword * @return none * * Checks for the existing keywords. @@ -801,10 +907,8 @@ BZPage.prototype.addKeyword = function(str) { /** * generalized hasKeyword ... search in the value of the box with given id * - * @param id - * String with ID of the element we want to check - * @param str - * String to be searched for + * @param id String with ID of the element we want to check + * @param str String to be searched for * @return Boolean found? */ BZPage.prototype.idContainsWord = function(id, str) { @@ -821,8 +925,7 @@ BZPage.prototype.idContainsWord = function(id, str) { /** * Check for the presence of a keyword * - * @param str - * string with the keyword + * @param str String with the keyword * @return Boolean */ BZPage.prototype.hasKeyword = function(str) { @@ -832,8 +935,7 @@ BZPage.prototype.hasKeyword = function(str) { /** * Set additional keyword if it isn't there * - * @param str - * string with the keyword + * @param str String with the keyword * @return none */ BZPage.prototype.setKeyword = function(str) { @@ -854,24 +956,16 @@ BZPage.prototype.getOptionValue = function(id) { * 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. * - * @param originalLocation - * object after which the new button will be added - * @param newId - * string with the id of the new button; has to be unique in whole + * @param originalLocation Object after which the new button will be added + * @param newId String with the id of the new button; has to be unique in whole * page - * @param newLabel - * string with the label which will be shown to user - * @param commentString - * string with comment to be added to the comment box - * @param nState - * string with the new state bug should switch to (see + * @param newLabel String with the label which will be shown to user + * @param commentString String with comment to be added to the comment box + * @param nState String with the new state bug should switch to (see * generalPurposeCureForAllDisease function for details) - * @param secPar - * string with second parameter for generalPurposeForAllDisease - * @param doSubmit - * bool optional whether the button should submit whole page (default - * true) - * + * @param secPar String with second parameter for generalPurposeForAllDisease + * @param doSubmit Boolean optional whether the button should submit whole + * page (default true) * @return none */ BZPage.prototype.addNewButton = function(originalLocation, newId, newLabel, @@ -1538,10 +1632,8 @@ RHBugzillaPage.prototype.setBranding = function() { * Given line to be parsed, find out which chipset it is and fill in the * whiteboard * - * @param iLine - * string with the whole unparsed "interesting line" - * @param driverStr - * string with the driver name + * @param iLine String with the whole unparsed "interesting line" + * @param driverStr String with the driver name * @return None */ RHBugzillaPage.prototype.fillInWhiteBoard = function(iLine, driverStr) { @@ -1559,12 +1651,9 @@ RHBugzillaPage.prototype.fillInWhiteBoard = function(iLine, driverStr) { /** * Given PCI IDs for manufacturer and card ID return chipset string * - * @param manufacturerNo - * string with manufacturer PCI ID - * @param cardNo - * string with card PCI ID - * - * @return array with chip string and optinoal variants + * @param manufacturerNo String with manufacturer PCI ID + * @param cardNo String with card PCI ID + * @return Array with chip string and optinoal variants */ function checkChipStringFromID(manufacturerNo, cardNo) { var soughtID = (manufacturerNo + "," + cardNo).toUpperCase(); @@ -1684,12 +1773,9 @@ RHBugzillaPage.prototype.fillInChipMagic = function () { /** * Opens a new tab with a query for the given text in the selected component * - * @param text - * to be searched for - * @param component - * string with the component name (maybe latter regexp?) - * @param product - * (optional) string with the product name + * @param text to be searched for + * @param component String with the component name (maybe latter regexp?) + * @param product (optional) string with the product name * @return None * */ @@ -1821,8 +1907,7 @@ RHBugzillaPage.prototype.parseAttachmentLine = function(inElem) { /** * Check for the presence of a keyword * - * @param str - * string with the keyword + * @param str String with the keyword * @return Boolean * */ @@ -1834,14 +1919,10 @@ RHBugzillaPage.prototype.hasKeyword = function(str) { /** * Add accesskey to the particular element * - * @param rootElement - * element to which the new text object will be attached - * @param beforeText - * text before the accesskey character - * @param accKey - * what will be the accesskey itself - * @param afterText - * text after the accesskey character + * @param rootElement Element to which the new text object will be attached + * @param beforeText Text before the accesskey character + * @param accKey what will be the accesskey itself + * @param afterText text after the accesskey character * @return modified element with the fixed accesskey FIXME isn't this closure * and possible memleak? */ @@ -1854,8 +1935,7 @@ RHBugzillaPage.prototype.fixElement = function(elem, beforeText, accKey, afterTe /** * Add XGL to the CC list * - * @param evt - * event which made this function active + * @param evt Event which made this function active * @return none */ RHBugzillaPage.prototype.changeOwner = function(newAssignee) { @@ -1868,7 +1948,7 @@ RHBugzillaPage.prototype.changeOwner = function(newAssignee) { this.doc.getElementById("newcc").textContent = newAssignee; } if (newAssignee) { - this.clickMouse(this.doc.getElementById("bz_assignee_edit_action")); + 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 @@ -1882,20 +1962,18 @@ RHBugzillaPage.prototype.changeOwner = function(newAssignee) { * Set the bug to NEEDINFO state * * Working function. - * * @return none */ RHBugzillaPage.prototype.setNeedinfoReporter = function() { - this.clickMouse(this.doc.getElementById("needinfo")); + this.clickMouse("needinfo"); this.selectOption("needinfo_role", "reporter"); }; /** * Return string with the ID for the external_id SELECT for external bugzilla * - * @param URLhostname - * string hostname of the external bugzilla - * @return string with the string for the external_id SELECT + * @param URLhostname String hostname of the external bugzilla + * @return String with the string for the external_id SELECT */ RHBugzillaPage.prototype.getBugzillaName = function(URLhostname) { var bugzillaID = ""; @@ -1910,10 +1988,9 @@ RHBugzillaPage.prototype.getBugzillaName = function(URLhostname) { /** * Generate URL of the bug on remote bugzilla * - * @param selectValue - * Number which is index of the bugzilla in hashBugzillaWholeURL - * @param bugID - * Number which is bug ID + * @param selectValue Number which is index of the bugzilla + * in hashBugzillaWholeURL + * @param bugID Number which is bug ID * @return string with the URL */ RHBugzillaPage.prototype.getWholeURL = function(selectValue, bugID) { @@ -1929,9 +2006,11 @@ RHBugzillaPage.prototype.getWholeURL = function(selectValue, bugID) { /** * Callback function for the XMLRPC request * - * @param ret - * object with xmlhttprequest response with attributes: + status -- - * int return code + statusText + responseHeaders + responseText + * @param ret Object with xmlhttprequest response with attributes: + * + status -- int return code + * + statusText + * + responseHeaders + * + responseText */ RHBugzillaPage.prototype.callBack = function(data, textStatus) { if (--this.reqCounter <= 0) { @@ -1943,12 +2022,9 @@ RHBugzillaPage.prototype.callBack = function(data, textStatus) { * The worker function -- call XMLRPC to fix MIME type of the particular * attachment * - * @param id - * integer with the attachment id to be fixed - * @param type - * string with the new MIME type, optional defaults to "text/plain" - * @param email - * Boolean whether email should be sent to appropriate person; + * @param id Integer with the attachment id to be fixed + * @param type String with the new MIME type, optional defaults to "text/plain" + * @param email Boolean whether email should be sent to appropriate person; * option, defaults to false * * updateAttachMimeType($data_ref, $username, $password) @@ -2015,8 +2091,7 @@ RHBugzillaPage.prototype.fixAllAttachments = function(list) { /** * Create a button for fixing all bad attachments. * - * @param list - * Array of all bad attachmentss + * @param list Array of all bad attachmentss * @return button fixing all bad Attachments */ RHBugzillaPage.prototype.createFixAllButton = function(list) { @@ -2054,9 +2129,7 @@ RHBugzillaPage.prototype.addTextLink = function(row) { /** * Add information about the upstream bug upstream, and closing it. * - * @param evt - * event which called this handler - * + * @param evt Event which called this handler * @return none */ RHBugzillaPage.prototype.addClosingUpstream = function() { @@ -2113,10 +2186,8 @@ RHBugzillaPage.prototype.addClosingUpstream = function() { /** * Insert a row of buttons before the marked element * - * @param anchor - * element before which the row of buttons will be inserted - * @param array - * array of data for buttons to be generated + * @param anchor Element before which the row of buttons will be inserted + * @param array Array of data for buttons to be generated * @return none */ RHBugzillaPage.prototype.generateToolBar = function(anchor, array) { @@ -2130,13 +2201,11 @@ RHBugzillaPage.prototype.generateToolBar = function(anchor, array) { /** * Generalized function for all actions * - * @param addString - * string to be added as new comment - * @param nextState - * string signifying next state of the bug (whatever is in Bugzilla + + * @param addString String to be added as new comment + * @param nextState String signifying next state of the bug (whatever is in Bugzilla + * "NEEDINFO" meaning NEEDINFO(Reporter)) - * @param secondParameter - * string with label on the subbutton for reason of closing the bug + * @param secondParameter String with label on the subbutton for reason of + * closing the bug * @return none */ RHBugzillaPage.prototype.generalPurposeCureForAllDisease = function(addString, @@ -2270,8 +2339,7 @@ RHBugzillaPage.prototype.parseBacktrace = function(ret) { * separated into function, so that it could be called from onload method of the * XMLHttpRequest. * - * @param jsonList - * Array created from JSON + * @param jsonList Array created from JSON * @return none */ RHBugzillaPage.prototype.buildButtons = function(above, below) { -- cgit