File size: 7,167 Bytes
530729e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
package components
import (
"fmt"
"html/template"
"strings"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/modules/language"
"github.com/GoAdminGroup/go-admin/modules/utils"
form2 "github.com/GoAdminGroup/go-admin/plugins/admin/modules/form"
"github.com/GoAdminGroup/go-admin/template/types"
"github.com/GoAdminGroup/go-admin/template/types/form"
)
type FormAttribute struct {
Name string
Id string
Header template.HTML
Content types.FormFields
ContentList []types.FormFields
Layout form.Layout
TabContents []types.FormFields
TabHeaders []string
Footer template.HTML
Url string
FieldsHTML template.HTML
Method string
PrimaryKey string
Ajax bool
AjaxSuccessJS template.JS
AjaxErrorJS template.JS
HeadWidth int
InputWidth int
HiddenFields map[string]string
Title template.HTML
OperationFooter template.HTML
Prefix string
CdnUrl string
Horizontal bool
types.Attribute
}
func (compo *FormAttribute) SetHeader(value template.HTML) types.FormAttribute {
compo.Header = value
return compo
}
func (compo *FormAttribute) SetPrimaryKey(value string) types.FormAttribute {
compo.PrimaryKey = value
return compo
}
func (compo *FormAttribute) SetHorizontal(value bool) types.FormAttribute {
compo.Horizontal = value
return compo
}
func (compo *FormAttribute) SetContent(value types.FormFields) types.FormAttribute {
compo.Content = value
return compo
}
func (compo *FormAttribute) SetId(id string) types.FormAttribute {
compo.Id = id
return compo
}
func (compo *FormAttribute) SetAjax(successJS, errorJS template.JS) types.FormAttribute {
if successJS != template.JS("") && errorJS != template.JS("") {
compo.Ajax = true
compo.AjaxErrorJS = errorJS
compo.AjaxSuccessJS = successJS
}
return compo
}
func (compo *FormAttribute) SetTabContents(value []types.FormFields) types.FormAttribute {
compo.TabContents = value
return compo
}
func (compo *FormAttribute) SetTabHeaders(value []string) types.FormAttribute {
compo.TabHeaders = value
return compo
}
func (compo *FormAttribute) SetHeadWidth(width int) types.FormAttribute {
if width > 0 {
if width > 12 {
width = 12
}
compo.HeadWidth = width
}
return compo
}
func (compo *FormAttribute) SetInputWidth(width int) types.FormAttribute {
if width > 0 {
if width > 12 {
width = 12
}
compo.InputWidth = width
}
return compo
}
func (compo *FormAttribute) SetFieldsHTML(html template.HTML) types.FormAttribute {
compo.FieldsHTML = html
return compo
}
func (compo *FormAttribute) SetFooter(value template.HTML) types.FormAttribute {
compo.Footer = value
return compo
}
func (compo *FormAttribute) SetLayout(layout form.Layout) types.FormAttribute {
compo.Layout = layout
return compo
}
func (compo *FormAttribute) SetPrefix(value string) types.FormAttribute {
compo.Prefix = value
return compo
}
func (compo *FormAttribute) SetUrl(value string) types.FormAttribute {
compo.Url = value
return compo
}
func (compo *FormAttribute) SetHiddenFields(fields map[string]string) types.FormAttribute {
compo.HiddenFields = fields
return compo
}
func (compo *FormAttribute) SetMethod(value string) types.FormAttribute {
compo.Method = value
return compo
}
func (compo *FormAttribute) SetTitle(value template.HTML) types.FormAttribute {
compo.Title = value
return compo
}
func (compo *FormAttribute) GetDefaultBoxHeader(hideBack bool) template.HTML {
if hideBack {
return template.HTML(fmt.Sprintf(`<h3 class="box-title">%s</h3>`, language.GetFromHtml(compo.Title)))
}
return template.HTML(fmt.Sprintf(`<h3 class="box-title">%s</h3>
<div class="box-tools">
<div class="btn-group pull-right" style="margin-right: 10px">
<a href='%s' class="btn btn-sm btn-default form-history-back"><i
class="fa fa-arrow-left"></i> %s</a>
</div>
</div>`, language.GetFromHtml(compo.Title), compo.HiddenFields[form2.PreviousKey], language.Get("Back")))
}
func (compo *FormAttribute) GetDetailBoxHeader(editUrl, deleteUrl string) template.HTML {
var (
editBtn string
deleteBtn string
)
if editUrl != "" {
editBtn = fmt.Sprintf(`
<div class="btn-group pull-right" style="margin-right: 10px">
<a href='%s' class="btn btn-sm btn-primary"><i
class="fa fa-edit"></i> %s</a>
</div>`, editUrl, language.Get("Edit"))
}
if deleteUrl != "" {
deleteBtn = fmt.Sprintf(`
<div class="btn-group pull-right" style="margin-right: 10px">
<a href='javascript:;' class="btn btn-sm btn-danger delete-btn"><i
class="fa fa-trash"></i> %s</a>
</div>`, language.Get("Delete"))
}
return template.HTML(`<h3 class="box-title">`) + language.GetFromHtml(compo.Title) + template.HTML(`</h3>
<div class="box-tools">
`+deleteBtn+editBtn+`
<div class="btn-group pull-right" style="margin-right: 10px">
<a href='`+compo.HiddenFields[form2.PreviousKey]+`' class="btn btn-sm btn-default form-history-back"><i
class="fa fa-arrow-left"></i> `+language.Get("Back")+`</a>
</div>
</div>`)
}
func (compo *FormAttribute) GetBoxHeaderNoButton() template.HTML {
return template.HTML(fmt.Sprintf(`<h3 class="box-title">%s</h3>`, language.GetFromHtml(compo.Title)))
}
func (compo *FormAttribute) SetOperationFooter(value template.HTML) types.FormAttribute {
compo.OperationFooter = value
return compo
}
func (compo *FormAttribute) GetContent() template.HTML {
compo.CdnUrl = config.GetAssetUrl()
if compo.Id == "" {
compo.Id = utils.Uuid(10)
}
if col := compo.Layout.Col(); col > 0 {
compo.ContentList = make([]types.FormFields, col)
index := 0
for i := 0; i < len(compo.Content); i++ {
ii := index % col
compo.ContentList[ii] = append(compo.ContentList[ii], compo.Content[i])
if i < len(compo.Content)-1 {
if strings.Contains(compo.Content[i+1].Field, "__goadmin_operator__") {
compo.ContentList[ii] = append(compo.ContentList[ii], compo.Content[i+1])
i++
}
}
index++
}
}
return ComposeHtml(compo.TemplateList, compo.Separation, *compo, "form",
"form/default", "form/file", "form/multi_file", "form/textarea", "form/custom", "form/rate", "form/slider",
"form/selectbox", "form/text", "form/table", "form/radio", "form/switch", "form/checkbox", "form/checkbox_single",
"form/checkbox_stacked", "form/password", "form/code", "form/array", "form/select", "form/singleselect",
"form/richtext", "form/iconpicker", "form/datetime", "form/number", "form/number_range",
"form/email", "form/url", "form/ip", "form/color", "form/currency", "form_components", "form/datetime_range",
"form_layout_default", "form_layout_two_col", "form_layout_tab", "form_components_layout", "form_layout_flow", "form_layout_filter")
}
|