Proyectos de Subversion Moodle

Rev

Autoría | Ultima modificación | Ver Log |

{"version":3,"file":"acceptances_filter_datasource.min.js","sources":["../src/acceptances_filter_datasource.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 * Datasource for the tool_policy/acceptances_filter.\n *\n * This module is compatible with core/form-autocomplete.\n *\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:tool_policy/acceptances_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 (query.trim() !== '' && 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"],"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":";;;;;;;;AAwBAA,mDAAO,CAAC,SAAU,YAAa,sBAAsB,SAASC,EAAGC,KAAMC,oBAEG,CAQlEC,KAAM,SAASC,SAAUC,WACjBC,gBAAkB,GAElBC,GAAKP,EAAEI,UACPI,gBAAkBR,EAAEI,UAAUK,KAAK,uBACnCC,gBAAkBH,GAAGI,MACzBX,EAAEY,KAAKJ,iBAAiB,SAASK,MAAOC,cAEf,KAAjBT,MAAMU,SAA0F,IAAzED,OAAOE,MAAMC,oBAAoBC,QAAQb,MAAMY,sBAItEjB,EAAEmB,QAAQL,OAAOM,MAAOV,kBAAoB,GAIhDJ,gBAAgBe,KAAKP,SAPV,SAWXQ,SAAW,IAAItB,EAAEuB,gBACrBD,SAASE,QAAQlB,iBAEVgB,SAASG,WAUpBC,eAAgB,SAAStB,SAAUuB,aAC3BC,QAAU,UACd5B,EAAEY,KAAKe,SAAS,SAASd,MAAOJ,MAC5BmB,QAAQP,KAAK,CACTD,MAAOX,KAAKW,MACZJ,MAAOP,KAAKO,WAGbY,SAWXC,UAAW,SAASzB,SAAUC,MAAOyB,eAC5B3B,KAAKC,SAAUC,OAAO0B,KAAKD,UAAUE,MAAM9B,aAAa+B"}