Documentation
¶
Overview ¶
Package action defines actions that you can trigger using events. Normally you would do this with the .On() function that all goradd controls have.
Defining Your Own Actions You can define your own actions by creating a class that implements the ActionI interface, AND that is encodable by gob.Serialize, meaning it either implements the gob.Encoder interface or exports its structure, AND registers itself with gob.Register so that the gob.Decoder knows how to deserialize it into an interface. We have chosen to export the structures that represent an action here, but we prefix the name of the structures with a greek capital Omega (Ω). We do this to call out that these exported structures and variables are not for general use.
Index ¶
- type ActionGroup
- type ActionI
- type CallbackAction
- type CallbackActionI
- type ΩajaxAction
- func (a *ΩajaxAction) ActionValue(v interface{}) *ΩajaxAction
- func (a *ΩajaxAction) Async() *ΩajaxAction
- func (a *ΩajaxAction) DestinationControlID(id string) *ΩajaxAction
- func (a *ΩajaxAction) IsServerAction() bool
- func (a *ΩajaxAction) Validator(v int) *ΩajaxAction
- func (a *ΩajaxAction) ΩRenderScript(params ΩrenderParams) string
- type ΩconfirmAction
- type ΩgoraddAction
- type ΩjavascriptAction
- type ΩredirectAction
- type ΩrenderParams
- type ΩserverAction
- func (a *ΩserverAction) ActionValue(v interface{}) *ΩserverAction
- func (a *ΩserverAction) Async() *ΩserverAction
- func (a *ΩserverAction) DestinationControlID(id string) *ΩserverAction
- func (a *ΩserverAction) IsServerAction() bool
- func (a *ΩserverAction) Validator(v int) *ΩserverAction
- func (a *ΩserverAction) ΩRenderScript(params ΩrenderParams) string
- type ΩwidgetAction
- func AddClass(controlID string, classes string) ΩwidgetAction
- func Blur(controlID string) ΩwidgetAction
- func Css(controlID string, property string, value interface{}) ΩwidgetAction
- func Focus(controlID string) ΩwidgetAction
- func RemoveClass(controlID string, classes string) ΩwidgetAction
- func Select(controlID string) ΩwidgetAction
- func ToggleClass(controlID string, classes string) ΩwidgetAction
- func Trigger(controlID string, event string, data interface{}) ΩwidgetAction
- func WidgetFunction(controlID string, operation string, arguments ...interface{}) ΩwidgetAction
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ActionGroup ¶ added in v0.2.3
type ActionGroup struct {
Actions []ActionI
}
ActionGroup groups multiple actions as a single action. To use it, call Group() and pass a list of actions.
func Group ¶ added in v0.2.3
func Group(actions ...ActionI) ActionGroup
Call Group to join multiple actions into a single action.
func (ActionGroup) GetCallbackAction ¶ added in v0.2.3
func (g ActionGroup) GetCallbackAction() CallbackActionI
GetCallbackAction returns the embedded callback action in the group, if one exists. Note that you can only have at most one callback action in a group
func (ActionGroup) HasCallbackAction ¶ added in v0.3.0
func (g ActionGroup) HasCallbackAction() bool
func (ActionGroup) HasServerAction ¶ added in v0.2.3
func (g ActionGroup) HasServerAction() bool
func (ActionGroup) ΩRenderScript ¶ added in v0.2.3
func (g ActionGroup) ΩRenderScript(params ΩrenderParams) (s string)
ΩRenderScript renders the group of actions as a single action.
type ActionI ¶
type ActionI interface { // ΩRenderScript is called by the framework to return the action's javascript ΩRenderScript(params ΩrenderParams) string }
ActionI is an interface that defines actions that can be triggered by events
type CallbackAction ¶ added in v0.3.0
type CallbackAction struct { ActionID int DestControlID string SubID string Value interface{} ValidationOverride int // overrides the validation setting that is on the control CallAsync bool }
CallbackAction is a kind of superclass for Ajax and Server actions. Do not use this class directly.
func (*CallbackAction) GetActionValue ¶ added in v0.3.0
func (a *CallbackAction) GetActionValue() interface{}
GetActionValue returns the action value given to the action when it was created.
func (*CallbackAction) GetDestinationControlID ¶ added in v0.3.0
func (a *CallbackAction) GetDestinationControlID() string
GetDestinationControlID returns the control that the action will operate on.
func (*CallbackAction) GetDestinationControlSubID ¶ added in v0.3.0
func (a *CallbackAction) GetDestinationControlSubID() string
GetDestinationControlSubID returns the sub id so that a composite control can send the action to a sub control.
func (*CallbackAction) ID ¶ added in v0.3.0
func (a *CallbackAction) ID() int
ID returns the action id that was defined when the action was created.
func (*CallbackAction) ΩRenderScript ¶ added in v0.3.0
func (a *CallbackAction) ΩRenderScript(params ΩrenderParams) string
type CallbackActionI ¶
type CallbackActionI interface { ActionI // ID returns the id assigned to the action when the action was created. ID() int // GetDestinationControlID returns the id that the action was sent to. GetDestinationControlID() string // GetDestinationControlSubID returns the id of the subcontrol that is the destination of the action, if one was assigned. GetDestinationControlSubID() string // GetActionValue returns the action value that was assigned to the action when the action was fired. GetActionValue() interface{} IsServerAction() bool }
CallbackI defines actions that result in a callback to us. Specifically Server and Ajax actions are defined for now. There is potential for Message action, like through WebSocket, PubHub, etc.
type ΩajaxAction ¶
type ΩajaxAction struct {
CallbackAction
}
func Ajax ¶
func Ajax(destControlId string, actionID int) *ΩajaxAction
Ajax creates an ajax action. When the action fires, the Action() function of the Goradd control identified by the destControlId will be called, and the given actionID will be the ID passed in the ActionParams of the call. You can specify a sub id which indicates that the action should be sent to something inside the main control by concatenating the controls id with another id that indicates the internal destination, separated with an underscore.
The returned action uses a Builder pattern to add options, so for example you might call:
myControl.On(event.Click(), action.Ajax("myControl", MyActionIdConst).ActionValue("myActionValue").Async())
func (*ΩajaxAction) ActionValue ¶
func (a *ΩajaxAction) ActionValue(v interface{}) *ΩajaxAction
ActionValue lets you set a value that will be available to the action handler as the ActionValue() function in the ActionParam structure sent to the event handler. This can be any go type, including slices and maps, or a javascript.JavaScripter interface type. javascript.Closures will be called immediately with a (this) parameter.
func (*ΩajaxAction) Async ¶
func (a *ΩajaxAction) Async() *ΩajaxAction
Aysnc will cause the action to be handled asynchronously. Use this only in special situations where you know that you do not need information from other actions.
func (*ΩajaxAction) DestinationControlID ¶
func (a *ΩajaxAction) DestinationControlID(id string) *ΩajaxAction
DestinationControlID sets the id of the control that will receive the action. You can specify a sub id which indicates that the action should be sent to something inside the main control by concatenating the controls id with another id that indicates the internal destination, separated with an underscore.
func (*ΩajaxAction) IsServerAction ¶ added in v0.0.3
func (a *ΩajaxAction) IsServerAction() bool
func (*ΩajaxAction) Validator ¶
func (a *ΩajaxAction) Validator(v int) *ΩajaxAction
Validator lets you override the validation setting for the control that the action is being sent to.
func (*ΩajaxAction) ΩRenderScript ¶ added in v0.0.3
func (a *ΩajaxAction) ΩRenderScript(params ΩrenderParams) string
ΩRenderScript renders the script as javascript.
type ΩconfirmAction ¶
type ΩconfirmAction struct {
Message interface{}
}
func Confirm ¶
func Confirm(m interface{}) ΩconfirmAction
Confirm will put up a standard browser confirmation dialog box, and will cancel any following actions if the user does not agree.
func (ΩconfirmAction) ΩRenderScript ¶ added in v0.0.3
func (a ΩconfirmAction) ΩRenderScript(params ΩrenderParams) string
type ΩgoraddAction ¶ added in v0.2.0
type ΩgoraddAction struct { Op string Args []interface{} }
func GoraddFunction ¶ added in v0.2.0
func GoraddFunction(operation string, arguments ...interface{}) ΩgoraddAction
GoraddFunction calls a goradd function with the given parameters. This is a function defined on the goradd object in goradd.js.
func Message ¶
func Message(m interface{}) ΩgoraddAction
Message returns an action that will display a standard browser alert message. Specify a string, or one of the javascript.* types.
func SetControlValue ¶
func SetControlValue(id string, key string, value interface{}) ΩgoraddAction
SetControlValue is primarily used by custom controls to set a value that eventually can get picked up by the control in the ΩUpdateFormValues function. It is an aid to tying javascript powered widgets together with the go version of the control. Value gets converted to a javascript value, so use the javascript.* helpers if you want to interpret a javascript value and pass it on. For example:
action.SetControlValue(myControl.ID(), "myKey", javascript.JsCode("event.target.id"))
will pass the id of the target of an event to the receiver of the action.
func (ΩgoraddAction) ΩRenderScript ¶ added in v0.2.0
func (a ΩgoraddAction) ΩRenderScript(params ΩrenderParams) string
type ΩjavascriptAction ¶
type ΩjavascriptAction struct {
JavaScript string
}
func Javascript ¶
func Javascript(js string) ΩjavascriptAction
Javascript will execute the given javascript
func (ΩjavascriptAction) ΩRenderScript ¶ added in v0.0.3
func (a ΩjavascriptAction) ΩRenderScript(params ΩrenderParams) string
type ΩredirectAction ¶
type ΩredirectAction struct {
Location string
}
func Redirect ¶
func Redirect(url string) ΩredirectAction
Redirect will navigate to the given page. TODO: If javascript is turned off, this should still work. We would need to detect the presence of javascript, and then emit a server action instead
func (ΩredirectAction) ΩRenderScript ¶ added in v0.0.3
func (a ΩredirectAction) ΩRenderScript(params ΩrenderParams) string
type ΩrenderParams ¶
type ΩserverAction ¶
type ΩserverAction struct {
CallbackAction
}
func Server ¶
func Server(destControlId string, actionId int) *ΩserverAction
Server creates a server action, which is an action that will use a POST submission mechanism to trigger the action. Generally, with modern browsers, server actions are not that useful, since they cause an entire page to reload, while Ajax actions do not, and so are Ajax actions are quicker to process. However, there are special cases where a server action might be useful, like: - You are moving to a new page anyway. - You are having trouble making an Ajax action work for some reason, and a Server action might get around the problem. - You are submitting a multi-part form, like when uploading a file. When the action fires, the Action() function of the Goradd control identified by the destControlId will be called, and the given actionID will be the ID passed in the ActionParams of the call. You can specify a sub id which indicates that the action should be sent to something inside the main control by concatenating the controls id with another id that indicates the internal destination, separated with an underscore.
The returned action uses a Builder pattern to add options, so for example you might call:
myControl.On(event.Click(), action.Server("myControl", MyActionIdConst).ActionValue("myActionValue").Async())
func (*ΩserverAction) ActionValue ¶
func (a *ΩserverAction) ActionValue(v interface{}) *ΩserverAction
ActionValue lets you set a value that will be available to the action handler as the ActionValue() function in the ActionParam structure sent to the event handler. This can be any go type, including slices and maps, or a javascript.JavaScripter interface type. javascript.Closures will be called immediately with a (this) parameter.
func (*ΩserverAction) Async ¶
func (a *ΩserverAction) Async() *ΩserverAction
Aysnc will cause the action to be handled asynchronously. Use this only in special situations where you know that you do not need information from other actions.
func (*ΩserverAction) DestinationControlID ¶
func (a *ΩserverAction) DestinationControlID(id string) *ΩserverAction
DestinationControlID sets the id of the control that will receive the action. You can specify a sub id which indicates that the action should be sent to something inside the main control by concatenating the controls id with another id that indicates the internal destination, separated with an underscore.
func (*ΩserverAction) IsServerAction ¶ added in v0.0.3
func (a *ΩserverAction) IsServerAction() bool
func (*ΩserverAction) Validator ¶
func (a *ΩserverAction) Validator(v int) *ΩserverAction
Validator lets you override the validation setting for the control that the action is being sent to.
func (*ΩserverAction) ΩRenderScript ¶ added in v0.0.3
func (a *ΩserverAction) ΩRenderScript(params ΩrenderParams) string
ΩRenderScript is called by the framework to render the script as javascript.
type ΩwidgetAction ¶ added in v0.2.0
func AddClass ¶
func AddClass(controlID string, classes string) ΩwidgetAction
AddClass will add the given class, or space separated classes, to the html object specified by the id.
func Blur ¶
func Blur(controlID string) ΩwidgetAction
Blur will blur the html object specified by the id.
func Css ¶ added in v0.2.0
func Css(controlID string, property string, value interface{}) ΩwidgetAction
Css will set the css property to the given value on the given html object.
func Focus ¶
func Focus(controlID string) ΩwidgetAction
Focus will focus the html object specified by the id.
func RemoveClass ¶ added in v0.2.0
func RemoveClass(controlID string, classes string) ΩwidgetAction
RemoveClass will turn off the given space separated classes in the html object specified by the id.
func Select ¶
func Select(controlID string) ΩwidgetAction
Select will set all of the text in the html object specified by the id. The object should be a text box.
func ToggleClass ¶
func ToggleClass(controlID string, classes string) ΩwidgetAction
ToggleClass will turn on or off the given space separated classes in the html object specified by the id.
func Trigger ¶
func Trigger(controlID string, event string, data interface{}) ΩwidgetAction
Trigger will trigger a javascript event on a control
func WidgetFunction ¶ added in v0.2.0
func WidgetFunction(controlID string, operation string, arguments ...interface{}) ΩwidgetAction
WidgetFunction calls a goradd widget function in javascript on an html control with the given id. Available functions are defined by the widget object in goradd.js
func (ΩwidgetAction) ΩRenderScript ¶ added in v0.2.0
func (a ΩwidgetAction) ΩRenderScript(params ΩrenderParams) string