weekly release 4.1dev
[moodle.git] / admin / tool / templatelibrary / amd / build / search.min.js
1 /**
2  * This module adds ajax search functions to the template library page.
3  *
4  * @module     tool_templatelibrary/search
5  * @copyright  2015 Damyon Wiese <damyon@moodle.com>
6  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
7  */
8 define("tool_templatelibrary/search",["jquery","core/ajax","core/log","core/notification","core/templates","core/config"],(function($,ajax,log,notification,templates,config){var reloadListTemplate=function(templateList){templates.render("tool_templatelibrary/search_results",{templates:templateList}).done((function(result,js){templates.replaceNode($('[data-region="searchresults"]'),result,js)})).fail(notification.exception)},refreshSearch=function(themename){var componentStr=$('[data-field="component"]').val(),searchStr=$('[data-region="list-templates"] [data-region="input"]').val();""!==searchStr?$('[data-region="list-templates"] [data-action="clearsearch"]').removeClass("d-none"):$('[data-region="list-templates"] [data-action="clearsearch"]').addClass("d-none"),ajax.call([{methodname:"tool_templatelibrary_list_templates",args:{component:componentStr,search:searchStr,themename:themename},done:reloadListTemplate,fail:notification.exception}],!0,!1)},throttle=null,changeHandler=function(){var callback,delay;callback=refreshSearch.bind(this,config.theme),delay=400,null!==throttle&&window.clearTimeout(throttle),throttle=window.setTimeout((function(){callback(),throttle=null}),delay)};return $('[data-region="list-templates"]').on("change",'[data-field="component"]',changeHandler),$('[data-region="list-templates"]').on("input",'[data-region="input"]',changeHandler),$('[data-action="clearsearch"]').on("click",(function(){$('[data-region="input"]').val(""),refreshSearch(config.theme),$(this).addClass("d-none")})),refreshSearch(config.theme),{}}));
10 //# sourceMappingURL=search.min.js.map