aboutsummaryrefslogtreecommitdiffstats
path: root/bugzillaBugTriage.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2009-11-16 01:32:51 +0100
committerMatěj Cepl <mcepl@redhat.com>2009-11-16 01:32:51 +0100
commit4ac78835a325a733a46e20ccd00559381cbca953 (patch)
treebc6a304cfd175a8d7c6ef8e8d8f017017eb04221 /bugzillaBugTriage.js
parent39ab570c1841d4826b695315c3d7978fde6eb7a5 (diff)
downloadbugzilla-triage-4ac78835a325a733a46e20ccd00559381cbca953.tar.gz
XML-RPC should work but it doesn't :( plus couple of small fixes.
* new method for generating XML-RPC message * use $.post to post it to the server * get correctly login and password * get correctly ITS number (.attr("value") NOT .text() !!!)
Diffstat (limited to 'bugzillaBugTriage.js')
-rw-r--r--bugzillaBugTriage.js152
1 files changed, 114 insertions, 38 deletions
diff --git a/bugzillaBugTriage.js b/bugzillaBugTriage.js
index a285081..f54c6a5 100644
--- a/bugzillaBugTriage.js
+++ b/bugzillaBugTriage.js
@@ -716,24 +716,27 @@ bzPage.prototype.sendRequest = function(url,data,method,callback) {
* + responseHeaders
* + responseText
*/
-bzPage.prototype.callBack = function(ret) {
- if (ret.status != 200) {
- alert([ret.status,ret.statusText,ret.responseHeaders,
- ret.responseText]);
- }
+bzPage.prototype.callBack = function(data,textStatus) {
+// if (ret.status != 200) {
+// alert([ret.status,ret.statusText,ret.responseHeaders,
+// ret.responseText]);
+// }
if (--this.reqCounter <= 0) {
setTimeout(document.location.reload,1000);
}
}
/**
- * The worker function -- call XMLRPC to fix MIME type of the
- * particular attachment
+ * Create XML-RPC message for updateAttachMimeType procedure with given parameters.
+ * Yes, I know this is very ugly, but in the current state of jetpack it is not possible
+ * to import external jQuery modules, so I cannot use jquery.rpc as much as I would like to.
*
- * @param id integer with the attachment id to be fixed
- * @param type string with the new MIME type, e.g. "text/plain"
- *
-
+ * @param login string with login
+ * @param password string with password
+ * @param attachID Number with the attachment ID#
+ * @param mimeType string with MIME type, optional and defaults to text/plain
+ * @return string with the XML-RPC message
+
updateAttachMimeType($data_ref, $username, $password)
Update the attachment mime type of an attachment. The first argument is a data hash containing information on the new MIME type and the attachment id that you want to act on.
@@ -747,19 +750,66 @@ Update the attachment mime type of an attachment. The first argument is a data h
# OPTIONAL Flag that is either 1 or 0 if you want email to be sent or not for this change
};
*/
+bzPage.prototype.createXMLRPCMessage = function(login,password,attachId,mimeType,email) {
+ if (mimeType === null) {
+ mimeType = "text/plain";
+ }
+ if (email === null) {
+ email = false;
+ };
+ var emailStr = email ? "0" : "1";
+
+ var msg = <methodCall>
+ <methodName>bugzilla.updateAttachMimeType</methodName>
+ <params>
+ <param>
+ <value><struct>
+ <member>
+ <name>attach_id</name>
+ <value><i4>{attachId}</i4></value>
+ </member>
+ <member>
+ <name>mimeType</name>
+ <value><string>{mimeType}</string></value>
+ </member>
+ <member>
+ <name>nomail</name>
+ <value><string>{emailStr}</string></value>
+ </member>
+ </struct></value>
+ </param>
+ <param>
+ <value><string>{login}</string></value>
+ </param>
+ <param>
+ <value><string>{password}</string></value>
+ </param>
+ </params>
+ </methodCall>;
+ console.log("XMLRPC message:\n" + msg.toXMLString());
+ return msg.toXMLString();
+}
+
+/**
+ * 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"
+ */
bzPage.prototype.fixAttachById = function(id,type) {
var ret = {};
- var msg = new XMLRPCMessage("bugzilla.updateAttachMimeType");
- msg.addParameter({'attach_id':id, 'mime_type':type});
- msg.addParameter(login);
- msg.addParameter(password);
- try {
- ret = sendRequest(XMLRPCurl,
- msg.xml(),'post',callBack);
- }
- catch (e) {
- alert([e,ret]);
- }
+ var msg = this.createXMLRPCMessage(this.login,this.password,id,type);
+// try {
+ ret = $.post(XMLRPCurl,
+ msg,this.callBack);
+// // The following is most likely nonsense, because jQuery.post doesn't return
+// // with failure. Commenting out for now.
+// }
+// catch (e) {
+// console.log("XMLRPC failed: error = " + e + ", return = " + ret);
+// throw(e);
+// }
this.reqCounter++;
}
@@ -768,22 +818,33 @@ bzPage.prototype.fixAllAttachments = function(list) {
for(var i=0;i<list.length;i++) {
tmpElem = list[i];
- fixAttachById(tmpElem[1],"text/plain");
+ this.fixAttachById(tmpElem[1]);
}
}
+/**
+ * Create a button for fixing all bad attachments.
+ *
+ * @param list Array of all bad attachmentss
+ * @return button fixing all bad Attachments
+ */
bzPage.prototype.createFixAllButton = function (list) {
- var aElem = $("<a href=''></a>", this.doc).click(function() {
- this.fixAllAttachments(list);
+ var that = this;
+ var elem = this.doc.get(0).createElement("a");
+ var jQelem = $(elem).attr({
+ href:"",
+ accesskey:"f"
+ }).append("<b>F</b>ix all").click(function() {
+ that.fixAllAttachments(list);
});
- this.fixElement(aElem,"","F","ix all");
- return aElem;
-}
-
-bzPage.prototype.getTextAllLink = function (table,list) {
- var vAllElem = $("a[href*='action=enter']", $(table)).get();
+ return jQelem.get(0);
}
+/**
+ *
+ *
+ * CURRENTLY BROKEN
+ */
bzPage.prototype.addTextLink = function (row) {
var aList = row[row.length-1].getElementsByTagName("a");
var curElem = aList[aList.length-1];
@@ -791,13 +852,17 @@ bzPage.prototype.addTextLink = function (row) {
var t2Elem = {};
var that = this;
- var tElem = $(" <a href=''>Text</a>",this.doc).click(function (event) {
+ var tElem = this.doc.get(0).createElement("a");
+ var jElem = $(tElem).attr("href","").click(function (event) {
that.fixAttachById(row[1],"text/plain");
});
$("a",row).after(tElem).after("<br/>");
}
+/**
+ *
+ */
bzPage.prototype.isOctetStream = function (element, index, array) {
return(inArray.indexOf(element[2]) != -1);
}
@@ -971,8 +1036,19 @@ bzPage.prototype.buildButtons = function (above,below) {
///////////////////////////////////////////////////////////////////////////////
function bzPage(doc) {
this.doc = $(doc);
- that = this;
+ var that = this;
this.originalButton = $("#commit", this.doc);
+ var loginArr = $("#header ul:first li:last", this.doc).text().split("\n");
+ this.login = $.trim(loginArr[loginArr.length-1]);
+ console.log("login = " + this.login);
+ this.password = "";
+ if (myConfig.BZpassword) {
+ this.password = myConfig.BZpassword;
+ } else {
+ this.password = this.doc.get(0).defaultView.prompt("Enter your Bugzilla password","");
+ myConfig.BZpassword = this.password;
+ }
+
var bugNoTitle = $.trim($("#title > p:first", this.doc).text());
this.bugNo = new RegExp("[0-9]+").exec(bugNoTitle)[0];
@@ -981,7 +1057,8 @@ function bzPage(doc) {
this.product = $("#product option:selected:first", this.doc).text();
this.component = $("#component option:selected:first", this.doc).text();
this.version = $("#version option:selected:first", this.doc).text();
- this.its = $.trim($("#cf_issuetracker", this.doc).text());
+ this.its = $.trim($("#cf_issuetracker", this.doc).attr("value"));
+ console.log("its = " + this.its);
this.CCList = $.makeArray($("#cc", this.doc).attr("value"));
this.owner = $("#bz_assignee_edit_container .fn:first", this.doc).text();
this.defaultAssignee = filterByRegexp(defAssigneeList, this.component).toLowerCase();
@@ -1002,10 +1079,10 @@ function bzPage(doc) {
if (badAttachments.length > 0) {
console.log("we have " + badAttachments.length + " bad attachments.");
- var titleElement = $(".bz_alias_short_desc_container:first").css("background-color",
- "olive").append($(this.createFixAllButton(badAttachments)));
+ var titleElement = $(".bz_alias_short_desc_container:first",this.doc).
+ css("background-color","olive").append($(this.createFixAllButton(badAttachments)));
badAttachments.forEach(function (x) {
- this.addTextLink(x);
+ that.addTextLink(x);
});
}
@@ -1025,7 +1102,6 @@ function bzPage(doc) {
this.checkComments();
this.buildButtons(topRow,bottomRow);
- var that = this;
$("#component",this.doc).change(function (){
that.changeOwner(that.maintCCAddr);
});