MDL-68169 user: Limit the number of filter conditions
[moodle.git] / user / amd / build / unified_filter_datasource.min.js.map
1 {"version":3,"sources":["../src/unified_filter_datasource.js"],"names":["define","$","Ajax","Notification","list","selector","query","filteredOptions","el","originalOptions","data","selectedFilters","val","each","index","option","trim","label","toLocaleLowerCase","indexOf","inArray","value","push","deferred","Deferred","resolve","promise","processResults","results","options","transport","callback","then","catch","exception"],"mappings":"AAyBAA,OAAM,uCAAC,CAAC,QAAD,CAAW,WAAX,CAAwB,mBAAxB,CAAD,CAA+C,SAASC,CAAT,CAAYC,CAAZ,CAAkBC,CAAlB,CAAgC,CAEjF,MAAgE,CAQ5DC,IAAI,CAAE,cAASC,CAAT,CAAmBC,CAAnB,CAA0B,IACxBC,CAAAA,CAAe,CAAG,EADM,CAGxBC,CAAE,CAAGP,CAAC,CAACI,CAAD,CAHkB,CAIxBI,CAAe,CAAGR,CAAC,CAACI,CAAD,CAAD,CAAYK,IAAZ,CAAiB,qBAAjB,CAJM,CAKxBC,CAAe,CAAGH,CAAE,CAACI,GAAH,EALM,CAM5BX,CAAC,CAACY,IAAF,CAAOJ,CAAP,CAAwB,SAASK,CAAT,CAAgBC,CAAhB,CAAwB,CAE5C,GAAsB,EAAlB,GAAAd,CAAC,CAACe,IAAF,CAAOV,CAAP,GAAgG,CAAC,CAAzE,GAAAS,CAAM,CAACE,KAAP,CAAaC,iBAAb,GAAiCC,OAAjC,CAAyCb,CAAK,CAACY,iBAAN,EAAzC,CAA5B,CAAwG,CACpG,QACH,CAED,GAA+C,CAAC,CAA5C,CAAAjB,CAAC,CAACmB,OAAF,CAAUL,CAAM,CAACM,KAAjB,CAAwBV,CAAxB,CAAJ,CAAmD,CAC/C,QACH,CAEDJ,CAAe,CAACe,IAAhB,CAAqBP,CAArB,EACA,QACH,CAZD,EAcA,GAAIQ,CAAAA,CAAQ,CAAG,GAAItB,CAAAA,CAAC,CAACuB,QAArB,CACAD,CAAQ,CAACE,OAAT,CAAiBlB,CAAjB,EAEA,MAAOgB,CAAAA,CAAQ,CAACG,OAAT,EACV,CAhC2D,CAyC5DC,cAAc,CAAE,wBAAStB,CAAT,CAAmBuB,CAAnB,CAA4B,CACxC,GAAIC,CAAAA,CAAO,CAAG,EAAd,CACA5B,CAAC,CAACY,IAAF,CAAOe,CAAP,CAAgB,SAASd,CAAT,CAAgBJ,CAAhB,CAAsB,CAClCmB,CAAO,CAACP,IAAR,CAAa,CACTD,KAAK,CAAEX,CAAI,CAACW,KADH,CAETJ,KAAK,CAAEP,CAAI,CAACO,KAFH,CAAb,CAIH,CALD,EAMA,MAAOY,CAAAA,CACV,CAlD2D,CA4D5DC,SAAS,CAAE,mBAASzB,CAAT,CAAmBC,CAAnB,CAA0ByB,CAA1B,CAAoC,CAC3C,KAAK3B,IAAL,CAAUC,CAAV,CAAoBC,CAApB,EAA2B0B,IAA3B,CAAgCD,CAAhC,EAA0CE,KAA1C,CAAgD9B,CAAY,CAAC+B,SAA7D,CACH,CA9D2D,CAiEnE,CAnEK,CAAN","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 * Datasource for the core_user/unified_filter.\n *\n * This module is compatible with core/form-autocomplete.\n *\n * @package    core_user\n * @copyright  2017 Jun Pataleta\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\ndefine(['jquery', 'core/ajax', 'core/notification'], function($, Ajax, Notification) {\n\n    return /** @alias module:core_user/unified_filter_datasource */ {\n        /**\n         * List filter options.\n         *\n         * @param {String} selector The select element selector.\n         * @param {String} query The query string.\n         * @return {Promise}\n         */\n        list: function(selector, query) {\n            var filteredOptions = [];\n\n            var el = $(selector);\n            var originalOptions = $(selector).data('originaloptionsjson');\n            var selectedFilters = el.val();\n            $.each(originalOptions, function(index, option) {\n                // Skip option if it does not contain the query string.\n                if ($.trim(query) !== '' && option.label.toLocaleLowerCase().indexOf(query.toLocaleLowerCase()) === -1) {\n                    return true;\n                }\n                // Skip filters that have already been selected.\n                if ($.inArray(option.value, selectedFilters) > -1) {\n                    return true;\n                }\n\n                filteredOptions.push(option);\n                return true;\n            });\n\n            var deferred = new $.Deferred();\n            deferred.resolve(filteredOptions);\n\n            return deferred.promise();\n        },\n\n        /**\n         * Process the results for auto complete elements.\n         *\n         * @param {String} selector The selector of the auto complete element.\n         * @param {Array} results An array or results.\n         * @return {Array} New array of results.\n         */\n        processResults: function(selector, results) {\n            var options = [];\n            $.each(results, function(index, data) {\n                options.push({\n                    value: data.value,\n                    label: data.label\n                });\n            });\n            return options;\n        },\n\n        /**\n         * Source of data for Ajax element.\n         *\n         * @param {String} selector The selector of the auto complete element.\n         * @param {String} query The query string.\n         * @param {Function} callback A callback function receiving an array of results.\n         */\n        /* eslint-disable promise/no-callback-in-promise */\n        transport: function(selector, query, callback) {\n            this.list(selector, query).then(callback).catch(Notification.exception);\n        }\n    };\n\n});\n"],"file":"unified_filter_datasource.min.js"}