github.com/kotovmak/go-admin@v1.1.1/template/types/components.go (about) 1 // Copyright 2019 GoAdmin Core Team. All rights reserved. 2 // Use of this source code is governed by a Apache-2.0 style 3 // license that can be found in the LICENSE file. 4 5 package types 6 7 import ( 8 "html/template" 9 10 "github.com/kotovmak/go-admin/modules/menu" 11 "github.com/kotovmak/go-admin/plugins/admin/modules" 12 "github.com/kotovmak/go-admin/template/types/form" 13 ) 14 15 type FormAttribute interface { 16 SetHeader(value template.HTML) FormAttribute 17 SetContent(value FormFields) FormAttribute 18 SetTabContents(value []FormFields) FormAttribute 19 SetTabHeaders(value []string) FormAttribute 20 SetFooter(value template.HTML) FormAttribute 21 SetPrefix(value string) FormAttribute 22 SetUrl(value string) FormAttribute 23 SetPrimaryKey(value string) FormAttribute 24 SetId(id string) FormAttribute 25 SetAjax(successJS, errorJS template.JS) FormAttribute 26 SetHiddenFields(fields map[string]string) FormAttribute 27 SetFieldsHTML(html template.HTML) FormAttribute 28 SetMethod(value string) FormAttribute 29 SetHeadWidth(width int) FormAttribute 30 SetInputWidth(width int) FormAttribute 31 SetTitle(value template.HTML) FormAttribute 32 SetLayout(layout form.Layout) FormAttribute 33 SetOperationFooter(value template.HTML) FormAttribute 34 GetDefaultBoxHeader(hideBack bool) template.HTML 35 GetDetailBoxHeader(editUrl, deleteUrl string) template.HTML 36 GetBoxHeaderNoButton() template.HTML 37 GetContent() template.HTML 38 } 39 40 type BoxAttribute interface { 41 SetHeader(value template.HTML) BoxAttribute 42 SetBody(value template.HTML) BoxAttribute 43 SetNoPadding() BoxAttribute 44 SetFooter(value template.HTML) BoxAttribute 45 SetTitle(value template.HTML) BoxAttribute 46 WithHeadBorder() BoxAttribute 47 SetIframeStyle(iframe bool) BoxAttribute 48 SetAttr(attr template.HTMLAttr) BoxAttribute 49 SetStyle(value template.HTMLAttr) BoxAttribute 50 SetHeadColor(value string) BoxAttribute 51 SetTheme(value string) BoxAttribute 52 SetSecondHeader(value template.HTML) BoxAttribute 53 SetSecondHeadColor(value string) BoxAttribute 54 WithSecondHeadBorder() BoxAttribute 55 SetSecondHeaderClass(value string) BoxAttribute 56 GetContent() template.HTML 57 } 58 59 type ColAttribute interface { 60 SetSize(value S) ColAttribute 61 SetContent(value template.HTML) ColAttribute 62 AddContent(value template.HTML) ColAttribute 63 GetContent() template.HTML 64 } 65 66 type ImgAttribute interface { 67 SetWidth(value string) ImgAttribute 68 SetHeight(value string) ImgAttribute 69 WithModal() ImgAttribute 70 SetSrc(value template.HTML) ImgAttribute 71 GetContent() template.HTML 72 } 73 74 type LabelAttribute interface { 75 SetContent(value template.HTML) LabelAttribute 76 SetColor(value template.HTML) LabelAttribute 77 SetType(value string) LabelAttribute 78 GetContent() template.HTML 79 } 80 81 type RowAttribute interface { 82 SetContent(value template.HTML) RowAttribute 83 AddContent(value template.HTML) RowAttribute 84 GetContent() template.HTML 85 } 86 87 type ButtonAttribute interface { 88 SetContent(value template.HTML) ButtonAttribute 89 SetOrientationRight() ButtonAttribute 90 SetOrientationLeft() ButtonAttribute 91 SetMarginLeft(int) ButtonAttribute 92 SetMarginRight(int) ButtonAttribute 93 SetThemePrimary() ButtonAttribute 94 SetSmallSize() ButtonAttribute 95 AddClass(class string) ButtonAttribute 96 SetID(id string) ButtonAttribute 97 SetMiddleSize() ButtonAttribute 98 SetHref(string) ButtonAttribute 99 SetThemeWarning() ButtonAttribute 100 SetTheme(value string) ButtonAttribute 101 SetLoadingText(value template.HTML) ButtonAttribute 102 SetThemeDefault() ButtonAttribute 103 SetType(string) ButtonAttribute 104 GetContent() template.HTML 105 } 106 107 type TableAttribute interface { 108 SetThead(value Thead) TableAttribute 109 SetInfoList(value []map[string]InfoItem) TableAttribute 110 SetType(value string) TableAttribute 111 SetName(name string) TableAttribute 112 SetMinWidth(value string) TableAttribute 113 SetHideThead() TableAttribute 114 SetLayout(value string) TableAttribute 115 SetStyle(style string) TableAttribute 116 GetContent() template.HTML 117 } 118 119 type DataTableAttribute interface { 120 GetDataTableHeader() template.HTML 121 SetThead(value Thead) DataTableAttribute 122 SetInfoList(value []map[string]InfoItem) DataTableAttribute 123 SetEditUrl(value string) DataTableAttribute 124 SetDeleteUrl(value string) DataTableAttribute 125 SetNewUrl(value string) DataTableAttribute 126 SetPrimaryKey(value string) DataTableAttribute 127 SetStyle(style string) DataTableAttribute 128 SetAction(action template.HTML) DataTableAttribute 129 SetIsTab(value bool) DataTableAttribute 130 SetActionFold(fold bool) DataTableAttribute 131 SetHideThead() DataTableAttribute 132 SetLayout(value string) DataTableAttribute 133 SetButtons(btns template.HTML) DataTableAttribute 134 SetHideFilterArea(value bool) DataTableAttribute 135 SetHideRowSelector(value bool) DataTableAttribute 136 SetActionJs(aj template.JS) DataTableAttribute 137 SetNoAction() DataTableAttribute 138 SetInfoUrl(value string) DataTableAttribute 139 SetDetailUrl(value string) DataTableAttribute 140 SetHasFilter(hasFilter bool) DataTableAttribute 141 SetSortUrl(value string) DataTableAttribute 142 SetExportUrl(value string) DataTableAttribute 143 SetUpdateUrl(value string) DataTableAttribute 144 GetContent() template.HTML 145 } 146 147 type TreeAttribute interface { 148 SetTree(value []menu.Item) TreeAttribute 149 SetEditUrl(value string) TreeAttribute 150 SetOrderUrl(value string) TreeAttribute 151 SetUrlPrefix(value string) TreeAttribute 152 SetDeleteUrl(value string) TreeAttribute 153 GetContent() template.HTML 154 GetTreeHeader() template.HTML 155 } 156 157 type TreeViewAttribute interface { 158 SetTree(value TreeViewData) TreeViewAttribute 159 SetUrlPrefix(value string) TreeViewAttribute 160 SetID(id string) TreeViewAttribute 161 GetContent() template.HTML 162 } 163 164 type PaginatorAttribute interface { 165 SetCurPageStartIndex(value string) PaginatorAttribute 166 SetCurPageEndIndex(value string) PaginatorAttribute 167 SetTotal(value string) PaginatorAttribute 168 SetPreviousClass(value string) PaginatorAttribute 169 SetPreviousUrl(value string) PaginatorAttribute 170 SetPages(value []map[string]string) PaginatorAttribute 171 SetPageSizeList(value []string) PaginatorAttribute 172 SetNextClass(value string) PaginatorAttribute 173 SetNextUrl(value string) PaginatorAttribute 174 SetOption(value map[string]template.HTML) PaginatorAttribute 175 SetUrl(value string) PaginatorAttribute 176 SetExtraInfo(value template.HTML) PaginatorAttribute 177 SetEntriesInfo(value template.HTML) PaginatorAttribute 178 GetContent() template.HTML 179 } 180 181 type TabsAttribute interface { 182 SetData(value []map[string]template.HTML) TabsAttribute 183 GetContent() template.HTML 184 } 185 186 type AlertAttribute interface { 187 SetTheme(value string) AlertAttribute 188 SetTitle(value template.HTML) AlertAttribute 189 SetContent(value template.HTML) AlertAttribute 190 Warning(msg string) template.HTML 191 GetContent() template.HTML 192 } 193 194 type LinkAttribute interface { 195 OpenInNewTab() LinkAttribute 196 SetURL(value string) LinkAttribute 197 SetAttributes(attr template.HTMLAttr) LinkAttribute 198 SetClass(class template.HTML) LinkAttribute 199 NoPjax() LinkAttribute 200 SetTabTitle(value template.HTML) LinkAttribute 201 SetContent(value template.HTML) LinkAttribute 202 GetContent() template.HTML 203 } 204 205 type PopupAttribute interface { 206 SetID(value string) PopupAttribute 207 SetTitle(value template.HTML) PopupAttribute 208 SetDraggable() PopupAttribute 209 SetHideFooter() PopupAttribute 210 SetWidth(width string) PopupAttribute 211 SetHeight(height string) PopupAttribute 212 SetFooter(value template.HTML) PopupAttribute 213 SetFooterHTML(value template.HTML) PopupAttribute 214 SetBody(value template.HTML) PopupAttribute 215 SetSize(value string) PopupAttribute 216 GetContent() template.HTML 217 } 218 219 type PanelInfo struct { 220 Thead Thead `json:"thead"` 221 InfoList InfoList `json:"info_list"` 222 } 223 224 type Thead []TheadItem 225 226 type TheadItem struct { 227 Head string `json:"head"` 228 Sortable bool `json:"sortable"` 229 Field string `json:"field"` 230 Hide bool `json:"hide"` 231 Editable bool `json:"editable"` 232 EditType string `json:"edit_type"` 233 EditOption FieldOptions `json:"edit_option"` 234 Width string `json:"width"` 235 } 236 237 func (t Thead) GroupBy(group [][]string) []Thead { 238 var res = make([]Thead, len(group)) 239 240 for key, value := range group { 241 var newThead = make(Thead, 0) 242 243 for _, info := range t { 244 if modules.InArray(value, info.Field) { 245 newThead = append(newThead, info) 246 } 247 } 248 249 res[key] = newThead 250 } 251 252 return res 253 } 254 255 type TreeViewData struct { 256 Data TreeViewItems `json:"data,omitempty"` 257 Levels int `json:"levels,omitempty"` 258 BackColor string `json:"backColor,omitempty"` 259 BorderColor string `json:"borderColor,omitempty"` 260 CheckedIcon string `json:"checkedIcon,omitempty"` 261 CollapseIcon string `json:"collapseIcon,omitempty"` 262 Color string `json:"color,omitempty"` 263 EmptyIcon string `json:"emptyIcon,omitempty"` 264 EnableLinks bool `json:"enableLinks,omitempty"` 265 ExpandIcon string `json:"expandIcon,omitempty"` 266 MultiSelect bool `json:"multiSelect,omitempty"` 267 NodeIcon string `json:"nodeIcon,omitempty"` 268 OnhoverColor string `json:"onhoverColor,omitempty"` 269 SelectedIcon string `json:"selectedIcon,omitempty"` 270 SearchResultColor string `json:"searchResultColor,omitempty"` 271 SelectedBackColor string `json:"selectedBackColor,omitempty"` 272 SelectedColor string `json:"selectedColor,omitempty"` 273 ShowBorder bool `json:"showBorder,omitempty"` 274 ShowCheckbox bool `json:"showCheckbox,omitempty"` 275 ShowIcon bool `json:"showIcon,omitempty"` 276 ShowTags bool `json:"showTags,omitempty"` 277 UncheckedIcon string `json:"uncheckedIcon,omitempty"` 278 279 SearchResultBackColor string `json:"searchResultBackColor,omitempty"` 280 HighlightSearchResults bool `json:"highlightSearchResults,omitempty"` 281 } 282 283 type TreeViewItems []TreeViewItem 284 285 type TreeViewItemState struct { 286 Checked bool `json:"checked,omitempty"` 287 Disabled bool `json:"disabled,omitempty"` 288 Expanded bool `json:"expanded,omitempty"` 289 Selected bool `json:"selected,omitempty"` 290 } 291 292 type TreeViewItem struct { 293 Text string `json:"text,omitempty"` 294 Icon string `json:"icon,omitempty"` 295 SelectedIcon string `json:"selected_icon,omitempty"` 296 Color string `json:"color,omitempty"` 297 BackColor string `json:"backColor,omitempty"` 298 Href string `json:"href,omitempty"` 299 Selectable bool `json:"selectable,omitempty"` 300 State TreeViewItemState `json:"state,omitempty"` 301 Tags []string `json:"tags,omitempty"` 302 Nodes TreeViewItems `json:"nodes,omitempty"` 303 }