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

This commit is contained in:
Damyon Wiese 2017-11-02 12:21:39 +08:00
commit ae348e78a0
4 changed files with 37 additions and 19 deletions

View File

@ -1 +1 @@
define(["jquery","core/form-autocomplete","core/str","core/notification"],function(a,b,c,d){var e={UNIFIED_FILTERS:"#unified-filters"},f=function(){var f=[{key:"userfilterplaceholder",component:"moodle"},{key:"nofiltersapplied",component:"moodle"}];c.get_strings(f).done(function(a){var c=a[0],d=a[1];b.enhance(e.UNIFIED_FILTERS,!0,"core_user/unified_filter_datasource",c,!1,!0,d,!0)}).fail(d.exception);var g=a(e.UNIFIED_FILTERS).val();a(e.UNIFIED_FILTERS).on("change",function(){var b=a(this).val();g.join(",")!=b.join(",")&&this.form.submit(),g=b})};return{init:function(){f()}}});
define(["jquery","core/form-autocomplete","core/str","core/notification"],function(a,b,c,d){var e={UNIFIED_FILTERS:"#unified-filters"},f=function(){var f=[{key:"userfilterplaceholder",component:"moodle"},{key:"nofiltersapplied",component:"moodle"}];c.get_strings(f).done(function(a){var c=a[0],d=a[1];b.enhance(e.UNIFIED_FILTERS,!0,"core_user/unified_filter_datasource",c,!1,!0,d,!0)}).fail(d.exception);var g=a(e.UNIFIED_FILTERS).val();a(e.UNIFIED_FILTERS).on("change",function(){var b=a(this).val(),c=[],d=!1;if(a.each(b,function(a,b){var e=b.split(":",2);if(2!==e.length)return!0;var f=e[0],g=e[1];return"undefined"!=typeof c[f]&&(d=!0),c[f]=g,!0}),d){var e=[];for(var f in c)e.push(f+":"+c[f]);a(this).val(e)}g.join(",")!=b.join(",")&&this.form.submit()})};return{init:function(){f()}}});

View File

@ -1 +1 @@
define(["jquery","core/ajax","core/notification"],function(a,b,c){return{list:function(b,c){var d=[],e=a(b),f=a(b).data("originaloptionsjson"),g=e.val(),h=[];a.each(g,function(a,b){var c=b.split(":",2);if(2===c.length){var d=c[0];h.push(d)}}),a.each(f,function(b,e){if(""!==a.trim(c)&&e.label.toLocaleLowerCase().indexOf(c.toLocaleLowerCase())===-1)return!0;if(a.inArray(e.value,g)>-1)return!0;var f=e.value.split(":",2);if(2===f.length){var i=f[0];if(a.inArray(i,h)>-1)return!0}return d.push(e),!0});var i=new a.Deferred;return i.resolve(d),i.promise()},processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.value,label:b.label})}),d},transport:function(a,b,d){this.list(a,b).then(d)["catch"](c.exception)}}});
define(["jquery","core/ajax","core/notification"],function(a,b,c){return{list:function(b,c){var d=[],e=a(b),f=a(b).data("originaloptionsjson"),g=e.val();a.each(f,function(b,e){return""!==a.trim(c)&&e.label.toLocaleLowerCase().indexOf(c.toLocaleLowerCase())===-1||(a.inArray(e.value,g)>-1||(d.push(e),!0))});var h=new a.Deferred;return h.resolve(d),h.promise()},processResults:function(b,c){var d=[];return a.each(c,function(a,b){d.push({value:b.value,label:b.label})}),d},transport:function(a,b,d){this.list(a,b).then(d)["catch"](c.exception)}}});

View File

@ -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;
});
};

View File

@ -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;