Skip to content

Commit

Permalink
Use named attributes to store page elements instead of array indexes …
Browse files Browse the repository at this point in the history
…so things can be added/removed more easily.
  • Loading branch information
Patrick Leamon committed Jan 17, 2011
1 parent a2df901 commit 4539482
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions content/restclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,21 +504,26 @@ var restclient = {
fp.init(window, "Save As", nsIFilePicker.modeSave);
fp.appendFilters(nsIFilePicker.filterText);


var outputObject = new Object();
outputObject["requestUrl"] = requestUrl;
outputObject["requestMethod"] = requestMethod;
outputObject["requestBody"] = requestBody;

var index = 0;
var outputArray = new Array();
outputArray[index++] = requestUrl;
outputArray[index++] = requestMethod;
outputArray[index++] = requestBody;
var headerArray = new Array();

// Now save headers in pairs
// Now store headers in pairs
for (var i = reqHeaderChilds.childNodes.length-1; i>=0; i--) {
var headerKey = reqHeaderChilds.childNodes[i].childNodes[0].childNodes[0].getAttribute('label')
var headerValue = reqHeaderChilds.childNodes[i].childNodes[0].childNodes[1].getAttribute('label')
outputArray[index++] = headerKey;
outputArray[index++] = headerValue;
headerArray[index++] = headerKey;
headerArray[index++] = headerValue;
}

var output = JSON.stringify(outputArray);
outputObject["headers"] = headerArray;

var output = JSON.stringify(outputObject);

var res = fp.show();
if (res == nsIFilePicker.returnOK) {
Expand Down Expand Up @@ -597,16 +602,16 @@ var restclient = {

sstream.close();
fstream.close();
var tokens = JSON.parse(data);
var dataObject = JSON.parse(data);

setRequestUrl(tokens[0]);
setRequestMethod(tokens[1]);
setRequestBody(tokens[2])
setRequestUrl(dataObject["requestUrl"]);
setRequestMethod(dataObject["requestMethod"]);
setRequestBody(dataObject["requestBody"]);

var headerPairs = (tokens.length - 3) / 2;
for (index = 0; index < headerPairs; index++) {
var tokenIndex = (index * 2) + 3;
this.addHttpRequestHeader(tokens[tokenIndex], tokens[tokenIndex + 1]);
var headerPairs = dataObject["headers"];
var index = 0;
while (index < headerPairs.length) {
this.addHttpRequestHeader(headerPairs[index++], headerPairs[index++]);
}
}
this.requestBodyChange();
Expand Down

0 comments on commit 4539482

Please sign in to comment.