Simplification in explorer

This commit is contained in:
Théo Marchal 2021-03-07 00:27:45 +01:00
parent 3283d11c02
commit 862a7348e6

View File

@ -234,142 +234,146 @@ jQuery(document).ready(function($)
URLGeneration(originalAvailableOptions); URLGeneration(originalAvailableOptions);
updateMenu(availableOptions); updateMenu(availableOptions);
function makeFilterChanges() function handleVisualFilterChanges()
{ {
selectedOptions = gatherURLdata(); function makeFilterChanges()
data = originalData;
filterData(selectedOptions);
availableOptions = [];
availableOptions = gatherData();
updateMenu(availableOptions);
}
// handle tags
function handleTags()
{
$('input[name="tags"]').change(function()
{ {
params["tag"] = []; // remove filter selectedOptions = gatherURLdata();
if (this.checked) data = originalData;
{ filterData(selectedOptions);
$('select[name="tag"] option[value=""]').prop('selected', true); availableOptions = [];
$('select[name="tag"]').attr('disabled', 'disabled'); availableOptions = gatherData();
$(".box.tags span:not(.first) select").parent().remove(); updateMenu(availableOptions);
} }
else
$('select[name="tag"]').removeAttr('disabled');
makeFilterChanges(); // handle tags
}); function handleTags()
$('.box.tags .item-cont').delegate('select[name="tag"]', 'change', function()
{ {
params.tag = []; // collect all tags from all dropdowns $('input[name="tags"]').change(function()
$('.box.tags .item-cont select[name="tag"]').each(function()
{ {
if (params.tag.indexOf(this.value) === -1 && this.value != "") params["tag"] = []; // remove filter
params.tag.push(this.value); if (this.checked)
{
$('select[name="tag"] option[value=""]').prop('selected', true);
$('select[name="tag"]').attr('disabled', 'disabled');
$(".box.tags span:not(.first) select").parent().remove();
}
else
$('select[name="tag"]').removeAttr('disabled');
makeFilterChanges();
}); });
if (this.value != "") $('.box.tags .item-cont').delegate('select[name="tag"]', 'change', function()
{ {
createNewElem = true; // if we modify an existing element to a value, we don't delete it params.tag = []; // collect all tags from all dropdowns
$('.box.tags select').each(function() $('.box.tags .item-cont select[name="tag"]').each(function()
{ {
if ($(this).val() == "") if (params.tag.indexOf(this.value) === -1 && this.value != "")
createNewElem = false; params.tag.push(this.value);
}); });
if (createNewElem)
if (this.value != "")
{ {
html = '<span><span class="inline">&#x203B;&nbsp;</span><select name="tag">'; createNewElem = true; // if we modify an existing element to a value, we don't delete it
html += '<option value="">Aucun filtre</option>'; $('.box.tags select').each(function()
for (a of originalAvailableOptions.tags) {
html += '<option value="' + a + '">' + a + '</option>'; if ($(this).val() == "")
html += '</select></span>'; createNewElem = false;
$(".box.tags .item-cont").append(html); });
if (createNewElem)
{
html = '<span><span class="inline">&#x203B;&nbsp;</span><select name="tag">';
html += '<option value="">Aucun filtre</option>';
for (a of originalAvailableOptions.tags)
html += '<option value="' + a + '">' + a + '</option>';
html += '</select></span>';
$(".box.tags .item-cont").append(html);
}
} }
} else
else
{
// if the element has no value, we delete it
$(this).parent().remove();
}
makeFilterChanges();
});
}
handleTags();
function visualFilterCheckboxItem(name)
{
$('input[name="' + name + 's"]').change(function()
{
params[name] = []; // remove filter
makeFilterChanges();
});
$('input[name="' + name + '"]').change(function()
{
if (this.checked)
{
if (this.id == "exist") // photos special case
{ {
params[name].push("bad"); // if the element has no value, we delete it
params[name].push("ok"); $(this).parent().remove();
params[name].push("good");
} }
params[name].push(this.id);
} makeFilterChanges();
else });
}
handleTags();
function visualFilterCheckboxItem(name)
{
$('input[name="' + name + 's"]').change(function()
{ {
if (this.id == "exist") // photos special case params[name] = []; // remove filter
makeFilterChanges();
});
$('input[name="' + name + '"]').change(function()
{
if (this.checked)
{ {
removeFromArray(params[name], "bad"); if (this.id == "exist") // photos special case
removeFromArray(params[name], "ok"); {
removeFromArray(params[name], "good"); params[name].push("bad");
params[name].push("ok");
params[name].push("good");
}
params[name].push(this.id);
}
else
{
if (this.id == "exist") // photos special case
{
removeFromArray(params[name], "bad");
removeFromArray(params[name], "ok");
removeFromArray(params[name], "good");
}
removeFromArray(params[name], this.id);
} }
removeFromArray(params[name], this.id);
}
makeFilterChanges(); makeFilterChanges();
}); });
} }
function visualFilterListItem(name) function visualFilterListItem(name)
{
$('input[name="' + name + 's"]').change(function()
{ {
params[name] = []; // remove filter $('input[name="' + name + 's"]').change(function()
if (this.checked)
{ {
$('select[name="' + name + '"] option[value=""]').prop('selected', true); params[name] = []; // remove filter
$('select[name="' + name + '"]').attr('disabled', 'disabled'); if (this.checked)
} {
else $('select[name="' + name + '"] option[value=""]').prop('selected', true);
$('select[name="' + name + '"]').removeAttr('disabled'); $('select[name="' + name + '"]').attr('disabled', 'disabled');
}
else
$('select[name="' + name + '"]').removeAttr('disabled');
makeFilterChanges(); makeFilterChanges();
}); });
$('select[name="' + name + '"]').change(function() $('select[name="' + name + '"]').change(function()
{ {
if (this.value == "" && name == "place") if (this.value == "" && name == "place")
params[name].pop(); params[name].pop();
else else
params[name].push(this.value); params[name].push(this.value);
makeFilterChanges(); makeFilterChanges();
}); });
}
visualFilterCheckboxItem("photo");
visualFilterCheckboxItem("year");
visualFilterCheckboxItem("month");
visualFilterCheckboxItem("genre");
visualFilterCheckboxItem("theme");
visualFilterCheckboxItem("dimension");
visualFilterCheckboxItem("help");
visualFilterListItem("place");
} }
handleVisualFilterChanges();
visualFilterCheckboxItem("photo");
visualFilterCheckboxItem("year");
visualFilterCheckboxItem("month");
visualFilterCheckboxItem("genre");
visualFilterCheckboxItem("theme");
visualFilterCheckboxItem("dimension");
visualFilterCheckboxItem("help");
visualFilterListItem("place");
}); });
/*********************/ /*********************/