Skip to content

Commit

Permalink
Auto apply filter when JavaScript is available
Browse files Browse the repository at this point in the history
  • Loading branch information
codesoap committed Aug 10, 2024
1 parent 8981a4e commit f6aeafd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/mycolog/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var tmpls = make(map[string]*template.Template)
func init() {
tmplMap := map[string][]string{
"intro": {"base", "overview", "intro"},
"list": {"base", "overview", "list"},
"list": {"base", "auto_apply_filter", "overview", "list"},
"error": {"base", "error"},
"add": {"base", "register_change_script", "add"},
"details": {"base", "register_change_script", "details"},
Expand Down
11 changes: 11 additions & 0 deletions cmd/mycolog/tmpl/auto_apply_filter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{{define "script"}}
<script>
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('applyFilter').style.display = 'none';
});

function applyFilter() {
document.getElementById('filter').submit();
}
</script>
{{end}}
11 changes: 6 additions & 5 deletions cmd/mycolog/tmpl/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,27 +61,28 @@
{{if .MycSelected}}{{$typeName = "mycelium"}}{{end}}
{{if .SpawnSelected}}{{$typeName = "spawn"}}{{end}}
{{if .GrowSelected}}{{$typeName = "grows"}}{{end}}
<form class="pure-form pure-form-stacked filter">
<form id="filter" class="pure-form pure-form-stacked filter">
{{if gt (len .KnownSpecies) 1}}
<label for="species">Species</label>
<select name="species" id="species" autocomplete="off">
<select name="species" id="species" autocomplete="off"
onchange="applyFilter()">
<option>any</option>
{{range .KnownSpecies -}}
<option{{if eq $.WantedSpecies .}} selected{{end}}>{{.}}</option>
{{- end}}
</select>
{{end}}
<label for="gone" class="pure-checkbox">
<input type="checkbox" name="gone" id="gone"
<input type="checkbox" name="gone" id="gone" onchange="applyFilter()"
autocomplete="off" {{if .ShowGone}} checked{{end}}/>
List gone {{$typeName}}
</label>
{{if .MycSelected}}<label for="old" class="pure-checkbox">
<input type="checkbox" name="old" id="old"
<input type="checkbox" name="old" id="old" onchange="applyFilter()"
autocomplete="off" {{if .ShowOld}} checked{{end}}/>
List {{$typeName}} older than 30 days
</label>{{end}}
<button type="submit" class="pure-button pure-button-primary">
<button id="applyFilter" type="submit" class="pure-button pure-button-primary">
Apply filters
</button>
</form>
Expand Down

0 comments on commit f6aeafd

Please sign in to comment.