Commit b81ae4bd authored by Matija Obreza's avatar Matija Obreza
Browse files

Automatically add current value of filters when "Apply" is clicked

parent 0f5278be
......@@ -365,6 +365,10 @@ var GenesysFilter = {
var inputId = '#' + normKey + '_input';
var value = $(element).parent().find(inputId).val();
if (value === '') {
return;
}
if (!GenesysFilterUtil.existInJson(value, key, jsonData)) {
GenesysFilterUtil.appendHtml(key, value, value, element);
jsonData[key] = GenesysFilterUtil.collectData(key, value, jsonData);
......@@ -400,6 +404,10 @@ var GenesysFilter = {
if (!isNaN(inputValue1) && !isNaN(inputValue2)) {
if (inputValue1 === inputValue2) {
if (inputValue1 === '') {
// Ignore blank
return;
}
jsonValue.push(parseFloat(inputValue1));
value = inputValue1;
} else if (inputValue1 !== '' && inputValue2 === '') {
......@@ -482,16 +490,16 @@ var GenesysFilter = {
// add filter with options for crop
filterCrop : function(element, jsonData) {
var selectBox = document.getElementById('cropselector');
var value = selectBox.options[selectBox.selectedIndex].value;
if (value === 'null') {
var value = element.val();
if (value === 'null' || value === '') {
value = null;
}
var key = $(element).attr('i-key');
delete jsonData[key];
$(selectBox).parent().parent().parent().parent().find('.complex').remove();
// Clear previous crop selection
element.parent().parent().parent().parent().find('.complex').remove();
if (value !== '') {
if (value !== null) {
GenesysFilterUtil.appendHtml(key, value, value, element);
jsonData[key] = GenesysFilterUtil.collectData(key, value, jsonData);
$('#menu2').show();
......@@ -506,6 +514,10 @@ var GenesysFilter = {
var inputId = '#' + normKey + '_input';
var value = $(element).parent().find(inputId).val();
if (value === '') {
return;
}
var likeArray = {};
likeArray.like = value;
......
......@@ -52,7 +52,7 @@
</div>
<%--Filters--%>
<div id="toggleFilters" class="applied-filters">
<div id="toggleFilters" class="applied-filters ${pagedData.number eq 0 ? 'hide' : ''}">
<ul class="nav nav-pills">
<li class="active filter-toggler"><a><spring:message code="filters.toggle-filters" /></a></li>
<li class="message">
......@@ -61,7 +61,7 @@
</li>
</ul>
</div>
<div id="allfilters" class="applied-filters hide">
<div id="allfilters" class="applied-filters ${pagedData.number gt 0 ? 'hide' : ''}">
<ul class="nav nav-pills">
<li class="filter-toggler"><a><spring:message code="filters.toggle-filters" /></a></li>
<li class="active dropdown form-horizontal" id="menu1">
......@@ -296,14 +296,6 @@
$("#menu2").show();
}
if (page == 0) {
$("#allfilters").removeClass("hide");
$("#toggleFilters").addClass("hide");
} else {
$("#allfilters").addClass("hide");
$("#toggleFilters").removeClass("hide");
}
$(".filter-toggler").on("click", function (ev) {
ev.preventDefault();
$("#allfilters").toggleClass("hide");
......@@ -378,7 +370,7 @@
GenesysFilter.filterBoolean($(this), jsonData);
});
$("body").on("click", ".filter-crop", function () {
$('body').on('keyup keypress click blur change', '.filter-crop', function () {
GenesysFilter.filterCrop($(this), jsonData);
});
......@@ -390,7 +382,10 @@
});
$("body").on("click", ".apply", function () {
GenesysFilterUtil.submitJson('<c:url value="/explore" />', jsonData);
// Trigger the 'add-filter' event
$('button.filter-range, button.filter-auto').click();
// Upload
GenesysFilterUtil.submitJson('<c:url value="/explore" />', jsonData);
});
$("body").on("click", ".remove-filter", function () {
......
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