dojo.provide("dojo._base.xhr"); dojo.require("dojo._base.Deferred"); dojo.require("dojo._base.json"); dojo.require("dojo._base.lang"); dojo.require("dojo._base.query"); dojo.formToObject = function(/*DOMNode||String*/ formNode){ // summary: // dojo.formToObject returns the values encoded in an HTML form as // string properties in an object which it then returns. Disabled form // elements, buttons, and other non-value form elements are skipped. // Multi-select elements are returned as an array of string values. // description: // This form: // //
// // yields this object structure as the result of a call to // formToObject(): // // { // blah: "blah", // multi: [ // "thud", // "thonk" // ] // }; // FIXME: seems that dojo.query needs negation operators!! var ret = {}; var iq = "input[type!=file][type!=submit][type!=image][type!=reset][type!=button], select, textarea"; dojo.query(iq, formNode).filter(function(node){ return (!node.disabled); }).forEach(function(item){ var _in = item.name; var type = (item.type||"").toLowerCase(); if((type == "radio")||(type == "checkbox")){ if(item.checked){ ret[_in] = item.value; } }else if(item.multiple){ var ria = ret[_in] = []; dojo.query("option[selected]", item).forEach(function(opt){ ria.push(opt.value); }); }else{ ret[_in] = item.value; if(type == "image"){ ret[_in+".x"] = ret[_in+".y"] = ret[_in].x = ret[_in].y = 0; } } }); return ret; } dojo.objectToQuery = function(/*Object*/ map){ // summary: // takes a key/value mapping object and returns a string representing // a URL-encoded version of that object. // examples: // this object: // // { // blah: "blah", // multi: [ // "thud", // "thonk" // ] // }; // // yeilds the following query string: // // "blah=blah&multi=thud&multi=thonk" // FIXME: need to implement encodeAscii!! var ec = encodeURIComponent; var ret = ""; var backstop = {}; for(var x in map){ if(map[x] != backstop[x]){ if(dojo.isArray(map[x])){ for(var y=0; y