From f7b895b19f0e97010b5be089e92a811cd052da62 Mon Sep 17 00:00:00 2001 From: Matěj Cepl Date: Wed, 13 Jan 2010 00:22:47 +0100 Subject: Use external library instead of the űber ugly createXMLRPCMessage. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It actually is possible to load external libraries to jetpack, but it is very very ugly hack. Based on http://groups.google.com/group/mozilla-labs-jetpack/msg/b4ff8f22f179771b and example by Aza Raskin at http://www.azarask.in/blog/post/jetpack_image_editor/ (listen to the demo). --- bugzillaBugTriage.js | 90 +++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 53 deletions(-) (limited to 'bugzillaBugTriage.js') diff --git a/bugzillaBugTriage.js b/bugzillaBugTriage.js index eb1668b..ec6efd9 100644 --- a/bugzillaBugTriage.js +++ b/bugzillaBugTriage.js @@ -147,6 +147,25 @@ loadJSON(PCIIDsURL, PCI_ID_Array = response; }); +//======== load external library =============================== + +var XMLRPCMessage = {}; +var req = new XMLHttpRequest(); +req.open("GET","http://mcepl.fedorapeople.org/scripts/xmlrpc.js",true); +req.onreadystatechange = function (aEvt) { + if (req.readyState == 4) { + if (req.status == 200) { + var thisDoc = jetpack.tabs.focused.contentDocument; + var script = thisDoc.createElement("script"); + script.setAttribute("type","text/javascript"); + script.innerHTML = req.responseText; + thisDoc.getElementsByTagName("head")[0].appendChild(script); + XMLRPCMessage = jetpack.tabs.focused.contentWindow.wrappedJSObject.XMLRPCMessage; + } + } +}; +req.send(""); + //============================================================== /** @@ -1243,16 +1262,13 @@ BzPage.prototype.callBack = function(data,textStatus) { }; /** - * 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. + * The worker function -- call XMLRPC to fix MIME type of the + * particular attachment * - * @param login string with login - * @param password string with password - * @param attachID Number with the attachment ID# - * @param mimeType stri ng with MIME type, optional and defaults to text/plain - * @param email Boolean whether we should send email or not - * @return string with the XML-RPC message + * @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) @@ -1266,56 +1282,24 @@ Update the attachment mime type of an attachment. The first argument is a data h "nomail" => 0, # 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 === undefined) { - mimeType = "text/plain"; +BzPage.prototype.fixAttachById = function(id,type,email) { + if (type === undefined) { + type = "text/plain"; } if (email === undefined) { email = false; } - var emailStr = email ? "0" : "1"; - - var msg = - bugzilla.updateAttachMimeType - - - - - attach_id - {attachId} - - - mime_type - {mimeType} - - - nomail - {emailStr} - - - - - {login} - - - {password} - - - ; - 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 msg = this.createXMLRPCMessage(this.login,this.password,id,type); + var msg = new XMLRPCMessage("bugzilla.updateAttachMimeType"); + msg.addParameter({'attach_id':id, 'mime_type':type, 'nomail':!email}); + msg.addParameter(this.login); + msg.addParameter(this.password); + console.log("testing XMLRPCMessage:\n" + msg.xml()); + var req = new XMLHttpRequest(); + var that = this; req.open("POST",XMLRPCurl,true); req.overrideMimeType("text/xml"); req.setRequestHeader("Content-type","text/xml"); @@ -1329,7 +1313,7 @@ BzPage.prototype.fixAttachById = function(id,type) { } } }; - req.send(msg); + req.send(msg.xml()); this.reqCounter++; }; -- cgit