N°1556 Advanced Search : fix removing only criteria in first row (was generating "AND 1")

This commit is contained in:
Pierre Goiffon
2018-10-09 17:19:23 +02:00
parent 80be4b4371
commit 91b7130671

View File

@@ -229,32 +229,38 @@ $(function()
}] }]
}; };
// - Retrieve criterion // - Retrieve criterion
this.elements.criterion_area.find('.sf_criterion_row').each(function(iIdx){ var iCurrentCriterionRow = 0;
var oCriterionRowElem = $(this); this.elements.criterion_area.find('.sf_criterion_row').each(function (iDomCriterionRowIdx) {
var isFirstRow = (iDomCriterionRowIdx === 0),
oCriterionRowElem = $(this),
oCriteriaRowCriterias = oCriterionRowElem.find('.search_form_criteria');
if (oCriterionRowElem.find('.search_form_criteria').length == 0 && iIdx > 0) if (oCriteriaRowCriterias.length === 0)
{ {
$(this).remove(); if (!isFirstRow)
{
$(this).remove();
}
} }
else else
{ {
oCriterionRowElem.find('.search_form_criteria').each(function () oCriteriaRowCriterias.each(function () {
{
var oCriteriaData = $(this).triggerHandler('itop.search.criteria.get_data'); var oCriteriaData = $(this).triggerHandler('itop.search.criteria.get_data');
if (null != oCriteriaData) if (null != oCriteriaData)
{ {
if (!oCriterion['or'][iIdx]) if (!oCriterion['or'][iCurrentCriterionRow])
{ {
oCriterion['or'][iIdx] = {'and': []}; oCriterion['or'][iCurrentCriterionRow] = {'and': []};
} }
oCriterion['or'][iIdx]['and'].push(oCriteriaData); oCriterion['or'][iCurrentCriterionRow]['and'].push(oCriteriaData);
} }
else else
{ {
$(this).remove(); $(this).remove();
} }
}); });
iCurrentCriterionRow++;
} }
}); });
// - Update search // - Update search