Proyectos de Subversion Moodle

Rev

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

{"version":3,"file":"search.min.js","sources":["../src/search.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 * This module adds ajax search functions to the template library page.\n *\n * @module     tool_templatelibrary/search\n * @copyright  2015 Damyon Wiese <damyon@moodle.com>\n * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates', 'core/config'],\n       function($, ajax, log, notification, templates, config) {\n\n    /**\n     * The ajax call has returned with a new list of templates.\n     *\n     * @method reloadListTemplate\n     * @param {String[]} templateList List of template ids.\n     */\n    var reloadListTemplate = function(templateList) {\n        templates.render('tool_templatelibrary/search_results', {templates: templateList})\n            .done(function(result, js) {\n                templates.replaceNode($('[data-region=\"searchresults\"]'), result, js);\n            }).fail(notification.exception);\n    };\n\n    /**\n     * Get the current values for the form inputs and refresh the list of matching templates.\n     *\n     * @method refreshSearch\n     * @param {String} themename The naeme of the theme.\n     */\n    var refreshSearch = function(themename) {\n        var componentStr = $('[data-field=\"component\"]').val();\n        var searchStr = $('[data-region=\"list-templates\"] [data-region=\"input\"]').val();\n\n        if (searchStr !== '') {\n            $('[data-region=\"list-templates\"] [data-action=\"clearsearch\"]').removeClass('d-none');\n        } else {\n            $('[data-region=\"list-templates\"] [data-action=\"clearsearch\"]').addClass('d-none');\n        }\n\n        // Trigger the search.\n        ajax.call([\n            {methodname: 'tool_templatelibrary_list_templates',\n              args: {component: componentStr, search: searchStr, themename: themename},\n              done: reloadListTemplate,\n              fail: notification.exception}\n        ], true, false);\n    };\n\n    var throttle = null;\n\n    /**\n     * Call the specified function after a delay. If this function is called again before the function is executed,\n     * the function will only be executed once.\n     *\n     * @method queueRefresh\n     * @param {function} callback\n     * @param {Number} delay The time in milliseconds to delay.\n     */\n    var queueRefresh = function(callback, delay) {\n        if (throttle !== null) {\n            window.clearTimeout(throttle);\n        }\n\n        throttle = window.setTimeout(function() {\n            callback();\n            throttle = null;\n        }, delay);\n    };\n\n    var changeHandler = function() {\n        queueRefresh(refreshSearch.bind(this, config.theme), 400);\n    };\n    // Add change handlers to refresh the list.\n    $('[data-region=\"list-templates\"]').on('change', '[data-field=\"component\"]', changeHandler);\n    $('[data-region=\"list-templates\"]').on('input', '[data-region=\"input\"]', changeHandler);\n    $('[data-action=\"clearsearch\"]').on('click', function() {\n        $('[data-region=\"input\"]').val('');\n        refreshSearch(config.theme);\n        $(this).addClass('d-none');\n    });\n\n    refreshSearch(config.theme);\n    return {};\n});\n"],"names":["define","$","ajax","log","notification","templates","config","reloadListTemplate","templateList","render","done","result","js","replaceNode","fail","exception","refreshSearch","themename","componentStr","val","searchStr","removeClass","addClass","call","methodname","args","component","search","throttle","changeHandler","callback","delay","bind","this","theme","window","clearTimeout","setTimeout","on"],"mappings":";;;;;;;AAsBAA,qCAAO,CAAC,SAAU,YAAa,WAAY,oBAAqB,iBAAkB,gBAC3E,SAASC,EAAGC,KAAMC,IAAKC,aAAcC,UAAWC,YAQ/CC,mBAAqB,SAASC,cAC9BH,UAAUI,OAAO,sCAAuC,CAACJ,UAAWG,eAC/DE,MAAK,SAASC,OAAQC,IACnBP,UAAUQ,YAAYZ,EAAE,iCAAkCU,OAAQC,OACnEE,KAAKV,aAAaW,YASzBC,cAAgB,SAASC,eACrBC,aAAejB,EAAE,4BAA4BkB,MAC7CC,UAAYnB,EAAE,wDAAwDkB,MAExD,KAAdC,UACAnB,EAAE,8DAA8DoB,YAAY,UAE5EpB,EAAE,8DAA8DqB,SAAS,UAI7EpB,KAAKqB,KAAK,CACN,CAACC,WAAY,sCACXC,KAAM,CAACC,UAAWR,aAAcS,OAAQP,UAAWH,UAAWA,WAC9DP,KAAMH,mBACNO,KAAMV,aAAaW,aACtB,GAAM,IAGTa,SAAW,KAqBXC,cAAgB,WAXD,IAASC,SAAUC,MAAVD,SAYXd,cAAcgB,KAAKC,KAAM3B,OAAO4B,OAZXH,MAYmB,IAXpC,OAAbH,UACAO,OAAOC,aAAaR,UAGxBA,SAAWO,OAAOE,YAAW,WACzBP,WACAF,SAAW,OACZG,eAOP9B,EAAE,kCAAkCqC,GAAG,SAAU,2BAA4BT,eAC7E5B,EAAE,kCAAkCqC,GAAG,QAAS,wBAAyBT,eACzE5B,EAAE,+BAA+BqC,GAAG,SAAS,WACzCrC,EAAE,yBAAyBkB,IAAI,IAC/BH,cAAcV,OAAO4B,OACrBjC,EAAEgC,MAAMX,SAAS,aAGrBN,cAAcV,OAAO4B,OACd"}