当前位置: 首页>>代码示例>>Golang>>正文


Golang MetaData.Selector方法代码示例

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


在下文中一共展示了MetaData.Selector方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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

示例2: NewInput

func (self ModelTextController) NewInput(withLabel bool, metaData *model.MetaData, form *Form) (input View, err error) {
	text := metaData.Value.Addr().Interface().(*model.Text)
	var cols int // will be zero if not available, which is OK
	if str, ok := metaData.Attrib(StructTagKey, "cols"); ok {
		cols, err = strconv.Atoi(str)
		if err != nil {
			panic("Error in StandardFormFieldFactory.NewInput(): " + err.Error())
		}
	}
	var rows int // will be zero if not available, which is OK
	if str, ok := metaData.Attrib(StructTagKey, "rows"); ok {
		rows, err = strconv.Atoi(str)
		if err != nil {
			panic("Error in StandardFormFieldFactory.NewInput(): " + err.Error())
		}
	}
	textArea := &TextArea{
		Class:       form.FieldInputClass(metaData),
		Name:        metaData.Selector(),
		Text:        text.Get(),
		Cols:        cols,
		Rows:        rows,
		Disabled:    form.IsFieldDisabled(metaData),
		Placeholder: form.InputFieldPlaceholder(metaData),
	}
	if metaData.BoolAttrib("view", "autofocus") {
		textArea.Autofocus = true
	}
	if withLabel {
		return AddStandardLabel(form, textArea, metaData), nil
	}
	return textArea, nil
}
开发者ID:prinsmike,项目名称:go-start,代码行数:33,代码来源: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) && !metaData.IsSelfOrParentIndexed(),
		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:roleyzhang,项目名称:go-start,代码行数:27,代码来源:formfieldcontrollers.go

示例4: 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

示例5: IsFieldRequired

func (self *Form) IsFieldRequired(metaData *model.MetaData) bool {
	if val, ok := metaData.ModelValue(); ok && val.Required(metaData) {
		return true
	}
	selector := metaData.Selector()
	wildcardSelector := metaData.WildcardSelector()
	return utils.StringIn(selector, self.RequiredFields) || utils.StringIn(wildcardSelector, self.RequiredFields)
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:8,代码来源:form.go

示例6: IsFieldHidden

func (self *Form) IsFieldHidden(metaData *model.MetaData) bool {
	if metaData.BoolAttrib("hidden") {
		return true
	}
	selector := metaData.Selector()
	wildcardSelector := metaData.WildcardSelector()
	return utils.StringIn(selector, self.HiddenFields) || utils.StringIn(wildcardSelector, self.HiddenFields)
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:8,代码来源:form.go

示例7: IsFieldDisabled

func (self *Form) IsFieldDisabled(metaData *model.MetaData) bool {
	if metaData.BoolAttrib("disabled") {
		return true
	}
	selector := metaData.Selector()
	wildcardSelector := metaData.WildcardSelector()
	return utils.StringIn(selector, self.DisabledFields) || utils.StringIn(wildcardSelector, self.DisabledFields)
}
开发者ID:sedzinreri,项目名称:go-start,代码行数:8,代码来源:form.go

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: GetFieldDescription

func (self *Form) GetFieldDescription(metaData *model.MetaData) string {
	selector := metaData.Selector()
	if desc, ok := self.FieldDescriptions[selector]; ok {
		return desc
	}
	wildcardSelector := metaData.WildcardSelector()
	if desc, ok := self.FieldDescriptions[wildcardSelector]; ok {
		return desc
	}
	if desc, ok := metaData.Attrib(StructTagKey, "description"); ok {
		return desc
	}
	return ""
}
开发者ID:SohoStudio,项目名称:go-start,代码行数:14,代码来源:form.go

示例13: 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

示例14: 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

示例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


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