diff options
author | Matěj Cepl <mcepl@redhat.com> | 2010-01-13 00:21:24 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@redhat.com> | 2010-01-13 00:21:24 +0100 |
commit | fe3cb4306264db132978a24209367fe5ee14c85b (patch) | |
tree | 6cc4a953c1d91942218b5d1327d63cea0ebdd6ad | |
parent | e342e69af1f20e765f4fe8078a2ff3f7ecb216e2 (diff) | |
download | bugzilla-triage-fe3cb4306264db132978a24209367fe5ee14c85b.tar.gz |
Theoretically complete implementation of the offline functionatliy.
-rw-r--r-- | bugzillaBugTriage.js | 75 |
1 files changed, 42 insertions, 33 deletions
diff --git a/bugzillaBugTriage.js b/bugzillaBugTriage.js index 8abb419..be17161 100644 --- a/bugzillaBugTriage.js +++ b/bugzillaBugTriage.js @@ -497,14 +497,21 @@ BzPage.prototype.getOptionValue = function (id) { */ BzPage.prototype.serializeForm = function (form) { var serialForm = { - elements: [], + dataOut: "", name: form.name, method: form.method, acceptCharset: form.acceptCharset, action: form.action, // TODO shouldn't we get a non-relative URL? enctype: form.enctype, - autocomplete: form.getAttribute("autocomplete") + autocomplete: form.getAttribute("autocomplete"), + bugNo: this.bugNo; }; + + function genURIElement(sName,sValue) { + return encodeURIComponent(sName)+"="+ + encodeURIComponent(sValue); + } + /** * @param o control to be serialized * @return String with the serialized control @@ -514,39 +521,30 @@ BzPage.prototype.serializeForm = function (form) { console.log("serializeControl val = " + val); console.log("typeof val = " + typeof val); console.log("val.toSource() = " + val.toSource()); + /* FIXME what is element with type="select-one" ??? */ if (val == null) { return null; } else if (val instanceof Array) { return val.map(function (x) { - return {name: element.name, value: x.value}; - }); + return genURIElement(element.name,x.value); + }).join("&"); } else if (val instanceof String) { - return {name: element.name, value: val}; + return genURIElement(element.name,val); } else { // assume HTMLCollection return Array.map(val,function (x) { - return {name: element.name, value: x.value}; - }); + return genURIElement(element.name,x.value); + }).join("&"); + } else { + throw "Unknown element found during serialization " + + element.outerHTML; } - } - - /** - * - */ - function arr2str(arr) { - var outStr = ""; - arr.forEach(function (el) { - if (el instanceof Array) { - // - } - }); - } - - serialForm = Array.filter(form.elements,function (el) { + + serialForm.dataOut = Array.filter(form.elements,function (el) { return !el.disabled && el.name && (el.checked || /select|textarea/i.test(el.nodeName) || /text|hidden|password|search/i.test(el.type)); - }).map(serializeControl); + }).map(serializeControl).join("&"); return serialForm; }; @@ -555,14 +553,14 @@ BzPage.prototype.submitCallback = function(evt) { options.oldSubmit(); } else { var serForm = this.serializeForm(this.dok.forms.namedItem("changeform")); - myStorage.forms[this.bugNo] = serForm; // FIXME + myStorage.forms[this.bugNo] = serForm; } }; /** - * * - * Yes, this is corrent, this is NOT method of bzPage! + * + * Yes, this is correct, this is NOT method of bzPage! */ function onlineCallback() { function deserializeAndSend(formData) { @@ -579,18 +577,29 @@ function onlineCallback() { // /Global_Functions/encodeURI & co. // this seems to be also interesting // https://developer.mozilla.org/en/Code_snippets/Post_data_to_window + console.error("Sending bugs not implemented yet!"); + return ""; // FIXME check other HTTP headers to be set + + var bugID = formData.bugNo; var req = new XMLHTTPRequest(); - req.open("POST",formData.action); - // where to get the real form ... should we just download the page with another - // XMLHTTPRequest ... but we just need to emulate, what would happen if... - return success; + req.open("POST",formData.action,true); + req.onreadystatechange = function (aEvt) { + if (req.readyState == 4) { + if (req.status == 200) { + console.log("Sent form for bug " + bugID); + del myStorage.forms[bugID]; + } else { + console.error("Sending form for bug " + bugID + + "failed!"); + } + } + }; + req.send(formData.data); } if (myStorage.forms.length > 0) { myStorage.forms.forEach(function (x) { - if (deserializeAndSend(x)) { - //del x; // can I do it? - } + deserializeAndSend(x); }); } } |