2020-01-09 06:33:11 -08:00
|
|
|
package stanza
|
|
|
|
|
|
|
|
import "encoding/xml"
|
|
|
|
|
|
|
|
type FormType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
FormTypeCancel = "cancel"
|
|
|
|
FormTypeForm = "form"
|
|
|
|
FormTypeResult = "result"
|
|
|
|
FormTypeSubmit = "submit"
|
|
|
|
)
|
|
|
|
|
|
|
|
// See XEP-0004 and XEP-0068
|
|
|
|
// Pointer semantics
|
|
|
|
type Form struct {
|
2020-01-31 02:48:03 -08:00
|
|
|
XMLName xml.Name `xml:"jabber:x:data x"`
|
|
|
|
Instructions []string `xml:"instructions"`
|
|
|
|
Title string `xml:"title,omitempty"`
|
|
|
|
Fields []*Field `xml:"field,omitempty"`
|
|
|
|
Reported *FormItem `xml:"reported"`
|
|
|
|
Items []FormItem `xml:"item,omitempty"`
|
|
|
|
Type string `xml:"type,attr"`
|
2020-01-09 06:33:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type FormItem struct {
|
2020-01-31 02:48:03 -08:00
|
|
|
XMLName xml.Name
|
|
|
|
Fields []Field `xml:"field,omitempty"`
|
2020-01-09 06:33:11 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
type Field struct {
|
|
|
|
XMLName xml.Name `xml:"field"`
|
|
|
|
Description string `xml:"desc,omitempty"`
|
|
|
|
Required *string `xml:"required"`
|
|
|
|
ValuesList []string `xml:"value"`
|
|
|
|
Options []Option `xml:"option,omitempty"`
|
|
|
|
Var string `xml:"var,attr,omitempty"`
|
|
|
|
Type string `xml:"type,attr,omitempty"`
|
|
|
|
Label string `xml:"label,attr,omitempty"`
|
|
|
|
}
|
|
|
|
|
2020-01-14 13:47:49 -08:00
|
|
|
func NewForm(fields []*Field, formType string) *Form {
|
2020-01-09 06:33:11 -08:00
|
|
|
return &Form{
|
|
|
|
Type: formType,
|
|
|
|
Fields: fields,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type FieldType string
|
|
|
|
|
|
|
|
const (
|
|
|
|
FieldTypeBool = "boolean"
|
|
|
|
FieldTypeFixed = "fixed"
|
|
|
|
FieldTypeHidden = "hidden"
|
|
|
|
FieldTypeJidMulti = "jid-multi"
|
|
|
|
FieldTypeJidSingle = "jid-single"
|
|
|
|
FieldTypeListMulti = "list-multi"
|
|
|
|
FieldTypeListSingle = "list-single"
|
|
|
|
FieldTypeTextMulti = "text-multi"
|
|
|
|
FieldTypeTextPrivate = "text-private"
|
|
|
|
FieldTypeTextSingle = "text-Single"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Option struct {
|
|
|
|
XMLName xml.Name `xml:"option"`
|
|
|
|
Label string `xml:"label,attr,omitempty"`
|
|
|
|
ValuesList []string `xml:"value"`
|
|
|
|
}
|