dialog

package
v0.25.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package dialog contains dialog controls.

Dialogs use javascript to popup a "window" above the current page.

Index

Constants

View Source
const (
	SaveButtonID    = "saveBtn"
	CancelButtonnID = "cancelBtn"
	DeleteButtonID  = "deleteBtn"
)
View Source
const (
	ClosedAction = iota + 3000
)
View Source
const OverlayID = "gr-dlg-overlay"

Variables

This section is empty.

Functions

func RestoreNewDialogFunction

func RestoreNewDialogFunction()

RestoreNewDialogFunction restores the new dialog function to the default one. This is primarily used by the example code, or in situations where you have multiple styles of dialog to demonstrate.

func SetNewDialogFunction

func SetNewDialogFunction(f DialogIFuncType)

SetNewDialogFunction sets the function that will create new dialogs. This is normally called by a CSS dialog implementation to set how dialogs are created in the application.

Types

type ButtonOptions

type ButtonOptions struct {
	// Validates indicates that this button will validate the dialog
	Validates bool
	// The ConfirmationMessage string will appear with a yes/no box making sure the user wants the action.
	// This is usually used when the action could be destructive, like a Delete button.
	ConfirmationMessage string
	// PushLeft pushes this button to the left side of the dialog. Buttons are typically aligned right.
	// This is helpful to separate particular buttons from the main grouping of buttons. Be sure to insert
	// all the PushLeft buttons before the other buttons.
	PushLeft bool
	// IsClose will set the button up to automatically close the dialog. Detect closes with the DialogCloseEvent if needed.
	// The button will not send a DialogButton event.
	IsClose bool
	// IsPrimary styles the button as a primary button and makes it the default when a return is pressed
	IsPrimary bool
	// OnClick is the action that will happen when the button is clicked. If you provide an action, the DialogButton event
	// will not be sent to the dialog. If you do not provide an action, the dialog will receive a DialogButton event instead.
	OnClick action.ActionI
	// Options are additional options specific to the dialog implementation you are using.
	Options map[string]interface{}
}

ButtonOptions are optional additional items you can add to a dialog button.

type Dialog

type Dialog struct {
	control.Panel
	// contains filtered or unexported fields
}

Dialog is the default implementation of a dialog in GoRADD. You should not normally call this directly, but rather call GetDialogPanel to create a dialog. GetDialogPanel will then call NewDialogI to create a dialog that wraps the panel. To change the default dialog style to a different one, call SetNewDialogFunction()

func NewDialog

func NewDialog(parent page.ControlI, id string) *Dialog

NewDialog creates a new dialog.

func (*Dialog) AddButton

func (d *Dialog) AddButton(
	label string,
	id string,
	options *ButtonOptions,
)

AddButton adds the given button to the dialog.

func (*Dialog) AddCloseButton

func (d *Dialog) AddCloseButton(label string, id string)

AddCloseButton adds a button to the list of buttons with the given label, but this button will trigger the DialogCloseEvent instead of the DialogButtonEvent. The button will also close the dialog.

func (*Dialog) ButtonBar

func (d *Dialog) ButtonBar() *control.Panel

func (*Dialog) CloseBox

func (d *Dialog) CloseBox() *button.Button

func (*Dialog) Deserialize

func (d *Dialog) Deserialize(dec page.Decoder)

func (*Dialog) DoPrivateAction

func (d *Dialog) DoPrivateAction(_ context.Context, a action.Params)

DoPrivateAction is called by the framework and will respond to the DialogClose action sent by any close buttons on the page to close the dialog. You do not normally need to call this.

func (*Dialog) DrawInnerHtml

func (d *Dialog) DrawInnerHtml(ctx context.Context, w io.Writer)

func (*Dialog) DrawingAttributes

func (d *Dialog) DrawingAttributes(ctx context.Context) html5tag.Attributes

DrawingAttributes is called by the framework to set temporary attributes just before drawing.

func (*Dialog) Hide

func (d *Dialog) Hide()

Hide will hide the dialog. The dialog will still be part of the form, just in a hidden state.

func (*Dialog) Init

func (d *Dialog) Init(parent page.ControlI, id string)

Init is called by subclasses of the dialog.

func (*Dialog) RemoveAllButtons

func (d *Dialog) RemoveAllButtons()

RemoveAllButtons removes all the buttons from the dialog

func (*Dialog) RemoveButton

func (d *Dialog) RemoveButton(id string)

RemoveButton removes the given button from the dialog

func (*Dialog) Serialize

func (d *Dialog) Serialize(e page.Encoder)

func (*Dialog) SetButtonStyle

func (d *Dialog) SetButtonStyle(id string, a html5tag.Style)

SetButtonStyle sets css styles on a button that is already in the dialog

func (*Dialog) SetButtonText

func (d *Dialog) SetButtonText(id string, text string)

SetButtonText sets the text of a button that was previously created

func (*Dialog) SetButtonVisible

func (d *Dialog) SetButtonVisible(id string, visible bool)

SetButtonVisible sets the visible state of the button. Hidden buttons are still rendered, but are styled so that they are not shown.

func (*Dialog) SetDialogStyle

func (d *Dialog) SetDialogStyle(s Style)

SetDialogStyle sets the style of the dialog.

func (*Dialog) SetHasCloseBox

func (d *Dialog) SetHasCloseBox(h bool)

SetHasCloseBox adds a close box so that the dialog can be closed in a way that is independent of buttons. Often this is an X button in the upper right corner of the dialog.

func (*Dialog) SetTitle

func (d *Dialog) SetTitle(t string)

SetTitle sets the title of the dialog

func (*Dialog) Show

func (d *Dialog) Show()

Show will show the dialog.

func (*Dialog) Title

func (d *Dialog) Title() string

Title returns the title of the dialog

func (*Dialog) TitleBar

func (d *Dialog) TitleBar() *control.Panel

type DialogI

type DialogI interface {
	control.PanelI

	SetTitle(string)
	SetDialogStyle(state Style)
	SetHasCloseBox(bool)
	Show()
	Hide()
	AddButton(label string, id string, options *ButtonOptions)
	AddCloseButton(label string, id string)
	SetButtonText(id string, text string)
	SetButtonVisible(id string, visible bool)
	SetButtonStyle(id string, a html5tag.Style)
	RemoveButton(id string)
	RemoveAllButtons()
}

DialogI defines the publicly consumable api that the goradd framework uses to interact with a dialog.

More and more CSS and javascript frameworks are coming out with their own forms of dialog, which is usually a combination of html, css and a javascript widget. goradd has many ways of potentially interacting with dialogs, but to be able to inject a dialog into the framework, we need a consistent interface for all to use.

This particular interface has been implemented in a simple default dialog and Bootstrap dialogs. As more needs arise, we can modify the interface to accommodate as many frameworks as possible.

Dialog implementations should descend from the Panel control. Dialogs should be able to be a member of a form or control object and appear with an Open call, but they should also be able to be instantiated on the fly. The framework has hooks for both, and if you are creating a dialog implementation, see the current Bootstrap implementation for more direction. Feel free to implement more than just the functions listed. These are the minimal set to allow goradd to use a dialog implementation. When possible, implementations should use the same function signatures found here to do the same work. For example, SetHasCloseBox is defined here, and in the Bootstrap Modal implementation with the same function signature, and other implementations should attempt to do the same, but it is not enforced by an interface.

func NewDialogI

func NewDialogI(form page.FormI, id string) DialogI

NewDialogI creates a new dialog in a css framework independent way, by returning a DialogI interface. Call SetNewDialogFunction() to set the function that controls how dialogs are created throughout the framework.

type DialogIFuncType

type DialogIFuncType func(form page.FormI, id string) DialogI

type DialogPanel

type DialogPanel struct {
	control.Panel
}

A DialogPanel is the interface between the default dialog style, and a panel. To put a dialog on the screen, call GetDialogPanel() and then add child controls to that panel, call AddButton() to add buttons to the dialog, and then call Show().

func Alert

func Alert(parent page.ControlI, message string, buttons interface{}) *DialogPanel

Alert is used by the framework to create an alert type message dialog.

If you specify no buttons, a close box in the corner will be created that will just close the dialog. If you specify just a string in buttons, or just one string as a slice of strings, one button will be shown that will just close the message.

If you specify more than one button, the first button will be the default button (the one pressed if the user presses the return key). In this case, you will need to detect the button by calling OnButton(action) on the dialog panel returned. You will also be responsible for calling Hide() on the dialog panel after detecting a button in this case. You can detect a close button by calling OnClose(action). Call SetDialogStyle on the result to control the look of the alery.

func GetDialogPanel

func GetDialogPanel(parent page.ControlI, id string) (dialogPanel *DialogPanel, isNew bool)

GetDialogPanel will return a new dialog panel if the given dialog panel does not already exist on the form, or it returns the dialog panel with the given id that already exists. isNew will indicate whether it created a new dialog, or is returning an existing one.

func YesNo

func YesNo(parent page.ControlI, message string, resultAction action.ActionI) *DialogPanel

YesNo is an alert that has just two buttons, a Yes and a No button.

func (*DialogPanel) AddButton

func (p *DialogPanel) AddButton(label string, id string, options *ButtonOptions)

AddButton adds a button to the dialog.

func (*DialogPanel) AddCloseButton

func (p *DialogPanel) AddCloseButton(label string, id string)

AddCloseButton will add a button to the dialog that just closes the dialog.

func (*DialogPanel) Hide

func (p *DialogPanel) Hide()

Hide will make a dialog invisible. The dialog will still be part of the form object.

func (*DialogPanel) Init

func (p *DialogPanel) Init(parent page.ControlI, id string)

func (*DialogPanel) OnButton

func (p *DialogPanel) OnButton(a action.ActionI)

OnButton attaches an action handler that responds to button presses. The id of the pressed button will be in the event value of the action.

func (*DialogPanel) OnClose

func (p *DialogPanel) OnClose(a action.ActionI)

OnClose attaches an action that will happen when the dialog closes.

func (*DialogPanel) RemoveAllButtons

func (p *DialogPanel) RemoveAllButtons()

RemoveAllButtons removes all the buttons from the dialog

func (*DialogPanel) RemoveButton

func (p *DialogPanel) RemoveButton(id string)

RemoveButton removes the given button from the dialog

func (*DialogPanel) SetButtonStyle

func (p *DialogPanel) SetButtonStyle(id string, a html5tag.Style)

SetButtonStyle sets the style of the given button

func (*DialogPanel) SetButtonText

func (p *DialogPanel) SetButtonText(id string, text string)

SetButtonText sets the text of the given button

func (*DialogPanel) SetButtonVisible

func (p *DialogPanel) SetButtonVisible(id string, visible bool)

SetButtonVisible will show or hide a specific button that has already been added to the dialog.

func (*DialogPanel) SetDialogStyle

func (p *DialogPanel) SetDialogStyle(s Style)

SetDialogStyle sets the style of the dialog.

func (*DialogPanel) SetHasCloseBox

func (p *DialogPanel) SetHasCloseBox(h bool)

SetHasCloseBox will put a close box in the upper right corner of the dialog

func (*DialogPanel) SetTitle

func (p *DialogPanel) SetTitle(t string)

SetTitle sets the title of the dialog

func (*DialogPanel) Show

func (p *DialogPanel) Show()

Show will bring a hidden dialog up on the screen.

type EditPanel

type EditPanel struct {
	DialogPanel
	ObjectName string
}

EditPanel is a dialog panel that pre-loads Save, Cancel and Delete buttons, and treats its one child control as an EditablePanel.

func GetEditPanel

func GetEditPanel(parent page.ControlI, id string, objectName string) (*EditPanel, bool)

GetEditPanel creates a panel that is designed to hold an EditablePanel. It itself will be wrapped with the application's default dialog style, and it will automatically get Save, Cancel and Delete buttons.

func (*EditPanel) DoAction

func (p *EditPanel) DoAction(ctx context.Context, a action.Params)

func (*EditPanel) EditPanel

func (p *EditPanel) EditPanel() EditablePanel

EditPanel returns the panel that has the edit controls

func (*EditPanel) Init

func (p *EditPanel) Init(dlg page.ControlI, id string, objectName string)

func (*EditPanel) Load

func (p *EditPanel) Load(ctx context.Context, pk string) (data interface{}, err error)

type EditablePanel

type EditablePanel interface {
	control.PanelI
	Load(ctx context.Context, pk string) error
	Save(ctx context.Context)
	Delete(ctx context.Context)
	DataI() interface{}
}

type SavePanel

type SavePanel struct {
	DialogPanel
}

SavePanel is a dialog panel that pre-loads Save, Cancel and Delete buttons, and treats its one child control as an EditablePanel.

func GetSavePanel

func GetSavePanel(parent page.ControlI, id string) (*SavePanel, bool)

GetSavePanel creates a panel that is designed to hold an SaveablePanel. It itself will be wrapped with the application's default dialog style, and it will automatically get Save, Cancel and Delete buttons.

func (*SavePanel) DoAction

func (p *SavePanel) DoAction(ctx context.Context, a action.Params)

func (*SavePanel) Init

func (p *SavePanel) Init(dlg page.ControlI, id string)

func (*SavePanel) Load

func (p *SavePanel) Load(ctx context.Context, pk string) (data interface{}, err error)

func (*SavePanel) SavePanel

func (p *SavePanel) SavePanel() SaveablePanel

SavePanel returns the panel that has the controls

type SaveablePanel

type SaveablePanel interface {
	control.PanelI
	Load(ctx context.Context, pk string) error
	Save(ctx context.Context)
	Data() interface{}
}

type Style

type Style int

Style represents the style of the dialog, whether its a plain dialog (the default), or whether it should display additional indicators showing that its indicating an error, warning, information, or success. Not all css frameworks support all of these styles.

const (
	DefaultStyle Style = iota
	ErrorStyle
	WarningStyle
	InfoStyle
	SuccessStyle
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL