page

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2019 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FrameworkErrNone = iota
	FrameworkErrNoTemplate
	FrameworkErrRecordNotFound
	FrameworkErrNotAuthorized
)
View Source
const (
	ResponseWatcher        = "watcher"
	ResponseControls       = "controls"
	ResponseCommandsHigh   = "commandsHigh"
	ResponseCommandsMedium = "commands"
	ResponseCommandsLow    = "commandsLow"
	ResponseCommandsFinal  = "commandsFinal"
	ResponseRegC           = "regc" // register control list
	ResponseHtml           = "html"
	ResponseValue          = "value"
	ResponseId             = "id"
	ResponseAttributes     = "attributes"
	ResponseCss            = "css"
	ResponseClose          = "winclose"
	ResponseLocation       = "loc"
	ResponseAlert          = "alert"
	ResponseStyleSheets    = "ss"
	ResponseJavaScripts    = "js"
)
View Source
const (
	ErrorWrapper = "page.Error"
	LabelWrapper = "page.Label"
	DivWrapper   = "page.Div"
)

Wrapper constants used in the With function

View Source
const EncodingVersion = 1 //
View Source
const MaxStackDepth = 50
View Source
const PrivateActionBase = 1000
View Source
const RequiredErrorMessage string = "A value is required"

Variables

View Source
var DefaultCheckboxLabelDrawingMode = html.LabelAfter // Setting used by checkboxes and radio buttons to default how they draw labels.
View Source
var MaxBufferSize = 10000
View Source
var MultipartFormMax int64 = 10000000 // 10MB max in memory file
View Source
var PageCacheVersion int32 = 1

PageCacheVersion helps us keep track of when a change to the application changes the pagecache format. It is only needed when serializing the pagecache. Some page cache stores may be difficult to invalidate the whole thing, so this lets lets us invalidate old pagecaches individually. If you implement your own pagecache, you may want to control this independently of goradd, which is why this is exported. Goradd should bump this value whenever the pagecache serialization format changes.

View Source
var PagePathPrefix = ""

Functions

func ControlConnectorParams

func ControlConnectorParams() *maps.SliceMap

ConnectorParams returns a list of options setable by the connector dialog (not currently implemented)

func ConvertToBool

func ConvertToBool(v interface{}) bool

ConvertToBool is a helper function that can convert Put or Get values and other possible kinds of values into a bool value.

func DebugErrorPageTmpl

func DebugErrorPageTmpl(ctx context.Context, partialHtml string, err *Error, buf *bytes.Buffer)

The DebugErrorPageTmpl writes a debug error page to the html output so that it will display the error in the browser, possibly as a popup. Do not use this on the release server, as it may expose details of your application that you do not want exposed.

func DivTmpl

func DivTmpl(ctx context.Context, ctrl ControlI, h string, buf *bytes.Buffer)

func ErrorTmpl

func ErrorTmpl(ctx context.Context, ctrl ControlI, h string, buf *bytes.Buffer)

func GetAssetLocation

func GetAssetLocation(url string) string

func GetAssetUrl

func GetAssetUrl(location string) string

func GetBuffer

func GetBuffer() *bytes.Buffer

GetBuffer returns a buffer from the pool. It will create a new pool if one is not already allocated. This allows you to inject your own replacement BufferPool before the first use of GetBuffer()

func IsError

func IsError(e error) bool

func LabelTmpl

func LabelTmpl(ctx context.Context, w *LabelWrapperType, ctrl ControlI, h string, buf *bytes.Buffer)

func PageTmpl

func PageTmpl(ctx context.Context, page *Page, buf *bytes.Buffer) (err error)

func PutBuffer

func PutBuffer(buffer *bytes.Buffer)

PutBuffer puts a buffer back into the pool. Be very careful that you do not refer to the buffer after putting it back, including using a slice of a buffer.

func PutContext

func PutContext(r *http.Request, cliArgs []string) *http.Request

func Redirect

func Redirect(url string)

Redirect aborts the current page load and tells the browser to load a different url

func RegisterAssetDirectory

func RegisterAssetDirectory(dir string, pattern string)

RegisterAssetDirectory registers the given directory as a static file server. The files are served by the normal go static file process. This must happen during application initialization, as the static file directories are added to the MUX at startup time.

func RegisterControlWrapper

func RegisterControlWrapper(name string, w WrapperI)

func RegisterPage

func RegisterPage(path string, creationFunction FormCreationFunction, formId string)

func RegisterTemplate

func RegisterTemplate(name string, t TemplateExecuter)

func ReleaseErrorPageTmpl

func ReleaseErrorPageTmpl(ctx context.Context, partialHtml string, err *Error, buf *bytes.Buffer)

The ReleaseErrorPageTmpl function will output a friendly error message to a user in release mode, and log the error to the Error log.

func ServeAsset

func ServeAsset(w http.ResponseWriter, r *http.Request)

func SetPageCache

func SetPageCache(c PageCacheI)

func SetPageEncoder

func SetPageEncoder(e PageEncoderI)

Types

type ActionParams

type ActionParams struct {
	// Id is the id assigned when the action is created
	ID int
	// Action is an interface to the action itself
	Action action.ActionI
	// ControlID is the control that originated the action
	ControlId string
	// contains filtered or unexported fields
}

ActionParams are sent to the Action() function in controls in response to a user action.

func (*ActionParams) ActionValue

func (a *ActionParams) ActionValue(i interface{}) (ok bool, err error)

ActionValue will attempt to put the Action value into the given object using json.Unmarshal. You should primarily use it to get object or array values out of the Action value. If you are expecting a basic type, use one of the ActionValue* helper functions instead. The given value should be a pointer to an object or variable that is the expected type for the data. ok will be false if no data was found. It will return an error if the data was found, but could not be converted to the given type.

func (*ActionParams) ActionValueBool

func (a *ActionParams) ActionValueBool() bool

func (*ActionParams) ActionValueFloat

func (a *ActionParams) ActionValueFloat() float64

func (*ActionParams) ActionValueInt

func (a *ActionParams) ActionValueInt() int

func (*ActionParams) ActionValueString

func (a *ActionParams) ActionValueString() string

ActionString returns the action value as a string. It will convert to a string, even if the value is not a string.

func (*ActionParams) ControlValue

func (a *ActionParams) ControlValue(i interface{}) (ok bool, err error)

ControlValue will attempt to put the Control value into the given object using json.Unmarshal. You should primarily use it to get object or array values out of the Control value. If you are expecting a basic type, use one of the ControlValue* helper functions instead. The given value should be a pointer to an object or variable that is the expected type for the data. ok will be false if no data was found. It will return an error if the data was found, but could not be converted to the given type.

func (*ActionParams) ControlValueBool

func (a *ActionParams) ControlValueBool() (ret bool)

func (*ActionParams) ControlValueFloat

func (a *ActionParams) ControlValueFloat() float64

func (*ActionParams) ControlValueInt

func (a *ActionParams) ControlValueInt() int

func (*ActionParams) ControlValueString

func (a *ActionParams) ControlValueString() string

ControlString returns the control value as a string. It will convert to a string, even if the value is not a string.

func (*ActionParams) EventValue

func (a *ActionParams) EventValue(i interface{}) (ok bool, err error)

EventValue will attempt to put the Event value into the given object using json.Unmarshal. You should primarily use it to get object or array values out of the Action value. If you are expecting a basic type, use one of the EventValue* helper functions instead. The given value should be a pointer to an object or variable that is the expected type for the data. ok will be false if no data was found. It will return an error if the data was found, but could not be converted to the given type.

func (*ActionParams) EventValueBool

func (a *ActionParams) EventValueBool() bool

func (*ActionParams) EventValueFloat

func (a *ActionParams) EventValueFloat() float64

func (*ActionParams) EventValueInt

func (a *ActionParams) EventValueInt() int

func (*ActionParams) EventValueString

func (a *ActionParams) EventValueString() string

EventValueString returns the event value as a string. It will convert to a string, even if the value is not a string.

type AppContext

type AppContext struct {
	OutBuf *bytes.Buffer
	// contains filtered or unexported fields
}

AppContext has Goradd application specific nodes

type BufferPoolI

type BufferPoolI interface {
	GetBuffer() *bytes.Buffer
	PutBuffer(buffer *bytes.Buffer)
}

BufferPoolI describes a buffer pool that can be used to improve memory allocation and garbage collection for the frequent memory use.

var BufferPool BufferPoolI

BufferPool is the global buffer pool used by the page drawing system. You can use it to get buffers for you own writes as well. The default buffer pool uses MaxBufferSize to limit the size of buffers that are put back into the pool. If a particular http request required a large buffer to satisfy, this prevents that buffer from hanging around too long. You should set MaxBufferSize to a value that is bigger than most http request sizes.

type Context

type Context struct {
	HttpContext
	AppContext
}

func GetContext

func GetContext(ctx context.Context) *Context

func (*Context) CheckableValue

func (ctx *Context) CheckableValue(key string) (value interface{}, ok bool)

func (*Context) CheckableValues

func (ctx *Context) CheckableValues() map[string]interface{}

func (*Context) CustomControlValue

func (ctx *Context) CustomControlValue(id string, key string) interface{}

func (*Context) FillApp

func (ctx *Context) FillApp(cliArgs []string)

FillApp fills the app structure with app specific information from the request Do not panic here!

func (*Context) FillHttp

func (ctx *Context) FillHttp(r *http.Request) (err error)

func (*Context) FormValue

func (ctx *Context) FormValue(key string) (value string, ok bool)

Returns the given form variable value, either from post or get variables If the value does not exist, or is a multi-part value, returns false in ok Use FormValues for multipart values

func (*Context) FormValues

func (ctx *Context) FormValues(key string) (value []string, ok bool)

Returns the corresponding form value as a string slice. Use this when you are expecting more than one value in the given form variable

func (*Context) RequestMode

func (ctx *Context) RequestMode() RequestMode

func (*Context) String

func (c *Context) String() string

type ContextI

type ContextI interface {
	Http() *HttpContext
	App() *AppContext
}

type Control

type Control struct {
	base.Base

	Tag       string
	IsVoidTag bool // tag does not get wrapped with a terminating tag, but just ends instead

	// ErrorForRequired is the error that will display if a control value is required but not set.
	ErrorForRequired string
	// ValidMessage is the message to display if the control has successfully been validated. Leave blank if you don't want a message to show when valid. Can be useful to contrast between invalid and valid controls in a busy form.
	ValidMessage string
	// contains filtered or unexported fields
}

func (*Control) Action

func (c *Control) Action(ctx context.Context, a ActionParams)

Action processes actions. Typically, the Action function will first look at the id to know how to handle it. This is just an empty implemenation. Sub-controls should implement this.

func (*Control) ActionValue

func (c *Control) ActionValue() interface{}

ActionValue returns the control's action value

func (*Control) AddClass

func (c *Control) AddClass(class string) ControlI

func (*Control) AddRelatedRenderScript

func (c *Control) AddRelatedRenderScript(id string, f string, params ...interface{})

AddRelatedRenderScript adds a render script for a related html object. This is primarily used by control implementations.

func (*Control) AddRenderScript

func (c *Control) AddRenderScript(f string, params ...interface{})

Adds a jQuery command to be executed on the next ajax draw. These commands allow javascript to change an aspect of the control without having to redraw the entire control. This should primarily be used by control implementations only.

func (*Control) AddWrapperClass

func (c *Control) AddWrapperClass(class string) ControlI

func (*Control) Attribute

func (c *Control) Attribute(name string) string

func (*Control) Child

func (c *Control) Child(id string) ControlI

func (*Control) Children

func (c *Control) Children() []ControlI

func (*Control) Deserialize

func (c *Control) Deserialize(d Decoder, p *Page) (err error)

func (*Control) Draw

func (c *Control) Draw(ctx context.Context, buf *bytes.Buffer) (err error)

Draws the default control structure into the given buffer.

func (*Control) DrawAjax

func (c *Control) DrawAjax(ctx context.Context, response *Response) (err error)

func (*Control) DrawChildren

func (c *Control) DrawChildren(ctx context.Context, buf *bytes.Buffer) (err error)

func (*Control) DrawInnerHtml

func (c *Control) DrawInnerHtml(ctx context.Context, buf *bytes.Buffer) (err error)

Returns the inner text of the control, if the control is not a self terminating (void) control. Sub-controls can override this.

func (*Control) DrawTag

func (c *Control) DrawTag(ctx context.Context) string

Draw the control tag itself. Override to draw the tag in a different way, or draw more than one tag if drawing a compound control.

func (*Control) DrawTemplate

func (c *Control) DrawTemplate(ctx context.Context, buf *bytes.Buffer) (err error)

Controls that use templates should use this function signature for the template. That will override this one, and we will then detect that the template was drawn. Otherwise, we detect that no template was defined and it will move on to drawing the controls without a template, or just the text if text is defined.

func (*Control) DrawText

func (c *Control) DrawText(ctx context.Context, buf *bytes.Buffer)

Draws the text of the control, escaping if needed

func (*Control) DrawingAttributes

func (c *Control) DrawingAttributes() *html.Attributes

Returns a set of attributes that should override those set by the user. This allows controls to set attributes just before drawing that should take precedence over other attributes, and that are critical to drawing the tag of the control. This function is designed to only be called by overriding functions, changes will not be remembered.

func (*Control) ExecuteJqueryFunction

func (c *Control) ExecuteJqueryFunction(command string, params ...interface{})

ExecuteJqueryFunction will execute the given JQuery function on the given command, with the given parameters. i.e. jQuery("#id").command(params...); will get executed in javascript.

func (*Control) GetActionScripts

func (c *Control) GetActionScripts(r *Response)

GetActionScripts is an internal function called during drawing to recursively gather up all the event related scripts attached to the control and send them to the response.

func (*Control) GobDecode

func (c *Control) GobDecode(data []byte) (err error)

func (*Control) GobEncode

func (c *Control) GobEncode() (data []byte, err error)

GobEncode here is implemented to intercept the GobSerializer to only encode an empty structure. We use this as part of our overall serialization stratgey for forms. Controls still need to be registered with gob.

func (*Control) HasAttribute

func (c *Control) HasAttribute(name string) bool

func (*Control) HasFor

func (c *Control) HasFor() bool

func (*Control) HasWrapper

func (c *Control) HasWrapper() bool

func (*Control) ID

func (c *Control) ID() string

func (*Control) Init

func (c *Control) Init(self ControlI, parent ControlI, id string)

Init should be called immediately after a control is created and is responsible for setting up the initial state of a new control. Your subclasses should have their own Init function, and should call the superclass function. This Init function sets up a parent-child relationship with the given parent control, and sets up data structures to use the control in object-oriented ways with virtual functions. The id is the control id that will appear as the id in html. Leave blank for the system to create a unique id for you.

func (*Control) Instructions

func (c *Control) Instructions() string

func (*Control) IsDisabled

func (c *Control) IsDisabled() bool

func (*Control) IsDisplayed

func (c *Control) IsDisplayed() bool

func (*Control) IsRendering

func (c *Control) IsRendering() bool

func (*Control) IsRequired

func (c *Control) IsRequired() bool

func (*Control) IsVisible

func (c *Control) IsVisible() bool

func (*Control) Label

func (c *Control) Label() string

func (*Control) MarshalJSON

func (c *Control) MarshalJSON() (data []byte, err error)

func (*Control) MarshalState

func (c *Control) MarshalState(m maps.Setter)

MarshalState is a helper function for controls to save their basic state, so that if the form is reloaded, the value that the user entered will not be lost. Implementing controls should add items to the given map. Note that the control id is used as a key for the state, so that if you are dynamically adding controls, you should make sure you give a specific, non-changing control id to the control, or the state may be lost.

func (*Control) Off

func (c *Control) Off()

Off removes all event handlers from the control

func (*Control) On

func (c *Control) On(e EventI, actions ...action2.ActionI) EventI

On adds an event listener to the control that will trigger the given actions

func (*Control) Page

func (c *Control) Page() *Page

func (*Control) Parent

func (c *Control) Parent() ControlI

Control Hierarchy Functions

func (*Control) ParentForm

func (c *Control) ParentForm() FormI

ParentForm returns the form object that encloses this control.

func (*Control) PostRender

func (c *Control) PostRender(ctx context.Context, buf *bytes.Buffer) (err error)

func (*Control) PreRender

func (c *Control) PreRender(ctx context.Context, buf *bytes.Buffer) error

func (*Control) PrivateAction

func (c *Control) PrivateAction(ctx context.Context, a ActionParams)

PrivateAction processes actions that a control sets up for itself, and that it does not want to give the opportunity for users of the control to manipulate or remove those actions. Generally, private actions should call their superclass PrivateAction function too.

func (*Control) PutCustomScript

func (c *Control) PutCustomScript(ctx context.Context, response *Response)

PutCustomScript is the place where you add javascript that transforms the html into a custom javascript control. Do this by calling functions on the response object. This implementation is a stub.

func (*Control) Refresh

func (c *Control) Refresh()

Drawing aids

func (*Control) Remove

func (c *Control) Remove()

Remove removes the current control from its parent. After this is done, the control and all its child items will not be part of the override, but the child items will still be accessible through the control itself.

func (*Control) RemoveChild

func (c *Control) RemoveChild(id string)

RemoveChild removes the given child control from both the control and the override.

func (*Control) RemoveChildren

func (c *Control) RemoveChildren()

RemoveChildren removes all the child controls from this control and the override

func (*Control) RemoveClass

func (c *Control) RemoveClass(class string) ControlI

func (*Control) RemoveClassesWithPrefix

func (c *Control) RemoveClassesWithPrefix(prefix string)

func (*Control) RenderAutoControls

func (c *Control) RenderAutoControls(ctx context.Context, buf *bytes.Buffer) (err error)

RenderAutoControls is an internal function to draw controls marked to autoRender. These are generally used for hidden controls that can be shown without impacting layout, or that are scripts only.

func (*Control) Restore

func (c *Control) Restore(self ControlI)

Restore is called after the control has been deserialized. It creates any required data structures that are not saved in serialization.

func (*Control) SaveState

func (c *Control) SaveState(ctx context.Context, saveIt bool)

SaveState sets whether the control should save its value and other state information so that if the form is redrawn, the value can be restored. This function is also responsible for restoring the previously saved state of the control, so call This only after you have set the default state of a control during creation or initialization.

func (*Control) Serialize

func (c *Control) Serialize(e Encoder) (err error)

func (*Control) SetActionValue

func (c *Control) SetActionValue(v interface{}) ControlI

SetActionValue sets a value that is provided to actions when they are triggered. The value can be a static value or one of the javascript.* objects that can dynamically generate values. The value is then sent back to the action handler after the action is triggered.

func (*Control) SetAttribute

func (c *Control) SetAttribute(name string, val interface{}) ControlI

func (*Control) SetBlockParentValidation

func (c *Control) SetBlockParentValidation(block bool)

SetBlockParentValidation will prevent a parent from validating this control. This is generally useful for panels and other containers of controls that wish to have their own validation scheme. Dialogs in particular need this since they essentially act as a separate form, even though technically they are included in a form.

func (*Control) SetDataAttribute

func (c *Control) SetDataAttribute(name string, val interface{})

func (*Control) SetDisabled

func (c *Control) SetDisabled(d bool)

func (*Control) SetDisplay

func (c *Control) SetDisplay(d string)

func (*Control) SetEscapeText

func (c *Control) SetEscapeText(e bool) ControlI

SetEscapeText to false to turn off html escaping of the text output. It is on by default.

func (*Control) SetHasFor

func (c *Control) SetHasFor(v bool) ControlI

func (*Control) SetHeightStyle

func (c *Control) SetHeightStyle(h interface{}) ControlI

SetHeightStyle sets the height css property

func (*Control) SetInstructions

func (c *Control) SetInstructions(i string) ControlI

func (*Control) SetIsRequired

func (c *Control) SetIsRequired(r bool) ControlI

func (*Control) SetLabel

func (c *Control) SetLabel(n string) ControlI

func (*Control) SetParent

func (c *Control) SetParent(newParent ControlI)

func (*Control) SetShouldAutoRender

func (c *Control) SetShouldAutoRender(r bool)

func (*Control) SetStyle

func (c *Control) SetStyle(name string, value string) ControlI

func (*Control) SetStyles

func (c *Control) SetStyles(s *html.Style)

func (*Control) SetText

func (c *Control) SetText(t string) ControlI

func (*Control) SetValidationError

func (c *Control) SetValidationError(e string)

SetValidationError sets the validation error to the given string. It will also handle setting the wrapper class to indicate an error. Override if you have a different way of handling errors.

func (*Control) SetValidationTargets

func (c *Control) SetValidationTargets(controlIDs ...string)

SetValidationTargets specifies which controls to validate, in conjunction with the ValidationType setting, giving you very fine-grained control over validation. The default is to use just this control as the target.

func (*Control) SetValidationType

func (c *Control) SetValidationType(typ ValidationType)

SetValidationType specifies how this control validates other controls. Typically its either ValidateNone or ValidateForm. ValidateForm will validate all the controls on the form. ValidateSiblingsAndChildren will validate the immediate siblings of the target controls and their children ValidateSiblingsOnly will validate only the siblings of the target controls ValidateTargetsOnly will validate only the specified target controls

func (*Control) SetVisible

func (c *Control) SetVisible(v bool)

func (*Control) SetWidthStyle

func (c *Control) SetWidthStyle(w interface{}) ControlI

SetWidthStyle sets the width css property

func (*Control) SetWillBeValidated

func (c *Control) SetWillBeValidated(v bool)

SetWillBeValidated indicates to the wrapper whether to save a spot for a validation message or not.

func (*Control) SetWrapperAttribute

func (c *Control) SetWrapperAttribute(name string, val interface{}) ControlI

func (*Control) ShouldAutoRender

func (c *Control) ShouldAutoRender() bool

func (*Control) T

func (c *Control) T(message string, params ...interface{}) string

T sends strings to the translator for translation, and returns the translated string. The language is taken from the session. See the i18n package for more info on that mechanism. Additionally, you can add an i18n.ID() call to add an id to the translation to disambiguate it from similar strings, and you can add a i18n.Comment() call to add an extracted comment for the translators. The message string should be a literal string and not a variable, so that an extractor can extract it from your source to put it into a translation file. This version passes the literal string.

Examples

  textbox.T("I have %d things", count, i18n.Comment("This will need multiple translations based on the count value"));
	 textbox.SetLabel(textbox.T("S", i18n.ID("South")));

func (*Control) TPrintf

func (c *Control) TPrintf(message string, params ...interface{}) string

This is like T(), but works like Sprintf, returning the translated string, but sending the arguments to the message as if the message was an Sprintf format string. The go/text extractor has code that can do interesting things with this kind of string.

func (*Control) Text

func (c *Control) Text() string

func (*Control) TextIsLabel

func (c *Control) TextIsLabel() bool

TextIsLabel is used by the drawing routines to determine if the control's text should be wrapped with a label tag, Meaning the Label itself

func (*Control) UnmarshalJSON

func (c *Control) UnmarshalJSON(data []byte) (err error)

func (*Control) UnmarshalState

func (c *Control) UnmarshalState(m maps.Loader)

UnmarshalState is a helper function for controls to get their state from the stateStore. To implement it, a control should read the data out of the given map. If needed, implemet your own version checking scheme. The given map will be guaranteed to have been written out by the same kind of control as the one reading it. Be sure to call the super-class version too.

func (*Control) UpdateFormValues

func (c *Control) UpdateFormValues(ctx *Context)

UpdateFormValues should be implemented by controls to get their values from the context.

func (*Control) Validate

func (c *Control) Validate(ctx context.Context) bool

Validate is designed to be overridden. Overriding controls should call the parent version before doing their own validation.

func (*Control) ValidationMessage

func (c *Control) ValidationMessage() string

func (*Control) ValidationState

func (c *Control) ValidationState() ValidationState

func (*Control) ValidationType

func (c *Control) ValidationType(e EventI) ValidationType

ValidationType is an internal function to return the validation type. It allows subclasses to override it.

func (*Control) WasRendered

func (c *Control) WasRendered() bool

func (*Control) With

func (c *Control) With(w WrapperI) ControlI

With sets the wrapper style for the control, essentially setting the wrapper template function that will be used.

func (*Control) WrapEvent

func (c *Control) WrapEvent(eventName string, selector string, eventJs string) string

WrapEvent is an internal function to allow the control to customize its treatment of event processing.

func (*Control) Wrapper

func (c *Control) Wrapper() WrapperI

func (*Control) WrapperAttributes

func (c *Control) WrapperAttributes() *html.Attributes

WrapperAttributes returns the actual attributes for the wrapper. Changes WILL be remembered so that subsequent ajax drawing will draw the wrapper correctly. However, it is up to you to refresh the control if you change anything.

func (*Control) ΩT

func (c *Control) ΩT(message string) string

ΩT is a shortcut for the translator that uses the internal Goradd domain for translations.

func (*Control) ΩisSerializer

func (c *Control) ΩisSerializer(i ControlI) bool

ΩisSerializer is used by the automated control serializer to determine how far down the control chain the control has to go before just calling serialize and deserialize

type ControlI

type ControlI interface {
	ID() string

	DrawI

	DrawTag(context.Context) string
	DrawInnerHtml(context.Context, *bytes.Buffer) error
	DrawTemplate(context.Context, *bytes.Buffer) error
	PreRender(context.Context, *bytes.Buffer) error
	PostRender(context.Context, *bytes.Buffer) error
	ShouldAutoRender() bool
	SetShouldAutoRender(bool)
	DrawAjax(ctx context.Context, response *Response) error
	DrawChildren(ctx context.Context, buf *bytes.Buffer) error
	DrawText(ctx context.Context, buf *bytes.Buffer)
	With(w WrapperI) ControlI
	HasWrapper() bool
	Wrapper() WrapperI

	Parent() ControlI
	Children() []ControlI
	SetParent(parent ControlI)
	Remove()
	RemoveChild(id string)
	RemoveChildren()
	Page() *Page
	ParentForm() FormI
	Child(string) ControlI

	SetAttribute(name string, val interface{}) ControlI
	SetWrapperAttribute(name string, val interface{}) ControlI
	Attribute(string) string
	HasAttribute(string) bool
	DrawingAttributes() *html.Attributes
	WrapperAttributes() *html.Attributes
	AddClass(class string) ControlI
	RemoveClass(class string) ControlI
	AddWrapperClass(class string) ControlI
	SetStyles(*html.Style)
	SetStyle(name string, value string) ControlI
	SetWidthStyle(w interface{}) ControlI
	SetHeightStyle(w interface{}) ControlI

	PutCustomScript(ctx context.Context, response *Response)

	HasFor() bool
	SetHasFor(bool) ControlI

	Label() string
	SetLabel(n string) ControlI
	TextIsLabel() bool
	Text() string
	SetText(t string) ControlI
	ValidationMessage() string
	SetValidationError(e string)
	Instructions() string
	SetInstructions(string) ControlI

	WasRendered() bool
	IsRendering() bool
	IsVisible() bool
	SetVisible(bool)

	Refresh()

	Action(context.Context, ActionParams)
	PrivateAction(context.Context, ActionParams)
	SetActionValue(interface{}) ControlI
	ActionValue() interface{}
	On(e EventI, a ...action2.ActionI) EventI
	Off()
	WrapEvent(eventName string, selector string, eventJs string) string

	UpdateFormValues(*Context)

	Validate(ctx context.Context) bool
	ValidationState() ValidationState
	ValidationType(EventI) ValidationType

	// SaveState tells the control whether to save the basic state of the control, so that when the form is reentered, the
	// data in the control will remain the same. This is particularly useful if the control is used as a filter for the
	// contents of another control.
	SaveState(context.Context, bool)
	MarshalState(m maps.Setter)
	UnmarshalState(m maps.Loader)

	// Shortcuts for translation
	ΩT(format string) string
	T(format string, params ...interface{}) string
	TPrintf(format string, params ...interface{}) string

	// Serialization helpers
	Restore(self ControlI)

	// API
	SetIsRequired(r bool) ControlI

	Serialize(e Encoder) (err error)
	Deserialize(d Decoder, p *Page) (err error)
	ΩisSerializer(i ControlI) bool
	// contains filtered or unexported methods
}

type ControlLoc

type ControlLoc int8
const (
	ControlIsNil ControlLoc = iota
	ControlIsHere
	ControlIsInPage
)

type ControlTemplateFunc

type ControlTemplateFunc func(ctx context.Context, control ControlI, buffer *bytes.Buffer) error

type ControlWrapperFunc

type ControlWrapperFunc func(ctx context.Context, control ControlI, ctrl string, buffer *bytes.Buffer)

type DbError

type DbError struct {
	Error
	// captured database statement if one caused the error, returned by the db adapter
	DbStatement string
}

func NewDbErr

func NewDbErr(ctx context.Context, msg interface{}, dbStatement string) *DbError

type Decoder

type Decoder interface {
	Decode(v interface{}) error
	DecodeControl(p *Page) (ControlI, error)
}

Decoder defines objects that can be decoded from a pagestate. If the object does not implement this, we will look for GobDecode support.

type DivWrapperType

type DivWrapperType struct {
}

func NewDivWrapper

func NewDivWrapper() *DivWrapperType

func (DivWrapperType) TypeName

func (w DivWrapperType) TypeName() string

func (DivWrapperType) ΩAjaxRender

func (w DivWrapperType) ΩAjaxRender(ctx context.Context, response *Response, c ControlI)

func (DivWrapperType) ΩModifyDrawingAttributes

func (w DivWrapperType) ΩModifyDrawingAttributes(ctrl ControlI, a *html.Attributes)

func (DivWrapperType) ΩNewI

func (w DivWrapperType) ΩNewI() WrapperI

func (DivWrapperType) ΩSetValidationMessageChanged

func (w DivWrapperType) ΩSetValidationMessageChanged()

func (DivWrapperType) ΩSetValidationStateChanged

func (w DivWrapperType) ΩSetValidationStateChanged()

func (DivWrapperType) ΩWrap

func (w DivWrapperType) ΩWrap(ctx context.Context, ctrl ControlI, html string, buf *bytes.Buffer)

type DrawI

type DrawI interface {
	Draw(context.Context, *bytes.Buffer) error
}

Anything that draws into the draw buffer must implement this interface

type Encoder

type Encoder interface {
	Encode(v interface{}) error
	EncodeControl(v ControlI) error
}

Encoder defines objects that can be encoded into a pagestate.

type Error

type Error struct {
	// the error string
	Err error
	// the time the error occurred
	Time time.Time
	// the copied context when the error occurred
	Ctx *Context
	// unwound Stack info
	Stack []StackFrame
}

The error structure, specifically designed to manage panics during request handling

func NewError

func NewError(ctx context.Context, msg string) *Error

Call and return a generic message error

func (*Error) Error

func (e *Error) Error() string

type ErrorPageFuncType

type ErrorPageFuncType func(ctx context.Context, html string, err *Error, buf *bytes.Buffer)

The ErrorPageTemplate type specifies the signature for the error template function. You can replace the built-in error function with your own function by setting the config.ErrorPage value. html is the html that was able to be generated before the error occurred, which can be helpful in tracking down the source of an error.

var ErrorPageFunc ErrorPageFuncType

type ErrorWrapperType

type ErrorWrapperType struct {
	ValidationMessageChanged bool
	ValidationStateChanged   bool
}

An ErrorWrapperType wraps a control with a validation message

func NewErrorWrapper

func NewErrorWrapper() *ErrorWrapperType

func (*ErrorWrapperType) TypeName

func (w *ErrorWrapperType) TypeName() string

func (*ErrorWrapperType) ΩAjaxRender

func (w *ErrorWrapperType) ΩAjaxRender(ctx context.Context, response *Response, c ControlI)

ΩAjaxRender is called by the framework to draw any changes to the wrapper that we have recorded. This has to work closely with the wrapper template so that it would create the same effect as if that entire control had been redrawn

func (*ErrorWrapperType) ΩModifyDrawingAttributes

func (w *ErrorWrapperType) ΩModifyDrawingAttributes(c ControlI, a *html.Attributes)

ΩModifyDrawingAttributes should only be called by the framework during a draw. It changes attributes of the wrapped control based on the validation state of the control.

func (ErrorWrapperType) ΩNewI

func (w ErrorWrapperType) ΩNewI() WrapperI

Copy copies itself and returns it. This is used when a new wrapper is created from a named type.

func (*ErrorWrapperType) ΩSetValidationMessageChanged

func (w *ErrorWrapperType) ΩSetValidationMessageChanged()

func (*ErrorWrapperType) ΩSetValidationStateChanged

func (w *ErrorWrapperType) ΩSetValidationStateChanged()

func (*ErrorWrapperType) ΩWrap

func (w *ErrorWrapperType) ΩWrap(ctx context.Context, ctrl ControlI, html string, buf *bytes.Buffer)

ΩWrap wraps the given control with an ErrorWrapperTemplate. The ErrorWrapperTemplate adds a validation message to a control's html, and also an instructions message.

type Event

type Event struct {
	JsEvent string
	// contains filtered or unexported fields
}

Event represents a javascript event that triggers an action. Create it with a call to NewEvent(), or one of the predefined events in the event package, like event.Click()

func (*Event) ActionValue

func (e *Event) ActionValue(r interface{}) EventI

ActionValue is a value that will be returned to the actions that will be process by this event. Specify a static value, or javascript objects that will gather data at the time the event fires. The event will appear in the ActionParams as the EventValue. Example: ActionValue(javascript.ModelName("ui")) will return the "ui" variable that is part of the event call.

func (*Event) Blocking

func (e *Event) Blocking() EventI

Call Blocking to cause this event to prevent other events from firing after this fires, but before it processes. If another event fires between the time when this event fires and when a response is received, it will be lost.

func (*Event) Condition

func (e *Event) Condition(javascript string) EventI

Condition specifies a javascript condition to check before triggering the event. The given string should be javascript code that evaluates to a boolean value.

func (*Event) Delay

func (e *Event) Delay(d int) EventI

Delay is the time in milliseconds to wait before triggering the actions.

func (*Event) GetActionValue

func (e *Event) GetActionValue() interface{}

func (*Event) GobDecode

func (e *Event) GobDecode(data []byte) (err error)

func (*Event) GobEncode

func (e *Event) GobEncode() (data []byte, err error)

func (*Event) PreventBubbling

func (e *Event) PreventBubbling() EventI

Call PreventBubbling to cause the event to not bubble to enclosing objects.

func (*Event) PreventingDefault

func (e *Event) PreventingDefault() EventI

Call PreventingDefault to cause the event not to do the default action.

func (*Event) Selector

func (e *Event) Selector(s string) EventI

Selector specifies a CSS filter that is used to check for bubbled events. This allows the event to be fired from child controls.

func (*Event) String

func (e *Event) String() string

func (*Event) Terminating

func (e *Event) Terminating() EventI

Call Terminating to cause the event not to bubble or do the default action.

func (*Event) Validate

func (e *Event) Validate(v ValidationType) EventI

Validate overrides the controls validation setting just for this event.

func (*Event) ValidationTargets

func (e *Event) ValidationTargets(targets ...string) EventI

ValidationTargets overrides the control's validation targets just for this event.

type EventI

type EventI interface {
	// Condition sets a javascript condition that will be used to decide whether to fire the event.  The condition
	// will be evaluated when the event fires, and if its true, the associated action will be queued.
	Condition(string) EventI
	// Delay sets a delay for when the action happens after the event is fired, in milliseconds.
	Delay(int) EventI
	// Selector is a jQuery CSS selector that will filter bubbled events, only allowing events from the specified sub-items.
	Selector(string) EventI
	// Blocking will create an event that prevents all other events from firing before it is handled. Events that get
	// fired during this time are lost. This is particularly useful for Ajax or Server events that should not be
	// interrupted.
	Blocking() EventI
	// Terminating creates an event that does not bubble, nor will it do the browser default for the event.
	Terminating() EventI
	// Validate overrides the default validation specified by the control.
	Validate(v ValidationType) EventI
	// ValidationTargets overrides the validation targets specified by the control.
	ValidationTargets(targets ...string) EventI
	// ActionValue lets you specify a value that will be sent with the resulting action, and that will be accessible
	// through the EventValue() call on the ActionParams structure in the action handler. This is useful for Ajax and
	// Server actions primarily. This can be a static value, or a javascript.* type object to get dynamic values from javascript.
	ActionValue(interface{}) EventI

	// String returns a description of the event, primarily for debugging
	String() string
	// contains filtered or unexported methods
}

EventI defines the interface for an event. Many of the routines implement a Builder pattern, allowing you to add options by chaining function calls on the event.

func NewEvent

func NewEvent(name string) EventI

NewEvent creates an event that triggers on the given event type. Use the builder pattern functions from EventI to add delays, conditions, etc.

type EventID

type EventID uint16

type EventMap

type EventMap map[EventID]EventI

type FastPageCache

type FastPageCache struct {
	types.LruCache
}

FastPageCache is an in memory override cache that does no serialization and uses an LRU cache of override objects. Objects that are too old are removed, and if the cache is full, the oldest item(s) will be removed. Pages that are set multiple times will be pushed to the top. Whenever an item is set, we could potentially garbage collect. This cache is only appropriate when the pagecache itself is operating on a single machine.

func NewFastPageCache

func NewFastPageCache(maxEntries int, TTL int64) *FastPageCache

func (*FastPageCache) Get

func (o *FastPageCache) Get(pageId string) *Page

Get returns the override based on its override id. If not found, will return null.

func (*FastPageCache) Has

func (o *FastPageCache) Has(pageId string) bool

Has tests to see if the given page id is in the page cache, without actually loading the page

func (*FastPageCache) NewPageID

func (o *FastPageCache) NewPageID() string

Returns a new override id

func (*FastPageCache) Set

func (o *FastPageCache) Set(pageId string, page *Page)

Puts the override into the override cache, and updates its access time, pushing it to the end of the removal queue Page must already be assigned a state ID. Use NewPageId to do that.

type FormCreationFunction

type FormCreationFunction func(context.Context) FormI

type FormI

type FormI interface {
	ControlI
	// Init initializes the base structures of the form. Do this before adding controls to the form.
	Init(ctx context.Context, self FormI, path string, id string)
	PageDrawingFunction() PageDrawFunc

	LoadControls(ctx context.Context)
	AddHeadTags()
	DrawHeaderTags(ctx context.Context, buf *bytes.Buffer)
	Response() *Response

	AddStyleSheetFile(path string, attributes *html.Attributes)
	AddJavaScriptFile(path string, forceHeader bool, attributes *html.Attributes)
	DisplayAlert(ctx context.Context, msg string)
	AddJQueryUI()

	// Lifecycle calls
	Run(ctx context.Context) error
	Exit(ctx context.Context, err error)
	// contains filtered or unexported methods
}

type FrameworkError

type FrameworkError struct {
	Err int
}

FrameworkError is an expected error that is part of the framework. Usually you would respond to the error by displaying a message to the user, but not always.

func NewFrameworkError

func NewFrameworkError(err int) FrameworkError

func (FrameworkError) Error

func (e FrameworkError) Error() string

type GobDeserializer

type GobDeserializer struct {
	*gob.Decoder
}

func (GobDeserializer) Decode

func (e GobDeserializer) Decode(v interface{}) (err error)

func (GobDeserializer) DecodeControl

func (e GobDeserializer) DecodeControl(p *Page) (c ControlI, err error)

DecodeControl decodes a control from the stream and returns it as a ControlI.

type GobPageEncoder

type GobPageEncoder struct {
}

func (GobPageEncoder) NewDecoder

func (e GobPageEncoder) NewDecoder(b *bytes.Buffer) Decoder

func (GobPageEncoder) NewEncoder

func (e GobPageEncoder) NewEncoder(b *bytes.Buffer) Encoder

type GobSerializer

type GobSerializer struct {
	*gob.Encoder
}

func (GobSerializer) Encode

func (e GobSerializer) Encode(v interface{}) (err error)

Serialize sends

func (GobSerializer) EncodeControl

func (e GobSerializer) EncodeControl(c ControlI) (err error)

type HttpContext

type HttpContext struct {
	Req *http.Request
	URL *url.URL

	Host       string
	RemoteAddr string
	Referrer   string
	Cookies    map[string]*http.Cookie
	Files      map[string][]*multipart.FileHeader
	Header     http.Header
	// contains filtered or unexported fields
}

Typical things we can extract from http

type HttpError

type HttpError struct {
	// contains filtered or unexported fields
}

func (*HttpError) Send

func (e *HttpError) Send(errCode int)

func (*HttpError) SetResponseHeader

func (e *HttpError) SetResponseHeader(key, value string)

type LabelWrapperType

type LabelWrapperType struct {
	ErrorWrapperType
	// contains filtered or unexported fields
}

func NewLabelWrapper

func NewLabelWrapper() *LabelWrapperType

func (*LabelWrapperType) Copy

Copy returns a copy of the wrapper

func (*LabelWrapperType) HasLabelAttributes

func (w *LabelWrapperType) HasLabelAttributes() bool

HasLabelAttributes returns true if attributes are defined on the wrapper itself

func (*LabelWrapperType) LabelAttributes

func (w *LabelWrapperType) LabelAttributes() *html.Attributes

LabelAttributes returns attributes that will apply to the label. Changes will be remembered, but will not be applied unless you redraw the control.

func (*LabelWrapperType) TypeName

func (w *LabelWrapperType) TypeName() string

func (*LabelWrapperType) ΩModifyDrawingAttributes

func (w *LabelWrapperType) ΩModifyDrawingAttributes(c ControlI, a *html.Attributes)

ΩModifyDrawingAttributes is a framework function that allows wrappers to modify a control's attributes at draw time. Label wrappers will set the aria-labeledby attribute in the control if needed.

func (*LabelWrapperType) ΩNewI

func (w *LabelWrapperType) ΩNewI() WrapperI

Copy copies itself and returns it. This is used when a new wrapper is created from a named type.

func (*LabelWrapperType) ΩWrap

func (w *LabelWrapperType) ΩWrap(ctx context.Context, ctrl ControlI, html string, buf *bytes.Buffer)

ΩWrap wraps the given control and html output from that control with html from the LabelWrapperTemplate. The LabelWrapperTemplate will associate a label tag with the control, and also add tags to display validation errors and information or instructions associated with the control. See the template_source/wrapper_label.tpl.got source file for details on how this is done.

type NoErr

type NoErr struct {
}

Represents no error. A request starts with this.

func (*NoErr) Error

func (e *NoErr) Error() string

type Page

type Page struct {
	// BodyAttributes contains the attributes that will be output with the body tag. It should be set before the
	// form draws, like in the AddHeadTags function.
	BodyAttributes string
	// contains filtered or unexported fields
}

The Page object is the top level drawing object, and is essentially a wrapper for the form. The Page draws the html, head and body tags, and includes the one Form object on the page. The page also maintains a record of all the controls included on the form.

func (*Page) AddHtmlHeaderTag

func (p *Page) AddHtmlHeaderTag(t html.VoidTag)

AddHtmlHeaderTag adds the given tag to the head section of the page.

func (*Page) ClearResponseHeaders

func (p *Page) ClearResponseHeaders()

ClearResponseHeaders removes all the current response headers.

func (*Page) Decode

func (p *Page) Decode(d Decoder) (err error)

Decode is called by the framework to serialize the page state.

func (*Page) Draw

func (p *Page) Draw(ctx context.Context, buf *bytes.Buffer) (err error)

Draw draws the page.

func (*Page) DrawAjax

func (p *Page) DrawAjax(ctx context.Context, buf *bytes.Buffer) (err error)

DrawAjax renders the page during an ajax call. Since the page itself is already rendered, it simply hands off this responsibility to the form.

func (*Page) DrawHeaderTags

func (p *Page) DrawHeaderTags(ctx context.Context, buf *bytes.Buffer)

func (*Page) Encode

func (p *Page) Encode(e Encoder) (err error)

Encode is called by the framework to serialize the page state.

func (*Page) Form

func (p *Page) Form() FormI

Returns the form for the page

func (*Page) GenerateControlID

func (p *Page) GenerateControlID(id string) string

Generates unique control ids. If you want to do your own id generation, or modifying of given ids, implement that in an override to the control.Init function. The given id is one that the user supplies. User provided ids and generated ids can be further munged by providing an id prefix through SetControlIdPrefix().

func (*Page) GetControl

func (p *Page) GetControl(id string) ControlI

GetControl returns the control with the given id. If not found, it returns nil.

func (*Page) GobDecode

func (p *Page) GobDecode(data []byte) (err error)

func (*Page) GobEncode

func (p *Page) GobEncode() (data []byte, err error)

GobEncode here is implemented to intercept the GobSerializer to only encode an empty structure. We use this as part of our overall serialization stratgey for forms. Controls still need to be registered with gob.

func (*Page) Init

func (p *Page) Init(path string)

Initialize the page base. Should be called by a form just after creating Page.

func (*Page) LanguageCode

func (p *Page) LanguageCode() string

LanguageCode returns the language code that will be put in the lang attribute of the html tag. It is taken from the i18n package.

func (*Page) MarshalJSON

func (p *Page) MarshalJSON() (data []byte, err error)

func (*Page) Path

func (p *Page) Path() string

Path returns the URL path that corresponds to this page. This is what is output in the form's action tag so that the form calls back onto itself.

func (*Page) PushRedraw

func (p *Page) PushRedraw()

PushRedraw will cause the form to refresh in between events. This will cause the client to pull the ajax response. Its possible that this will happen while drawing. We avoid the race condition by sending the message anyways, and allowing the client to send an event back to us, essentially using the javascript event mechanism to synchronize us. We might get an unnecessary redraw, but that is not a big deal.

func (*Page) Restore

func (p *Page) Restore()

Restore is called immediately after the page has been unserialized, to restore data that did not get serialized.

func (*Page) SetControlIdPrefix

func (p *Page) SetControlIdPrefix(prefix string) *Page

Sets the prefix for control ids. Some javascript frameworks (i.e. jQueryMobile) require that control ids be unique across the application, vs just in the page, because they create internal caches of control ids. This allows you to set a per page prefix that will be added to all control ids to make them unique across the whole application. However, its up to you to make sure the names are unique per page.

func (*Page) SetResponseHeader

func (p *Page) SetResponseHeader(key, value string)

SetResponseHeader sets a value in the html response header. You generally would only need to do this if your are outputting custom content, like a pdf file.

func (*Page) SetTitle

func (p *Page) SetTitle(title string)

Call SetTitle to set the content of the <title> tag to be output in the head of the page.

func (*Page) StateID

func (p *Page) StateID() string

StateID returns the page state id. This is output by the form so that we can recover the saved state of the page each time we call into the application.

func (*Page) Title

func (p *Page) Title() string

Title returns the content of the <title> tag that will be output in the head of the page.

func (*Page) UnmarshalJSON

func (p *Page) UnmarshalJSON(data []byte) (err error)

type PageCacheI

type PageCacheI interface {
	Set(pageId string, page *Page)
	Get(pageId string) *Page
	NewPageID() string
	Has(pageId string) bool
}

func GetPageCache

func GetPageCache() PageCacheI

GetPageCache returns the page cache. Used internally by goradd.

type PageDrawFunc

type PageDrawFunc func(context.Context, *Page, *bytes.Buffer) error

type PageEncoderI

type PageEncoderI interface {
	NewEncoder(b *bytes.Buffer) Encoder
	NewDecoder(b *bytes.Buffer) Decoder
}

type PageManager

type PageManager struct {
	// contains filtered or unexported fields
}

func GetPageManager

func GetPageManager() *PageManager

func NewPageManager

func NewPageManager() *PageManager

func (*PageManager) HasPage

func (m *PageManager) HasPage(pageStateId string) bool

func (*PageManager) IsPage

func (m *PageManager) IsPage(path string) bool

func (*PageManager) RunPage

func (m *PageManager) RunPage(ctx context.Context, buf *bytes.Buffer) (headers map[string]string, httpErrCode int)

RunPage processes the page and writes the response into the buffer. Any special response headers are returned.

type PageManagerI

type PageManagerI interface {
	RegisterPage(path string, creationFunction FormCreationFunction)
}

type PageRenderStatus

type PageRenderStatus int
const (
	PageIsNotRendering PageRenderStatus = iota // FormBase has started rendering but has not finished
	PageIsRendering
)

Future note. Below is for general information but should NOT be used to synchronize multiple drawing routines An architecture using channels to synchronize page changes and drawing would be better For now, except for testing, we should not get in a situation where multiple copies of a form are being used.

type Priority

type Priority int
const (
	PriorityExclusive Priority = iota
	PriorityHigh
	PriorityStandard
	PriorityLow
	PriorityFinal // TODO: Note that this currently requires a preliminary ajax command, or it will not fire. Should fix that, but its tricky.
)

type RequestMode

type RequestMode int
const (
	Server     RequestMode = iota // calling back in to currently showing override using a standard form post
	Http                          // new override request
	Ajax                          // calling back in to a currently showing override using an ajax request
	CustomAjax                    // calling an entry point from ajax, but not through our js file. REST API perhaps?
	Cli                           // From command line
)

func (RequestMode) String

func (m RequestMode) String() string

type Response

type Response struct {
	// contains filtered or unexported fields
}

func NewResponse

func NewResponse() Response

func (*Response) CloseWindow

func (r *Response) CloseWindow()

func (*Response) ExecuteControlCommand

func (r *Response) ExecuteControlCommand(controlID string, functionName string, args ...interface{})

func (*Response) ExecuteJavaScript

func (r *Response) ExecuteJavaScript(js string, priorities ...Priority)

ExecuteJavaScript will execute the given code with the given priority. Note that all javascript code is run in strict mode.

func (*Response) ExecuteJsFunction

func (r *Response) ExecuteJsFunction(functionName string, args ...interface{})

Call the given function with the given arguments. If just a function label, then the window object is searched. The function can be inside an object accessible from the global namespace by separating with periods.

func (*Response) ExecuteSelectorFunction

func (r *Response) ExecuteSelectorFunction(selector string, functionName string, args ...interface{})

Calls a function on a jQuery selector

func (*Response) JavaScript

func (r *Response) JavaScript() (script string)

*

  • Function renders all the Javascript commands as output to the client browser. This is a mirror of what
  • occurs in the success function in the qcubed.js ajax code. *
  • @param bool $blnBeforeControls True to only render the javascripts that need to come before the controls are defined.
  • This is used to break the commands issued into two groups.
  • @static
  • @return string

func (*Response) MarshalJSON

func (r *Response) MarshalJSON() (buf []byte, err error)

Return the JSON for use by the form ajax response. Will essentially do the same thing as above, but working in cooperation with the javascript file to process these through an ajax response.

func (*Response) SetControlAttribute

func (r *Response) SetControlAttribute(id string, attribute string, value string)

func (*Response) SetControlHtml

func (r *Response) SetControlHtml(id string, html string)

func (*Response) SetControlValue

func (r *Response) SetControlValue(id string, value string)

func (*Response) SetLocation

func (r *Response) SetLocation(newLocation string)

type ResponseCommand

type ResponseCommand struct {
	// contains filtered or unexported fields
}

ResponseCommand is a response packet that leads to execution of a javascript function

func (ResponseCommand) MarshalJSON

func (r ResponseCommand) MarshalJSON() (buf []byte, err error)

type ResponseControl

type ResponseControl struct {
	// contains filtered or unexported fields
}

A response packet that leads to the manipulation or replacement of an html object

func (ResponseControl) MarshalJSON

func (r ResponseControl) MarshalJSON() (buf []byte, err error)

type Serializable

type Serializable interface {
	Serialize(e Encoder) error
	Deserialize(d Decoder) error
}

Serializable defines the interface that allows an object to be encodable using a pre-set encoder. This saves time on memory allocations/deallocations, which might be extensive. Controls are Serializable by default. Other objects that contain controls, or that are not gob.Encoders should implement this as well if they are part of the pagestate.

type SerializedPageCache

type SerializedPageCache struct {
	types.LruCache
}

SerializedPageCache is an in memory override cache that does serialization and uses an LRU cache of override objects. Use the serialized override cache during development to ensure that you can eventually move your override cache to a database or a separate machine so that your application is scalable. Objects that are too old are removed, and if the cache is full, the oldest item(s) will be removed. Pages that are set multiple times will be pushed to the top. Whenever an item is set, we could potentially garbage collect.

func NewSerializedPageCache

func NewSerializedPageCache(maxEntries int, TTL int64) *SerializedPageCache

func (*SerializedPageCache) Get

func (o *SerializedPageCache) Get(pageId string) *Page

Get returns the page based on its page id. If not found, will return null.

func (*SerializedPageCache) Has

func (o *SerializedPageCache) Has(pageId string) bool

func (*SerializedPageCache) NewPageID

func (o *SerializedPageCache) NewPageID() string

Returns a new override id

func (*SerializedPageCache) Set

func (o *SerializedPageCache) Set(pageId string, page *Page)

Puts the override into the override cache, and updates its access time, pushing it to the end of the removal queue Page must already be assigned a state ID. Use NewPageId to do that.

type StackFrame

type StackFrame struct {
	File string
	Line int
	Func string
}

type TemplateExecuter

type TemplateExecuter interface {
	Execute(wr io.Writer, data interface{}) error
}

TemplateExecuter is an interface that will work with either text/template or html/template types of templates

func GetTemplate

func GetTemplate(name string) TemplateExecuter

type ValidationState

type ValidationState int

ValidationState is used internally by the framework to determine how the control's wrapper handles drawing validation error messages. Different wrappers use it to set classes or attributes of the error message or the overall control.

const (
	// ValidationWaiting is the default for controls that accept validation. It means that the control expects to be validated,
	// but has not yet been validated. Wrappers should save a spot for the error message of this control so that if
	// an error appears, it will not change the layout of the form.
	ValidationWaiting ValidationState = iota
	// ValidationNever indicates that the control will never fail validation. Essentially it indicates that the wrapper does not
	// need to save a spot for an error message for this control.
	ValidationNever
	// ValidationValid indicates the control has been validated. This state gets entered if some control on the form has failed validation, but
	// this control passed validation. You can choose to display a special message, or a special color, etc., to
	// indicate to the user that this is not the source of the validation problem, or do nothing.
	ValidationValid
	// ValidationInvalid indicates the control has failed validation, and the wrapper should somehow call that out to the user. The error message
	// should be displayed at a minimum, but likely other things should happen as well, like a special color, and
	// aria attributes should be set.
	ValidationInvalid
)

type ValidationType

type ValidationType int

ValidationType is used by active controls, like buttons, to determine what other items on the form will get validated when the button is pressed. You can set the ValidationType for a control, but you can also set it for individual events and override the control's validation setting.

const (
	ValidateDefault ValidationType = iota // This is used by the event to indicate it is not overriding.
	ValidateNone                          // Force no validation.
	ValidateForm

	ValidateSiblingsAndChildren // container validations. Will include validating the current control.
	ValidateSiblingsOnly
	ValidateChildrenOnly

	// ValidateContainer will use the validation setting of a parent control with ValidateSiblingsAndChildren, ValidateSiblingsOnly,
	// ValidateChildrenOnly, or ValidateTarget as the stopping point for validation.
	ValidateContainer

	// ValidateTargetsOnly will only validate the specified targets
	ValidateTargetsOnly
)

type WrapperI

type WrapperI interface {
	// ΩWrap is used by the framework to wrap the control and html with the wrapper's html tags.
	ΩWrap(ctx context.Context, ctrl ControlI, html string, buf *bytes.Buffer)
	// ΩNewI returns a new wrapper. It is used by the wrapper registry to return a named wrapper.
	ΩNewI() WrapperI
	// ΩSetValidationMessageChanged notifies the wrapper that the validation message has changed.
	ΩSetValidationMessageChanged()
	// ΩSetValidationStateChanged notifies the wrapper that the validation state has changed.
	ΩSetValidationStateChanged()
	// ΩAjaxRender does an ajax render of the wrapper.
	ΩAjaxRender(ctx context.Context, response *Response, c ControlI)
	// TypeName returns the named type of the wrapper.
	TypeName() string
	// ΩModifyDrawingAttributes is used by the framework to allow the wrapper to modify the attributes of the control and draw time.
	ΩModifyDrawingAttributes(ctrl ControlI, attributes *html.Attributes)
}

WrapperI defines the control wrapper interface. Generally you will not call any of these functions. The interface is used by the framework to control wrapper drawing. To call wrapper specific functions, cast to the specific wrapper type.

func NewWrapper

func NewWrapper(name string) WrapperI

NewWrapper returns a newly allocated wrapper from the wrapper registry.

type ΩFormBase

type ΩFormBase struct {
	Control
	// contains filtered or unexported fields
}

ΩFormBase is a base for the FormBase struct that is in the control package. Normally, you should not descend your forms from here, but rather from the control.Form struct. It is the basic control structure for the application and also serves as the drawing mechanism for the <form> tag in the html output.

func (*ΩFormBase) AddFontAwesome

func (f *ΩFormBase) AddFontAwesome()

AddFontAwesome adds the font-awesome files fo the form

func (*ΩFormBase) AddGoraddFiles

func (f *ΩFormBase) AddGoraddFiles()

AddGoraddFiles adds the various goradd files to the form

func (*ΩFormBase) AddHeadTags

func (f *ΩFormBase) AddHeadTags()

AddHeadTags is a lifecycle call that happens when a new form is created. This is where you should call AddHtmlHeaderTag or SetTitle on the page to set tags that appear in the <head> tag of the page. Head tags cannot be changed after the page is created.

func (*ΩFormBase) AddJQuery

func (f *ΩFormBase) AddJQuery()

AddJQuery adds the jquery javascript to the form

func (*ΩFormBase) AddJQueryUI

func (f *ΩFormBase) AddJQueryUI()

AddJQueryUI adds the JQuery UI javascript to the form. This is not loaded by default, but many add-ons use it, so its here for convenience.

func (*ΩFormBase) AddJavaScriptFile

func (f *ΩFormBase) AddJavaScriptFile(path string, forceHeader bool, attributes *html.Attributes)

AddJavaScriptFile registers a JavaScript file such that it will get loaded on the page. If forceHeader is true, the file will be listed in the header, which you should only do if the file has some preliminary javascript that needs to be executed before the dom loads. Otherwise, the file will be loaded after the dom is loaded, allowing the browser to show the page and then load the javascript in the background, giving the appearance of a more responsive website. If you add the file during an ajax operation, the file will be loaded dynamically by the goradd javascript. Controls generally should call This during the initial creation of the control if the control requires additional javascript to function.

The path is either a url, or an internal path to the location of the file in the development environment.

func (*ΩFormBase) AddMasterJavaScriptFile

func (f *ΩFormBase) AddMasterJavaScriptFile(url string, attributes []string, files []string)

Add a javascript file that is a concatenation of other javascript files the system uses. This allows you to concatenate and minimize all the javascript files you are using without worrying about libraries and controls that are adding the individual files through the AddJavaScriptFile function

func (*ΩFormBase) AddRelatedFiles

func (f *ΩFormBase) AddRelatedFiles()

AddRelatedFiles adds related javascript and style sheet files. This is the default to get the minimum goradd installation working., The order is important, so if you override this, be sure these files get loaded before other files.

func (*ΩFormBase) AddStyleSheetFile

func (f *ΩFormBase) AddStyleSheetFile(path string, attributes *html.Attributes)

AddStyleSheetFile registers a StyleSheet file such that it will get loaded on the page. The file will be loaded on the page at initial draw in the header, or will be inserted into the file if the page is already drawn. The path is either a url, or an internal path to the location of the file in the development environment. AppModeDevelopment files will automatically get copied to the local assets directory for easy deployment and so that the MUX can find the file and serve it (This happens at draw time). The attributes will be extra attributes included with the tag, which is useful for things like crossorigin and integrity attributes.

func (*ΩFormBase) ChangeLocation

func (f *ΩFormBase) ChangeLocation(url string)

func (*ΩFormBase) Deserialize

func (f *ΩFormBase) Deserialize(d Decoder, p *Page) (err error)

func (*ΩFormBase) DisplayAlert

func (f *ΩFormBase) DisplayAlert(ctx context.Context, msg string)

func (*ΩFormBase) Draw

func (f *ΩFormBase) Draw(ctx context.Context, buf *bytes.Buffer) (err error)

Draw renders the form. Even though forms are technically controls, we use a custom drawing routine for performance reasons and for control.

func (*ΩFormBase) DrawHeaderTags

func (f *ΩFormBase) DrawHeaderTags(ctx context.Context, buf *bytes.Buffer)

DrawHeaderTags is called by the page drawing routine to draw its header tags If you override this, be sure to call this version too

func (*ΩFormBase) DrawingAttributes

func (f *ΩFormBase) DrawingAttributes() *html.Attributes

func (*ΩFormBase) Exit

func (f *ΩFormBase) Exit(ctx context.Context, err error)

Exit is a lifecycle function that gets called after the form is processed, just before control is returned to the client. err will be set if an error response was detected.

func (*ΩFormBase) Init

func (f *ΩFormBase) Init(ctx context.Context, self FormI, path string, id string)

Init initializes the form control. Note that ctx might be nil if we are unit testing.

func (*ΩFormBase) LoadControls

func (f *ΩFormBase) LoadControls(ctx context.Context)

LoadControls is a lifecycle call that happens after a form is first created. It is the place to initialize the value of the controls in the form based on variables sent to the form.

func (*ΩFormBase) PageDrawingFunction

func (f *ΩFormBase) PageDrawingFunction() PageDrawFunc

PageDrawingFunction returns the function used to draw the page object. If you want a custom drawing function for your page, implement this function in your form override.

func (*ΩFormBase) PopLocation

func (f *ΩFormBase) PopLocation(ctx context.Context)

PopLocation pops the most recent location off of the location stack and goes to that location.

func (*ΩFormBase) PreRender

func (f *ΩFormBase) PreRender(ctx context.Context, buf *bytes.Buffer) (err error)

func (*ΩFormBase) PushLocation

func (f *ΩFormBase) PushLocation(ctx context.Context)

PushLocation pushes the URL that got us to the current page on to the location stack.

func (*ΩFormBase) Refresh

func (f *ΩFormBase) Refresh()

func (*ΩFormBase) Response

func (f *ΩFormBase) Response() *Response

Response returns the form's response object that you can use to queue up javascript commands to the browser to be sent on the next ajax or server request

func (*ΩFormBase) Run

func (f *ΩFormBase) Run(ctx context.Context) error

Run is a lifecycle function that gets called whenever a page is run, either by a whole page load, or an ajax call. Its a good place to validate that the current user should have access to the information on the page. Returning an error will result in the error message being displayed.

func (*ΩFormBase) Serialize

func (f *ΩFormBase) Serialize(e Encoder) (err error)

func (*ΩFormBase) ΩisSerializer

func (f *ΩFormBase) ΩisSerializer(i ControlI) bool

ΩisSerializer is used by the automated control serializer to determine how far down the control chain the control has to go before just calling serialize and deserialize

Directories

Path Synopsis
The action package defines actions that you can trigger using events.
The action package defines actions that you can trigger using events.
The widget package contains supported composite and special purpose controls that are not part of the html standard
The widget package contains supported composite and special purpose controls that are not part of the html standard

Jump to

Keyboard shortcuts

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