Commit 5badbae1 authored by Matija Obreza's avatar Matija Obreza
Browse files

Allow Enter keypress in filtering

parent dcdb3d1d
......@@ -86,7 +86,7 @@
<div class="pull-right searcher" style="margin-top: 5px;">
<form class="search form-horizontal" method="get" action="<c:url value="/search" />">
<input type="text" name="q" class="" placeholder="Search"/> <button type="submit" class="btn">Search</button>
<input type="text" name="q" class="" placeholder="Search"/> <button type="submit" class="btn notimportant">Search</button>
</form>
</div>
</div>
......
......@@ -18,10 +18,10 @@
<div class="filter-values pull-left"></div>
<c:choose>
<c:when test="${filter.type=='NUMERIC'}">
<div class="filter-new pull-left">Min: <input class="span1" type="text" /> Max: <input class="span1" type="text" /> <button>+</button></div>
<div class="filter-new pull-left">Min: <input class="span1" type="text" /> Max: <input class="span1" type="text" /> <button class="notimportant">+</button></div>
</c:when>
<c:otherwise>
<div class="filter-new pull-left"><input class="span2" type="text" /><button>+</button></div>
<div class="filter-new pull-left"><input class="span2" type="text" /><button class="notimportant">+</button></div>
</c:otherwise>
</c:choose>
</div>
......@@ -73,6 +73,48 @@ jQuery(document).ready(function() {
refreshJson: function(newFilter) {
$("#filtersJson").html(JSON.stringify(newFilter));
$("#filtersHref").attr("href", "/acn/f?filter="+JSON.stringify(newFilter));
},
addFilterValue: function(element) {
var name=$(element).closest(".clearfix").attr("x-filtername");
//debugger;
var inputs=$(element).parent().children("input");
var a=null, b=null;
if (inputs.length==1) {
// add 1
a=b=inputs[0].value.trim();
} else {
var a=inputs[0].value.trim();
var b=inputs[1].value.trim();
}
var r=null;
if (a=='' && b=='') {
} else if (a==b) {
r=a;
} else if (b=='') {
r={"min":parseFloat(a)};
if (isNaN(r["min"])) r=null;
} else if (a=='') {
r={"max":parseFloat(b)};
if (isNaN(r["max"])) r=null;
} else {
r={"range":[parseFloat(a),parseFloat(b)]};
if (isNaN(r["range"][0]) || isNaN(r["range"][1])) r=null;
}
console.log(r);
if (r!=null) {
if (filters[name]==null) {
filters[name]=[r];
} else {
filters[name][filters[name].length]=r;
}
inputs[0].value='';
inputs[0].focus();
if (inputs[1]) inputs[1].value='';
}
console.log(filters);
FF.refreshJson(filters);
FF.updateValues("#filter-" + name + " .filter-values", name, filters[name]);
}
};
......@@ -96,45 +138,14 @@ jQuery(document).ready(function() {
$("body").on("click", ".filter-block .filter-new button", function(event) {
event.preventDefault();
var name=$(this).closest(".clearfix").attr("x-filtername");
//debugger;
var inputs=$(this).parent().children("input");
var a=null, b=null;
if (inputs.length==1) {
// add 1
a=b=inputs[0].value.trim();
} else {
var a=inputs[0].value.trim();
var b=inputs[1].value.trim();
}
var r=null;
if (a=='' && b=='') {
} else if (a==b) {
r=a;
} else if (b=='') {
r={"min":parseFloat(a)};
if (isNaN(r["min"])) r=null;
} else if (a=='') {
r={"max":parseFloat(b)};
if (isNaN(r["max"])) r=null;
} else {
r={"range":[parseFloat(a),parseFloat(b)]};
if (isNaN(r["range"][0]) || isNaN(r["range"][1])) r=null;
}
console.log(r);
if (r!=null) {
if (filters[name]==null) {
filters[name]=[r];
} else {
filters[name][filters[name].length]=r;
}
inputs[0].value='';
inputs[0].focus();
if (inputs[1]) inputs[1].value='';
FF.addFilterValue(this);
});
$("body").on("keydown", ".filter-block .filter-new input", function(event) {
if (event.keyCode==13) {
event.preventDefault();
FF.addFilterValue(this);
}
console.log(filters);
FF.refreshJson(filters);
FF.updateValues("#filter-" + name + " .filter-values", name, filters[name]);
});
FF.refreshJson(filters);
......
......@@ -43,7 +43,7 @@
display: none;
}
td.notimportant, td.idx-col {
.notimportant, td.idx-col {
display: none;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment