Commit ae348e78 authored by Damyon Wiese's avatar Damyon Wiese
Browse files

Merge branch 'MDL-59982_master' of git://github.com/markn86/moodle

parents 71fc06aa 9a428ae0
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -62,11 +62,45 @@ define(['jquery', 'core/form-autocomplete', 'core/str', 'core/notification'],
var last = $(SELECTORS.UNIFIED_FILTERS).val();
$(SELECTORS.UNIFIED_FILTERS).on('change', function() {
var current = $(this).val();
var listoffilters = [];
var updatedselectedfilters = false;
$.each(current, function(index, catoption) {
var catandoption = catoption.split(':', 2);
if (catandoption.length !== 2) {
return true; // Skip.
}
var category = catandoption[0];
var option = catandoption[1];
// The last option (eg. 'Teacher') out of a category (eg. 'Role') in this loop is the one that was last
// selected, so we want to use that if there are multiple options from the same category. Eg. The user
// may have chosen to filter by the 'Student' role, then wanted to filter by the 'Teacher' role - the
// last option in the category to be selected (in this case 'Teacher') will come last, so will overwrite
// 'Student' (after this if). We want to let the JS know that the filters have been updated.
if (typeof listoffilters[category] !== 'undefined') {
updatedselectedfilters = true;
}
listoffilters[category] = option;
return true;
});
// Check if we have something to remove from the list of filters.
if (updatedselectedfilters) {
// Go through and put the list into something we can use to update the list of filters.
var updatefilters = [];
for (var category in listoffilters) {
updatefilters.push(category + ":" + listoffilters[category]);
}
$(this).val(updatefilters);
}
// Prevent form from submitting unnecessarily, eg. on blur when no filter is selected.
if (last.join(',') != current.join(',')) {
this.form.submit();
}
last = current;
});
};
......
......@@ -39,14 +39,6 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat
var el = $(selector);
var originalOptions = $(selector).data('originaloptionsjson');
var selectedFilters = el.val();
var categoriesToSkip = [];
$.each(selectedFilters, function(index, filter) {
var filterCatAndValue = filter.split(':', 2);
if (filterCatAndValue.length === 2) {
var category = filterCatAndValue[0];
categoriesToSkip.push(category);
}
});
$.each(originalOptions, function(index, option) {
// Skip option if it does not contain the query string.
if ($.trim(query) !== '' && option.label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) === -1) {
......@@ -56,14 +48,6 @@ define(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notificat
if ($.inArray(option.value, selectedFilters) > -1) {
return true;
}
// Skip filters for categories that belong to the already selected filters.
var optionCatAndValue = option.value.split(':', 2);
if (optionCatAndValue.length === 2) {
var category = optionCatAndValue[0];
if ($.inArray(category, categoriesToSkip) > -1) {
return true;
}
}
filteredOptions.push(option);
return true;
......
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