AutorÃa | Ultima modificación | Ver Log |
{"version":3,"file":"acceptances_filter.min.js","sources":["../src/acceptances_filter.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Unified filter page JS module for the course participants page.\n *\n * @module tool_policy/acceptances_filter\n * @copyright 2017 Jun Pataleta\n * @license http://www.gnu.org/copyleft/gpl.html GNU
GPL v3 or later\n */\ndefine(['jquery', 'core/form-autocomplete', 'core/str', 'core/notification'],\n function($, Autocomplete, Str, Notification) {\n\n /**\n * Selectors.\n *\n * @access private\n * @type {{UNIFIED_FILTERS: string}}\n */\n var SELECTORS = {\n UNIFIED_FILTERS: '#unified-filters'\n };\n\n /**\n * Init function.\n *\n * @method init\n * @private\n */\n var init = function() {\n var stringkeys = [{\n key: 'filterplaceholder',\n component: 'tool_policy'\n }, {\n key: 'nofiltersapplied',\n component: 'tool_policy'\n }];\n\n M.util.js_pending('acceptances_filter_datasource');\n Str.get_strings(stringkeys).done(function(langstrings) {\n var placeholder = langstrings[0];\n var noSelectionString = langstrings[1];\n A
utocomplete.enhance(SELECTORS.UNIFIED_FILTERS, true, 'tool_policy/acceptances_filter_datasource', placeholder,\n false, true, noSelectionString, true)\n .then(function() {\n M.util.js_complete('acceptances_filter_datasource');\n\n return;\n })\n .fail(Notification.exception);\n }).fail(Notification.exception);\n\n var last = $(SELECTORS.UNIFIED_FILTERS).val();\n $(SELECTORS.UNIFIED_FILTERS).on('change', function() {\n var current = $(this).val();\n var listoffilters = [];\n var textfilters = [];\n var updatedselectedfilters = false;\n\n $.each(current, function(index, catoption) {\n var catandoption = catoption.split(':', 2);\n if (catandoption.length !== 2) {\n textfilters.push(catoption);\n return
true; // Text search filter.\n }\n\n var category = catandoption[0];\n var option = catandoption[1];\n\n // The last option (eg. 'Teacher') out of a category (eg. 'Role') in this loop is the one that was last\n // selected, so we want to use that if there are multiple options from the same category. Eg. The user\n // may have chosen to filter by the 'Student' role, then wanted to filter by the 'Teacher' role - the\n // last option in the category to be selected (in this case 'Teacher') will come last, so will overwrite\n // 'Student' (after this if). We want to let the JS know that the filters have been updated.\n if (typeof listoffilters[category] !== 'undefined') {\n updatedselectedfilters = true;\n }\n\n listoffilters[category] = option;\n return true;\n
});\n\n // Check if we have something to remove from the list of filters.\n if (updatedselectedfilters) {\n // Go through and put the list into something we can use to update the list of filters.\n var updatefilters = [];\n for (var category in listoffilters) {\n updatefilters.push(category + \":\" + listoffilters[category]);\n }\n updatefilters = updatefilters.concat(textfilters);\n $(this).val(updatefilters);\n }\n\n // Prevent form from submitting unnecessarily, eg. on blur when no filter is selected.\n if (last.join(',') != current.join(',')) {\n this.form.submit();\n }\n });\n };\n\n /**\n * Return the unified user filter form.\n *\n * @method getForm\n * @return {DOMElement}\n */\n
var getForm = function() {\n return $(SELECTORS.UNIFIED_FILTERS).closest('form');\n };\n\n return /** @alias module:core/form-autocomplete */ {\n /**\n * Initialise the unified user filter.\n *\n * @method init\n */\n init: function() {\n init();\n },\n\n /**\n * Return the unified user filter form.\n *\n * @method getForm\n * @return {DOMElement}\n */\n getForm: function() {\n return getForm();\n }\n };\n });\n"],"names":["define","$","Autocomplete","Str","Notification","SELECTORS","init","M","util","js_pending","get_strings","key","component","done","langstrings","placeholder","noSelectionString","enhance","then","js_complete","fail","exception","last","val","on","current","this","listoffilters","textfilters","updatedselectedfilters","each","index","catoption","catando
ption","split","length","push","category","option","updatefilters","concat","join","form","submit","getForm","closest"],"mappings":";;;;;;;AAsBAA,wCAAO,CAAC,SAAU,yBAA0B,WAAY,sBACpD,SAASC,EAAGC,aAAcC,IAAKC,kBAQvBC,0BACiB,yBA0F8B,CAM/CC,KAAM,YAvFC,WASPC,EAAEC,KAAKC,WAAW,iCAClBN,IAAIO,YATa,CAAC,CACdC,IAAK,oBACLC,UAAW,eACZ,CACCD,IAAK,mBACLC,UAAW,iBAIaC,MAAK,SAASC,iBAClCC,YAAcD,YAAY,GAC1BE,kBAAoBF,YAAY,GACpCZ,aAAae,QAAQZ,2BAA2B,EAAM,4CAA6CU,aAC/F,GAAO,EAAMC,mBAAmB,GAC/BE,MAAK,WACFX,EAAEC,KAAKW,YAAY,oCAItBC,KAAKhB,aAAaiB,cACxBD,KAAKhB,aAAaiB,eAEjBC,KAAOrB,EAAEI,2BAA2BkB,MACxCtB,EAAEI,2BAA2BmB,GAAG,UAAU,eAClCC,QAAUxB,EAAEyB,MAAMH,MAClBI,cAAgB,GAChBC,YAAc,GACdC,wBAAyB,KAE7B5B,EAAE6B,KAAKL,SAAS,SAASM,MAAOC,eACxBC,aAAeD,UAAUE,MAAM,IAAK,MACZ,IAAxBD,aAAaE,cACbP,YAAYQ,KAAKJ,YACV,MAGPK,SAAWJ,aAAa,GACxBK,OAASL,aAAa,eAOa,IAA5BN,cAAcU,YACrBR,wBAAyB,GAG7BF,cAAcU,UAAYC,QACnB,KAIPT,uBAAwB,KAEpBU,cAAgB,OACf,IAAIF,YAAYV,cACjBY,cAAcH,KAAKC,SAAW,IAAMV,cAAcU,WAEtDE,cAAgBA,cAAcC,OAAOZ,aACrC3B,EAAEyB,MAAMH,IAAIgB,eAIZjB,KAAKmB,KAAK,MA
AQhB,QAAQgB,KAAK,WAC1BC,KAAKC,YAsBdrC,IASJsC,QAAS,kBAnBF3C,EAAEI,2BAA2BwC,QAAQ"}