Skip to content

Commit

Permalink
feat(form): add many form components
Browse files Browse the repository at this point in the history
  • Loading branch information
cg33 committed May 17, 2020
1 parent 0e7e029 commit 0f31eea
Show file tree
Hide file tree
Showing 9 changed files with 201 additions and 105 deletions.
82 changes: 41 additions & 41 deletions adminlte/resource/assets.go

Large diffs are not rendered by default.

48 changes: 40 additions & 8 deletions adminlte/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,27 +185,57 @@ var TemplateList = map[string]string{"admin_panel": `{{define "admin_panel"}}
{{range $key, $v := .Options }}
<span class="icheck">
<label class="checkbox-inline">
<input type="checkbox" class="{{$.Field}}" {{$v.SelectedLabel}} value='{{$v.Value}}' name="{{$.Field}}[]" class="grid-select-all" style="position: absolute; opacity: 0;">
&nbsp;{{$v.Text}}&nbsp;&nbsp;
<input type="checkbox" class="{{$.FieldClass}}" {{$v.SelectedLabel}} value='{{$v.Value}}' name="{{$.Field}}" style="position: absolute; opacity: 0;">
{{if ne $v.Text ""}}
&nbsp;{{$v.Text}}&nbsp;&nbsp;
{{end}}
</label>
</span>
{{end}}
<script>
$('.{{.Field}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'})
$('input.{{.FieldClass}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'})
</script>
{{end}}`, "components/form/checkbox_stacked": `{{define "form_checkbox_stacked"}}
{{end}}`, "components/form/checkbox_single": `{{define "form_checkbox_single"}}
<span class="icheck">
<label class="checkbox-inline">
<input type="checkbox" class="{{.FieldClass}}" {{(index .Options 0).SelectedLabel}} value='{{(index .Options 0).Value}}' name="{{.Field}}" style="position: absolute; opacity: 0;">
{{if ne (index .Options 0).Text ""}}
&nbsp;{{(index .Options 0).Text}}&nbsp;&nbsp;
{{end}}
{{if ne (index .Options 0).SelectedLabel "checked"}}
<input type="hidden" value="{{(index .Options 1).Value}}" name="{{.Field}}">
{{end}}
</label>
</span>
<script>
$('input.{{.FieldClass}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'}).on('ifChanged', function () {
if (this.checked) {
let next = $(this).parent().next();
if (next) {
next.remove();
}
} else {
$(this).parent().parent().append('<input type="hidden" value="{{(index .Options 1).Value}}" name="{{.Field}}">')
}
});
</script>
{{end}}
`, "components/form/checkbox_stacked": `{{define "form_checkbox_stacked"}}
<div class="checkbox_stacked" style="margin-top: -7px;">
{{range $key, $v := .Options }}
<div class="checkbox icheck">
<label class="checkbox-inline">
<input type="checkbox" class="{{$.Field}}" {{$v.SelectedLabel}} value='{{$v.Value}}' name="{{$.Field}}[]" class="grid-select-all" style="position: absolute; opacity: 0;">
&nbsp;{{$v.Text}}&nbsp;&nbsp;
<input type="checkbox" class="{{$.FieldClass}}" {{$v.SelectedLabel}} value='{{$v.Value}}' name="{{$.Field}}" style="position: absolute; opacity: 0;">
{{if ne $v.Text ""}}
&nbsp;{{$v.Text}}&nbsp;&nbsp;
{{end}}
</label>
</div>
{{end}}
</div>
<script>
$('.{{.Field}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'})
$('input.{{.FieldClass}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'})
</script>
{{end}}`, "components/form/code": `{{define "form_code"}}
<pre id="{{.Field}}" class="ace_editor" style="min-height:200px">
Expand Down Expand Up @@ -506,7 +536,7 @@ var TemplateList = map[string]string{"admin_panel": `{{define "admin_panel"}}
</div>
<script>
$(function () {
$('.{{.Field}}').iCheck({radioClass: 'iradio_minimal-blue'});
$('input.{{.Field}}').iCheck({radioClass: 'iradio_minimal-blue'});
});
</script>
{{else}}
Expand Down Expand Up @@ -828,6 +858,8 @@ var TemplateList = map[string]string{"admin_panel": `{{define "admin_panel"}}
{{ template "form_rich_text" . }}
{{else if eq .FormType.String "code"}}
{{ template "form_code" . }}
{{else if eq .FormType.String "checkbox_single"}}
{{ template "form_checkbox_single" . }}
{{else if eq .FormType.String "checkbox"}}
{{ template "form_checkbox" . }}
{{else if eq .FormType.String "checkbox_stacked"}}
Expand Down
8 changes: 5 additions & 3 deletions common/pages/components/form/checkbox.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
{{range $key, $v := .Options }}
<span class="icheck">
<label class="checkbox-inline">
<input type="checkbox" class="{{$.Field}}" {{$v.SelectedLabel}} value='{{$v.Value}}' name="{{$.Field}}[]" class="grid-select-all" style="position: absolute; opacity: 0;">
&nbsp;{{$v.Text}}&nbsp;&nbsp;
<input type="checkbox" class="{{$.FieldClass}}" {{$v.SelectedLabel}} value='{{$v.Value}}' name="{{$.Field}}" style="position: absolute; opacity: 0;">
{{if ne $v.Text ""}}
&nbsp;{{$v.Text}}&nbsp;&nbsp;
{{end}}
</label>
</span>
{{end}}
<script>
$('.{{.Field}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'})
$('input.{{.FieldClass}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'})
</script>
{{end}}
26 changes: 26 additions & 0 deletions common/pages/components/form/checkbox_single.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{{define "form_checkbox_single"}}
<span class="icheck">
<label class="checkbox-inline">
<input type="checkbox" class="{{.FieldClass}}" {{(index .Options 0).SelectedLabel}} value='{{(index .Options 0).Value}}' name="{{.Field}}" style="position: absolute; opacity: 0;">
{{if ne (index .Options 0).Text ""}}
&nbsp;{{(index .Options 0).Text}}&nbsp;&nbsp;
{{end}}
{{if ne (index .Options 0).SelectedLabel "checked"}}
<input type="hidden" value="{{(index .Options 1).Value}}" name="{{.Field}}">
{{end}}
</label>
</span>
<script>
$('input.{{.FieldClass}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'}).on('ifChanged', function () {
if (this.checked) {
let next = $(this).parent().next();
if (next) {
next.remove();
}
} else {
$(this).parent().parent().append('<input type="hidden" value="{{(index .Options 1).Value}}" name="{{.Field}}">')
}
});
</script>
{{end}}

8 changes: 5 additions & 3 deletions common/pages/components/form/checkbox_stacked.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
{{range $key, $v := .Options }}
<div class="checkbox icheck">
<label class="checkbox-inline">
<input type="checkbox" class="{{$.Field}}" {{$v.SelectedLabel}} value='{{$v.Value}}' name="{{$.Field}}[]" class="grid-select-all" style="position: absolute; opacity: 0;">
&nbsp;{{$v.Text}}&nbsp;&nbsp;
<input type="checkbox" class="{{$.FieldClass}}" {{$v.SelectedLabel}} value='{{$v.Value}}' name="{{$.Field}}" style="position: absolute; opacity: 0;">
{{if ne $v.Text ""}}
&nbsp;{{$v.Text}}&nbsp;&nbsp;
{{end}}
</label>
</div>
{{end}}
</div>
<script>
$('.{{.Field}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'})
$('input.{{.FieldClass}}').iCheck({checkboxClass: 'icheckbox_minimal-blue'})
</script>
{{end}}
2 changes: 1 addition & 1 deletion common/pages/components/form/radio.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</div>
<script>
$(function () {
$('.{{.Field}}').iCheck({radioClass: 'iradio_minimal-blue'});
$('input.{{.Field}}').iCheck({radioClass: 'iradio_minimal-blue'});
});
</script>
{{else}}
Expand Down
2 changes: 2 additions & 0 deletions common/pages/components/form_components.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
{{ template "form_rich_text" . }}
{{else if eq .FormType.String "code"}}
{{ template "form_code" . }}
{{else if eq .FormType.String "checkbox_single"}}
{{ template "form_checkbox_single" . }}
{{else if eq .FormType.String "checkbox"}}
{{ template "form_checkbox" . }}
{{else if eq .FormType.String "checkbox_stacked"}}
Expand Down
Loading

0 comments on commit 0f31eea

Please sign in to comment.