Пример #1
0
Файл: addpop.go Проект: kego/ke
func (v *AddPopupView) Render() *vecty.HTML {
	if v.model == nil || !v.model.Visible {
		return v.modal()
	}

	v.nameInput = nil
	v.typeSelect = nil

	var nameControl, typeControl *vecty.HTML
	if v.model.HasName() {
		v.nameInput = elem.Input(
			prop.Class("form-control"),
			prop.ID("add-modal-name"),
		)
		nameControl = elem.Div(
			prop.Class("form-group"),
			elem.Label(
				prop.For("add-modal-name"),
				vecty.Text("name"),
			),
			v.nameInput,
			elem.Paragraph(
				prop.Class("help-block"),
				vecty.Text("Enter a name for the new item"),
			),
		)
	}
	if len(v.model.Types) > 1 {

		var options vecty.List
		for _, t := range v.model.Types {
			displayName, err := t.Id.ValueContext(v.Ctx)
			if err != nil {
				// we shouldn't be able to get here
				v.App.Fail <- kerr.Wrap("NTSWPIEAHC", err)
			}
			options = append(options, elem.Option(
				prop.ID(t.Id.String()),
				vecty.Text(displayName),
			))
		}

		v.typeSelect = elem.Select(
			prop.Class("form-control"),
			prop.ID("add-modal-type"),
			elem.Option(
				prop.ID(""),
				vecty.Text(""),
			),
			options,
		)

		typeControl = elem.Div(
			prop.Class("form-group"),
			elem.Label(
				prop.For("add-modal-type"),
				vecty.Text("type"),
			),
			v.typeSelect,
			elem.Paragraph(
				prop.Class("help-block"),
				vecty.Text("Select a type for the new object"),
			),
		)
	}

	return v.modal(
		elem.Div(
			prop.Class("modal-body"),
			elem.Form(
				event.Submit(func(ev *vecty.Event) {
					v.save()
				}).PreventDefault(),
				nameControl,
				typeControl,
			),
		),
	)
}
Пример #2
0
func (v *EditorListView) Render() *vecty.HTML {

	if v.model == nil || v.model.Node.Missing || v.model.Node.Null {
		return elem.Div(vecty.Text("editor (nil)"))
	}

	children := vecty.List{}

	add := func(n *node.Node) {

		for _, v := range v.exclude {
			if n.Key == v {
				return
			}
		}

		if n.Null || n.Missing {
			children = append(children, nullEditor(v.Ctx, n, v.App))
			return
		}

		f := editable.Branch
		if e := models.GetEditable(v.Ctx, n); e != nil {
			f = e.Format(n.Rule)
			if f == editable.Block || f == editable.Inline {
				children = append(children,
					NewEditorView(v.Ctx, n).Controls(
						func() vecty.MarkupOrComponentOrHTML {
							return e.EditorView(v.Ctx, n, editable.Block)
						},
					),
				)
				return
			}
		}
		if f == editable.Branch {
			b := v.App.Branches.Get(n)
			children = append(children, NewEditorView(v.Ctx, n).Icons(
				func() vecty.MarkupOrComponentOrHTML {
					return elem.Anchor(
						prop.Href("#"),
						event.Click(func(e *vecty.Event) {
							v.App.Dispatch(&actions.BranchSelecting{Branch: b, Op: models.BranchOpClickEditorLink})
						}).PreventDefault(),
						elem.Italic(
							prop.Class("editor-icon editor-icon-after glyphicon glyphicon-share-alt"),
						),
					)
				},
			))
		}
	}

	for _, n := range v.model.Node.Map {
		// TODO: hide optional fields
		//if n.Missing || n.Null {
		//	continue
		//}
		if v.filter != nil && *n.Origin != *v.filter {
			continue
		}
		add(n)
	}

	for _, n := range v.model.Node.Array {
		add(n)
	}

	v.items = len(children)

	if len(children) == 0 {
		v.container = elem.Div()
	} else {
		v.container = elem.Form(
			event.Submit(func(*vecty.Event) {}).PreventDefault(),
			children,
		)
	}

	return v.container
}