Documentation ¶
Overview ¶
Package dialog contains dialog controls.
Dialogs use javascript to popup a "window" above the current page.
Index ¶
- Constants
- func RestoreNewDialogFunction()
- func SetNewDialogFunction(f DialogIFuncType)
- type ButtonOptions
- type Dialog
- func (d *Dialog) AddButton(label string, id string, options *ButtonOptions)
- func (d *Dialog) AddCloseButton(label string, id string)
- func (d *Dialog) ButtonBar() *control.Panel
- func (d *Dialog) CloseBox() *button.Button
- func (d *Dialog) Deserialize(dec page.Decoder)
- func (d *Dialog) DoPrivateAction(_ context.Context, a action.Params)
- func (d *Dialog) DrawInnerHtml(ctx context.Context, w io.Writer)
- func (d *Dialog) DrawingAttributes(ctx context.Context) html5tag.Attributes
- func (d *Dialog) Hide()
- func (d *Dialog) Init(parent page.ControlI, id string)
- func (d *Dialog) RemoveAllButtons()
- func (d *Dialog) RemoveButton(id string)
- func (d *Dialog) Serialize(e page.Encoder)
- func (d *Dialog) SetButtonStyle(id string, a html5tag.Style)
- func (d *Dialog) SetButtonText(id string, text string)
- func (d *Dialog) SetButtonVisible(id string, visible bool)
- func (d *Dialog) SetDialogStyle(s Style)
- func (d *Dialog) SetHasCloseBox(h bool)
- func (d *Dialog) SetTitle(t string)
- func (d *Dialog) Show()
- func (d *Dialog) Title() string
- func (d *Dialog) TitleBar() *control.Panel
- type DialogI
- type DialogIFuncType
- type DialogPanel
- func (p *DialogPanel) AddButton(label string, id string, options *ButtonOptions)
- func (p *DialogPanel) AddCloseButton(label string, id string)
- func (p *DialogPanel) Hide()
- func (p *DialogPanel) Init(parent page.ControlI, id string)
- func (p *DialogPanel) OnButton(a action.ActionI)
- func (p *DialogPanel) OnClose(a action.ActionI)
- func (p *DialogPanel) RemoveAllButtons()
- func (p *DialogPanel) RemoveButton(id string)
- func (p *DialogPanel) SetButtonStyle(id string, a html5tag.Style)
- func (p *DialogPanel) SetButtonText(id string, text string)
- func (p *DialogPanel) SetButtonVisible(id string, visible bool)
- func (p *DialogPanel) SetDialogStyle(s Style)
- func (p *DialogPanel) SetHasCloseBox(h bool)
- func (p *DialogPanel) SetTitle(t string)
- func (p *DialogPanel) Show()
- type EditPanel
- type EditablePanel
- type SavePanel
- type SaveablePanel
- type Style
Constants ¶
const ( SaveButtonID = "saveBtn" CancelButtonnID = "cancelBtn" DeleteButtonID = "deleteBtn" )
const (
ClosedAction = iota + 3000
)
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 ¶
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 (*Dialog) AddButton ¶
func (d *Dialog) AddButton( label string, id string, options *ButtonOptions, )
AddButton adds the given button to the dialog.
func (*Dialog) AddCloseButton ¶
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) Deserialize ¶
func (*Dialog) DoPrivateAction ¶
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) 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) RemoveAllButtons ¶
func (d *Dialog) RemoveAllButtons()
RemoveAllButtons removes all the buttons from the dialog
func (*Dialog) RemoveButton ¶
RemoveButton removes the given button from the dialog
func (*Dialog) SetButtonStyle ¶
SetButtonStyle sets css styles on a button that is already in the dialog
func (*Dialog) SetButtonText ¶
SetButtonText sets the text of a button that was previously created
func (*Dialog) SetButtonVisible ¶
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 ¶
SetDialogStyle sets the style of the dialog.
func (*Dialog) SetHasCloseBox ¶
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.
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.
type DialogPanel ¶
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 (*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) 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 ¶
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) EditPanel ¶
func (p *EditPanel) EditPanel() EditablePanel
EditPanel returns the panel that has the edit controls
type EditablePanel ¶
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 ¶
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) SavePanel ¶
func (p *SavePanel) SavePanel() SaveablePanel
SavePanel returns the panel that has the controls