|
|
@ -208,9 +208,11 @@ Reporting.Filters = { |
|
|
|
|
|
|
|
|
|
|
|
remove_filter: function (field) { |
|
|
|
remove_filter: function (field) { |
|
|
|
Reporting.Filters.show_filter(field, { show_filter: false }); |
|
|
|
Reporting.Filters.show_filter(field, { show_filter: false }); |
|
|
|
var dependents = Reporting.Filters.get_dependents($(field + '_arg_1_val')); |
|
|
|
var dependent = Reporting.Filters.get_dependents($(field + '_arg_1_val'), false).find(function(d) { |
|
|
|
if (dependents.size() !== 0) { |
|
|
|
return Reporting.Filters.visible_filters().include(d); |
|
|
|
Reporting.Filters.remove_filter(dependents.first()); |
|
|
|
}); |
|
|
|
|
|
|
|
if (dependent !== undefined) { |
|
|
|
|
|
|
|
Reporting.Filters.remove_filter(dependent); |
|
|
|
} |
|
|
|
} |
|
|
|
Reporting.Filters.select_option_enabled($("add_filter_select"), field, true); |
|
|
|
Reporting.Filters.select_option_enabled($("add_filter_select"), field, true); |
|
|
|
}, |
|
|
|
}, |
|
|
@ -229,9 +231,16 @@ Reporting.Filters = { |
|
|
|
}); |
|
|
|
}); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
get_dependents: function (element) { |
|
|
|
// Returns an array of dependents of the given element
|
|
|
|
if (element.hasAttribute("data-dependents")) { |
|
|
|
// get_all -> Boolean: whether to return all dependends (even the
|
|
|
|
return element.getAttribute("data-dependents").replace(/'/g, '"').evalJSON(true); |
|
|
|
// dependents of this filters dependents) or not
|
|
|
|
|
|
|
|
get_dependents: function (element, get_all) { |
|
|
|
|
|
|
|
var dependent_field = "data-all-dependents"; |
|
|
|
|
|
|
|
if (get_all === false) { |
|
|
|
|
|
|
|
dependent_field = "data-next-dependents"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (element.hasAttribute(dependent_field)) { |
|
|
|
|
|
|
|
return element.getAttribute(dependent_field).replace(/'/g, '"').evalJSON(true); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return []; |
|
|
|
return []; |
|
|
|
} |
|
|
|
} |
|
|
@ -242,35 +251,55 @@ Reporting.Filters = { |
|
|
|
// narrowing down their values.
|
|
|
|
// narrowing down their values.
|
|
|
|
// Param: select [optional] - the select-box of the filter which should activate it's dependents
|
|
|
|
// Param: select [optional] - the select-box of the filter which should activate it's dependents
|
|
|
|
activate_dependents: function (selectBox, callbackWhenFinished) { |
|
|
|
activate_dependents: function (selectBox, callbackWhenFinished) { |
|
|
|
var dependents, active_filters, source; |
|
|
|
var all_dependents, next_dependents, dependent, active_filters, source; |
|
|
|
if (selectBox === undefined || selectBox.type.toLowerCase() == 'change') { |
|
|
|
if (selectBox === undefined || selectBox.type.toLowerCase() == 'change') { |
|
|
|
selectBox = this; |
|
|
|
selectBox = this; |
|
|
|
} |
|
|
|
} |
|
|
|
if (callbackWhenFinished === undefined) { |
|
|
|
if (callbackWhenFinished === undefined) { |
|
|
|
callbackWhenFinished = function() {}; |
|
|
|
callbackWhenFinished = function() {}; |
|
|
|
} |
|
|
|
} |
|
|
|
dependents = Reporting.Filters.get_dependents(selectBox); |
|
|
|
source = selectBox.getAttribute("data-filter-name"); |
|
|
|
|
|
|
|
all_dependents = Reporting.Filters.get_dependents(selectBox); |
|
|
|
|
|
|
|
next_dependents = Reporting.Filters.get_dependents(selectBox, false); |
|
|
|
|
|
|
|
dependent = Reporting.Filters.which_dependent_shall_i_take(source, next_dependents); |
|
|
|
active_filters = Reporting.Filters.visible_filters(); |
|
|
|
active_filters = Reporting.Filters.visible_filters(); |
|
|
|
if (!active_filters.include(dependents.first())) { |
|
|
|
|
|
|
|
Reporting.Filters.show_filter(dependents.first(), { slowly: true, insert_after: $(selectBox.up(".filter")) }); |
|
|
|
if (!active_filters.include(dependent)) { |
|
|
|
|
|
|
|
// in case we run into a situation where the dependent to show is not in the currently selected dependency chain
|
|
|
|
|
|
|
|
// we have to remove all filters until we reach the source and add the new dependent
|
|
|
|
|
|
|
|
if (next_dependents.any( function(d){ return active_filters.include(d) } )) { |
|
|
|
|
|
|
|
while (active_filters.last() !== source) { |
|
|
|
|
|
|
|
Reporting.Filters.show_filter(active_filters.pop(1), { show_filter: false, slowly: true }); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Reporting.Filters.show_filter(dependent, { slowly: true, insert_after: $(selectBox.up(".filter")) }); |
|
|
|
// render filter inactive if possible to avoid unintended filtering
|
|
|
|
// render filter inactive if possible to avoid unintended filtering
|
|
|
|
$(dependents.first() + '_arg_1_val').value = '<<inactive>>' |
|
|
|
$(dependent + '_arg_1_val').value = '<<inactive>>' |
|
|
|
Reporting.Filters.operator_changed(dependents.first(), $('operators[' + dependents.first() + ']')); |
|
|
|
Reporting.Filters.operator_changed(dependent, $('operators[' + dependent + ']')); |
|
|
|
// Hide remove box of dependent
|
|
|
|
// Hide remove box of dependent
|
|
|
|
$('rm_box_' + dependents.first()).hide(); |
|
|
|
$('rm_box_' + dependent).hide(); |
|
|
|
$('tr_' + dependents.first()).addClassName("no-border"); |
|
|
|
|
|
|
|
// Remove border of dependent, so it "merges" with the filter before
|
|
|
|
// Remove border of dependent, so it "merges" with the filter before
|
|
|
|
active_filters.unshift(dependents.first()); |
|
|
|
$('tr_' + dependent).addClassName("no-border"); |
|
|
|
|
|
|
|
active_filters.unshift(dependent); |
|
|
|
} |
|
|
|
} |
|
|
|
source = selectBox.getAttribute("data-filter-name"); |
|
|
|
|
|
|
|
setTimeout(function () { // Make sure the newly shown filters are in the DOM
|
|
|
|
setTimeout(function () { // Make sure the newly shown filters are in the DOM
|
|
|
|
var active_dependents = dependents.select(function (d) { |
|
|
|
var active_dependents = all_dependents.select(function (d) { |
|
|
|
return active_filters.include(d); |
|
|
|
return active_filters.include(d); |
|
|
|
}); |
|
|
|
}); |
|
|
|
Reporting.Filters.narrow_values([source], active_dependents, callbackWhenFinished); |
|
|
|
Reporting.Filters.narrow_values(Reporting.Filters.dependent_for(source), active_dependents, callbackWhenFinished); |
|
|
|
}, 1); |
|
|
|
}, 1); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// return an array of all filters that depend on the given filter plus the given filter
|
|
|
|
|
|
|
|
dependent_for: function(field) { |
|
|
|
|
|
|
|
var deps = $$('.filters-select[data-all-dependents]').findAll(function(selectBox) { |
|
|
|
|
|
|
|
return Reporting.Filters.get_dependents(selectBox).include(field) |
|
|
|
|
|
|
|
}).map(function(selectBox) { |
|
|
|
|
|
|
|
return selectBox.getAttribute("data-filter-name"); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return deps === undefined ? [ field ] : [ field ].concat(deps) |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
// Select the given values of the selectBox.
|
|
|
|
// Select the given values of the selectBox.
|
|
|
|
// Toggle multi-select state of the selectBox depending on how many values were given.
|
|
|
|
// Toggle multi-select state of the selectBox depending on how many values were given.
|
|
|
|
select_values: function(selectBox, values_to_select) { |
|
|
|
select_values: function(selectBox, values_to_select) { |
|
|
@ -293,7 +322,8 @@ Reporting.Filters = { |
|
|
|
if (callbackWhenFinished === undefined) { |
|
|
|
if (callbackWhenFinished === undefined) { |
|
|
|
callbackWhenFinished = function() {}; |
|
|
|
callbackWhenFinished = function() {}; |
|
|
|
} |
|
|
|
} |
|
|
|
var params = "?narrow_values=1&dependent=" + dependents.first(); |
|
|
|
var params = document.location.href.include('?') ? '&' : '?' |
|
|
|
|
|
|
|
params = params + "narrow_values=1&dependent=" + dependents.first(); |
|
|
|
sources.each(function (filter) { |
|
|
|
sources.each(function (filter) { |
|
|
|
params = params + "&sources[]=" + filter; |
|
|
|
params = params + "&sources[]=" + filter; |
|
|
|
}); |
|
|
|
}); |
|
|
@ -357,6 +387,13 @@ Reporting.Filters = { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// This method may be overridden by the actual application to define custon behavior
|
|
|
|
|
|
|
|
// If there are multiple possible dependents to follow.
|
|
|
|
|
|
|
|
// The dependent to follow should be returned.
|
|
|
|
|
|
|
|
which_dependent_shall_i_take: function(source, dependents) { |
|
|
|
|
|
|
|
return dependents.first(); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@ -392,7 +429,7 @@ Reporting.onload(function () { |
|
|
|
Reporting.Filters.value_changed(filter_name); |
|
|
|
Reporting.Filters.value_changed(filter_name); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
$$('.filters-select[data-dependents]').each(function (dependency) { |
|
|
|
$$('.filters-select[data-all-dependents]').each(function (dependency) { |
|
|
|
dependency.observe("change", Reporting.Filters.activate_dependents); |
|
|
|
dependency.observe("change", Reporting.Filters.activate_dependents); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|