page

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: MIT Imports: 40 Imported by: 0

Documentation

Overview

Package page is the user-interface layer of goradd, and implements state management and rendering of an html page, as well as the framework for rendering controls.

To use the page package, you start by creating a form object, and then adding controls to that form. You also should add a drawing template to define additional html for the form.

Index

Constants

View Source
const (
	FrameworkErrNone = iota
	// FrameworkErrNoTemplate indicates a template does not exist. The control will move on to other ways of rendering.
	// No message should be displayed.
	FrameworkErrNoTemplate
	// FrameworkErrRecordNotFound is a rare situation that might come up as a race condition error between viewing a
	// record, and actually editing it. If in the time between clicking on a record to see detail, and viewing the detail,
	// the record was deleted by another user, we would return this error.
	FrameworkErrRecordNotFound
	// A standard situation when someone tries to go to a page they are not authorized to view.
	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 HtmlVarAction = "Goradd_Action"
View Source
const HtmlVarPagestate = "Goradd__PageState"
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

DefaultCheckboxLabelDrawingMode is a setting used by checkboxes and radio buttons to default how they draw labels. Some CSS framworks are very picky about whether checkbox labels wrap the control, or sit next to the control, and whether the label is before or after the control

View Source
var MultipartFormMax int64 = 10000000 // 10MB max in memory file

MultipartFormMax is the maximum size of a mult-part form that we will allow.

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 = ""

PagePathPrefix is a prefix you can use in front of all goradd pages, like a directory path, to indicate that this is a goradd path.

Functions

func ControlConnectorParams

func ControlConnectorParams() *maps.SliceMap

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

DivTmpl is the template function that outputs a DivWrapper.

func ErrorTmpl

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

ErrorTmpl is the template function that outputs an ErrorWrapper.

func GetAssetLocation

func GetAssetLocation(url string) string

GetAssetLocation returns the disk location of the asset file indicated by the given url. Asset directories must be registered with the RegisterAssetDirectory function. In debug mode, the file is taken from the registered location, but in release mode, the file will have been copied to a location on the server, and we will serve the file from there.

func GetAssetUrl

func GetAssetUrl(location string) string

GetAssetUrl returns the url that corresponds to the asset at the given location. Its the reverse of GetAssetLocation.

func IsError

func IsError(e error) bool

func LabelTmpl

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

LabelTmpl is the template function that outputs an LabelWrapper.

func NewMockContext added in v0.0.3

func NewMockContext() (ctx context.Context)

NewMockContext creates a context for testing.

func OutputBuffer added in v0.0.5

func OutputBuffer(ctx context.Context) *bytes.Buffer

func PageTmpl

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

PageTmpl is the template used to draw the initial html of a page, including the doctype tag, html tag, head and body tag.

func PutContext

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

PutContext is used by the framework to insert the goradd context as a value in the standard GO context. You should not normally call this, unless you are customizing how your http server works.

func Redirect

func Redirect(url string)

Redirect aborts the current page load and tells the browser to load a different url. Usually you should use Form.ChangeLocation, but you can use this in extreme situations where you really do not want to return a goradd page at all and just change locations. For example, if you detect some kind of attempt to hack your website, you can use this to redirect to a login page or an error page.

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)

RegisterControlWrapper registers a wrapper with goradd so that it can be called by name using the Control.With() function. It should be called at init time.

func RegisterPage

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

RegisterPage associates the given URL path with the given form creation function and form id and registers it with page manager. Call this from an init() function. Afterwards, whenever a user navigates to the given path, the form will be created and presented to the user.

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)

ServeAsset is the default server for files in asset directories.

func SetPageCache

func SetPageCache(c PageCacheI)

SetPageCache will set the page cache to the given object.

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

ActionValueBool returns the action value as a bool.

func (*ActionParams) ActionValueFloat

func (a *ActionParams) ActionValueFloat() float64

ActionValueFloat returns the action value as a float64.

func (*ActionParams) ActionValueInt

func (a *ActionParams) ActionValueInt() int

ActionValueInt returns the action value as an integer.

func (*ActionParams) ActionValueString

func (a *ActionParams) ActionValueString() string

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

ControlValueBool returns the control value as a bool.

func (*ActionParams) ControlValueFloat

func (a *ActionParams) ControlValueFloat() float64

ControlValueFloat returns the control value as a float64.

func (*ActionParams) ControlValueInt

func (a *ActionParams) ControlValueInt() int

ControlValueInt returns the control value as an int.

func (*ActionParams) ControlValueString

func (a *ActionParams) ControlValueString() string

ControlValueString 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

EventValueBool returns the event value as a bool. To be false, the value should be a boolean false, a numeric 0, an empty string, null or undefined on the client side. Otherwise, will return true.

func (*ActionParams) EventValueFloat

func (a *ActionParams) EventValueFloat() float64

EventValueFloat returns the event value as a float64. If the value was not numeric, it will return 0.

func (*ActionParams) EventValueInt

func (a *ActionParams) EventValueInt() int

EventValueInt returns the event value as an integer. If the value was a floating point value at the client, it will be truncated to an integer. If the value is not numeric, will return 0.

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 {

	// NoJavaScript indicates javascript is turned off by the browser
	NoJavaScript bool
	// contains filtered or unexported fields
}

AppContext has Goradd application specific information.

type Context

type Context struct {
	HttpContext
	AppContext
}

Context is the page context that we embed in the context.Context object that is passed throughout the application, and contains the per-request information that needs to be sent to various parts of the program. It primarily consists of items that we unpack from the http request. To get to it, simply call GetContext(ctx), where ctx is the context taken from the http request. The framework will take care of setting this up when a request is received.

func GetContext

func GetContext(ctx context.Context) *Context

GetContext returns the page context from the GO context.

func (*Context) CheckableValue

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

CheckableValue returns the value of the named checkable value. This would be something coming from a checkbox or radio button. You do not normally call this unless you are implementing a checkable control widget.

func (*Context) CheckableValues

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

CheckableValues returns multiple checkable values. You do not normally call this unless you are implementing a widget that would have multiple checkable values, like a checklist.

func (*Context) CustomControlValue

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

CustomControlValue returns the value of a control that is using the custom control mechanism to report its values. You would only call this if your are implementing a control that has custom javascript to operate its UI.

func (*Context) FormValue

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

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

FormValues 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

RequestMode returns the request mode of the current request.

func (*Context) String

func (c *Context) String() string

String is a string representation of all the information in the context, and should primarily be used for debugging.

type Control

type Control struct {
	base.Base

	// Tag is text of the tag that will enclose the control, like "div" or "input"
	Tag string
	// IsVoidTag should be true if the tag should not have a closing tag, like "img"
	IsVoidTag bool

	// 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
}

A Control is a basic UI widget in goradd. It corresponds to a standard html form object or tag, or a custom javascript widget. The Control renders a tag and everything inside of the tag, but can also include a wrapper which associates a label, instructions and error messages with the tag. A Control can also associate javascript with itself to make sure the javascript is loaded on the page when the control is drawn, and can render javascript that will initialize a custom javascript widget.

A Control can have child Controls. It can either allow the framework to automatically draw the child Controls as part of the inner-html of the Control, can use a template to draw the Child controls, or manually draw them. The Control is part of a hierarchical tree structure, with the Form being the root of the tree.

A Control is part of a system that will reflect the state of the control between the client and server. When a user updates a control in the browser and performs an action that requires a response from the server, the goradd javascript will gather up all the changes in the form and send those to the server. The control can read those values and update its own internal state, so that from the perspective of the programmer referring to the control, the values in the Control are the same as what the user sees in a browser.

This Control struct is a mixin that all controls should use. You would not normally create a Control directly, but rather create one of the "subclasses" of Control. See the control package for Controls that implement standard html widgets.

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

AddAttributeValue will add a class or classes to the control. If adding multiple classes at once, separate them with a space.

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{})

AddRenderScript 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 be used by Control implementations only.

func (*Control) AddWrapperClass

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

AddWrapperClass will add a class or classes to the control's wrapper, if one is defined. Separate multiple classes with a space.

func (*Control) Attribute

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

Return the value of a custom attribute. Note that this will not return values that are set only during drawing and that are managed by the Control implementation.

func (*Control) Child

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

Child returns the child control with the given id.

func (*Control) Children

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

Children returns the child controls of the control.

func (*Control) Deserialize

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

Deserialize is called by the page serializer.

func (*Control) Draw

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

Draw renders the default control structure into the given buffer. Call this function from your templates to draw the control.

func (*Control) DrawAjax

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

DrawAjax will be called by the frameowkr during an Ajax rendering of the Control. Every Control gets called. Each Control is responsible for rendering itself. Some objects automatically render their child objects, and some don't, so we detect whether the parent is being rendered, and assume the parent is taking care of rendering for us if so.

Override if you want more control over ajax drawing, like if you detect parts of your control that have changed and then want to draw only those parts. This will get called on every control on every ajax draw request. It is up to you to test the blnRendered flag of the control to know whether the control was already rendered by a parent control before drawing here.

func (*Control) DrawChildren

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

DrawChildren renders the child controls into the buffer.

func (*Control) DrawTemplate

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

DrawTemplate is used by the framework to draw the Control with a template. 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)

DrawText renders the text of the control, escaping if needed.

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) GetEvent added in v0.0.4

func (c *Control) GetEvent(eventName string) EventI

GetEvent returns the event associated with the eventName, which corresponds to the javascript trigger name.

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

HasAttribute returns true if the control has the indicated custom attribute defined.

func (*Control) HasFor

func (c *Control) HasFor() bool

HasFor is true if the label should have a "for" attribute. Most browsers respond to this by allowing the label to be clicked in order to give focus to the control. Not all controls use this.

func (*Control) HasServerAction added in v0.0.3

func (c *Control) HasServerAction(eventName string) bool

HasServerAction returns true if one of the actions attached to the given event is a Server action.

func (*Control) HasWrapper

func (c *Control) HasWrapper() bool

HasWrapper returns true if the control has a wrapper.

func (*Control) ID

func (c *Control) ID() string

ID returns the id assigned to the control. If you do not provide an ID when the control is created, the framework will give the control a unique id.

func (*Control) Init

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

Init is used by Control implementations to initialize the standard control structure. You would only call this if you are subclassing one of the standard controls. Control implementations should call this immediately after a control is created. The Control subclasses should have their own Init function that call this 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

Instructions returns the instructions to be printed with the control

func (*Control) IsDisabled

func (c *Control) IsDisabled() bool

IsDisabled returns true if the disabled attribute is true.

func (*Control) IsDisplayed

func (c *Control) IsDisplayed() bool

IsDisplayed returns true if the control will be displayed.

func (*Control) IsOnPage added in v0.0.3

func (c *Control) IsOnPage() bool

func (*Control) IsRendering

func (c *Control) IsRendering() bool

IsRendering returns true if we are in the process of rendering the control.

func (*Control) IsRequired

func (c *Control) IsRequired() bool

IsRequired returns true if the control requires input from the user to pass validation.

func (*Control) IsVisible

func (c *Control) IsVisible() bool

IsVisible returns whether the control will be drawn.

func (*Control) Label

func (c *Control) Label() string

Label returns the text of the label associated with the control.

func (*Control) MarshalJSON

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

func (*Control) MockFormValue added in v0.0.3

func (c *Control) MockFormValue(value string) bool

MockFormValue will mock the process of getting a form value from an http response for testing purposes. This includes calling ΩUpdateFormValues and Validate on the control. It returns the result of the Validate function.

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. It returns the event for chaining.

func (*Control) Page

func (c *Control) Page() *Page

Page returns the page object associated with the control.

func (*Control) Parent

func (c *Control) Parent() ControlI

Parent returns the parent control of the control. All controls have a parent, except the Form control.

func (*Control) ParentForm

func (c *Control) ParentForm() FormI

ParentForm returns the form object that encloses this control.

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

func (c *Control) Refresh()

Refresh will force the control to be completely redrawn on the next update.

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 drawn form, 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 form.

func (*Control) RemoveChildren

func (c *Control) RemoveChildren()

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

func (*Control) RemoveClass

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

RemoveClass will remove the named class from the control.

func (*Control) RemoveClassesWithPrefix

func (c *Control) RemoveClassesWithPrefix(prefix string)

RemoveClassesWithPrefix will remove the classes on a control that start with the given string. Some CSS frameworks use prefixes to as a kind of namespace for their class tags, and this can make it easier to remove a group of classes with this kind of prefix.

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. Control implementations that need to put these controls in particular locations on the form can override this.

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. TODO: Serialization is not yet implemented

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. Call this during control initialization to cause the control to remember what it is set to, so that if the user returns to the form, it will keep its value. 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)

Serialize is used by the framework to serialize a control to be saved in the formstate.

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

SetAttribute sets an html attribute of the control. You can manually set most any attribute, but be careful not to set the id attribute, or any attribute that is managed by the control itself. If you are setting a data-* attribute, use SetDataAttribute instead. If you are adding a class to the control, use AddAttributeValue.

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{})

SetDataAttribute will set a data-* attribute. You do not need to include the "data-" in the name, it will be added automatically.

func (*Control) SetDisabled

func (c *Control) SetDisabled(d bool)

SetDisable will set the "disabled" attribute of the control.

func (*Control) SetDisplay

func (c *Control) SetDisplay(d string)

SetDisplay sets the "display" property of the style attribute of the html control to the given value. Also consider using SetVisible. If you use SetDisplay to hide a control, the control will still be rendered in html, but the browser will not show it.

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

SetHasFor sets whether the control's label should have a "for" attribute that points to the Control.

func (*Control) SetHasNoSpace added in v0.0.3

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

SetHasNoSpace tells the control to draw its inner html with no space around it. This should generally only be called by control implementations. If this is not set, spaces might be added to make the HTML more readable, which can affect some html control types.

func (*Control) SetHeightStyle

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

SetHeightStyle sets the height style property

func (*Control) SetInstructions

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

SetInstructions sets the instructions that will be printed with the control. Instructions only get rendered by wrappers, so if there is no wrapper, or the wrapper does not render the instructions, this will not appear.

func (*Control) SetIsRequired

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

SetIsRequired will set whether the control requires a value from the user. Setting it to true will cause the Control to check this during validation, and show an appropriate error message if the user did not enter a value.

func (*Control) SetLabel

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

SetLabel sets the text of the label that will be associated with the control. Labels only get rendered by wrappers, so if there is no wrapper with the control, no label will be printed.

func (*Control) SetParent

func (c *Control) SetParent(newParent ControlI)

SetParent sets the parent of the control. Use this primarily if you are responding to some kind of user interface that will move a child Control from one parent Control to another.

func (*Control) SetShouldAutoRender

func (c *Control) SetShouldAutoRender(r bool)

SetShouldAutoRender sets whether this control will automatically render. AutoRendered controls are drawn by the form automatically, after all other controls are drawn, if the control was not drawn in some other way. An example of an auto-rendered control would be a dialog box that starts out hidden, but then is shown by some user response. Such controls are normally shown by javascript, and are absolutely positioned so that they do not effect the layout of the rest of the form.

func (*Control) SetStyle

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

SetStyle sets a particular property of the style attribute on the control.

func (*Control) SetStyles

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

SetStyles sets the style attribute of the control to the given values.

func (*Control) SetText

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

SetText sets the text of the control. Not all controls use this value.

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)

SetVisible controls whether the Control will be drawn. Controls that are not visible are not rendered in html, but rather a hidden stub is rendered as a placeholder in case the control is made visible again.

func (*Control) SetWidthStyle

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

SetWidthStyle sets the width style 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

SetWrapperAttribute sets an attribute for the tag that wraps the control. Obviously this only works if you have defined a wrapper for the control.

func (*Control) ShouldAutoRender

func (c *Control) ShouldAutoRender() bool

ShouldAutoRender returns true if the control is set up to auto-render.

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

TPrintf 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

Text returns the text of the control.

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. This is normally used by checkboxes and radio buttons that use the label tag in a special way.

func (*Control) UnmarshalJSON

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

func (*Control) Validate

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

Validate is called by the framework to validate a control, but not the control's children. It is designed to be overridden by Control implementations. Overriding controls should call the parent version before doing their own validation.

func (*Control) ValidationMessage

func (c *Control) ValidationMessage() string

ValidationMessage is the currently set validation message that will print with the control. Normally this only gets set when a validation error occurs.

func (*Control) ValidationState

func (c *Control) ValidationState() ValidationState

ValidationState returns the current ValidationState value.

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

WasRendered returns true if the control has been rendered.

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

Wrapper returns the controls wrapper, or nil if the control does not have a wrapper defined.

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) ΩDrawInnerHtml added in v0.0.3

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

ΩDrawInnerHtml is used by the framework to draw just the inner html of the control, if the control is not a self terminating (void) control. Sub-controls can override this.

func (*Control) ΩDrawTag added in v0.0.3

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

ΩDrawTag is responsible for drawing the Control's tag itself. Control implementations can override this to draw the tag in a different way, or draw more than one tag if drawing a compound control.

func (*Control) ΩDrawingAttributes added in v0.0.3

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

ΩDrawingAttributes is called by the framework just before drawing a control, and should return a set of attributes that should override those set by the user. This allows controls to set attributes 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 Control implementations.

func (*Control) ΩMarshalState added in v0.0.3

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) ΩPostRender added in v0.0.3

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

ΩPostRender is called by the framework at the end of drawing, and is the place where controls do any post-drawing cleanup needed.

func (*Control) ΩPreRender added in v0.0.3

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

ΩPreRender is called by the framework to notify the control that it is about to be drawn. If you override it, be sure to also call this parent function as well.

func (*Control) ΩPutCustomScript added in v0.0.3

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

ΩPutCustomScript is called by the framework to ask the control to inject any javascript it needs into the form. In particular, this is the place where Controls add javascript that transforms the html into a custom javascript control. A Control implementation does this by calling functions on the response object. This implementation is a stub.

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) ΩUnmarshalState added in v0.0.3

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 added in v0.0.3

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

ΩUpdateFormValues should be implemented by Control implementations to get their values from the context. This is where a Control updates its internal state based on actions by the client.

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)
	IsOnPage() 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
	HasServerAction(eventName string) bool

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

	ΩT(format string) string
	T(format string, params ...interface{}) string
	TPrintf(format string, params ...interface{}) string

	Restore(self ControlI)

	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
}

ControlI is the interface that all controls must support. The functions are implemented by the Control methods. See the Control method implementation for a description of each method.

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

ControlTemplateFunc is the type of function control templates should create

type ControlWrapperFunc

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

ControlWrapperFunc is a template function that specifies how wrappers will draw

type DbError

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

DbError represents a database error.

func NewDbErr

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

NewDbErr returns a new database error

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 {
}

DivWrapperType is a wrapper that only wraps the control in a div tag. No instructions, error message or label is included.

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
}

DrawI is the interface for items that draw into the draw buffer

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

NewError 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

NewErrorWrapper creates a new ErrorWrapperType.

func (*ErrorWrapperType) TypeName

func (w *ErrorWrapperType) TypeName() string

TypeName returns the name of the type of wrapper.

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

ΩNewI creates a new wrapper. This is used when a new wrapper is created from a named type.

func (*ErrorWrapperType) ΩSetValidationMessageChanged

func (w *ErrorWrapperType) ΩSetValidationMessageChanged()

ΩSetValidationMessageChanged is called by the framework to indicate the validation message changed.

func (*ErrorWrapperType) ΩSetValidationStateChanged

func (w *ErrorWrapperType) ΩSetValidationStateChanged()

ΩSetValidationStateChanged is called by the framework to indicate the validation state changed.

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 is the JavaScript event that will be triggered by the event.
	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{}

GetActionValue returns the value associated with the action of the event.

func (*Event) GetID added in v0.0.4

func (e *Event) GetID() EventID

EventId returns the private event id generated when the event was assigned a control Useful in special situations when drawing a control

func (*Event) GobDecode

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

func (*Event) GobEncode

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

func (*Event) HasServerAction added in v0.0.3

func (e *Event) HasServerAction() bool

HasServerAction returns true if at least one of the event's actions is a server action.

func (*Event) Name added in v0.0.3

func (e *Event) Name() string

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

String returns a debug string listing the conents of the event.

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
	// HasServerAction returns true if one of the actions attached to the event is a Server action
	HasServerAction() bool
	// Name returns the event name the event responds to, like 'click' or 'change'
	Name() string
	GetID() EventID
	// 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

EventID is a unique id used to specify which event is triggering.

type EventMap

type EventMap map[EventID]EventI

type FastPageCache

type FastPageCache struct {
	types.LruCache
}

FastPageCache is an in memory page cache that does no serialization and uses an LRU cache of page objects. Objects that are too old are removed, and if the cache is full, the oldest item(s) will be removed. When a page is updated, it is moved 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

NewFastPageCache creates a new FastPageCache cache

func (*FastPageCache) Get

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

Get returns the page based on its page 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

NewPageID returns a new page id

func (*FastPageCache) Set

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

Set puts the page into the page 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()
	ChangeLocation(url string)
	PushLocation(ctx context.Context)
	PopLocation(ctx context.Context, fallback string)

	// 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

NewFrameworkError creates a new FrameworkError

func (FrameworkError) Error

func (e FrameworkError) Error() string

Error returns the 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 is the original http.Request object
	Req *http.Request
	// URL is the url being queried
	URL *url.URL

	// Host is the host value extracted from the request
	Host string
	// RemoteAddr is the ip address of the client
	RemoteAddr string
	// Referrer is the referring url, if there is one and it is included in the request. In other words, if a link was
	// clicked to get here, it would be the URL of the page that had the link
	Referrer string
	// Cookies are the cookies coming from the client, mapped by name
	Cookies map[string]*http.Cookie
	// Files are the files being uploaded, if this is a file upload. This currently only works with Server calls
	// in response to a file upload control.
	Files map[string][]*multipart.FileHeader
	// Header is the http header coming from the client.
	Header http.Header
	// contains filtered or unexported fields
}

HttpContext contains typical things we can extract from an http request.

type HttpError

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

HttpError represents an error response to a http request.

func (*HttpError) Send

func (e *HttpError) Send(errCode int)

Send will cause the page to error with the given http error code.

func (*HttpError) SetResponseHeader

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

SetResponseHeader sets a key-value in the header response.

type LabelWrapperType

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

LabelWrapperType is a wrapper that associates a label tag with the control, as well as instuctions and an error message.

func NewLabelWrapper

func NewLabelWrapper() *LabelWrapperType

NewLabelWrapper returns a new 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

TypeName returns the name used to identify a LabelWrapper.

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

ΩNewI 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 {
}

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

DrawHeaderTags draws all the inner html for the head tag

func (*Page) Encode

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

Encode is called by the framework to serialize the page state. TODO: serialization is not completely implemented yet

func (*Page) Form

func (p *Page) Form() FormI

Returns the form for the page

func (*Page) GenerateControlID

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

GenerateControlID 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()

Init initializes the page. 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) 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

SetControlIdPrefix 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
}

PageCacheI is the page cache interface. The PageCache saves and restores pages in between page accesses by the user.

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

PageDrawFunc is the type of the page drawing function. This is implemented by the page drawing template.

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
}

The PageManager is a singleton global that manages the registration and deployment of pages. It acts like a URL router, returning the page that corresponds to a particular URL path. init() functions should be created for each page that associate a function to create a page, with the URL that corresponds to the page, and the ID of the page.

func GetPageManager

func GetPageManager() *PageManager

GetPageManager returns the current page manager.

func (*PageManager) HasPage

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

HasPage returns true if the given page state is currently in the page cache. This indicates that a user has recently accessed a page with the given state id. You can use this to validate client interactions.

func (*PageManager) IsPage

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

IsPage returns true if the given path has been registered with the page manager.

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

PageRenderStatus keeps track of whether we are rendering the page or not

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

type Priority

type Priority int

Priority orders the various responses to an Ajax request so that the framework can control the order they are processed, and not necessarily order the responses in the order they are sent.

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

RequestMode tracks what kind of request we are processing.

const (
	// Server indicates we are calling back to a previously sent form using a standard form post
	Server RequestMode = iota
	// Http indicates this is a first-time request for a page
	Http
	// Ajax indicates we are calling back in to a currently showing form using an ajax request
	Ajax
	// CustomAjax indicates we are calling an entry point from ajax, but not through our js file. This could be used to
	// implement a Rest API at a custom location.
	CustomAjax
	// Cli indicates we are being called from the command line and not through the http server.
	Cli
)

func (RequestMode) String

func (m RequestMode) String() string

String satisfies the Stringer interface and returns a description of the RequestMode

type Response

type Response struct {
	sync.RWMutex // This was inserted here for very rare situations of simultaneous access, like in the test harness.
	// contains filtered or unexported fields
}

Response contains the various commands you can send to the client in response to a goradd event. These commands are packed as JSON (for an Ajax response) or JavaScript (for a Server response), sent to the client, unpacked by JavaScript code in the goradd.js file, and then acted upon.

func NewResponse

func NewResponse() Response

NewResponse creates a new event response.

func (*Response) CloseWindow

func (r *Response) CloseWindow()

Call CloseWindow to close the current window.

func (*Response) ExecuteControlCommand

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

ExecuteControlCommand executes the named command on the given goradd control.

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{})

ExecuteJsFunction calls the given JavaScript function with the given arguments. If the function name has a dot(.) in it, the items preceeding the dot will be considered global objects to call the function on. If the named function just a function label, then the function is called on the window object.

func (*Response) ExecuteSelectorFunction

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

ExecuteSelectorFunction calls a function on a jQuery selector

func (*Response) GetAjaxResponse added in v0.0.4

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

GetAjaxResponse returns the JSON for use by the form ajax response. It will also reset the response

func (*Response) JavaScript

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

JavaScript renders the Response object as JavaScript that will be inserted into the page sent back to the client in response to a Server action.

func (*Response) SetControlAttribute

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

SetControlAttribute sets the named html attribute on the control to the given value.

func (*Response) SetControlHtml

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

SetControlHtml will cause the given control's html to be completely replaced by the given HTML.

func (*Response) SetControlValue

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

SetControlValue calls the jQuery ".val()" function on the given control, passing it the given value.

func (*Response) SetLocation

func (r *Response) SetLocation(newLocation string)

Call SetLocation to change the url of the browser.

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 page cache that does serialization and uses an LRU cache of page objects. Use the serialized page cache during development to ensure that you can eventually move your page 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

Has returns true if the page with the given pageId is in the cache.

func (*SerializedPageCache) NewPageID

func (o *SerializedPageCache) NewPageID() string

NewPageID returns a new page id

func (*SerializedPageCache) Set

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

Set puts the page into the page 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
}

StackFrame holds the file, line and function name in a call chain

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 is used by events to indicate they are not overriding a control validation. You should not need to use this.
	ValidateDefault ValidationType = iota
	// ValidateNone indicates the control will not validate the form
	ValidateNone
	// ValidateForm is the default validation for buttons, and indicates the entire form and all controls will validate.
	ValidateForm
	// ValidateSiblingsAndChildren will validate the current control, and all siblings of the control and all
	// children of the siblings and current control.
	ValidateSiblingsAndChildren
	// ValidateSiblingOnly will validate only the siblings of the current control, but not any child controls.
	ValidateSiblingsOnly
	// ValidateChildrenOnly will validate only the children of the current control.
	ValidateChildrenOnly
	// ValidateContainer will use the validation setting of a parent control with ValidateSiblingsAndChildren, ValidateSiblingsOnly,
	// ValidateChildrenOnly, or ValidateTargetsOnly 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)

AddMasterJavaScriptFile adds 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)

ChangeLocation will redirect the browser to a new URL. It does this AFTER processing the return values sent to the browser. Generally you should use this to redirect the browser since you may have some data that needs to be processed first. The exception is if you are responding to some kind of security concern where you only want to send back an html redirect without revealing any goradd information, in which case you should use the Page

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)

DisplayAlert will display a javascript alert with the given message.

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) 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, fallback string)

PopLocation pops the most recent location off of the location stack and goes to that location. It will go to the fallback url if there is nothing on the stack

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) ΩDrawingAttributes added in v0.0.3

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

ΩDrawingAttributes returns the attributes to add to the form tag.

func (*ΩFormBase) ΩPreRender added in v0.0.3

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

ΩPreRender performs setup operations just before drawing.

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
Package action defines actions that you can trigger using events.
Package action defines actions that you can trigger using events.
Package control contains the implementations of the standard controls in goradd.
Package control contains the implementations of the standard controls in goradd.
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