mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 15:01:31 +00:00
delete forms
This commit is contained in:
parent
3d74a1a436
commit
7a376c32be
@ -1,15 +0,0 @@
|
||||
package elements
|
||||
|
||||
type Button struct {
|
||||
Element
|
||||
}
|
||||
|
||||
func NewButton() *Button {
|
||||
b := &Button{}
|
||||
b.options = make(map[string]interface{})
|
||||
b.attributes = make(map[string]interface{})
|
||||
b.labelAttributes = make(map[string]interface{})
|
||||
b.labelOptions = make(map[string]interface{})
|
||||
b.SetAttribute("type", "button")
|
||||
return b
|
||||
}
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1,232 +0,0 @@
|
||||
package elements
|
||||
|
||||
type LableInterface interface {
|
||||
SetLable(label string)
|
||||
GetLable() (label string)
|
||||
SetLabelAttributes(labelattrs map[string]interface{})
|
||||
GetLabelAttributes() (labelattrs map[string]interface{})
|
||||
SetLabelOptions(labelOptions map[string]interface{})
|
||||
GetLabelOptions() (labelOptions map[string]interface{})
|
||||
ClearLabelOptions()
|
||||
RemoveLabelOptions(keys []string)
|
||||
SetLabelOption(key string, val interface{})
|
||||
GetLabelOption(key string) (val interface{})
|
||||
RemoveLabelOption(key string)
|
||||
HasLabelOption(key string) bool
|
||||
}
|
||||
|
||||
type ElementInterface interface {
|
||||
SetName(name string)
|
||||
GetName() (name string)
|
||||
SetOptions(options map[string]interface{})
|
||||
SetOption(key string, val interface{})
|
||||
GetOptions() (options map[string]interface{})
|
||||
GetOption(key string) (val interface{})
|
||||
SetAttribute(key string, val interface{})
|
||||
GetAttribute(key string) (val interface{})
|
||||
RemoveAttribute(key string)
|
||||
HasAttribute(key string) bool
|
||||
SetAttributes(attributes map[string]interface{})
|
||||
GetAttributes() (attributes map[string]interface{})
|
||||
RemoveAttributes(keys []string)
|
||||
ClearAttributes()
|
||||
SetValue(val interface{})
|
||||
GetValue() (val interface{})
|
||||
SetMessages(msg string)
|
||||
GetMessages() (msg string)
|
||||
SetValidator(v ValidatorInterface)
|
||||
Valid(val interface{}) bool
|
||||
GetMessage() string
|
||||
LableInterface
|
||||
}
|
||||
|
||||
type ValidatorInterface interface {
|
||||
IsValid(val interface{}) bool
|
||||
GetMessages() (msg string)
|
||||
}
|
||||
|
||||
type Element struct {
|
||||
options map[string]interface{}
|
||||
attributes map[string]interface{}
|
||||
labelAttributes map[string]interface{}
|
||||
labelOptions map[string]interface{}
|
||||
value interface{}
|
||||
lable string
|
||||
messages string
|
||||
validator ValidatorInterface
|
||||
}
|
||||
|
||||
func (e *Element) SetName(name string) {
|
||||
e.SetAttribute("name", name)
|
||||
}
|
||||
|
||||
func (e *Element) GetName() (name string) {
|
||||
return e.GetAttribute("name").(string)
|
||||
}
|
||||
|
||||
func (e *Element) SetOptions(options map[string]interface{}) {
|
||||
if val, ok := options["label"]; ok {
|
||||
e.SetLable(val.(string))
|
||||
}
|
||||
|
||||
if val, ok := options["label_attributes"]; ok {
|
||||
e.SetLabelAttributes(val.(map[string]interface{}))
|
||||
}
|
||||
|
||||
if val, ok := options["label_options"]; ok {
|
||||
e.SetLabelOptions(val.(map[string]interface{}))
|
||||
}
|
||||
e.options = options
|
||||
}
|
||||
|
||||
func (e *Element) SetOption(key string, val interface{}) {
|
||||
e.options[key] = val
|
||||
}
|
||||
|
||||
func (e *Element) GetOptions() (options map[string]interface{}) {
|
||||
return e.options
|
||||
}
|
||||
|
||||
func (e *Element) GetOption(key string) (val interface{}) {
|
||||
if val, ok := e.options[key]; ok {
|
||||
return val
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Element) SetAttribute(key string, val interface{}) {
|
||||
e.attributes[key] = val
|
||||
}
|
||||
|
||||
func (e *Element) GetAttribute(key string) (val interface{}) {
|
||||
if val, ok := e.attributes[key]; ok {
|
||||
return val
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Element) RemoveAttribute(key string) {
|
||||
delete(e.attributes, key)
|
||||
}
|
||||
|
||||
func (e *Element) HasAttribute(key string) bool {
|
||||
if _, ok := e.attributes[key]; ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e *Element) SetAttributes(attributes map[string]interface{}) {
|
||||
for key, val := range attributes {
|
||||
e.SetAttribute(key, val)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Element) GetAttributes() (attributes map[string]interface{}) {
|
||||
return e.attributes
|
||||
}
|
||||
|
||||
func (e *Element) RemoveAttributes(keys []string) {
|
||||
for _, key := range keys {
|
||||
e.RemoveAttribute(key)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Element) ClearAttributes() {
|
||||
e.attributes = make(map[string]interface{})
|
||||
}
|
||||
|
||||
func (e *Element) SetValue(val interface{}) {
|
||||
e.value = val
|
||||
}
|
||||
|
||||
func (e *Element) GetValue() (val interface{}) {
|
||||
return e.value
|
||||
}
|
||||
|
||||
func (e *Element) SetLable(label string) {
|
||||
e.lable = label
|
||||
}
|
||||
|
||||
func (e *Element) GetLable() (label string) {
|
||||
return e.lable
|
||||
}
|
||||
|
||||
func (e *Element) SetLabelAttributes(labelattrs map[string]interface{}) {
|
||||
e.labelAttributes = labelattrs
|
||||
}
|
||||
|
||||
func (e *Element) GetLabelAttributes() (labelattrs map[string]interface{}) {
|
||||
return e.labelAttributes
|
||||
}
|
||||
|
||||
func (e *Element) SetLabelOptions(labelOptions map[string]interface{}) {
|
||||
for key, val := range labelOptions {
|
||||
e.SetLabelOption(key, val)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Element) GetLabelOptions() (labelOptions map[string]interface{}) {
|
||||
return e.labelOptions
|
||||
}
|
||||
|
||||
func (e *Element) ClearLabelOptions() {
|
||||
e.labelOptions = make(map[string]interface{})
|
||||
}
|
||||
|
||||
func (e *Element) RemoveLabelOptions(keys []string) {
|
||||
for _, key := range keys {
|
||||
e.RemoveLabelOption(key)
|
||||
}
|
||||
}
|
||||
|
||||
func (e *Element) SetLabelOption(key string, val interface{}) {
|
||||
e.labelOptions[key] = val
|
||||
}
|
||||
|
||||
func (e *Element) GetLabelOption(key string) (val interface{}) {
|
||||
if v, ok := e.labelOptions[key]; ok {
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *Element) RemoveLabelOption(key string) {
|
||||
delete(e.labelOptions, key)
|
||||
}
|
||||
|
||||
func (e *Element) HasLabelOption(key string) bool {
|
||||
if _, ok := e.labelOptions[key]; ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e *Element) SetMessages(msg string) {
|
||||
e.messages = msg
|
||||
}
|
||||
|
||||
func (e *Element) GetMessages() (msg string) {
|
||||
return e.messages
|
||||
}
|
||||
|
||||
func (e *Element) SetValidator(v ValidatorInterface) {
|
||||
e.validator = v
|
||||
}
|
||||
|
||||
func (e *Element) Valid(val interface{}) bool {
|
||||
if e.validator == nil {
|
||||
return true
|
||||
}
|
||||
if e.validator.IsValid(val) {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (e *Element) GetMessage() string {
|
||||
if e.validator == nil {
|
||||
return ""
|
||||
}
|
||||
return e.validator.GetMessages()
|
||||
}
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1,15 +0,0 @@
|
||||
package elements
|
||||
|
||||
type Submit struct {
|
||||
Element
|
||||
}
|
||||
|
||||
func NewSubmit() *Submit {
|
||||
b := &Submit{}
|
||||
b.options = make(map[string]interface{})
|
||||
b.attributes = make(map[string]interface{})
|
||||
b.labelAttributes = make(map[string]interface{})
|
||||
b.labelOptions = make(map[string]interface{})
|
||||
b.SetAttribute("type", "submit")
|
||||
return b
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package elements
|
||||
|
||||
type Text struct {
|
||||
Element
|
||||
}
|
||||
|
||||
func NewText() *Text {
|
||||
b := &Text{}
|
||||
b.options = make(map[string]interface{})
|
||||
b.attributes = make(map[string]interface{})
|
||||
b.labelAttributes = make(map[string]interface{})
|
||||
b.labelOptions = make(map[string]interface{})
|
||||
b.SetAttribute("type", "text")
|
||||
return b
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package elements
|
||||
|
||||
type Textarea struct {
|
||||
Element
|
||||
}
|
||||
|
||||
func NewTextarea() *Textarea {
|
||||
b := &Textarea{}
|
||||
b.options = make(map[string]interface{})
|
||||
b.attributes = make(map[string]interface{})
|
||||
b.labelAttributes = make(map[string]interface{})
|
||||
b.labelOptions = make(map[string]interface{})
|
||||
b.SetAttribute("type", "textarea")
|
||||
return b
|
||||
}
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1 +0,0 @@
|
||||
package elements
|
@ -1,57 +0,0 @@
|
||||
// Beego (http://beego.me/)
|
||||
// @description beego is an open-source, high-performance web framework for the Go programming language.
|
||||
// @link http://github.com/astaxie/beego for the canonical source repository
|
||||
// @license http://github.com/astaxie/beego/blob/master/LICENSE
|
||||
// @authors astaxie
|
||||
|
||||
package forms
|
||||
|
||||
import (
|
||||
"github.com/astaxie/beego/forms/elements"
|
||||
)
|
||||
|
||||
type Form struct {
|
||||
elements map[string]elements.ElementInterface
|
||||
}
|
||||
|
||||
func NewForm() *Form {
|
||||
f := &Form{}
|
||||
f.elements = make(map[string]elements.ElementInterface)
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *Form) Init() *Form {
|
||||
f.elements = make(map[string]elements.ElementInterface)
|
||||
}
|
||||
|
||||
func (f *Form) Valid(data map[string]interface{}) bool {
|
||||
for k, val := range data {
|
||||
if e, ok := f.elements[k]; ok {
|
||||
if !e.Valid(val) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (f *Form) SetData() {
|
||||
|
||||
}
|
||||
|
||||
func (f *Form) Bind() {
|
||||
|
||||
}
|
||||
|
||||
func (f *Form) SaveData() {
|
||||
|
||||
}
|
||||
|
||||
func (f *Form) AddElement(e elements.ElementInterface) {
|
||||
name := e.GetName()
|
||||
f.elements[name] = e
|
||||
}
|
||||
|
||||
func (f *Form) Render() string {
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package forms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"./elements"
|
||||
)
|
||||
|
||||
func formTest(t *testing.T) {
|
||||
rf := NewForm()
|
||||
username := elements.NewText()
|
||||
username.SetAttribute("name", "username")
|
||||
username.SetAttribute("id", "username")
|
||||
rf.AddElement(username)
|
||||
|
||||
button := elements.NewSubmit()
|
||||
rf.AddElement(rf)
|
||||
|
||||
fmt.Println(rf.Render())
|
||||
}
|
Loading…
Reference in New Issue
Block a user