From 0a621387952f0bf969640ce6c5ef27c54bb8549e Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Tue, 17 Nov 2020 23:46:48 +0000 Subject: [PATCH] MDL-70279 tool_templatelibrary: preserve component search field value. --- .../templatelibrary/amd/build/search.min.js | Bin 1376 -> 1278 bytes .../amd/build/search.min.js.map | Bin 6648 -> 6311 bytes admin/tool/templatelibrary/amd/src/search.js | 4 +--- .../classes/output/list_templates_page.php | 18 ++++++++++++++++++ .../templates/list_templates_page.mustache | 12 ++++++------ lib/templates/search_input_auto.mustache | 1 + 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/admin/tool/templatelibrary/amd/build/search.min.js b/admin/tool/templatelibrary/amd/build/search.min.js index 74f8c50e9b3206246a7634c99b40bf727bc9205c..9645fa6341ef96caee09aa9dbd1921cfabfd61a4 100644 GIT binary patch delta 16 XcmaFB^^bEy6Vv9|Om<9@m00ZnI+6vh delta 89 zcmeyz`G9Lf6O&|0esXDUYF>$6PJVJ?NoIbYUPfYZhHaYl<|ZaPCgwy9rO68!< zO5{1vlxRC4o017MC7(lusmOVgkHIuL7T)BC+!nkx#ntoRN7G=kS*feH0h`NP25)avmN?6 z9ZKl@p~h557c(Oj#!ZgK*wYPb{vAc?gho9}GrGz}>S{ugHaMFEsQ@kR z)2XPAb{x}Nan9xV{Sf`a?#S!C@KRlhtW35Ro$M^iHWt_mw5ys`)(aggd2WpEr587K cNfLcun3ex-iH_GB2``6HARLzEBrW<1Ki0XP!vFvP diff --git a/admin/tool/templatelibrary/amd/src/search.js b/admin/tool/templatelibrary/amd/src/search.js index 9caf34416b2..1865457d91c 100644 --- a/admin/tool/templatelibrary/amd/src/search.js +++ b/admin/tool/templatelibrary/amd/src/search.js @@ -52,9 +52,8 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates' } else { $('[data-region="list-templates"] [data-action="clearsearch"]').addClass('d-none'); } - // Trigger the search. - document.location.hash = searchStr; + // Trigger the search. ajax.call([ {methodname: 'tool_templatelibrary_list_templates', args: {component: componentStr, search: searchStr, themename: themename}, @@ -96,7 +95,6 @@ define(['jquery', 'core/ajax', 'core/log', 'core/notification', 'core/templates' $(this).addClass('d-none'); }); - $('[data-region="input"]').val(document.location.hash.replace('#', '')); refreshSearch(config.theme); return {}; }); diff --git a/admin/tool/templatelibrary/classes/output/list_templates_page.php b/admin/tool/templatelibrary/classes/output/list_templates_page.php index cecf9cb6a12..27127b1f277 100644 --- a/admin/tool/templatelibrary/classes/output/list_templates_page.php +++ b/admin/tool/templatelibrary/classes/output/list_templates_page.php @@ -38,6 +38,22 @@ use tool_templatelibrary\api; */ class list_templates_page implements renderable, templatable { + /** @var string $component The currently selected component */ + protected $component; + /** @var string $search The current search */ + protected $search; + + /** + * Template page constructor + * + * @param string $component + * @param string $search + */ + public function __construct(string $component = '', string $search = '') { + $this->component = $component; + $this->search = $search; + } + /** * Export this data so it can be used as the context for a mustache template. * @@ -46,6 +62,7 @@ class list_templates_page implements renderable, templatable { public function export_for_template(renderer_base $output) { $data = new stdClass(); $data->allcomponents = array(); + $data->search = $this->search; $fulltemplatenames = api::list_templates(); $pluginmanager = core_plugin_manager::instance(); $components = array(); @@ -59,6 +76,7 @@ class list_templates_page implements renderable, templatable { foreach ($components as $component) { $info = new stdClass(); $info->component = $component; + $info->selected = ($component === $this->component); if (strpos($component, 'core') === 0) { $info->name = get_string('coresubsystem', 'tool_templatelibrary', $component); } else { diff --git a/admin/tool/templatelibrary/templates/list_templates_page.mustache b/admin/tool/templatelibrary/templates/list_templates_page.mustache index c5a454e8698..4fa788e3f61 100644 --- a/admin/tool/templatelibrary/templates/list_templates_page.mustache +++ b/admin/tool/templatelibrary/templates/list_templates_page.mustache @@ -72,10 +72,10 @@ {{/label}} {{$element}} - {{#allcomponents}} - + {{/allcomponents}} {{/element}} @@ -84,10 +84,10 @@ {{< core_form/element-template }} {{$element}} {{< core/search_input_auto }} - {{$label}}{{{ searchstring }}}{{/label}} - {{$placeholder}}{{#str}} - search, core - {{/str}}{{/placeholder}} + {{$label}} + {{#str}} search, tool_templatelibrary {{/str}} + {{/label}} + {{$value}}{{ search }}{{/value}} {{/ core/search_input_auto }} {{/element}} {{/ core_form/element-template }} diff --git a/lib/templates/search_input_auto.mustache b/lib/templates/search_input_auto.mustache index 7e89b09b105..d2cdc48776c 100644 --- a/lib/templates/search_input_auto.mustache +++ b/lib/templates/search_input_auto.mustache @@ -49,6 +49,7 @@ class="form-control withclear" placeholder="{{$placeholder}}{{#str}} search, core {{/str}}{{/placeholder}}" name="search" + value="{{$value}}{{/value}}" autocomplete="off" >