• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang model.MetaData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/ungerik/go-start/model.MetaData的典型用法代码示例。如果您正苦于以下问题:Golang MetaData类的具体用法?Golang MetaData怎么用?Golang MetaData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MetaData类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:JessonChan,项目名称:go-start,代码行数:35,代码来源:formfieldcontrollers.go


示例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
}
开发者ID:roleyzhang,项目名称:go-start,代码行数:32,代码来源:formfieldcontrollers.go


示例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
}
开发者ID:prinsmike,项目名称:go-start,代码行数:27,代码来源:formfieldcontrollers.go


示例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)
}
开发者ID:roleyzhang,项目名称:go-start,代码行数:7,代码来源:form.go


示例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
}
开发者ID:roleyzhang,项目名称:go-start,代码行数:8,代码来源:formfieldcontrollers.go


示例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
}
开发者ID:JessonChan,项目名称:go-start,代码行数:14,代码来源:labeledmodelview.go


示例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
}
开发者ID:prinsmike,项目名称:go-start,代码行数:56,代码来源:blobrefcontroller.go


示例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
}
开发者ID:SohoStudio,项目名称:go-start,代码行数:10,代码来源:form.go


示例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
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:10,代码来源:form.go


示例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
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:10,代码来源:form.go


示例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
}
开发者ID:prinsmike,项目名称:go-start,代码行数:12,代码来源:formfieldcontrollers.go


示例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
}
开发者ID:go-nut,项目名称:go-start,代码行数:53,代码来源:form.go


示例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
}
开发者ID:SohoStudio,项目名称:go-start,代码行数:13,代码来源:form.go


示例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
}
开发者ID:WaylandGod,项目名称:go-start,代码行数:14,代码来源:formfieldcontrollers.go


示例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
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:15,代码来源:form.go


示例16: BeginIndexedFields

func (self *setPostValuesStructVisitor) BeginIndexedFields(indexedFields *model.MetaData) error {
	if indexedFields.Kind == model.SliceKind && indexedFields.Value.CanSet() && !self.form.IsFieldExcluded(indexedFields, self.ctx) {
		if lengthStr := self.ctx.Request.FormValue(indexedFields.Selector() + ".length"); lengthStr != "" {
			length, err := strconv.Atoi(lengthStr)
			if err != nil {
				panic(err.Error())
			}
			if length != indexedFields.Value.Len() {
				indexedFields.Value.Set(utils.SetSliceLengh(indexedFields.Value, length))
				mongo.InitRefs(self.formModel)
			}
		}
	}
	return nil
}
开发者ID:SohoStudio,项目名称:go-start,代码行数:15,代码来源:form.go


示例17: IsFieldExcluded

// IsFieldExcluded returns weather a field will be excluded from the form.
// Fields will be excluded, if their selector matches one in Form.ExcludedFields
// or if a matching Authenticator from Form.ModelFieldAuth returns false.
// 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 Form.ExcludedFields.
func (self *Form) IsFieldExcluded(field *model.MetaData, ctx *Context) bool {
	if field.Parent == nil {
		return false // can't exclude root
	}
	if self.IsFieldExcluded(field.Parent, ctx) || field.SelectorsMatch(self.ExcludedFields) {
		return true
	}
	if len(self.ModelFieldAuth) > 0 {
		auth, hasAuth := self.ModelFieldAuth[field.Selector()]
		if !hasAuth {
			auth, hasAuth = self.ModelFieldAuth[field.WildcardSelector()]
		}
		if hasAuth {
			ok, err := auth.Authenticate(ctx)
			if err != nil {
				fmt.Println("Error in view.Form.IsFieldExcluded(): " + err.Error())
			}
			if !ok {
				return true
			}
		}
	}
	if len(Config.NamedAuthenticators) > 0 {
		if authAttrib, ok := field.Attrib(StructTagKey, "auth"); ok {
			for _, name := range strings.Split(authAttrib, ",") {
				// if multi := strings.Split(name, "+"); len(multi) > 1 {
				// 	// Needs to pass all sub-Authenticators
				// 	for _, name := range multi {
				// 		if auth, ok := NamedAuthenticator(name); ok {
				// 			ok, err := auth.Authenticate(response)
				// 			if err != nil {
				// 				fmt.Println("Error in view.Form.IsFieldExcluded(): " + err.Error())
				// 			}
				// 			if !ok {
				// 				return true
				// 			}
				// 		}
				// 	}
				// } else {
				if auth, ok := NamedAuthenticator(name); ok {
					ok, err := auth.Authenticate(ctx)
					if ok {
						// Only needs to pass one Authenticator
						return false
					}
					if err != nil {
						log.Println("Error in view.Form.IsFieldExcluded(): " + err.Error())
					}
				}
				// }
			}
			// No Authenticators passed, thus exclude
			return true
		}
	}
	return false
}
开发者ID:SohoStudio,项目名称:go-start,代码行数:63,代码来源:form.go



注:本文中的github.com/ungerik/go-start/model.MetaData类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang templatesystem.Template类代码示例发布时间:2022-05-28
下一篇:
Golang bson.Raw类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap