Commit 62b3a45d authored by Aleksandr Sharaban's avatar Aleksandr Sharaban
Browse files

Jshint task errors fix.

parent 6d4229c3
'use strict';
function renderCropSuggestions(filters) {
$(".radio-wrapper").remove();
$.each(filters, function (name, value) {
var input = $("<input/>", {
type: 'radio',
name: 'crops',
id: 'crops_' + name,
'i-key': 'crops',
'class': 'filter-crop',
value: name
});
if ($("div.filtval[x-key='crops" + name + "']")[0] !== undefined) {
input.prop('checked', true);
}
var key = Object.keys(this)[0];
var label = $("<label/>", {
'for': 'crops_' + name,
text: key + " (" + value[key] + ")"
});
var filtval = $("div.filtval[i-key^='crops']");
var attach = filtval[0] !== undefined ? filtval[0] : (".crops button.applyBtn");
var wrapper = $("<div/>", {'class': "radio-wrapper"});
wrapper.append(input);
wrapper.append(label);
$(attach).before(wrapper);
});
}
function renderListFilterSuggestions(filters, messages) {
$.each(filters, function (option) {
$("div." + option).find("div[class!='panel-body'][class!='filtval complex']").remove();
if (filters[option].options[0] === undefined) {
$("div." + option).find("button.applyBtn").before("<div>No suggestions</div>");
} else {
$.each(filters[option].options, function (index) {
var div = '<div class="checkbox-wrapper">' +
'<label>' +
'<input class="filter-list"' +
'id="' + option + this.value + '_input"' +
($("div.filtval[x-key='" + option + this.value + "']")[0] !== undefined ? 'checked ' : '') +
'norm-key="' + option + '"' +
'i-key="' + option + '" type="checkbox"' +
'value="' + this.value + '"/>' +
messages[this.name] +
' (' + filters[option].counts[index] + ')' +
'</label>' +
'</div>';
var filtval = $("div.filtval[x-key^='" + option + "']");
var attach = filtval[0] !== undefined ? filtval[0] : $("div." + option).find("button.applyBtn");
$(attach).before(div);
var BrowseUtil = {
renderCropSuggestions: function (filters) {
$('.radio-wrapper').remove();
$.each(filters, function (name, value) {
var input = $('<input/>', {
type: 'radio',
name: 'crops',
id: 'crops_' + name,
'i-key': 'crops',
'class': 'filter-crop',
value: name
});
}
});
}
function renderBooleanSuggestions(filters) {
$.each(filters, function (filter) {
$.each($("input[type='checkbox'][i-key='" + filter + "']"), function (index) {
var val = filters[filter][index === 0 ? "T" : "F"];
if (val === undefined) {
val = 0;
if ($('div.filtval[x-key="crops' + name + '"]')[0] !== undefined) {
input.prop('checked', true);
}
var text = $(this).parent().html();
var idx = text.indexOf("(");
if (idx !== -1) {
text = text.substring(0, idx);
var key = Object.keys(this)[0];
var label = $('<label/>', {
'for': 'crops_' + name,
text: key + ' (' + value[key] + ')'
});
var filtval = $('div.filtval[i-key^="crops"]');
var attach = filtval[0] !== undefined ? filtval[0] : ('.crops button.applyBtn');
var wrapper = $('<div/>', {'class': 'radio-wrapper'});
wrapper.append(input);
wrapper.append(label);
$(attach).before(wrapper);
});
},
renderListFilterSuggestions: function (filters, messages) {
$.each(filters, function (option) {
$('div.' + option).find('div[class!="panel-body"][class!="filtval complex"]').remove();
if (filters[option].options[0] === undefined) {
$('div.' + option).find('button.applyBtn').before('<div>No suggestions</div>');
} else {
$.each(filters[option].options, function (index) {
var div = '<div class="checkbox-wrapper">' +
'<label>' +
'<input class="filter-list"' +
'id="' + option + this.value + '_input"' +
($('div.filtval[x-key="' + option + this.value + '"]')[0] !== undefined ? 'checked ' : '') +
'norm-key="' + option + '"' +
'i-key="' + option + '" type="checkbox"' +
'value="' + this.value + '"/>' +
messages[this.name] +
' (' + filters[option].counts[index] + ')' +
'</label>' +
'</div>';
var filtval = $('div.filtval[x-key^="' + option + '"]');
var attach = filtval[0] !== undefined ? filtval[0] : $('div.' + option).find('button.applyBtn');
$(attach).before(div);
});
}
$(this).parent().html(text + " (" + val + ")");
if ($("div[x-key='" + filter + $(this).val() + "']")[0] !== undefined) {
$($("input[type='checkbox'][i-key='" + filter + "']")[index]).prop("checked", true);
});
},
renderBooleanSuggestions: function (filters) {
$.each(filters, function (filter) {
$.each($('input[type="checkbox"][i-key="' + filter + '"]'), function (index) {
var val = filters[filter][index === 0 ? 'T' : 'F'];
if (val === undefined) {
val = 0;
}
var text = $(this).parent().html();
var idx = text.indexOf('(');
if (idx !== -1) {
text = text.substring(0, idx);
}
$(this).parent().html(text + ' (' + val + ')');
if ($('div[x-key="' + filter + $(this).val() + '"]')[0] !== undefined) {
$($('input[type="checkbox"][i-key="' + filter + '"]')[index]).prop('checked', true);
}
});
});
},
applySuggestions: function (jsonData, messages) {
$.ajax({
url: '/explore/listFilterSuggestions',
method: 'get',
data: {
filter: JSON.stringify(jsonData)
},
success: function (response) {
BrowseUtil.renderListFilterSuggestions(response, messages);
}
});
});
}
function applySuggestions(jsonData, messages) {
$.ajax({
url: "/explore/listFilterSuggestions",
method: 'get',
data: {
filter: JSON.stringify(jsonData)
},
success: function (response) {
renderListFilterSuggestions(response, messages);
}
});
$.ajax({
url: "/explore/booleanSuggestions",
method: 'get',
data: {
filter: JSON.stringify(jsonData)
},
success: function (response) {
renderBooleanSuggestions(response);
}
});
$.ajax({
url: '/explore/booleanSuggestions',
method: 'get',
data: {
filter: JSON.stringify(jsonData)
},
success: function (response) {
BrowseUtil.renderBooleanSuggestions(response);
}
});
$.ajax({
url: "/explore/cropSuggestions",
method: 'get',
data: {
filter: JSON.stringify(jsonData)
},
success: function (response) {
renderCropSuggestions(response);
}
});
}
$.ajax({
url: '/explore/cropSuggestions',
method: 'get',
data: {
filter: JSON.stringify(jsonData)
},
success: function (response) {
BrowseUtil.renderCropSuggestions(response);
}
});
},
function enableFilter (btn, jsonData) {
var key = $(btn).attr("i-key");
jsonData[key] = [];
}
enableFilter: function (btn, jsonData) {
var key = $(btn).attr('i-key');
jsonData[key] = [];
},
function cleanJsonData(jsonData) {
$.each(jsonData, function (key) {
if ($(this).length === 0) {
delete jsonData[key];
}
});
}
var i18nFilterMessage = {
between: 'Between ',
varEnd: ' and ',
moreThan: 'More than ',
lessThan: 'Less than ',
like: 'Like ',
varTrue: 'Yes',
varFalse: 'No',
varNull: 'Unknown'
cleanJsonData: function (jsonData) {
$.each(jsonData, function (key) {
if ($(this).length === 0) {
delete jsonData[key];
}
});
},
i18nFilterMessage: {
between: 'Between ',
varEnd: ' and ',
moreThan: 'More than ',
lessThan: 'Less than ',
like: 'Like ',
varTrue: 'Yes',
varFalse: 'No',
varNull: 'Unknown'
}
};
document.addEventListener('DOMContentLoaded', function() {
......@@ -138,13 +141,13 @@ document.addEventListener('DOMContentLoaded', function() {
$(window).on('click', function (event) {
var popup = document.getElementById('error-loading-popup-id');
if(event.target === popup) {
popup.style.display = "none";
popup.style.display = 'none';
}
});
$(document.getElementsByClassName("close")).on('click', function (event) {
$(document.getElementsByClassName('close')).on('click', function (event) {
event.preventDefault();
document.getElementById('error-loading-popup-id').style.display = "none";
document.getElementById('error-loading-popup-id').style.display = 'none';
});
$('#collapseFilters').on('hidden.bs.collapse', function () {
......@@ -152,13 +155,13 @@ document.addEventListener('DOMContentLoaded', function() {
});
$('#collapseFilters').on('hidden.bs.collapse', function () {
$("#content-area").addClass('fullwidth');
$('#content-area').addClass('fullwidth');
}).children().on('hidden.bs.collapse', function () {
return false;
});
$('#collapseFilters').on('show.bs.collapse', function () {
$("#content-area").removeClass('fullwidth');
}).children().on('show.bs.collapse', function (child) {
$('#content-area').removeClass('fullwidth');
}).children().on('show.bs.collapse', function () {
return true;
});
......
......@@ -267,7 +267,7 @@
var selectedValue = $(this).parent().parent().find(".like-switcher option:selected").val();
if (selectedValue == "like") {
GenesysFilter.filterLike(btn, jsonData, i18nFilterMessage);
GenesysFilter.filterLike(btn, jsonData, BrowseUtil.i18nFilterMessage);
} else {
console.log("btn", btn)
console.log("jsonData", jsonData)
......@@ -280,12 +280,12 @@
$("body").on("click", ".filter-auto", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
var selectedValue = $(this).parent().parent().parent().find(".like-switcher option:selected").val();
if (selectedValue == "like") {
GenesysFilter.filterLike($(this), jsonData, i18nFilterMessage);
GenesysFilter.filterLike($(this), jsonData, BrowseUtil.i18nFilterMessage);
} else {
GenesysFilter.filterAutocomplete($(this), jsonData);
}
......@@ -293,7 +293,7 @@
$("body").on("click", ".filter-list", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
var text = $(this).parent().text();
text = text.substring(0, text.indexOf('('));
......@@ -302,16 +302,16 @@
$("body").on("click", ".filter-range", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
GenesysFilter.filterRange($(this), jsonData, i18nFilterMessage);
GenesysFilter.filterRange($(this), jsonData, BrowseUtil.i18nFilterMessage);
});
$("body").on("click", ".filter-bool", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
GenesysFilter.filterBoolean($(this), jsonData, i18nFilterMessage);
GenesysFilter.filterBoolean($(this), jsonData, BrowseUtil.i18nFilterMessage);
});
$('body').on('click', '.filter-crop', function () {
......@@ -320,10 +320,10 @@
$("body").on("click", ".applyBtn", function () {
applyFilters();
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
});
applySuggestions (jsonData, messages);
BrowseUtil.applySuggestions (jsonData, messages);
$("body").on("click", ".filtval", function (event) {
event.preventDefault();
......@@ -335,7 +335,7 @@
if (value == "null") value = null;
GenesysFilterUtil.removeValue(value, key, jsonData);
applyFilters();
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
$(this).remove();
$('input[i-key=" + normKey + "][value=" + value + "]').prop('checked', false);
......@@ -437,7 +437,7 @@
renderData(response);
}
});
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
} else {
location.reload();
}
......@@ -452,7 +452,7 @@
filter: JSON.stringify(jsonData)
},
success: function (response) {
renderBooleanSuggestions(response);
BrowseUtil.renderBooleanSuggestions(response);
}
});
......@@ -533,7 +533,7 @@
function applyFilters (path) {
document.getElementById('loading-popup-id').style.display = "block";
cleanJsonData(jsonData);
BrowseUtil.cleanJsonData(jsonData);
var filter = JSON.stringify(jsonData);
console.log("filter: " , filter);
var requestUrl = '//' + location.host + location.pathname + "/json" +
......
......@@ -110,7 +110,7 @@
</li>
<li style="margin-right: 5px" class="active form-horizontal pull-right" data-toggle="modal"
data-target="#modal-dialog">
<a class="btn-primary" href="#">
<a id="remember-map" class="btn-primary" href="#">
<spring:message code="savedmaps.save"/>
</a>
</li>
......@@ -182,7 +182,7 @@
var layer = null;
$(document).ready(function () {
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
$(document.getElementsByClassName("btn btn-default btn-back")).on('click', function (event) {
event.preventDefault();
......@@ -213,7 +213,7 @@
var btn = $(this).parent().find("button");
var selectedValue = $(this).parent().parent().find(".like-switcher option:selected").val();
if (selectedValue == "like") {
GenesysFilter.filterLike(btn, jsonData, i18nFilterMessage);
GenesysFilter.filterLike(btn, jsonData, BrowseUtil.i18nFilterMessage);
} else {
GenesysFilter.filterAutocomplete(btn, jsonData);
}
......@@ -222,12 +222,12 @@
$("body").on("click", ".filter-auto", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
var selectedValue = $(this).parent().parent().parent().find(".like-switcher option:selected").val();
if (selectedValue == "like") {
GenesysFilter.filterLike($(this), jsonData, i18nFilterMessage);
GenesysFilter.filterLike($(this), jsonData, BrowseUtil.i18nFilterMessage);
} else {
GenesysFilter.filterAutocomplete($(this), jsonData);
}
......@@ -235,7 +235,7 @@
$("body").on("click", ".filter-list", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
var text = $(this).parent().text();
text = text.substring(0, text.indexOf('('));
......@@ -244,16 +244,16 @@
$("body").on("click", ".filter-range", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
GenesysFilter.filterRange($(this), jsonData, i18nFilterMessage);
GenesysFilter.filterRange($(this), jsonData, BrowseUtil.i18nFilterMessage);
});
$("body").on("click", ".filter-bool", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
GenesysFilter.filterBoolean($(this), jsonData, i18nFilterMessage);
GenesysFilter.filterBoolean($(this), jsonData, BrowseUtil.i18nFilterMessage);
});
$('body').on('click', '.filter-crop', function () {
......@@ -269,7 +269,7 @@
if (value == "null") value = null;
GenesysFilterUtil.removeValue(value, key, jsonData);
applyFilters();
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
$(this).remove();
$('input[i-key=" + normKey + "][value=" + value + "]').prop('checked', false);
......@@ -301,12 +301,16 @@
if (value == "null") value = null;
GenesysFilterUtil.removeValue(value, key, jsonData);
applyFilters();
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
$(this).remove();
$('input[i-key=" + normKey + "][value=" + value + "]').prop('checked', false);
});
$('#remember-map').on('click', function(e) {
e.preventDefault();
});
$("#menuShareLink").on("click", function () {
if ($('#shortLink').val() === '') {
$.ajax({
......@@ -344,7 +348,7 @@
refreshData();
}
});
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
} else {
location.reload();
}
......@@ -368,7 +372,7 @@
$("body").on("click", ".applyBtn", function () {
applyFilters();
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
});
......@@ -686,7 +690,7 @@
var stepValue = (parseInt(localStorage.getItem("historyStep")) + 1);
localStorage.setItem("historyStep", stepValue);
cleanJsonData(jsonData);
BrowseUtil.cleanJsonData(jsonData);
var filter = JSON.stringify(jsonData);
var requestUrl = '//' + location.host + location.pathname +
......
......@@ -142,7 +142,7 @@
localStorage.setItem("historyStep", 1);
$(document).ready(function () {
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
$(document.getElementsByClassName("btn btn-default btn-back")).on('click', function (event) {
event.preventDefault();
......@@ -177,7 +177,7 @@
renderData(response);
}
});
applySuggestions(jsonData, messages);
BrowseUtil.applySuggestions(jsonData, messages);
} else {
location.reload();
}
......@@ -194,7 +194,7 @@
var selectedValue = $(this).parent().parent().find(".like-switcher option:selected").val();
console.log("2")
if (selectedValue == "like") {
GenesysFilter.filterLike(btn, jsonData, i18nFilterMessage);
GenesysFilter.filterLike(btn, jsonData, BrowseUtil.i18nFilterMessage);
} else {
console.log("btn", btn)
console.log("jsonData", jsonData)
......@@ -207,12 +207,12 @@
$("body").on("click", ".filter-auto", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
var selectedValue = $(this).parent().parent().parent().find(".like-switcher option:selected").val();
if (selectedValue == "like") {
GenesysFilter.filterLike($(this), jsonData, i18nFilterMessage);
GenesysFilter.filterLike($(this), jsonData, BrowseUtil.i18nFilterMessage);
} else {
GenesysFilter.filterAutocomplete($(this), jsonData);
}
......@@ -220,7 +220,7 @@
$("body").on("click", ".filter-list", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
var text = $(this).parent().text();
text = text.substring(0, text.indexOf('('));
......@@ -229,16 +229,16 @@
$("body").on("click", ".filter-range", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
GenesysFilter.filterRange($(this), jsonData, i18nFilterMessage);
GenesysFilter.filterRange($(this), jsonData, BrowseUtil.i18nFilterMessage);
});
$("body").on("click", ".filter-bool", function () {
if (jsonData[$(this).attr("i-key")] === undefined) {
enableFilter(this, jsonData);
BrowseUtil.enableFilter(this, jsonData);
}
GenesysFilter.filterBoolean($(this), jsonData, i18nFilterMessage);