} 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},
$(this).addClass('d-none');
});
- $('[data-region="input"]').val(document.location.hash.replace('#', ''));
refreshSearch(config.theme);
return {};
});
*/
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.
*
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();
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 {
{{/label}}
{{$element}}
- <select id="selectcomponent" class="form-control" data-field="component">
+ <select id="selectcomponent" name="component" class="form-control" data-field="component">
<option value="">{{#str}}all, tool_templatelibrary{{/str}}</option>
{{#allcomponents}}
- <option value="{{component}}">{{name}}</option>
+ <option value="{{component}}" {{#selected}}selected{{/selected}}>{{name}}</option>
{{/allcomponents}}
</select>
{{/element}}
{{< 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 }}
class="form-control withclear"
placeholder="{{$placeholder}}{{#str}} search, core {{/str}}{{/placeholder}}"
name="search"
+ value="{{$value}}{{/value}}"
autocomplete="off"
>
<button