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
ga.tracker-code=GA Tracker Code
boolean.true=Yes
boolean.false=No
boolean.null=Unknown
......@@ -19,9 +19,9 @@
<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>
</c:when>
<%-- <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>
</c:when> --%>
<c:when test="${filter.type=='BOOLEAN'}">
<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: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>
</c:otherwise>
......@@ -84,43 +84,66 @@ jQuery(document).ready(function() {
addFilterValue: function(element) {
var name=$(element).closest(".clearfix").attr("x-filtername");
//debugger;
var inputs=$(element).parent().children("input");
var a=null, b=null;
var inputs=$(element).parent().children("input");
var selects=$(element).parent().children("select");
var r=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;
a=inputs[0].value.trim();
if (a!='') r=a;
} else if (inputs.length==2) {
a=inputs[0].value.trim();
b=inputs[1].value.trim();
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;
}
} else if (selects.length==1) {
a=selects[0].value;
r = (a == 'true' ? true : a=='null' ? 'null' : false);
}
console.log(r);
if (r!=null) {
r = (r=='null' ? null : r);
if (filters[name]==null) {
filters[name]=[r];
} else {
filters[name][filters[name].length]=r;
}
inputs[0].value='';
inputs[0].focus();
if (inputs[0]) { inputs[0].value=''; inputs[0].focus(); }
if (inputs[1]) inputs[1].value='';
}
console.log(filters);
filters=FF.cleanup(filters);
console.log(filters);
FF.refreshJson(filters);
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;
}
};
......
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