aboutsummaryrefslogtreecommitdiffstats
path: root/data/lib/fixingAttMIME.js
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@redhat.com>2011-03-25 16:23:51 +0100
committerMatěj Cepl <mcepl@redhat.com>2011-03-25 17:55:56 +0100
commit0ace4d34ece35b717b64ee1d3312cdc3c07696b5 (patch)
tree0e9cfe3000295c14d08a09c617b8aa8b89285cc4 /data/lib/fixingAttMIME.js
parenta9e66d84f83d3f21fffd4cd9872ac8934e455edf (diff)
downloadbugzilla-triage-0ace4d34ece35b717b64ee1d3312cdc3c07696b5.tar.gz
Cut out general bugzilla functions to a special module.
Diffstat (limited to 'data/lib/fixingAttMIME.js')
-rw-r--r--data/lib/fixingAttMIME.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/data/lib/fixingAttMIME.js b/data/lib/fixingAttMIME.js
new file mode 100644
index 0000000..9297c06
--- /dev/null
+++ b/data/lib/fixingAttMIME.js
@@ -0,0 +1,87 @@
+// Released under the MIT/X11 license
+// http://www.opensource.org/licenses/mit-license.php
+
+var reqCounter = 0; // TODO should be probably a dict indexed by called method
+
+/**
+ * Callback function for the XMLRPC request
+ *
+ * @param ret Object with xmlhttprequest response with attributes:
+ * + status -- int return code
+ * + statusText
+ * + responseHeaders
+ * + responseText
+ */
+function XMLRPCcallback() {
+ reqCounter--;
+ if (reqCounter <= 0) {
+ setTimeout(function () {
+ window.location.reload(true);
+ }, 1000);
+ }
+}
+
+/**
+ * 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;
+ * option, defaults to false
+ *
+ * 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.
+ *
+ * $data_ref = { "attach_id" => "<Attachment ID>", # Attachment ID to perform
+ * MIME type change on. "mime_type" => "<New MIME Type Value>", # Legal MIME
+ * type value that you want to change the attachment to. "nomail" => 0, #
+ * OPTIONAL Flag that is either 1 or 0 if you want email to be sent or not for
+ * this change };
+ *
+ */
+function fixAttachById(id, type, email, XMLRPCURL) {
+ var params = [];
+
+ if (type === undefined) {
+ type = "text/plain";
+ }
+ if (email === undefined) {
+ email = false;
+ }
+
+ // https://bugzilla.redhat.com/\
+ // docs/en/html/api/extensions/compat_xmlrpc/code/webservice.html
+ // test on https://bugzilla.redhat.com/show_bug.cgi?id=485145
+ params.push({
+ 'attach_id' : id,
+ 'mime_type' : type,
+ 'nomail' : !email
+ });
+
+ postMessage(new Message("MakeXMLRPCall", {
+ url: XMLRPCURL,
+ login: getLogin(),
+ method: "bugzilla.updateAttachMimeType",
+ params: params,
+ callRPC: "FixAttachmentMIMECallback"
+ }));
+ reqCounter++;
+}
+
+/**
+ * Add a link to the bad attachment for fixing it.
+ *
+ * @param
+ * <TR> DOM jQuery element with a bad attachment
+ * @return none
+ */
+function addTextLink(row, xmlRpcUrl) {
+ var elemS = row[4].getElementsByTagName("td");
+ var elem = elemS[elemS.length - 1];
+ createDeadLink("addFix2TextLink", "text", elem,
+ fixAttachById, [row[1], xmlRpcUrl], "br");
+}