本文整理汇总了Golang中github.com/ungerik/go-start/model.MetaData类的典型用法代码示例。如果您正苦于以下问题:Golang MetaData类的具体用法?Golang MetaData怎么用?Golang MetaData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MetaData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewInput
func (self *MongoRefController) NewInput(withLabel bool, metaData *model.MetaData, form *Form) (input View, err error) {
mongoRef := metaData.Value.Addr().Interface().(*mongo.Ref)
options := []string{""}
for doc := self.OptionsIterator.Next(); doc != nil; doc = self.OptionsIterator.Next() {
name := self.getLabel(doc)
for _, option := range options {
if option == name {
return nil, fmt.Errorf("Names of mongo documents must be unique, found double '%s'", name)
}
}
options = append(options, name)
}
name := ""
doc, err := mongoRef.Get()
if err != nil {
return nil, err
}
if doc != nil {
name = self.getLabel(doc)
}
input = &Select{
Class: form.FieldInputClass(metaData),
Name: metaData.Selector(),
Model: &StringsSelectModel{options, name},
Disabled: form.IsFieldDisabled(metaData),
Size: 1,
}
if withLabel {
return AddStandardLabel(form, input, metaData), nil
}
return input, nil
}
示例2: NewInput
func (self ModelStringController) NewInput(withLabel bool, metaData *model.MetaData, form *Form) (input View, err error) {
str := metaData.Value.Addr().Interface().(*model.String)
textField := &TextField{
Class: form.FieldInputClass(metaData),
Name: metaData.Selector(),
Text: str.Get(),
Size: form.GetInputSize(metaData),
Disabled: form.IsFieldDisabled(metaData),
Placeholder: form.InputFieldPlaceholder(metaData),
Required: form.IsFieldRequired(metaData) && !metaData.IsSelfOrParentIndexed(),
Title: form.FieldLabel(metaData),
}
if maxlen, ok, _ := str.Maxlen(metaData); ok {
textField.MaxLength = maxlen
if maxlen < textField.Size {
textField.Size = maxlen
}
}
if metaData.BoolAttrib("view", "search") {
textField.Type = SearchTextField
}
if metaData.BoolAttrib("view", "autofocus") {
textField.Autofocus = true
}
if pattern, ok := metaData.Attrib("view", "pattern"); ok {
textField.Pattern = pattern
}
if withLabel {
return AddStandardLabel(form, textField, metaData), nil
}
return textField, nil
}
示例3: NewInput
func (self ModelPasswordController) NewInput(withLabel bool, metaData *model.MetaData, form *Form) (input View, err error) {
password := metaData.Value.Addr().Interface().(*model.Password)
textField := &TextField{
Class: form.FieldInputClass(metaData),
Name: metaData.Selector(),
Type: PasswordTextField,
Text: password.Get(),
Size: form.GetInputSize(metaData),
Disabled: form.IsFieldDisabled(metaData),
Placeholder: form.InputFieldPlaceholder(metaData),
Required: form.IsFieldRequired(metaData),
Title: form.FieldLabel(metaData),
}
if maxlen, ok, _ := password.Maxlen(metaData); ok {
textField.MaxLength = maxlen
if maxlen < textField.Size {
textField.Size = maxlen
}
}
if metaData.BoolAttrib("view", "autofocus") {
textField.Autofocus = true
}
if withLabel {
return AddStandardLabel(form, textField, metaData), nil
}
return textField, nil
}
示例4: field
func (self *setPostValuesStructVisitor) field(field *model.MetaData) error {
if self.form.IsFieldDisabled(field) || self.form.IsFieldExcluded(field, self.ctx) {
return nil
}
value := self.ctx.Request.FormValue(field.Selector())
return self.form.GetFieldControllers().SetValue(value, self.ctx, field, self.form)
}
示例5: SetValue
func (self SetModelValueControllerBase) SetValue(value string, ctx *Context, metaData *model.MetaData, form *Form) error {
mdl, ok := metaData.ModelValue()
if !ok {
panic("metaData must be model.Value")
}
mdl.SetString(value)
return nil
}
示例6: IsFieldExcluded
// IsFieldExcluded returns weather a field will be excluded.
// Fields will be excluded, if their selector matches one in LabeledModelView.ExcludedFields.
// A field is also excluded when its parent field is excluded.
// This function is not restricted to model.Value, it works with all struct fields.
// This way a whole sub struct an be excluded by adding its selector to LabeledModelView.ExcludedFields.
func (self *LabeledModelView) IsFieldExcluded(field *model.MetaData) bool {
if field.Parent == nil {
return false // can't exclude root
}
if self.IsFieldExcluded(field.Parent) || field.SelectorsMatch(self.ExcludedFields) {
return true
}
return false
}
示例7: NewInput
func (self BlobRefController) NewInput(withLabel bool, metaData *model.MetaData, form *view.Form) (input view.View, err error) {
blobRef := metaData.Value.Addr().Interface().(*BlobRef)
hiddenInput := &view.HiddenInput{Name: metaData.Selector(), Value: blobRef.String()}
uploadList := &view.List{Class: "qq-upload-list"}
removeButton := &view.Div{
Class: "qq-upload-button",
Content: view.HTML("Remove"),
OnClick: fmt.Sprintf(
`jQuery("#%s").attr("value", "");
jQuery("#%s").empty();`,
hiddenInput.ID(),
uploadList.ID(),
),
}
chooseList := view.Views{
view.JQueryUIAutocompleteFromURL(".gostart-select-blob", API.AllBlobs, 2),
}
uploadButton := UploadBlobButton(
"",
"#"+uploadList.ID(),
fmt.Sprintf(
`function(id, fileName, responseJSON) {
jQuery("#%s").attr("value", responseJSON.blobID);
}`,
hiddenInput.ID(),
),
)
editor := view.DIV(Config.BlobRefController.Class,
view.RequireScriptURL("/media/media.js", 0),
view.RequireStyle(
`.qq-upload-button {
margin: 0 0 5px 10px;
cursor: pointer;
}
.qq-upload-button:hover {
background-color: #cc0000;
}`,
10,
),
hiddenInput,
view.DIV(Config.BlobRefController.ActionsClass, chooseList, removeButton, uploadButton),
uploadList,
view.DivClearBoth(),
)
if withLabel {
return view.AddStandardLabel(form, editor, metaData), nil
}
return editor, nil
}
示例8: validateGeneral
func (self *validateAndFormLayoutStructVisitor) validateGeneral(data *model.MetaData) error {
if validator, ok := data.ModelValidator(); ok {
err := validator.Validate(data)
if err != nil {
self.generalValidationErrors = append(self.generalValidationErrors, err)
}
return err
}
return nil
}
示例9: validateGeneral
func (self *validateAndFormLayoutStructVisitor) validateGeneral(data *model.MetaData) error {
if !self.isPost {
return nil
}
err := data.Validate()
if err != nil {
self.generalValidationErrors = append(self.generalValidationErrors, err)
}
return err
}
示例10: validateField
func (self *validateAndFormLayoutStructVisitor) validateField(field *model.MetaData) error {
if !self.isPost {
return nil
}
err := field.Validate()
if err != nil {
self.fieldValidationErrors = append(self.fieldValidationErrors, err)
}
return err
}
示例11: SetValue
func (self ModelMultipleChoiceController) SetValue(value string, ctx *Context, metaData *model.MetaData, form *Form) error {
m := metaData.Value.Addr().Interface().(*model.MultipleChoice)
options := m.Options(metaData)
*m = nil
for i, option := range options {
name := fmt.Sprintf("%s_%d", metaData.Selector(), i)
if ctx.Request.FormValue(name) != "" {
*m = append(*m, option)
}
}
return nil
}
示例12: trySetFieldValue
func (self *setPostValuesStructVisitor) trySetFieldValue(field *model.MetaData) error {
if self.form.IsFieldDisabled(field) || self.form.IsFieldExcluded(field, self.ctx) {
return nil
}
switch s := field.Value.Addr().Interface().(type) {
case model.Reference:
// we don't handle references with forms yet
case *model.Bool:
s.Set(self.ctx.Request.FormValue(field.Selector()) != "")
case *model.MultipleChoice:
options := s.Options(field)
*s = nil
for i, option := range options {
name := fmt.Sprintf("%s_%d", field.Selector(), i)
if self.ctx.Request.FormValue(name) != "" {
*s = append(*s, option)
}
}
case *model.Blob:
file, _, err := self.ctx.Request.FormFile(field.Selector())
if err != nil {
return err
}
defer file.Close()
bytes, err := ioutil.ReadAll(file)
if err != nil {
return err
}
s.Set(bytes)
case *model.File:
file, header, err := self.ctx.Request.FormFile(field.Selector())
if err != nil {
return err
}
defer file.Close()
bytes, err := ioutil.ReadAll(file)
if err != nil {
return err
}
s.Name = header.Filename
s.Data = bytes
case model.Value:
// General case
s.SetString(self.ctx.Request.FormValue(field.Selector()))
}
return nil
}
示例13: validateField
func (self *validateAndFormLayoutStructVisitor) validateField(field *model.MetaData) error {
if value, ok := field.ModelValue(); ok {
err := value.Validate(field)
if err == nil && value.IsEmpty() && self.form.IsFieldRequired(field) {
err = model.NewRequiredError(field)
}
if err != nil {
self.fieldValidationErrors = append(self.fieldValidationErrors, err)
}
return err
}
return nil
}
示例14: NewInput
func (self ModelFileController) NewInput(withLabel bool, metaData *model.MetaData, form *Form) (input View, err error) {
accept, _ := metaData.Attrib("view", "accept")
form.Enctype = MultipartFormData
input = &FileInput{
Class: form.FieldInputClass(metaData),
Name: metaData.Selector(),
Accept: accept,
Disabled: form.IsFieldDisabled(metaData),
}
if withLabel {
return AddStandardLabel(form, input, metaData), nil
}
return input, nil
}
示例15: BeginSlice
func (self *setPostValuesStructVisitor) BeginSlice(slice *model.MetaData) error {
if slice.Value.CanSet() && !self.form.IsFieldExcluded(slice) {
if lengthStr := self.context.Request.FormValue(slice.Selector() + ".length"); lengthStr != "" {
length, err := strconv.Atoi(lengthStr)
if err != nil {
panic(err.Error())
}
if length != slice.Value.Len() {
slice.Value.Set(utils.SetSliceLengh(slice.Value, length))
mongo.InitRefs(self.formModel)
}
}
}
return nil
}