Commit 214dd3d2 authored by Matija Obreza's avatar Matija Obreza
Browse files

Yes/No/Unknown filter

parent 6ddc8825
...@@ -416,3 +416,7 @@ acl.permission.16=Manage ...@@ -416,3 +416,7 @@ acl.permission.16=Manage
ga.tracker-code=GA Tracker Code ga.tracker-code=GA Tracker Code
boolean.true=Yes
boolean.false=No
boolean.null=Unknown
...@@ -19,9 +19,9 @@ ...@@ -19,9 +19,9 @@
<c:when test="${filter.type=='NUMERIC'}"> <c:when test="${filter.type=='NUMERIC'}">
<div class="filter-new form-group pull-left input-group"><span class="input-group-btn"><input class="span1 form-control" type="text" /><input class="span1 form-control" type="text" /><button class="btn notimportant">+</button></span></div> <div class="filter-new form-group pull-left input-group"><span class="input-group-btn"><input class="span1 form-control" type="text" /><input class="span1 form-control" type="text" /><button class="btn notimportant">+</button></span></div>
</c:when> </c:when>
<%-- <c:when test="${filter.type=='BOOLEAN'}"> <c:when test="${filter.type=='BOOLEAN'}">
<div class="filter-new pull-left"><input type="checkbox" id="check.${filter.name}" /> <label for="check.${filter.name}">Yes</label> <button class="notimportant">+</button></div> <div class="filter-new pull-left"><select><option value="true"><spring:message code="boolean.true" /></option><option value="false"><spring:message code="boolean.false" /></option><option value="null"><spring:message code="boolean.null" /></option></select><button class="notimportant">+</button></div>
</c:when> --%> </c:when>
<c:otherwise> <c:otherwise>
<div class="filter-new form-group pull-left input-group"><span class="input-group-btn"><input class="span2 form-control" type="text" /><button class="btn notimportant">+</button></span></div> <div class="filter-new form-group pull-left input-group"><span class="input-group-btn"><input class="span2 form-control" type="text" /><button class="btn notimportant">+</button></span></div>
</c:otherwise> </c:otherwise>
...@@ -84,43 +84,66 @@ jQuery(document).ready(function() { ...@@ -84,43 +84,66 @@ jQuery(document).ready(function() {
addFilterValue: function(element) { addFilterValue: function(element) {
var name=$(element).closest(".clearfix").attr("x-filtername"); var name=$(element).closest(".clearfix").attr("x-filtername");
//debugger; //debugger;
var inputs=$(element).parent().children("input");
var a=null, b=null; var a=null, b=null;
var inputs=$(element).parent().children("input");
var selects=$(element).parent().children("select");
var r=null;
if (inputs.length==1) { if (inputs.length==1) {
// add 1 // add 1
a=b=inputs[0].value.trim(); a=inputs[0].value.trim();
} else { if (a!='') r=a;
var a=inputs[0].value.trim(); } else if (inputs.length==2) {
var b=inputs[1].value.trim(); a=inputs[0].value.trim();
} b=inputs[1].value.trim();
var r=null;
if (a=='' && b=='') { if (a=='' && b=='') {
} else if (a==b) { } else if (a==b) {
r=a; r=a;
} else if (b=='') { } else if (b=='') {
r={"min":parseFloat(a)}; r={"min":parseFloat(a)};
if (isNaN(r["min"])) r=null; if (isNaN(r["min"])) r=null;
} else if (a=='') { } else if (a=='') {
r={"max":parseFloat(b)}; r={"max":parseFloat(b)};
if (isNaN(r["max"])) r=null; if (isNaN(r["max"])) r=null;
} else { } else {
r={"range":[parseFloat(a),parseFloat(b)]}; r={"range":[parseFloat(a),parseFloat(b)]};
if (isNaN(r["range"][0]) || isNaN(r["range"][1])) r=null; if (isNaN(r["range"][0]) || isNaN(r["range"][1])) r=null;
}
} else if (selects.length==1) {
a=selects[0].value;
r = (a == 'true' ? true : a=='null' ? 'null' : false);
} }
console.log(r); console.log(r);
if (r!=null) { if (r!=null) {
r = (r=='null' ? null : r);
if (filters[name]==null) { if (filters[name]==null) {
filters[name]=[r]; filters[name]=[r];
} else { } else {
filters[name][filters[name].length]=r; filters[name][filters[name].length]=r;
} }
inputs[0].value=''; if (inputs[0]) { inputs[0].value=''; inputs[0].focus(); }
inputs[0].focus();
if (inputs[1]) inputs[1].value=''; if (inputs[1]) inputs[1].value='';
} }
console.log(filters); console.log(filters);
filters=FF.cleanup(filters);
console.log(filters);
FF.refreshJson(filters); FF.refreshJson(filters);
FF.updateValues("#filter-" + name + " .filter-values", name, filters[name]); FF.updateValues("#filter-" + name + " .filter-values", name, filters[name]);
},
cleanup: function(filt) {
var newFilt={};
for (var prop in filt) {
console.log("Yada: " + prop);
var nv=newFilt[prop]=[];
for (var i=0; i<filt[prop].length; i++) {
var pos=nv.indexOf(filt[prop][i]);
if (pos<0) nv[nv.length]=filt[prop][i];
}
}
return newFilt;
} }
}; };
......
Supports Markdown
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