diff options
-rw-r--r-- | bugzillaBugTriage.js | 1089 |
1 files changed, 512 insertions, 577 deletions
diff --git a/bugzillaBugTriage.js b/bugzillaBugTriage.js index 673da77..4330a7e 100644 --- a/bugzillaBugTriage.js +++ b/bugzillaBugTriage.js @@ -4,48 +4,70 @@ jetpack.future.import("pageMods"); jetpack.future.import("storage.simple"); -// ************* FUNCTIONS ******************** -/* EXTERNAL FUNCTIONS */ - -/** - * This function creates a new anchor element and uses location properties (inherent) - * to get the desired URL data. Some String operations are used (to normalize results - * across browsers). - * originally from http://snipplr.com/view.php?codeview&id=12659 - * - * @param url String with URL - * @return object with parameters set - * - */ -function parseURL(url) { - var a = jetpack.tabs.focused.contentDocument.createElement('a'); - a.href = url; - return { - source: url, - protocol: a.protocol.replace(':',''), - host: a.hostname, - port: a.port, - query: a.search, - params: (function(){ - var ret = {}, - seg = a.search.replace(/^\?/,'').split('&'), - len = seg.length, i = 0, s; - for (;i<len;i++) { - if (!seg[i]) { continue; } - s = seg[i].split('='); - ret[s[0]] = s[1]; - } - return ret; - })(), - file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1], - hash: a.hash.replace('#',''), - path: a.pathname.replace(/^([^\/])/,'/$1'), - relative: (a.href.match(/tp:\/\/[^\/]+(.+)/) || [,''])[1], - segments: a.pathname.replace(/^\//,'').split('/') - }; +// Static values +// ****************** STATIC DATA ************************* +var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi"; +var myStorage = jetpack.storage.simple; +// CONFIGURE: The easiest method how to set up the configuration +// value is to uncomment the following line with proper URL as +// the second parameter. Then reload the bug page and comment out +// again. +//GM_setValue("JSONURL","URL-somewhere-with-your-JSON"); +var jsonDataURL = ""; +myStorage.JSONURL = "http://barstool.build.redhat.com/~mcepl/RH_Data.json"; +if (myStorage.JSONURL) { + jsonDataURL = myStorage.JSONURL; +} +if (!jsonDataURL) { + jsonDataURL = "http://mcepl.fedorapeople.org/scripts/BugZappers_data.json"; } +console.log("jsonDataURL = " + jsonDataURL); +var PCIIDsURL = "http://mcepl.fedorapeople.org/scripts/drm_pciids.json"; +//var debug = GM_getValue("debug",false); +var debug = true; +var reqCounter = 0; +var msgStrs = {}; + +var RHColor = "#9E292B"; +var FedoraColor = "#002867"; +var RawhideColor = "#007700"; // or "green" +var RHITColor = "#660066"; +var SalmonPink = "#FFE0B0"; +var CommentRe = RegExp("^\\s*#"); +var BlankLineRe = RegExp("^\\s*$"); +var ChipsetRE = RegExp("^\\(--\\) ([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$"); +var ATIgetIDRE = RegExp("^.*\\(ChipID = 0x([0-9a-fA-F]+)\\).*$"); +var PCI_ID_Array = []; + +// For identification of graphics card +var manuChipStrs = [ + ["ATI Radeon","ATI","1002"], + ["ATI Mobility Radeon","ATI","1002"], + ["Intel Corporation","INTEL","8086"], + ["NVIDIA","NV","10de"] +]; +var backTranslateManufacturerPCIID = [{ + regexp: "ATI Technologies Inc", + addr: "1002" + },{ + regexp: "Intel Corporation", + addr: "8086" + },{ + regexp: "nVidia Corporation", + addr: "10de" +}]; +// Get card translation table +XMLHttpRequest({ + // anything called inside of this Request cannot have variables set in MAIN + method: 'GET', + url: PCIIDsURL, + onload: function(response) { + PCI_ID_Array = JSON.parse(response.responseText); + } +}); +// ************* FUNCTIONS ******************** /** * Clean the string from spaces around * @@ -69,7 +91,7 @@ function trim(str,cleanRE) { * @return string chosen element */ function filterByRegexp(list,chosingMark) { - var chosenPair = Array(); + var chosenPair = []; if (list.length > 0) { chosenPair = list.filter( function(pair){ @@ -77,7 +99,7 @@ function filterByRegexp(list,chosingMark) { }); }; if (chosenPair.length > 0) { - return trim(chosenPair[0]['addr']); + return $.trim(chosenPair[0]['addr']); } else { return ""; } @@ -96,7 +118,7 @@ function valuesToList(list) { for (var element in list) { if (element.hasAttribute("value")) { - outL[outL.length] = trim(element.getAttribute("value")); + outL[outL.length] = $.trim(element.getAttribute("value")); } } return outL; @@ -127,118 +149,226 @@ function getClipboardText() { this.netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect'); var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard); - if (!clip) return false; + if (!clip) return(false); +; var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable); - if (!trans) return false; + if (!trans) return(false); trans.addDataFlavor("text/unicode"); clip.getData(trans, clip.kGlobalClipboard); - var str = new Object(); - var strLength = new Object(); + var str = new {}; + var strLength = new {}; trans.getTransferData("text/unicode", str, strLength); - if (str) + if (str) { str = str.value.QueryInterface(Components.interfaces.nsISupportsString); - if (str) + } + if (str) { pastetext = str.data.substring(0, strLength.value / 2); + } return pastetext; }; /* Bugzilla functions.*/ -/** - * add Fedora Bug zapper's signature to the comment of the current bug - */ -function addSignature(evt) { - var cmntText = $("#comment",document); - if ((signatureFedoraString.length > 0) && (trim(cmntText.value).length > 0)) { - cmntText.value = trim(cmntText.value) + signatureFedoraString; - } -} +function bzPage(doc) { + this.document = $(doc); + + this.hashBugzillaName = []; + this.hashBugzillaWholeURL = []; + this.defAssigneeList = []; + this.signatureFedoraString = ""; + // TODO we should have an array SpecialFlags instead of multiple Boolean variables + this.queryButtonAvailable = false; + this.chipIDsGroupings = []; + this.AddrArray = []; + // Initialize data from remote URL + this.XMLHttpRequestDone = false; + this.XorgLogAttList = []; + this.XorgLogAttListIndex = 0; -/** - * Send mouse click to the specified element - * @param element where to send mouseclick to - * @return None - */ -function clickMouse(target) { - var localEvent = jetpack.tabs.focused.contentDocument.createEvent("MouseEvents"); - localEvent.initMouseEvent("click", true, true, window, - 0, 0, 0, 0, 0, false, false, false, false, 0, null); - target.dispatchEvent(localEvent); -} + // Get JSON configuration data + XMLHttpRequest({ + // anything called inside of this Request cannot have variables set in MAIN + method: 'GET', + url: jsonDataURL, + onload: function(response) { + var data = JSON.parse(response.responseText); + msgStrs = data['strings']; + signatureFedoraString = data['signature']; + hashBugzillaName = data['bugzillalabelNames']; + hashBugzillaWholeURL = data['bugzillaIDURLs']; + AddrArray = data['CCmaintainer']; + defAssigneeList = data['defaultAssignee']; + queryButtonAvailable = data['queryButton']; + chipIDsGroupings = data['chipIDsGroupings']; + buildButtons(data['topRow'],data['bottomRow']); + if (signatureFedoraString.length > 0) { + // (or a form named "changeform") + document.forms[1].addEventListener("submit",addSignature,true); + } + } + }); -/** - * Parse the row with the attachment - * @param <tr> element to be parsed - * @return array with string name of the attachment, - integer its id number, - string of MIME type, - integer of size in kilobytes, - and the whole element itself - */ -function parseAttachmentLine(inElem) { - var name = String(); - var MIMEtype = String(); - var size = Number(); - var id = Number(); + // FOR DEBUGGING ONLY!!! + if (debug) { + //console.log("signatureFedoraString = " + signatureFedoraString); + $("#bz_field_status",this.document).append("<span inline='font-size:x-small'>"+jsonDataURL+"</span>"); + } - // FIXME we should skip obsolete attachments + // *** collect information about the bug + // var bugNo = getBugNo(); + console.log("BBB"); + var bugNo = $("#title > p:first",this.document).text(); + console.log("BBB"); + console.log(bugNo); + this.reporter = $('#bz_show_bug_column_2 > .fn:first',this.document).text(); + this.owner = $.trim($("#bz_assignee_edit_container > .fn:first",this.document).text()).toLowerCase(); + this.CCList = $("select[name*='cc']:first > *[value]",this.document); + console.log(typeof(this.CCList)); + this.product = this.getProduct(); + this.version = this.getVersion(); + this.issueTracker = this.getIssueTracker(); + this.maintCCAddr = this.getCCMaintainer(AddrArray); + this.component = this.getComponent(); - inElem.normalize(); + this.checkPrivateValues(); - // getting name of the attachment - var bElem = inElem.getElementsByTagName("b")[0]; - name = trim(bElem.textContent); + this.login = this.getLogin(); + this.password = myStorage.BZpassword; - // getting id - var aElem = inElem.getElementsByTagName("a")[0]; - id = parseInt(aElem.getAttribute("href").replace(/^.*attachment.cgi\?id=/,""),10); + //*** set the main environment + this.setBranding(product,version,issueTracker); - //getting MIME type and size - var spanElems = inElem.getElementsByClassName("bz_attach_extra_info")[0]; - var roundedText = spanElems.innerHTML; + // fix process.cgi HREFs so that to avoid confusion on IRC + if (this.document.location.href.search(/process.cgi/) != -1) { + this.fixAllHrefs(bugNo); + } - var stringArray = trim(roundedText.replace(/^\s*\((.*)\s*KB,\s*$/,"$1")); - size = parseInt(stringArray,10); - MIMEtype = roundedText.split("\n")[2].replace(/^\s*(.*)\)\s*$/,"$1"); + this.fixAttachments(); + + this.originalButton = this.document("#commit"); // source button to be copied from + this.originalButton.attr("accesskey",'s'); + this.originalButton.attr("value","Submit"); +} - return([name,id,MIMEtype,size,inElem]); +/** + * This function creates a new anchor element and uses location properties (inherent) + * to get the desired URL data. Some String operations are used (to normalize results + * across browsers). + * originally from http://snipplr.com/view.php?codeview&id=12659 + * + * @param url String with URL + * @return object with parameters set + * + */ +function bzPage.prototype.parseURL(url) { + var a = $('<a href="'+url+'"></a>',this.document).get(0); + return { + source: url, + protocol: a.protocol.replace(':',''), + host: a.hostname, + port: a.port, + query: a.search, + params: (function(){ + var ret = {}, + seg = a.search.replace(/^\?/,'').split('&'), + len = seg.length, i = 0, s; + for (;i<len;i++) { + if (!seg[i]) { continue; } + s = seg[i].split('='); + ret[s[0]] = s[1]; + } + return ret; + })(), + file: (a.pathname.match(/\/([^\/?#]+)$/i) || [,''])[1], + hash: a.hash.replace('#',''), + path: a.pathname.replace(/^([^\/])/,'/$1'), + relative: (a.href.match(/tp:\/\/[^\/]+(.+)/) || [,''])[1], + segments: a.pathname.replace(/^\//,'').split('/') + }; } /** + * add Fedora Bug zapper's signature to the comment of the current bug + */ +function bzPage.prototype.addSignature = function(evt) { + var cmntText = $("#comment",this.document); + if ((this.signatureFedoraString.length > 0) && + ($.trim(cmntText.value).length > 0)) { + cmntText.value = $.trim(cmntText.value) + this.signatureFedoraString; + } + } + +/** * Get list of attachments to the bug * * @return array of attachments */ -function getAttachments(attTable) { - var attList = Array(); +function bzPage.prototype.fixAttachments(){ + + /** + * Parse the row with the attachment + * @param <tr> element to be parsed + * @return array with string name of the attachment, + integer its id number, + string of MIME type, + integer of size in kilobytes, + and the whole element itself + */ + function parseAttachmentLine(inElem) { + var name = ""; + var MIMEtype = ""; + var size = Number(); + var id = Number(); + + // FIXME we should skip obsolete attachments + inElem.normalize(); + + // getting name of the attachment + var bElem = $("b:first",inElem); + name = $.trim(bElem.text()); + + // getting id + id = parseInt($("a:first",inElem).attr("href").replace(/^.*attachment.cgi\?id=/,""),10); + + //getting MIME type and size + var roundedText = $(".bz_attach_extra_info:first",inElem).html(); + + var stringArray = $.trim(roundedText.replace(/^\s*\((.*)\s*KB,\s*$/,"$1")); + size = parseInt(stringArray,10); + MIMEtype = roundedText.split("\n")[2].replace(/^\s*(.*)\)\s*$/,"$1"); + + return([name,id,MIMEtype,size,inElem]); + } - var tempT = attTable.getElementsByTagName("tr"); - if (tempT.length > 2) { - for (var i=1;i<tempT.length-1;i++) { - attList.push(parseAttachmentLine(tempT[i])); - } - } - return(attList); -} + function getAttachments(attTable) { + var attList = []; -function isOctetStream(element, index, array) { - var inArray = ["application/octet-stream","text/x-log"]; - return(inArray.indexOf(element[2]) != -1); -} + var tempT = $("tr",attTable).get(); + if (tempT.length > 2) { + for (var i=1;i<tempT.length-1;i++) { + attList.push(parseAttachmentLine(tempT[i])); + } + } + return(attList); + } -function fixAttachments(){ - var aTable = $("#attachment_table",document); - var attachmentsList = getAttachments(aTable); + function isOctetStream(element, index, array) { + var inArray = ["application/octet-stream","text/x-log"]; + return(inArray.indexOf(element[2]) != -1); + } + + var aTable = $("#attachment_table",this.document); + var attachmentsList = getAttachments(aTable.get()); var badAttachments = attachmentsList.filter(isOctetStream); if (badAttachments.length>0) { - var titleElement = $(".bz_alias_short_desc_container:first",document); + var titleElement = $(".bz_alias_short_desc_container:first",this.document); titleElement.css("background-color","olive"); titleElement.append(createFixAllButton(badAttachments)); for(var i=0;i<badAttachments.length;i++) { @@ -247,35 +377,6 @@ function fixAttachments(){ } } -function groupIDs(manStr,cardStrID) { -// console.log("RegExpArr = " + chipIDsGroupings.toSource() + ", hledam = " + manStr + "," + cardStrID); - var outStr = filterByRegexp(chipIDsGroupings,manStr+","+cardStrID); - if (outStr.length == 0) { - outStr = "UNGROUPED_" + manStr+"/"+cardStrID; - } - return outStr; -} - -/** - * 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 - */ -function checkChipStringFromID(manufacturerNo,cardNo) { - console.log("This is the card ID: " + cardNo + " manufactured by " + manufacturerNo); - var soughtID = (manufacturerNo+","+cardNo).toUpperCase(); - var outList = PCI_ID_Array[soughtID]; - console.log("nalezeno = " + outList.toSource()); - if (outList) { - return outList; - } else { - return ""; - } -} - /** * Given line to be parsed, find out which chipset it is and fill in the whiteboard * @@ -283,11 +384,40 @@ function checkChipStringFromID(manufacturerNo,cardNo) { * @param driverStr string with the driver name * @return None */ -function fillInWhiteBoard(iLine,driverStr) { +function bzPage.prototype.fillInWhiteBoard(iLine,driverStr) { var outStr = ""; var cardIDStr = ""; - var cardIDArr = Array(); - + var cardIDArr = []; + + function groupIDs(manStr,cardStrID) { + // console.log("RegExpArr = " + chipIDsGroupings.toSource() + ", hledam = " + manStr + "," + cardStrID); + var outStr = filterByRegexp(chipIDsGroupings,manStr+","+cardStrID); + if (outStr.length == 0) { + outStr = "UNGROUPED_" + manStr+"/"+cardStrID; + } + return outStr; + } + + /** + * 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 + */ + function checkChipStringFromID(manufacturerNo,cardNo) { + console.log("This is the card ID: " + cardNo + " manufactured by " + manufacturerNo); + var soughtID = (manufacturerNo+","+cardNo).toUpperCase(); + var outList = PCI_ID_Array[soughtID]; + console.log("nalezeno = " + outList.toSource()); + if (outList) { + return outList; + } else { + return ""; + } + } + console.log("driverStr = " + driverStr); console.log("iLine: " + iLine); @@ -322,7 +452,7 @@ function fillInWhiteBoard(iLine,driverStr) { break chipSwitchboard; } // cardIDArr [0] = RE, [1] = ("RADEON","INTEL","NOUVEAU"), [2] = manu PCIID - iLine = trim(iLine.replace(RegExp(cardIDArr[0],"i"),"")); + iLine = $.trim(iLine.replace(RegExp(cardIDArr[0],"i"),"")); // FIXME is this necessary? Let's try without it // outStr = iLine.replace(/^\W*(\w*).*$/,"$1"); // nVidia developers opted-out from grouping @@ -333,12 +463,12 @@ function fillInWhiteBoard(iLine,driverStr) { } } console.log("result = " + outStr); - var whiteboardInput = $("#status_whiteboard",document); - var attachedText = trim("card_"+outStr); - if (whiteboardInput.value.length == 0) { - whiteboardInput.value = attachedText; + var whiteboardInput = $("#status_whiteboard",this.document); + var attachedText = $.trim("card_"+outStr); + if (whiteboardInput.val().length == 0) { + whiteboardInput.val(attachedText); } else { - whiteboardInput.value += ", " + attachedText; + whiteboardInput.val(whiteboardInput.val()+", " + attachedText); } } @@ -349,66 +479,18 @@ function fillInWhiteBoard(iLine,driverStr) { * etc.) * @return none */ -function fillInAddButton(interestLine,driverString) { - var newButt = originalButton.cloneNode(true); - var whiteboardInput = $("#status_whiteboard",document); - - newButt.setAttribute("id","chipmagic"); - newButt.setAttribute("value","Fill In"); - newButt.addEventListener('click',function (evt) { - fillInWhiteBoard(interestLine,driverString); - },true); - newButt.setAttribute("type","button"); - whiteboardInput.parentNode.appendChild(newButt); - whiteboardInput.parentNode.insertBefore(jetpack.tabs.focused.contentDocument.createTextNode("\u00A0"),newButt); -} - -/** - * Recursive function to run Get attached Xorg.0.log, parse it and find the value of chip - * @return None - */ -function fillInChipMagicProcessAtts(ret) { - if (ret) { - if (ret.status != 200) { - alert([ret.status,ret.statusText,ret.responseHeaders, - ret.responseText]); - throw "XMLHttpRequest got return code " + ret.status; - } - console.log('fetched ' + ret.finalUrl); - var interestingLineArr = ret.responseText.split("\n").filter(function (v,i,a) { - return ChipsetRE.test(v); - }); - console.log("interestingLineArr = " + interestingLineArr.toSource()); - if (interestingLineArr.length >0) { - // Process and exit - // .replace(ChipsetRE,"$1\t$2").split("\t") - var interestingArray = ChipsetRE.exec(interestingLineArr[0]); - console.log("interesting array = " + interestingArray.toSource()); - interestingLine = trim(interestingArray[2].replace(/[\s"]+/g," ")); - console.log("interesting line = " + interestingLine); - fillInAddButton(interestingLine,interestingArray[1].toUpperCase()); - console.log("XMLHttpRequest done!"); - return; - } - } - - if (XorgLogAttList[XorgLogAttListIndex]) { - var XorgLogAttID = XorgLogAttList[XorgLogAttListIndex][1]; - var attURL = "https://bugzilla.redhat.com/attachment.cgi?id="+XorgLogAttID; - XMLHttpRequest({ - method: 'GET', - url: attURL, - headers: { - 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey getXorgLog', - 'Accept': 'text/plain', - 'Content-type': 'text/xml' - }, - onload:fillInChipMagicProcessAtts - }); - XorgLogAttListIndex++; - } else { - console.log("No more Xorg.0.log attachments!"); - } +function bzPage.prototype.fillInAddButton(interestLine,driverString) { + var newButt = $(this.originalButton).clone(); + var whiteboardInput = $("#status_whiteboard",this.document); + + newButt.attr("id","chipmagic"); + newButt.attr("value","Fill In"); + newButt.attr("type","button"); + newButt.click(function (evt) { + this.fillInWhiteBoard(interestLine,driverString); + }); + whiteboardInput.after(newButt); + whiteboardInput.after("\u00A0"); } /** @@ -418,7 +500,55 @@ function fillInChipMagicProcessAtts(ret) { * @param none * @return none */ -function fillInChipMagic() { +function bzPage.prototype.fillInChipMagic() { + /** + * Recursive function to run Get attached Xorg.0.log, parse it and find the value of chip + * @return None + */ + function fillInChipMagicProcessAtts(ret) { + if (ret) { + if (ret.status != 200) { + jetpack.notifications.show([ret.status,ret.statusText,ret.responseHeaders, + ret.responseText].toSource()); + throw "XMLHttpRequest got return code " + ret.status; + } + console.log('fetched ' + ret.finalUrl); + var interestingLineArr = ret.responseText.split("\n").filter(function (v,i,a) { + return ChipsetRE.test(v); + }); + console.log("interestingLineArr = " + interestingLineArr.toSource()); + if (interestingLineArr.length >0) { + // Process and exit + // .replace(ChipsetRE,"$1\t$2").split("\t") + var interestingArray = ChipsetRE.exec(interestingLineArr[0]); + console.log("interesting array = " + interestingArray.toSource()); + interestingLine = $.trim(interestingArray[2].replace(/[\s"]+/g," ")); + console.log("interesting line = " + interestingLine); + fillInAddButton(interestingLine,interestingArray[1].toUpperCase()); + console.log("XMLHttpRequest done!"); + return; + } + } + + if (XorgLogAttList[XorgLogAttListIndex]) { + var XorgLogAttID = XorgLogAttList[XorgLogAttListIndex][1]; + var attURL = "https://bugzilla.redhat.com/attachment.cgi?id="+XorgLogAttID; + XMLHttpRequest({ + method: 'GET', + url: attURL, + headers: { + 'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey getXorgLog', + 'Accept': 'text/plain', + 'Content-type': 'text/xml' + }, + onload:fillInChipMagicProcessAtts + }); + XorgLogAttListIndex++; + } else { + console.log("No more Xorg.0.log attachments!"); + } + } + var XorgLogURL = ""; var XorgLogAttID = ""; var XorgLogFound = false; @@ -448,7 +578,7 @@ function fillInChipMagic() { * new * long_desc_type=substring&long_desc=Xpress%20200&bug_status=NEW&bug_status=ASSIGNED */ -function queryInNewTab(text,component,product) { +function bzPage.prototype.queryInNewTab(text,component,product) { // Optional parameter if (product == null) { product = "Fedora"; @@ -467,13 +597,13 @@ function queryInNewTab(text,component,product) { window.open(url); } -function queryForSelection(component) { - var text = window.getSelection().toString(); +function bzPage.prototype.queryForSelection(component) { + var text = window.getSelection().to""; if (text.length < 1) { text = getClipboardText(); }; if (text.length > 0) { - queryInNewTab(text, getComponent()); + this.queryInNewTab(text, getComponent()); } } @@ -485,7 +615,7 @@ function queryForSelection(component) { * @param method string -- either 'post' or 'get' * @param callback function catching callback */ -function sendRequest(url,data,method,callback) { +function bzPage.prototype.sendRequest(url,data,method,callback) { //$.rpc(url, dataType, onLoadCallback, version); XMLHttpRequest({ method: method, @@ -510,10 +640,10 @@ function sendRequest(url,data,method,callback) { * + responseHeaders * + responseText */ -function callBack(ret) { +function bzPage.prototype.callBack(ret) { if (ret.status != 200) { - alert([ret.status,ret.statusText,ret.responseHeaders, - ret.responseText]); + jetpack.notifications.show([ret.status,ret.statusText,ret.responseHeaders, + ret.responseText].toSource()); } if (--reqCounter <= 0) { setTimeout("document.location.reload()",1000); @@ -521,74 +651,53 @@ function callBack(ret) { } /** - * 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, e.g. "text/plain" - * - */ -function fixAttachById(id,type) { - var msg = new XMLRPCMessage("bugzilla.updateAttachMimeType"); - msg.addParameter({'attach_id':id, 'mime_type':type}); - msg.addParameter(login); - msg.addParameter(password); - try { - var ret = sendRequest(XMLRPCurl, - msg.xml(),'post',callBack); - } - catch (e) { - alert([e,ret]); - } - reqCounter++; -} - -/** * Callback function for "Fix all attachments" button * @param list Array of * @return none */ -function fixAllAttachments(list) { +function bzPage.prototype.fixAllAttachments(list) { var tmpElem = {}; + /** + * 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, e.g. "text/plain" + * + */ + function fixAttachById(id,type) { + // FIXME XMLRPCMessage + var msg = new XMLRPCMessage("bugzilla.updateAttachMimeType"); + msg.addParameter({'attach_id':id, 'mime_type':type}); + msg.addParameter(login); + msg.addParameter(password); + try { + var ret = sendRequest(XMLRPCurl, + msg.xml(),'post',callBack); + } + catch (e) { + jetpack.notifications.show([e,ret].toSource()); + } + reqCounter++; + } + for(var i=0;i<list.length;i++) { tmpElem = list[i]; fixAttachById(tmpElem[1],"text/plain"); } } -function createFixAllButton(list) { - var aElem = jetpack.tabs.focused.contentDocument.createElement("a"); - aElem.setAttribute("href",""); - aElem.addEventListener('click', - function(event) {fixAllAttachments(list);}, - true); +function bzPage.prototype.createFixAllButton(list) { + var aElem = $("<a href=''></a>"); + aElem.click(function(event) { + fixAllAttachments(list); + }); fixElement(aElem,"","F","ix all"); return aElem; } -function getTextAllLink(table,list) { - var AList = table.getElementsByTagName("a"); - var tElem = {}; - var t2Elem = {}; - var aElem = {}; - var hStr = ""; - var vAllElem = {}; - - for(var i=0;i<AList.length;i++) { - tElem = AList[i]; - if (tElem.hasAttribute("href")) { - hStr = tElem.getAttribute("href"); - } else { - hStr = ""; - } - if(hStr.indexOf("action=enter") != -1) { - vAllElem = tElem; - } - } -} - -function addTextLink(row) { +function bzPage.prototype.addTextLink(row) { var aList = row[row.length-1].getElementsByTagName("a"); var curElem = aList[aList.length-1]; var tElem = {}; @@ -603,11 +712,6 @@ function addTextLink(row) { $(curElem).parent().append(tElem); } -function isOctetStream(element, index, array) { - var inArray = ["application/octet-stream","text/x-log"]; - return(inArray.indexOf(element[2]) != -1); -} - //=========================== @@ -620,7 +724,7 @@ function isOctetStream(element, index, array) { * @param forward boolean optional should we search forward or backward? * @return element of the given tagName or null */ -function findNextSiblingByTagName(startElement,tagName,forward) { +function bzPage.prototype.findNextSiblingByTagName(startElement,tagName,forward) { if (forward === null) { // missing optional argument forward = true; } @@ -645,7 +749,7 @@ function findNextSiblingByTagName(startElement,tagName,forward) { * @param label * @return none */ -function selectOption(id,label) { +function bzPage.prototype.selectOption(id,label) { var selectElement = jetpack.tabs.focused.contentDocument.getElementById(id); var values = selectElement.options; for (var i = 0; i < values.length; i++) { @@ -665,8 +769,8 @@ function selectOption(id,label) { * * @return string component of the bug */ -function getComponent() { - return $.trim($("#component",document).attr("value")); +function bzPage.prototype.getComponent() { + return $.trim($("#component",this.document).attr("value")); } /** @@ -674,8 +778,8 @@ function getComponent() { * * @return string product the bug belongs to */ -function getProduct() { - var productSelect = $("#product",document); +function bzPage.prototype.getProduct() { + var productSelect = $("#product",this.document); var index = productSelect.selectedIndex; return productSelect.options[index].value; } @@ -685,8 +789,8 @@ function getProduct() { * * @return string revision of the product the bug belongs to */ -function getVersion() { - var versionSelect = $("#version",document); +function bzPage.prototype.getVersion() { + var versionSelect = $("#version",this.document).get(0); if (versionSelect) { var index = versionSelect.selectedIndex; return versionSelect.options[index].value; @@ -700,8 +804,8 @@ function getVersion() { * * @return int with the bug number */ -function getBugNo() { - var title = $.trim($("#title > p:first",document).html()); +function bzPage.prototype.getBugNo() { + var title = $.trim($("#title > p:first",this.document).html()); return eval(title.split(" ")[1]); } @@ -711,7 +815,7 @@ function getBugNo() { * * @return string email address to be on CC list. */ -function getCCMaintainer(addrs) { +function bzPage.prototype.getCCMaintainer(addrs) { return filterByRegexp(addrs,getComponent()).toLowerCase(); } @@ -719,7 +823,7 @@ function getCCMaintainer(addrs) { * Returns default assignee for the bug's component * @return string with the default assignee for given component */ -function getDefaultAssignee() { +function bzPage.prototype.getDefaultAssignee() { return filterByRegexp(defAssigneeList,getComponent()).toLowerCase(); } @@ -728,28 +832,20 @@ function getDefaultAssignee() { * @return string issuetracker numbers or empty string (either because we have no IT * or because it is not a RHEL bug). */ -function getIssueTracker() { - var interestingElement = $("#cf_issuetracker",document); +function bzPage.prototype.getIssueTracker() { + var interestingElement = $("#cf_issuetracker",this.document); if (interestingElement) { - return trim(interestingElement.value); + return $.trim(interestingElement.value); } else { return ""; } } /** - * Is this bug Xorg bug? - * @return boolean - */ -function isXorgBug() { - return maintCCAddr == "xgl-maint@redhat.com"; -} - -/** * Is this bug RHEL bug? * @return boolean */ -function isRHELBug() { +function bzPage.prototype.isRHELBug() { return getProduct().search(/Red Hat Enterprise Linux/) != -1; } @@ -763,8 +859,8 @@ function isRHELBug() { * @return modified element with the fixed accesskey * */ -function fixElement(rootElement,beforeText,accKey,afterText) { - rootElement.setAttribute("accesskey",accKey.toLowerCase()); +function bzPage.prototype.fixElement(rootElement,beforeText,accKey,afterText) { + rootElement.attr("accesskey",accKey.toLowerCase()); rootElement.innerHTML = beforeText + "<b><u>" + accKey + "</u></b>" + afterText; return rootElement; } @@ -776,7 +872,7 @@ function fixElement(rootElement,beforeText,accKey,afterText) { * @param its string with the IsueTracker numbers * @return */ -function setBranding(brand,version,its) { +function bzPage.prototype.setBranding(brand,version,its) { var brandColor = ""; if (brand.search(/Red Hat Enterprise Linux/) != -1) { @@ -795,12 +891,12 @@ function setBranding(brand,version,its) { // Comment each of the following lines to get only partial branding jetpack.tabs.focused.contentDocument.body.style.background = brandColor; - $("#titles",document).style.background = brandColor; + $("#titles",this.document).style.background = brandColor; // Make background-color of the body of bug salmon pink // for security bugs. if (hasKeyword("Security")) { - var divBody = $("#bugzilla-body",document); + var divBody = $("#bugzilla-body",this.document); divBody.style.backgroundImage = "none"; divBody.style.backgroundColor = SalmonPink; } @@ -808,7 +904,7 @@ function setBranding(brand,version,its) { // we should make visible whether maintCCAddr is in CCList if (isInList(maintCCAddr, CCList)) { - var switchCCEdit=$("#cc_edit_area_showhide",document); + var switchCCEdit=$("#cc_edit_area_showhide",this.document); //switchCCEdit.textContent = "*"+switchCCEdit.textContent; switchCCEdit.style.color = "navy"; switchCCEdit.style.fontWeight = "bolder"; @@ -834,16 +930,16 @@ function setBranding(brand,version,its) { * * @return none */ -function addNewButton(originalLocation,newId,newLabel,commentString,nState,secPar,doSubmit) { +function bzPage.prototype.addNewButton(originalLocation,newId,newLabel,commentString,nState,secPar,doSubmit) { if (doSubmit === null) { // missing optional argument doSubmit = true; } - var newButton = originalButton.cloneNode(true); + var newButton = this.originalButton.cloneNode(true); if (!doSubmit) { - newButton.setAttribute("type","button"); + newButton.attr("type","button"); } newButton.id=newId; - newButton.setAttribute("value",newLabel); + newButton.attr("value",newLabel); var commStr = ""; if (msgStrs[commentString]) { commStr = msgStrs[commentString]; @@ -851,7 +947,7 @@ function addNewButton(originalLocation,newId,newLabel,commentString,nState,secPa newButton.addEventListener('click',function (evt) { generalPurposeCureForAllDisease(commStr, nState, secPar); },true); - var textNode = jetpack.tabs.focused.contentDocument.createTextNode("\u00A0"); + var textNode = $("\u00A0"); originalLocation.parentNode.insertBefore(textNode,originalLocation); originalLocation.parentNode.insertBefore(newButton,textNode); } @@ -864,7 +960,7 @@ function addNewButton(originalLocation,newId,newLabel,commentString,nState,secPa * * Checks for the existing keywords. */ -function addKeyword(str) { +function bzPage.prototype.addKeyword(str) { var kwd = jetpack.tabs.focused.contentDocument.getElementById('keywords'); if (kwd.value.length == 0) { kwd.value = str; @@ -880,19 +976,18 @@ function addKeyword(str) { * @return Boolean * */ -function hasKeyword(str) { - var kwd = trim(jetpack.tabs.focused.contentDocument.getElementById('keywords').value); +function bzPage.prototype.hasKeyword(str) { + var kwd = $.trim($('#keywords').text()); return (RegExp(str).test(kwd)); } - /** * Add XGL to the CC list * * @param evt event which made this function active * @return none */ -function changeOwnerHandler(evt) { +function bzPage.prototype.changeOwnerHandler(evt) { /** Take care that when changing assignment of the bug, * current owner is added to CC list. * Switch off setting to the default assignee @@ -900,7 +995,7 @@ function changeOwnerHandler(evt) { if (!isInList(maintCCAddr, CCList)) { addToCC(maintCCAddr); } - var setDefaultAssigneeCheckbox = $("#set_default_assignee",document); + var setDefaultAssigneeCheckbox = $("#set_default_assignee",this.document); setDefaultAssigneeCheckbox.checked = false; selectOption("bug_status", "ASSIGNED"); } @@ -911,8 +1006,8 @@ function changeOwnerHandler(evt) { * Working function. * @return none */ -function setNeedinfoReporter() { - var checkbox = $("#needinfo",document); +function bzPage.prototype.setNeedinfoReporter() { + var checkbox = $("#needinfo",this.document); checkbox.click(); selectOption("needinfo_role", "reporter"); } @@ -923,8 +1018,8 @@ function setNeedinfoReporter() { * * @return none */ -function addTextToComment(string2BAdded) { - var commentTextarea = $("#comment",document); +function bzPage.prototype.addTextToComment(string2BAdded) { + var commentTextarea = $("#comment",this.document); // don't remove the current content of the comment box, // just behave accordingly @@ -940,8 +1035,8 @@ function addTextToComment(string2BAdded) { * @param address string address to be added * @return none */ -function addToCC(address) { - var sel = $("#newcc",document); +function bzPage.prototype.addToCC(address) { + var sel = $("#newcc",this.document); sel.value = address; } @@ -955,7 +1050,7 @@ function addToCC(address) { * of closing the bug * @return none */ -function generalPurposeCureForAllDisease(addString,nextState,secondParameter) { +function bzPage.prototype.generalPurposeCureForAllDisease(addString,nextState,secondParameter) { if (addString.length >0) { addTextToComment(addString); } @@ -990,9 +1085,9 @@ function generalPurposeCureForAllDisease(addString,nextState,secondParameter) { } if (secondParameter == "ADDSELFCC") { - $("#addselfcc",document).checked = true; + $("#addselfcc",this.document).checked = true; } else if (secondParameter == "NODEFAULTASSIGNEE") { - $("#set_default_assignee",document).checked = false; + $("#set_default_assignee",this.document).checked = false; } } @@ -1003,7 +1098,7 @@ function generalPurposeCureForAllDisease(addString,nextState,secondParameter) { * @param URLhostname string hostname of the external bugzilla * @return string with the string for the external_id SELECT */ -function getBugzillaName(URLhostname) { +function bzPage.prototype.getBugzillaName(URLhostname) { var bugzillaID = ""; if (hashBugzillaName[URLhostname]) { bugzillaID = hashBugzillaName[URLhostname]; @@ -1019,7 +1114,7 @@ function getBugzillaName(URLhostname) { * @param bugID Number which is bug ID * @return string with the URL */ -function getWholeURL(selectValue,bugID) { +function bzPage.prototype.getWholeURL(selectValue,bugID) { var returnURL = ""; if (hashBugzillaWholeURL[selectValue]) { returnURL = hashBugzillaWholeURL[selectValue]+bugID; @@ -1035,29 +1130,27 @@ function getWholeURL(selectValue,bugID) { * * @return none */ -function addClosingUpstream() { - var externalRefs = $("#external_bugs_table",document); - var refs = externalRefs.getElementsByTagName("tr"); - // that's a bad id, if there is a one. - var inputBox = $("#inputbox",document); +function bzPage.prototype.addClosingUpstream() { + var refs = $("#external_bugs_table > tr",this.document); + var inputBox = $("#inputbox",this.document); var externalBugID = 0; var wholeURL = ""; // Fix missing ID on the external_id SELECT - jetpack.tabs.focused.contentDocument.getElementsByName("external_id")[0].id = "external_id"; + $("*[name*='external_id']:first",this.document).attr("id","external_id"); - if (inputBox.value.match(/^http.*/)) { - wholeURL = inputBox.value; - var IBURLArr = parseURL(wholeURL); + if (inputBox.text().match(/^http.*/)) { + wholeURL = inputBox.text(); + var IBURLArr = this.parseURL(wholeURL); console.log("IBURLArr = " + IBURLArr.toSource()); externalBugID = parseInt(IBURLArr.params["id"]); - inputBox.value = externalBugID; + inputBox.text(externalBugID); var bugzillaName = getBugzillaName(IBURLArr.host); selectOption("external_id", bugzillaName); console.log("externalBugID = " + externalBugID); - } else if (!isNaN(inputBox.value)) { - externalBugID = parseInt(inputBox.value); - var bugzillaID = $("#external_id",document).value; + } else if (!isNaN(inputBox.text())) { + externalBugID = parseInt(inputBox.text()); + var bugzillaID = $("#external_id",this.document).text(); wholeURL = getWholeURL(bugzillaID,externalBugID); } else { // no inputBox.value -- maybe there is an external bug from @@ -1067,12 +1160,12 @@ function addClosingUpstream() { // It is not good to close bug as UPSTREAM, if there is no reference // to the upstream bug. - if ((refs.length > 2) || (externalBugID > 0)) { + if ((refs.get().length > 2) || (externalBugID > 0)) { addTextToComment(msgStrs['sentUpstreamString'].replace("§§§",wholeURL)); selectOption("bug_status", "CLOSED"); selectOption("resolution", "UPSTREAM"); } else { - alert("No external bug specified among the External References!"); + jetpack.notifications.show("No external bug specified among the External References!"); } } @@ -1081,7 +1174,7 @@ function addClosingUpstream() { * @param evt event send from DOM (not used) * @return none */ -function swapXGLMainToCCListHandler(evt) { +function bzPage.prototype.swapXGLMainToCCListHandler(evt) { /** Remove mcepl@redhat.com from CC list and put there * xgl-maint@redhat.com */ @@ -1091,9 +1184,9 @@ function swapXGLMainToCCListHandler(evt) { addToCC(maintCCAddr); } if (isInList(login, CCList)) { - var selBox = $("#cc",document); + var selBox = $("#cc",this.document); selBox[myAddrIndex].selected = true; - $("#removecc",document).checked = true; + $("#removecc",this.document).checked = true; } evt.stopPropagation(); evt.preventDefault(); @@ -1104,19 +1197,19 @@ function swapXGLMainToCCListHandler(evt) { * to point to the real bug, not to process.cgi page. * @param bugNo */ -function fixAllHrefs(bugNo) { - var AList = jetpack.tabs.focused.contentDocument.getElementsByTagName("a"); +function bzPage.prototype.fixAllHrefs(bugNo) { + var AList = $("a").get(); var curA; var hrefStr = ""; var reProcess = RegExp(""); for(var i=0;i<AList.length;i++) { - curA = AList[i]; - if (curA.hasAttribute("href")) { - hrefStr = curA.getAttribute("href"); + curA = $(AList[i]); + if (curA.attr("href")) { + hrefStr = curA.attr("href"); if (reProcess.test(hrefStr)) { - hrefStr = "show_bug.cgi?id="+bugNo.toString()+hrefStr; - curA.setAttribute("href",hrefStr); + hrefStr = "show_bug.cgi?id="+bugNo.to""+hrefStr; + curA.attr("href",hrefStr); } } } @@ -1126,7 +1219,7 @@ function fixAllHrefs(bugNo) { * @param anchor element before which the row of buttons will be inserted * @param array array of data for buttons to be generated */ -function generateToolBar(anchor,array) { +function bzPage.prototype.generateToolBar(anchor,array) { for (var i=0; i<array.length; i++) { var butt = array[i]; addNewButton(anchor, butt['idx'], @@ -1138,7 +1231,7 @@ function generateToolBar(anchor,array) { * make sure that prefs.js contain password for bugzilla * @return None */ -function checkPrivateValues() { +function bzPage.prototype.checkPrivateValues() { var password = ""; if (myStorage.BZpassword) { password = myStorage.BZpassword; @@ -1150,45 +1243,37 @@ function checkPrivateValues() { } /** - * There is a login printed on each page, go get it. - * @return string with the login - */ - function getLogin() { - var tmpElement = {}; - var tmpText = ""; - var divHeaderElement = $("#header",document); - - var headerLiElements = divHeaderElement.getElementsByTagName("ul")[0].getElementsByTagName("li"); - var loginLIElement = headerLiElements[headerLiElements.length-1]; - var loginText = trim(loginLIElement.lastChild.textContent); - return loginText; -} - -/** * Main executable functioning actually building all buttons on the page -- separated into function, so that * it could be called from onload method of the XMLHttpRequest. * @param jsonList Array created from JSON * @return none */ -function buildButtons(above,below) { - // TODO: I don't need this now and it isn't compatible with new style - // generalPurposeCureForAllDisease driving addNewButton. - //// Just for fixing wrong CC list - //if (isInList(login,CCList) && !isInList(maintCCAddr,CCList)) { - // addNewButton(IBList[1],"swapXGLMainToCCList","Swap -maint to CC", - // swapXGLMainToCCListHandler); - //} +function bzPage.prototype.buildButtons(above,below) { + /** + * There is a login printed on each page, go get it. + * @return string with the login + */ + function getLogin() { + var tmpElement = {}; + var tmpText = ""; + + // FIXME tohle bude špatně + var loginText = $.trim($("#header > ul:first > li:last >*:last",this.document).text()); + console.log("loginText = " + loginText); + return loginText; + } + + /** + * Is this bug Xorg bug? + * @return boolean + */ + function isXorgBug() { + return this.maintCCAddr == "xgl-maint@redhat.com"; + } //---------------------------------------------- //Generate a list of <input> elements in the page - var IBList = []; - var IBRawList = jetpack.tabs.focused.contentDocument.getElementsByTagName("input"); - for (var i=0;i<IBRawList.length;i++) { - if ((IBRawList[i].hasAttribute("type")) && - (IBRawList[i].getAttribute("type")=="submit")) { - IBList = IBList.concat(IBRawList[i]); - } - } + var IBList = $("input[type*='submit']",this.document).get(); // BUTTONS ON THE BOTTOM OF THE FORM // Create a new SUBMIT button adding current owner of the bug to @@ -1198,211 +1283,65 @@ function buildButtons(above,below) { "","ASSIGNED","NODEFAULTASSIGNEE"); // BUTTONS ABOVE THE COMMENT BOX - var textCommentElement = $("#comment",document); - var brElement = jetpack.tabs.focused.contentDocument.createElement("br"); - textCommentElement.parentNode.insertBefore(brElement,textCommentElement); + var insertAfterElement = $("<br/>"); + $("#comment",this.document).before(insertAfterElement); //var brElement = findNextSiblingByTagName(textCommentElement,"BR",false); - var insertAfterElement = brElement; - generateToolBar(insertAfterElement,above); + this.generateToolBar(insertAfterElement.get(0),above); // BUTTONS BELOW THE COMMENT BOX - generateToolBar(originalButton,below); + this.generateToolBar(this.originalButton,below); - // FIXME put this somehow into addNewButton and generalPurposeCureForAllDisease + // TODO put this somehow into addNewButton and generalPurposeCureForAllDisease // framework - if (queryButtonAvailable){ + if (this.queryButtonAvailable){ // Add query search button - var privateCheckbox = $("#newcommentprivacy",document); - var newPosition = privateCheckbox.nextSibling.nextSibling.nextSibling; - var newButt = originalButton.cloneNode(true); - newButt.setAttribute("id","newqueryintab"); - newButt.setAttribute("value","Query for string"); + var newPosition = $("#newcommentprivacy",this.document).siblings()[2]; + var newButt = $(this.originalButton).clone(); + newButt.attr("id","newqueryintab"); + newButt.attr("value","Query for string"); newButt.addEventListener('click',function (evt) { queryForSelection(); },true); - newButt.setAttribute("type","button"); - newPosition.parentNode.insertBefore(newButt,newPosition); - newPosition.parentNode.insertBefore(jetpack.tabs.focused.contentDocument.createTextNode("\u00A0"),newButt); + newButt.attr("type","button"); + newPosition.before(newButt); + newPosition.before("\u00A0"); } if ((chipIDsGroupings.length >0) && isXorgBug()) { // Add find chip magic button - var whiteboardInput = $("#status_whiteboard",document); - if (whiteboardInput.value.search(/card_/) == -1) { + var whiteboardInput = $("#status_whiteboard",this.document); + if (whiteboardInput.text().search(/card_/) == -1) { fillInChipMagic(); } } // Add setting default assignee var defAssignee = getDefaultAssignee(); - if ((defAssignee.length > 0) && (defAssignee != owner)) { - var divAssigned = $("#bz_assignee_edit_container",document); - var divAssignedInput = $("#assigned_to",document); - var divAssignedActiveCheckbox = $("#bz_assignee_edit_action",document); - newButt = originalButton.cloneNode(true); - newButt.setAttribute("id","setdefaultassigneebutton"); - newButt.setAttribute("value","Def. Assignee"); - newButt.addEventListener('click',function (evt) { + if ((defAssignee.length > 0) && (defAssignee != this.owner)) { + var divAssigned = $("#bz_assignee_edit_container",this.document); + var divAssignedInput = $("#assigned_to",this.document); + var divAssignedActiveCheckbox = $("#bz_assignee_edit_action",this.document); + newButt = $(this.originalButton).clone(); + newButt.attr("id","setdefaultassigneebutton"); + newButt.attr("value","Def. Assignee"); + newButt.click(function (evt) { if (defAssignee.length > 0) { - clickMouse(divAssignedActiveCheckbox); + $(divAssignedActiveCheckbox).click(); divAssignedInput.value = defAssignee; } - },true); - newButt.setAttribute("type","button"); - divAssigned.appendChild(newButt); - newButt.parentNode.insertBefore(jetpack.tabs.focused.contentDocument.createTextNode("\u00A0"),newButt); + }); + newButt.attr("type","button"); + divAssigned.append(newButt); + newButt.before("\u00A0"); } - var curComponentElement = $("#component",document); - curComponentElement.addEventListener('change', + var curComponentElement = $("#component",this.document); + $(curComponentElement).change( function(event) { - //FIXME We screw up default assignee value for unknown components var assignee = getDefaultAssignee(); if (assignee.length > 0) { - clickMouse($("#bz_assignee_edit_action",document)); - $("#assigned_to",document).value = assignee; - $("#set_default_assignee",document).checked = false; + $("#bz_assignee_edit_action",this.document).click(); + $("#assigned_to",this.document).val(assignee); + $("#set_default_assignee",this.document).get(0).checked = false; } - },false); -} - -// ****************** STATIC DATA ************************* -var XMLRPCurl = "https://bugzilla.redhat.com/xmlrpc.cgi"; -var myStorage = jetpack.storage.simple; -// CONFIGURE: The easiest method how to set up the configuration -// value is to uncomment the following line with proper URL as -// the second parameter. Then reload the bug page and comment out -// again. -//GM_setValue("JSONURL","URL-somewhere-with-your-JSON"); -var jsonDataURL = ""; -myStorage.JSONURL = "http://barstool.build.redhat.com/~mcepl/RH_Data.json"; -if (myStorage.JSONURL) { - jsonDataURL = myStorage.JSONURL -} -if (!jsonDataURL) { - jsonDataURL = "http://mcepl.fedorapeople.org/scripts/BugZappers_data.json"; -} -console.log("jsonDataURL = " + jsonDataURL); -var PCIIDsURL = "http://mcepl.fedorapeople.org/scripts/drm_pciids.json"; -//var debug = GM_getValue("debug",false); -var debug = true; -var reqCounter = 0; -var msgStrs = {}; - -var RHColor = "#9E292B"; -var FedoraColor = "#002867"; -var RawhideColor = "#007700"; // or "green" -var RHITColor = "#660066"; -var SalmonPink = "#FFE0B0"; -var CommentRe = RegExp("^\\s*#"); -var BlankLineRe = RegExp("^\\s*$"); -var ChipsetRE = RegExp("^\\(--\\) ([A-Za-z]+)\\([0-9]?\\): Chipset: (.*)$"); -var ATIgetIDRE = RegExp("^.*\\(ChipID = 0x([0-9a-fA-F]+)\\).*$"); -var PCI_ID_Array = Array(); - -// For identification of graphics card -var manuChipStrs = [ - ["ATI Radeon","ATI","1002"], - ["ATI Mobility Radeon","ATI","1002"], - ["Intel Corporation","INTEL","8086"], - ["NVIDIA","NV","10de"] -]; -var backTranslateManufacturerPCIID = [{ - regexp: "ATI Technologies Inc", - addr: "1002" - },{ - regexp: "Intel Corporation", - addr: "8086" - },{ - regexp: "nVidia Corporation", - addr: "10de" -}]; - -// Get card translation table -XMLHttpRequest({ - // anything called inside of this Request cannot have variables set in MAIN - method: 'GET', - url: PCIIDsURL, - onload: function(response) { - PCI_ID_Array = JSON.parse(response.responseText); - } -}); - -// ******************** MAIN ********************* -function main() { - var hashBugzillaName = Array(); - var hashBugzillaWholeURL = Array(); - var defAssigneeList = Array(); - var signatureFedoraString = ""; - // TODO we should have an array SpecialFlags instead of multiple Boolean variables - var queryButtonAvailable = false; - var chipIDsGroupings = Array(); - var AddrArray = Array(); - // Initialize data from remote URL - var XMLHttpRequestDone = false; - var XorgLogAttList = Array(); - var XorgLogAttListIndex = 0; - - // Get JSON configuration data - XMLHttpRequest({ - // anything called inside of this Request cannot have variables set in MAIN - method: 'GET', - url: jsonDataURL, - onload: function(response) { - var data = JSON.parse(response.responseText); - msgStrs = data['strings']; - signatureFedoraString = data['signature']; - hashBugzillaName = data['bugzillalabelNames']; - hashBugzillaWholeURL = data['bugzillaIDURLs']; - AddrArray = data['CCmaintainer']; - defAssigneeList = data['defaultAssignee']; - queryButtonAvailable = data['queryButton']; - chipIDsGroupings = data['chipIDsGroupings']; - buildButtons(data['topRow'],data['bottomRow']); - if (signatureFedoraString.length > 0) { - // (or a form named "changeform") - document.forms[1].addEventListener("submit",addSignature,true); - } - } - }); - - // FOR DEBUGGING ONLY!!! - if (debug) { - //console.log("signatureFedoraString = " + signatureFedoraString); - $("#bz_field_status",document).append("<span inline='font-size:x-small'>"+jsonDataURL+"</span>"); - } - - // *** collect information about the bug - // var bugNo = getBugNo(); - console.log("BBB"); - var bugNo = $("#title > p:first",document).text(); - console.log("BBB"); - console.log(bugNo); - var reporter = $('#bz_show_bug_column_2 > .fn:first',document).text(); - var owner = $.trim($("#bz_assignee_edit_container > .fn:first",document).text()).toLowerCase(); - var CCList = $("select[name*='cc']:first > *[value]",document); - console.log(typeof(CCList)); - var product = getProduct(); - var version = getVersion(); - var issueTracker = getIssueTracker(); - var maintCCAddr = getCCMaintainer(AddrArray); - var component = getComponent(); - - checkPrivateValues(); - - var login = getLogin(); - var password = myStorage.BZpassword; - - //*** set the main environment - setBranding(product,version,issueTracker); - - // fix process.cgi HREFs so that to avoid confusion on IRC - if (document.location.href.search(/process.cgi/) != -1) { - fixAllHrefs(bugNo); - } - - fixAttachments(); - - var originalButton = document.getElementById("commit"); // source button to be copied from - originalButton.setAttribute("accesskey",'s'); - originalButton.setAttribute("value","Submit"); + }); } // https://bugzilla.redhat.com/show_bug.cgi?id=451951 @@ -1412,21 +1351,17 @@ function main() { // https://wiki.mozilla.org/Labs/Jetpack/JEP/10 -- clipboard access // https://wiki.mozilla.org/Labs/Jetpack/JEP/17 -- page mods -var callback = function(document) { +var callback = function(doc) { jetpack.statusBar.append({ onReady: function(widget) { console.log("Boom!"); - main(); + curPage = new bzPage(doc); }, }); }; var options = {}; options.matches = [ "https://bugzilla.redhat.com/show_bug.cgi*", - "https://bugzilla.redhat.com/process_bug.cgi"]; + "https://bugzilla.redhat.com/process_bug.cgi" + ]; jetpack.pageMods.add(callback, options); - - -Chyba: document is not defined -Zdrojový soubor: file:///home/matej/Dokumenty/projekty/triage/jetpack/bugzillaBugTriage.js -Řádek: 1369 |