action

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2019 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

The action package 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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionI

type ActionI interface {
	// RenderScript returns the action's javascript
	RenderScript(params ΩrenderParams) string
}

ActionI is an interface that defines actions that can be triggered by events

type CallbackActionI

type CallbackActionI interface {
	ActionI

	ID() int
	GetDestinationControlID() string
	GetDestinationControlSubID() string
	GetActionValue() interface{}
}

CallbackI defines actions that result in a callback to us. Specifically Server and Ajax actions are defined for now. Potential for Message action, like through WebSocket, PubHub, etc.

type PrivateAction

type PrivateAction struct{}

PrivateAction is used by control implementations to add a private action to a controls action list. Unless you are creating a control, you should not use this.

func (PrivateAction) RenderScript

func (a PrivateAction) RenderScript(params ΩrenderParams) string

type ΩajaxAction

type ΩajaxAction struct {
	// contains filtered or unexported fields
}

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) GetActionValue

func (a *ΩajaxAction) GetActionValue() interface{}

func (*ΩajaxAction) GetDestinationControlID

func (a *ΩajaxAction) GetDestinationControlID() string

func (*ΩajaxAction) GetDestinationControlSubID

func (a *ΩajaxAction) GetDestinationControlSubID() string

func (*ΩajaxAction) ID

func (a *ΩajaxAction) ID() int

func (*ΩajaxAction) RenderScript

func (a *ΩajaxAction) RenderScript(params ΩrenderParams) string

func (*ΩajaxAction) Validator

func (a *ΩajaxAction) Validator(v interface{}) *ΩajaxAction

Validator lets you override the validation setting for the control that the action is being sent to.

type ΩblurAction

type ΩblurAction struct {
	ControlID string
}

func Blur

func Blur(controlID string) ΩblurAction

Blur will blur the html object specified by the id.

func (ΩblurAction) RenderScript

func (a ΩblurAction) RenderScript(params ΩrenderParams) string

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

func (a ΩconfirmAction) RenderScript(params ΩrenderParams) string

type ΩcssAddClassAction

type ΩcssAddClassAction struct {
	Classes   string
	ControlID string
}

func AddClass

func AddClass(id string, addClasses string) ΩcssAddClassAction

AddClass will add the given class, or space separated classes, to the html object specified by the id.

func (ΩcssAddClassAction) RenderScript

func (a ΩcssAddClassAction) RenderScript(params ΩrenderParams) string

type ΩcssPropertyAction

type ΩcssPropertyAction struct {
	Property  string
	Value     interface{}
	ControlID string
}

func SetCssProperty

func SetCssProperty(id string, property string, value interface{}) ΩcssPropertyAction

SetCssProperty will set the css property to the given value on the controlID html object.

func (ΩcssPropertyAction) RenderScript

func (a ΩcssPropertyAction) RenderScript(params ΩrenderParams) string

type ΩcssToggleClassAction

type ΩcssToggleClassAction struct {
	Classes   string
	ControlID string
}

func ToggleClass

func ToggleClass(id string, classes string) ΩcssToggleClassAction

ToggleClass will turn on or off the given space separated classes in the html object specified by the id.

func (ΩcssToggleClassAction) RenderScript

func (a ΩcssToggleClassAction) RenderScript(params ΩrenderParams) string

type ΩfocusAction

type ΩfocusAction struct {
	ControlID string
}

Focus will focus the html object specified by the id.

func Focus

func Focus(controlID string) ΩfocusAction

func (ΩfocusAction) RenderScript

func (a ΩfocusAction) 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

func (a ΩjavascriptAction) RenderScript(params ΩrenderParams) string

type ΩmessageAction

type ΩmessageAction struct {
	Message interface{}
}

func Message

func Message(m interface{}) ΩmessageAction

Message returns an action that will display a standard browser alert message. Specify a string, or one of the javascript.* types.

func (ΩmessageAction) RenderScript

func (a ΩmessageAction) 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.

func (ΩredirectAction) RenderScript

func (a ΩredirectAction) RenderScript(params ΩrenderParams) string

type ΩrenderParams

type ΩrenderParams struct {
	TriggeringControlID string
	ControlActionValue  interface{}
	EventID             uint16
	EventActionValue    interface{}
}

type ΩselectAction

type ΩselectAction struct {
	ControlID string
}

func Select

func Select(controlID string) ΩselectAction

Select will set all of the text in the html object specified by the id. The object should be a text box.

func (ΩselectAction) RenderScript

func (a ΩselectAction) RenderScript(params ΩrenderParams) string

type ΩserverAction

type ΩserverAction struct {
	// contains filtered or unexported fields
}

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) GetActionValue

func (a *ΩserverAction) GetActionValue() interface{}

func (*ΩserverAction) GetDestinationControlID

func (a *ΩserverAction) GetDestinationControlID() string

func (*ΩserverAction) GetDestinationControlSubID

func (a *ΩserverAction) GetDestinationControlSubID() string

func (*ΩserverAction) ID

func (a *ΩserverAction) ID() int

func (*ΩserverAction) RenderScript

func (a *ΩserverAction) RenderScript(params ΩrenderParams) string

func (*ΩserverAction) Validator

func (a *ΩserverAction) Validator(v interface{}) *ΩserverAction

Validator lets you override the validation setting for the control that the action is being sent to.

type ΩsetControlValueAction

type ΩsetControlValueAction struct {
	ID    string
	Key   string
	Value interface{}
}

func SetControlValue

func SetControlValue(id string, key string, value interface{}) ΩsetControlValueAction

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 (ΩsetControlValueAction) RenderScript

func (a ΩsetControlValueAction) RenderScript(params ΩrenderParams) string

type ΩtriggerAction

type ΩtriggerAction struct {
	ControlID string
	Event     string
	Data      interface{}
}

func Trigger

func Trigger(controlID string, event string, data interface{}) ΩtriggerAction

Trigger will trigger a javascript event on a control

func (ΩtriggerAction) RenderScript

func (a ΩtriggerAction) RenderScript(params ΩrenderParams) string

Jump to

Keyboard shortcuts

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