Beispiel #1
0
func (f *datepickerField) Build(form formData) string {
	f.Class = append(f.Class, "form-control")

	attrs := map[string]string{
		"type":              "text",
		"id":                fmt.Sprintf("%s%s", form.GetName(), f.ID),
		"name":              fmt.Sprintf("%s%s", form.GetName(), f.ID),
		"placeholder":       f.PlaceHolder,
		"class":             strings.Join(f.Class, " "),
		"ng-model":          fmt.Sprintf("%s.%s", form.GetObjName(), f.ID),
		"datepicker-popup":  f.DateFormat,
		"datepicker-manual": "",
	}
	if len(f.IsOpen) > 0 {
		attrs["is-open"] = f.IsOpen
	}
	if len(f.Options) > 0 {
		attrs["datepicker-options"] = f.Options
	}
	utils.UpdateMap(attrs, f.Attrs)

	newAttrs, container := f.buildContainer(form)
	utils.UpdateMap(attrs, newAttrs)

	ctrl := utils.BuildCtrlTag("<input", ">", attrs)
	return fmt.Sprintf(container, ctrl)
}
Beispiel #2
0
func (f *inputField) Build(form formData) string {
	if f.Type == "" {
		panic("input type should not be empty: " + f.ID)
	}

	f.Class = append(f.Class, "form-control")

	attrs := map[string]string{
		"type":        f.Type,
		"id":          fmt.Sprintf("%s%s", form.GetName(), f.ID),
		"name":        fmt.Sprintf("%s%s", form.GetName(), f.ID),
		"placeholder": f.PlaceHolder,
		"class":       strings.Join(f.Class, " "),
		"ng-model":    fmt.Sprintf("%s.%s", form.GetObjName(), f.ID),
	}
	utils.UpdateMap(attrs, f.Attrs)

	newAttrs, container := f.buildContainer(form)
	utils.UpdateMap(attrs, newAttrs)

	ctrl := utils.BuildCtrlTag("<input", ">", attrs)
	if len(f.Prefix) > 0 {
		ctrl = templates.Run("input-field-prefix", map[string]interface{}{
			"Prefix": f.Prefix,
			"Ctrl":   ctrl,
		})
	}
	return fmt.Sprintf(container, ctrl)
}
Beispiel #3
0
func (f *staticField) Build(form formData) string {
	f.Class = append(f.Class, "form-control-static")

	attrs := map[string]string{
		"class": strings.Join(f.Class, " "),
	}
	utils.UpdateMap(attrs, f.Attrs)

	newAttrs, container := f.buildContainer(form)
	utils.UpdateMap(attrs, newAttrs)

	ctrl := utils.BuildCtrlTag("<p", ">", attrs) + f.Content + "</p>"
	return fmt.Sprintf(container, ctrl)
}
Beispiel #4
0
func (f *textAreaField) Build(form formData) string {
	f.Class = append(f.Class, "form-control")

	attrs := map[string]string{
		"id":          fmt.Sprintf("%s%s", form.GetName(), f.ID),
		"name":        fmt.Sprintf("%s%s", form.GetName(), f.ID),
		"placeholder": f.PlaceHolder,
		"class":       strings.Join(f.Class, " "),
		"ng-model":    fmt.Sprintf("%s.%s", form.GetObjName(), f.ID),
		"rows":        fmt.Sprintf("%d", f.Rows),
	}
	utils.UpdateMap(attrs, f.Attrs)

	newAttrs, container := f.buildContainer(form)
	utils.UpdateMap(attrs, newAttrs)

	ctrl := utils.BuildCtrlTag("<textarea", "></textarea>", attrs)
	return fmt.Sprintf(container, ctrl)
}
Beispiel #5
0
func (f *checkboxField) Build(form formData) string {
	label := f.Label
	f.Label = ""

	attrs := map[string]string{
		"type":     "checkbox",
		"id":       fmt.Sprintf("%s%s", form.GetName(), f.ID),
		"name":     fmt.Sprintf("%s%s", form.GetName(), f.ID),
		"class":    strings.Join(f.Class, " "),
		"ng-model": fmt.Sprintf("%s.%s", form.GetObjName(), f.ID),
	}
	utils.UpdateMap(attrs, f.Attrs)

	newAttrs, container := f.buildContainer(form)
	utils.UpdateMap(attrs, newAttrs)

	ctrl := utils.BuildCtrlTag("<input", ">", attrs)
	ctrl = fmt.Sprintf(`<label for=""%s>%s %s</label>`, attrs["id"], ctrl, label)
	return fmt.Sprintf(container, ctrl)
}
Beispiel #6
0
func (f *submitField) Build(form formData) string {
	f.Class = append(f.Class, "btn")
	f.Class = append(f.Class, "btn-primary")

	label := f.Label
	f.Label = ""

	attrs := map[string]string{
		"ng-disabled": fmt.Sprintf("%s.val && !%s.$valid", form.GetName(), form.GetName()),
		"class":       strings.Join(f.Class, " "),
	}
	utils.UpdateMap(attrs, f.Attrs)

	newAttrs, container := f.buildContainer(form)
	utils.UpdateMap(attrs, newAttrs)

	ctrl := utils.BuildCtrlTag("<button", ">", attrs) + label + "</button>"
	ctrl = "<p>&nbsp;</p>\n      " + ctrl
	return fmt.Sprintf(container, ctrl)
}