From 6238c95aa80a6f1a109a64a0ada093976d1e834e Mon Sep 17 00:00:00 2001 From: Sathyanarayanan Gunasekaran Date: Fri, 31 Aug 2012 10:45:24 +0530 Subject: [PATCH] Set options based on request args --- static/js/custom.js | 54 ++++++++++++++++++++++++++++++++++++++-------------- templates/index.html | 37 +++++++++++++---------------------- 2 files changed, 53 insertions(+), 38 deletions(-) diff --git a/static/js/custom.js b/static/js/custom.js index 6ede41b..6ef85be 100644 --- a/static/js/custom.js +++ b/static/js/custom.js @@ -10,24 +10,10 @@ function addListener(){ }); } -function parseArgs(query){ - var newQuery = {}, key, value; - query = String(query); - query = query.split("?")[1]; - query = query.split("&"); - $.each(query, function(i, arg){ - arg = arg.split("="); - if (arg[0] != "sort") { - newQuery[arg[0]] = arg[1]; - } - }); - return newQuery; -} function doAjax(){ var path = window.location.search; if(path) { - console.log("Sending request"); $.ajax({ url: "result"+path, type: "GET", @@ -39,3 +25,43 @@ function doAjax(){ }); } } + +function filterArgs() { + var myForm = document.getElementById('form'); + var allInputs = myForm.getElementsByTagName('input'); + var input, i; + for(i = 0; input = allInputs[i]; i++) { + if(input.getAttribute('name') && !input.value) { + input.setAttribute('name', ''); + } + } +} + +function parseArgs(query){ + var newQuery = {}, key, value; + query = String(query); + query = query.split("?")[1]; + query = query.split("&"); + $.each(query, function(i, arg){ + arg = arg.split("="); + newQuery[arg[0]] = arg[1]; + }); + return newQuery; +} + +function setOptions(){ + var path = window.location.search; + if (path) { + var args = parseArgs(path); + $.each(args, function (arg, value) { + type = ($('input.'+arg).attr("type") || $('input#'+arg).attr("type")); + if (type == "checkbox" || type == "radio") { + $('input.'+arg).val([value]); + $('input#'+arg).val([value]); + } else if( type == "text") { + $('input.'+arg).val(value); + $('input#'+arg).val(value); + } + }); + } +} diff --git a/templates/index.html b/templates/index.html index bdb4421..85fd634 100644 --- a/templates/index.html +++ b/templates/index.html @@ -63,14 +63,14 @@
- +
@@ -81,13 +81,13 @@
- select only relays from AS number
- select only relays from country with code
@@ -95,20 +95,20 @@
@@ -117,12 +117,12 @@
- + group relays by AS
@@ -165,20 +165,9 @@ -- 2.11.4.GIT