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
- Variables
- func CacheBustedPath(url string) string
- func ConvertToBool(v interface{}) bool
- func DebugErrorPageTmpl(ctx context.Context, partialHtml string, err *Error, buf *bytes.Buffer)
- func GetAssetLocation(url string) string
- func GetAssetUrl(location string) string
- func HasPage(pageStateId string) bool
- func IsError(e error) bool
- func NewMockContext() (ctx context.Context)
- func Nodes(n ...query.NodeI) []query.NodeI
- func OutputBuffer(ctx context.Context) *bytes.Buffer
- func PageTmpl(ctx context.Context, page *Page, buf *bytes.Buffer) (err error)
- func PutContext(r *http.Request, cliArgs []string) *http.Request
- func Redirect(url string)
- func RedirectHtml(loc string) string
- func RegisterAssetDirectory(dir string, pattern string)
- func RegisterControl(i ControlI)
- func RegisterForm(path string, form FormI, id string)
- func RegisterTemplate(name string, t TemplateExecuter)
- func ReleaseErrorPageTmpl(ctx context.Context, partialHtml string, err *Error, buf *bytes.Buffer)
- func ServeAsset(w http.ResponseWriter, r *http.Request)
- func SetPageEncoder(e PageEncoderI)
- func SetPageManager(p PageManagerI)
- func SetPagestateCache(c PagestateCacheI)
- func StripCacheBusterPath(fPath string) string
- type ActionParams
- func (a *ActionParams) ActionValue(i interface{}) (ok bool, err error)
- func (a *ActionParams) ActionValueBool() bool
- func (a *ActionParams) ActionValueFloat() float64
- func (a *ActionParams) ActionValueInt() int
- func (a *ActionParams) ActionValueString() string
- func (a *ActionParams) ControlValue(i interface{}) (ok bool, err error)
- func (a *ActionParams) ControlValueBool() (ret bool)
- func (a *ActionParams) ControlValueFloat() float64
- func (a *ActionParams) ControlValueInt() int
- func (a *ActionParams) ControlValueString() string
- func (a *ActionParams) EventValue(i interface{}) (ok bool, err error)
- func (a *ActionParams) EventValueBool() bool
- func (a *ActionParams) EventValueFloat() float64
- func (a *ActionParams) EventValueInt() int
- func (a *ActionParams) EventValueString() string
- func (a *ActionParams) EventValueStringMap() (m map[string]string)
- type AppContext
- type Context
- func (ctx *Context) CustomControlValue(id string, key string) interface{}
- func (ctx *Context) FormValue(key string) (value string, ok bool)
- func (ctx *Context) FormValues(key string) (value []string, ok bool)
- func (ctx *Context) HasCustomControlValue(id string, key string) bool
- func (ctx *Context) RequestMode() RequestMode
- func (c *Context) String() string
- type ControlBase
- func (c *ControlBase) Action(ctx context.Context, a ActionParams)
- func (c *ControlBase) ActionValue() interface{}
- func (c *ControlBase) AddClass(class string) ControlI
- func (c *ControlBase) AddControls(ctx context.Context, creators ...Creator)
- func (c *ControlBase) AddRelatedRenderScript(id string, f string, params ...interface{})
- func (c *ControlBase) AddRenderScript(f string, params ...interface{})
- func (c *ControlBase) ApplyOptions(ctx context.Context, o ControlOptions)
- func (c *ControlBase) Attribute(name string) string
- func (c *ControlBase) Attributes() html.Attributes
- func (c *ControlBase) Child(id string) ControlI
- func (c *ControlBase) ChildValidationChanged()
- func (c *ControlBase) Children() []ControlI
- func (c *ControlBase) Cleanup()
- func (c *ControlBase) DataConnector() DataConnector
- func (c *ControlBase) Deserialize(d Decoder) (err error)
- func (c *ControlBase) Draw(ctx context.Context, buf *bytes.Buffer) (err error)
- func (c *ControlBase) DrawAjax(ctx context.Context, response *Response) (err error)
- func (c *ControlBase) DrawChildren(ctx context.Context, buf *bytes.Buffer) (err error)
- func (c *ControlBase) DrawInnerHtml(ctx context.Context, buf *bytes.Buffer) (err error)
- func (c *ControlBase) DrawTag(ctx context.Context) string
- func (c *ControlBase) DrawTemplate(ctx context.Context, buf *bytes.Buffer) (err error)
- func (c *ControlBase) DrawText(ctx context.Context, buf *bytes.Buffer)
- func (c *ControlBase) DrawingAttributes(ctx context.Context) html.Attributes
- func (c *ControlBase) ExecuteWidgetFunction(command string, params ...interface{})
- func (c *ControlBase) FireTestMarker(marker string)
- func (c *ControlBase) GT(message string) string
- func (c *ControlBase) GetActionScripts(r *Response)
- func (c *ControlBase) GetEvent(eventName string) *Event
- func (c *ControlBase) HasAttribute(name string) bool
- func (c *ControlBase) HasCallbackAction(eventName string) bool
- func (c *ControlBase) HasClass(class string) bool
- func (c *ControlBase) HasServerAction(eventName string) bool
- func (c *ControlBase) ID() string
- func (c *ControlBase) Init(parent ControlI, id string)
- func (c *ControlBase) IsDisabled() bool
- func (c *ControlBase) IsDisplayed() bool
- func (c *ControlBase) IsOnPage() bool
- func (c *ControlBase) IsRendering() bool
- func (c *ControlBase) IsRequired() bool
- func (c *ControlBase) IsVisible() bool
- func (c *ControlBase) MarshalJSON() (data []byte, err error)
- func (c *ControlBase) MarshalState(m maps.Setter)
- func (c *ControlBase) MergeAttributes(a html.Attributes) ControlI
- func (c *ControlBase) MockFormValue(value string) bool
- func (c *ControlBase) NeedsRefresh() bool
- func (c *ControlBase) Off()
- func (c *ControlBase) On(e *Event, a action.ActionI) ControlI
- func (c *ControlBase) Page() *Page
- func (c *ControlBase) Parent() ControlI
- func (c *ControlBase) ParentForm() FormI
- func (c *ControlBase) PostRender(ctx context.Context, buf *bytes.Buffer) (err error)
- func (c *ControlBase) PreRender(ctx context.Context, buf *bytes.Buffer) error
- func (c *ControlBase) PrivateAction(ctx context.Context, a ActionParams)
- func (c *ControlBase) ProcessAttributeString(s string) ControlI
- func (c *ControlBase) PutCustomScript(ctx context.Context, response *Response)
- func (c *ControlBase) RangeAllChildren(f func(child ControlI))
- func (c *ControlBase) RangeSelfAndAllChildren(f func(ctrl ControlI))
- func (c *ControlBase) Refresh()
- func (c *ControlBase) RefreshData(data interface{})
- func (c *ControlBase) Remove()
- func (c *ControlBase) RemoveChild(id string)
- func (c *ControlBase) RemoveChildren()
- func (c *ControlBase) RemoveClass(class string) ControlI
- func (c *ControlBase) RemoveClassesWithPrefix(prefix string)
- func (c *ControlBase) RenderAutoControls(ctx context.Context, buf *bytes.Buffer) (err error)
- func (f *ControlBase) ResetValidation()
- func (c *ControlBase) Restore()
- func (c *ControlBase) SaveState(ctx context.Context, saveIt bool)
- func (c *ControlBase) Serialize(e Encoder) (err error)
- func (c *ControlBase) SetActionValue(v interface{}) ControlI
- func (c *ControlBase) SetAttribute(name string, val interface{}) ControlI
- func (c *ControlBase) SetBlockParentValidation(block bool)
- func (c *ControlBase) SetDataAttribute(name string, val interface{})
- func (c *ControlBase) SetDataConnector(d DataConnector) ControlI
- func (c *ControlBase) SetDisabled(d bool)
- func (c *ControlBase) SetDisplay(d string) ControlI
- func (c *ControlBase) SetHasNoSpace(v bool) ControlI
- func (c *ControlBase) SetHeightStyle(h interface{}) ControlI
- func (c *ControlBase) SetIsRequired(r bool) ControlI
- func (c *ControlBase) SetParent(newParent ControlI)
- func (c *ControlBase) SetShouldAutoRender(r bool)
- func (c *ControlBase) SetStyle(name string, value string) ControlI
- func (c *ControlBase) SetStyles(s html.Style)
- func (c *ControlBase) SetText(t string) ControlI
- func (c *ControlBase) SetTextIsHtml(h bool) ControlI
- func (c *ControlBase) SetValidationError(e string)
- func (c *ControlBase) SetValidationTargets(controlIDs ...string)
- func (c *ControlBase) SetValidationType(typ ValidationType) ControlI
- func (c *ControlBase) SetVisible(v bool)
- func (c *ControlBase) SetWidthStyle(w interface{}) ControlI
- func (c *ControlBase) SetWillBeValidated(v bool)
- func (c *ControlBase) ShouldAutoRender() bool
- func (c *ControlBase) T(message string, params ...interface{}) string
- func (c *ControlBase) TPrintf(message string, params ...interface{}) string
- func (c *ControlBase) Text() string
- func (c *ControlBase) TextIsLabel() bool
- func (c *ControlBase) UnmarshalJSON(data []byte) (err error)
- func (c *ControlBase) UnmarshalState(m maps.Loader)
- func (c *ControlBase) UpdateData(data interface{})
- func (c *ControlBase) UpdateFormValues(ctx context.Context)
- func (c *ControlBase) Validate(ctx context.Context) bool
- func (c *ControlBase) ValidationMessage() string
- func (c *ControlBase) ValidationState() ValidationState
- func (c *ControlBase) ValidationType(e *Event) ValidationType
- func (c *ControlBase) WasRendered() bool
- func (c *ControlBase) WatchChannel(ctx context.Context, channel string)
- func (c *ControlBase) WatchDbRecord(ctx context.Context, n query.NodeI, pk string)
- func (c *ControlBase) WatchDbTables(ctx context.Context, nodes ...query.NodeI)
- func (c *ControlBase) WrapEvent(eventName string, selector string, eventJs string, ...) string
- type ControlI
- type ControlOptions
- type ControlTemplateFunc
- type ControlWrapperFunc
- type Creator
- type DataAttributeMap
- type DataConnector
- type DataLoader
- type DbError
- type Decoder
- type DrawI
- type Encoder
- type Error
- type ErrorPageFuncType
- type Event
- func (e *Event) ActionValue(r interface{}) *Event
- func (e *Event) Blocking() *Event
- func (e *Event) Bubbles() *Event
- func (e *Event) Capture() *Event
- func (e *Event) Condition(javascript string) *Event
- func (e *Event) Delay(d int) *Event
- func (e *Event) GetActionValue() interface{}
- func (e *Event) GetID() EventID
- func (e *Event) GobDecode(data []byte) (err error)
- func (e *Event) GobEncode() (data []byte, err error)
- func (e *Event) HasCallbackAction() bool
- func (e *Event) HasServerAction() bool
- func (e *Event) Name() string
- func (e *Event) PreventBubbling() *Event
- func (e *Event) PreventingDefault() *Event
- func (e *Event) Private() *Event
- func (e *Event) Selector(s string) *Event
- func (e *Event) String() string
- func (e *Event) Terminating() *Event
- func (e *Event) Validate(v ValidationType) *Event
- func (e *Event) ValidationTargets(targets ...string) *Event
- type EventID
- type EventList
- type EventMap
- type FastPagestateCache
- type FormBase
- func (f *FormBase) AddFontAwesome()
- func (f *FormBase) AddGoraddFiles()
- func (f *FormBase) AddHeadTags()
- func (f *FormBase) AddJQuery()
- func (f *FormBase) AddJQueryUI()
- func (f *FormBase) AddJavaScriptFile(path string, forceHeader bool, attributes html.Attributes)
- func (f *FormBase) AddMasterJavaScriptFile(url string, attributes []string, files []string)
- func (f *FormBase) AddRelatedFiles()
- func (f *FormBase) AddStyleSheetFile(path string, attributes html.Attributes)
- func (f *FormBase) ChangeLocation(url string)
- func (f *FormBase) CreateControls(ctx context.Context)
- func (f *FormBase) Deserialize(d Decoder) (err error)
- func (f *FormBase) DisplayAlert(ctx context.Context, msg string)
- func (f *FormBase) Draw(ctx context.Context, buf *bytes.Buffer) (err error)
- func (f *FormBase) DrawHeaderTags(ctx context.Context, buf *bytes.Buffer)
- func (f *FormBase) DrawingAttributes(ctx context.Context) html.Attributes
- func (f *FormBase) Exit(ctx context.Context, err error)
- func (f *FormBase) Init(ctx context.Context, id string)
- func (f *FormBase) LoadControls(ctx context.Context)
- func (f *FormBase) PageDrawingFunction() PageDrawFunc
- func (f *FormBase) PopLocation(ctx context.Context, fallback string)
- func (f *FormBase) PreRender(ctx context.Context, buf *bytes.Buffer) (err error)
- func (f *FormBase) PushLocation(ctx context.Context)
- func (f *FormBase) Refresh()
- func (f *FormBase) Response() *Response
- func (f *FormBase) Run(ctx context.Context) error
- func (f *FormBase) Serialize(e Encoder) (err error)
- type FormCreationFunction
- type FormI
- type FrameworkError
- type GobDeserializer
- type GobPageEncoder
- type GobSerializer
- type HttpContext
- type HttpError
- type NoErr
- type Page
- func (p *Page) AddHtmlHeaderTag(t html.VoidTag)
- func (p *Page) Cleanup()
- func (p *Page) ClearResponseHeaders()
- func (p *Page) Draw(ctx context.Context, buf *bytes.Buffer) (err error)
- func (p *Page) DrawAjax(ctx context.Context, buf *bytes.Buffer) (err error)
- func (p *Page) DrawHeaderTags(ctx context.Context, buf *bytes.Buffer)
- func (p *Page) Form() FormI
- func (p *Page) GenerateControlID(id string) string
- func (p *Page) GetControl(id string) ControlI
- func (p *Page) HasControl(id string) bool
- func (p *Page) HasMetaTag(name string) bool
- func (p *Page) Init()
- func (p *Page) LanguageCode() string
- func (p *Page) MarshalBinary() (data []byte, err error)
- func (p *Page) MarshalJSON() (data []byte, err error)
- func (p *Page) Restore()
- func (p *Page) SetControlIdPrefix(prefix string) *Page
- func (p *Page) SetResponseHeader(key, value string)
- func (p *Page) SetTitle(title string)
- func (p *Page) StateID() string
- func (p *Page) Title() string
- func (p *Page) UnmarshalBinary(data []byte) (err error)
- func (p *Page) UnmarshalJSON(data []byte) (err error)
- type PageDrawFunc
- type PageEncoderI
- type PageManager
- type PageManagerI
- type PageRenderStatus
- type PagestateCacheI
- type Priority
- type RequestMode
- type Response
- func (r *Response) AddClass(id string, class string, priorities ...Priority)
- func (r *Response) CloseWindow()
- func (r *Response) Deserialize(d Decoder) (err error)
- func (r *Response) ExecuteControlCommand(controlID string, functionName string, args ...interface{})
- func (r *Response) ExecuteJavaScript(js string, priorities ...Priority)
- func (r *Response) ExecuteJqueryCommand(controlID string, functionName string, args ...interface{})
- func (r *Response) ExecuteJsFunction(functionName string, args ...interface{})
- func (r *Response) ExecuteSelectorFunction(selector string, functionName string, args ...interface{})
- func (r *Response) GetAjaxResponse() (buf []byte, err error)
- func (r *Response) JavaScript() (script string)
- func (r *Response) RemoveClass(id string, class string, priorities ...Priority)
- func (r *Response) Serialize(e Encoder) (err error)
- func (r *Response) SetClass(id string, class string, priorities ...Priority)
- func (r *Response) SetControlAttribute(id string, attribute string, value string)
- func (r *Response) SetControlHtml(id string, html string)
- func (r *Response) SetControlValue(id string, value string)
- func (r *Response) SetLocation(newLocation string)
- type Serializable
- type SerializedPagestateCache
- type StackFrame
- type TemplateExecuter
- type TestFormI
- type ValidationState
- type ValidationType
Constants ¶
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. // In a REST environment, this is 404 error FrameworkErrRecordNotFound // FrameworkErrNotAuthenticated indicates that the user needs to log in, but has not done so. // This will result in a 401 http error. FrameworkErrNotAuthenticated // FrameworkErrNotAuthorized indicates the logged in user does not have permission to access the resource. // This will result in a 403 error. FrameworkErrNotAuthorized // FrameworkErrRedirect indicates the resource is at a different location. This will result in a 303 error // telling the browser to go that resource. FrameworkErrRedirect // FrameworkErrBadRequest is a generic bad request error, but most often it indicates that some FORM or GET // parameter was expected, but was either missing or invalid. This is a 400 error. FrameworkErrBadRequest // FrameworkErrMethodNotAllowed is for REST clients to indicate that the user tried to use a method (i.e. GET or PUT) // that is not allowed at the given endpoint. The HTTP spec says the client should also respond with an Allow // header with a comma separated list of what methods are allowed. This is a 405 error. FrameworkErrMethodNotAllowed )
const ( 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" )
const HtmlVarAction = "Goradd_Action"
const HtmlVarApistate = "__ApiState"
const HtmlVarPagestate = "Goradd__PageState"
const MaxStackDepth = 50
const PrivateActionBase = 1000
const RequiredErrorMessage string = "A value is required"
const UserPageCacheVersion = 10000
If you want to bump the page cache version yourself, you can use this as a starting point so there is no conflict with goradd itself
Variables ¶
var ControlRegistrySalt = "goradd"
This value is used to generate unique ids in the control registry. However, if the control registry detects a collision, you will need to change this value and restart your app. If you have a running page cache, you should change the PageCacheVersion above as well to invalidate it.
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
var MultipartFormMax int64 = 10000000 // 10MB max in memory file
MultipartFormMax is the maximum size of a mult-part form that we will allow.
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. Feel free to bump this as needed, though you should use a number after UserPageCacheVersion so there is no conflict with the goradd default.
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 CacheBustedPath ¶ added in v0.13.2
CacheBustedPath returns a path to an asset that was previously registered with the CacheBuster. The new path will contain a hash of the file that will change whenever the file changes, and cause the browser to reload the file. Since we are in control of serving these files, we will later remove the hash before serving it.
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 ¶
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 GetAssetLocation ¶
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 ¶
GetAssetUrl returns the url that corresponds to the asset at the given location. Its the reverse of GetAssetLocation.
func NewMockContext ¶ added in v0.0.3
NewMockContext creates a context for testing.
func PageTmpl ¶
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 ¶
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 RedirectHtml ¶ added in v0.9.5
func RegisterAssetDirectory ¶
RegisterAssetDirectory registers the given directory as a static file server. The files are served by the normal go static file process. RegisterAssetDirectory must be called during application initialization, as the static file directories are added to the MUX at startup time.
func RegisterControl ¶ added in v0.3.0
func RegisterControl(i ControlI)
RegisterControl registers the control for the serialize/deserialize process. You should call this for each control from an init() function.
As a control is added to the registry, it is assigned an id. That id is used to identify a control in the serialization and deserialization process. We make a significant attempt to prevent the addition of controls to an application from causing a change in these ids, since an id change will also cause the current page cache to be invalidated. We use a hashing function, and a collision detector to do that. If a collision is detected, it will panic, and you should change the hash salt and try again, as well as bump the cache version to invalidate the cache.
func RegisterForm ¶ added in v0.5.0
RegisterForm associates the given URL path with the given form 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 ¶
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.
Some things you get for free are:
- It will look for and use zipped versions of assets in the release version if available. See the goradd-project/build directory for examples on how to do that.
- It will use Go's default file server, which automatically gives you Last-Modified support in the header of these assets in the release version of the application. However, in order to actually get the client to validate, you must specify a Cache-Control policy of no-cache, or a max-age, etc. with the file. Also, remember that this will check the modification date of the file on the server, which will change each time you copy the file to the server.
Much more complicated servers are possible. You could, for example, package all your static files with the application itself and use an ETag to control caching. But, that is not available here, you would need to implement that yourself.
func SetPageEncoder ¶
func SetPageEncoder(e PageEncoderI)
func SetPageManager ¶ added in v0.5.0
func SetPageManager(p PageManagerI)
SetPageManger injects a new page manager. Call this at init time.
func SetPagestateCache ¶ added in v0.13.2
func SetPagestateCache(c PagestateCacheI)
SetPagestateCache will set the page cache to the given object.
func StripCacheBusterPath ¶ added in v0.13.2
StripCacheBusterPath removes the hash of the asset file from the path to the asset.
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 ControlBase value into the given object using json.Unmarshal. You should primarily use it to get object or array values out of the ControlBase 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.
func (*ActionParams) EventValueStringMap ¶ added in v0.9.3
func (a *ActionParams) EventValueStringMap() (m map[string]string)
EventValueStringMap returns the event value as a map[string]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 ¶
GetContext returns the page context from the GO context.
func (*Context) CustomControlValue ¶
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 ¶
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 ¶
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) HasCustomControlValue ¶ added in v0.12.0
HasCustomControlValue returns true if the given controls has a value for the given key. If you are potentially expecting a nil value, you can use this to know that a value is present.
func (*Context) RequestMode ¶
func (ctx *Context) RequestMode() RequestMode
RequestMode returns the request mode of the current request.
type ControlBase ¶ added in v0.4.0
type ControlBase 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 }
ControlBase is the basis for UI controls and widgets in goradd. It corresponds to a standard html form object or tag, or a custom javascript widget. A 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 ControlBase, can use a template to draw the Child controls, or manually draw them. The ControlBase 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 ControlBase are the same as what the user sees in a browser.
This ControlBase struct is a mixin that all controls should use. You would not normally create a ControlBase directly, but rather create one of the "subclasses" of ControlBase. See the control package for Controls that implement standard html widgets.
func (*ControlBase) Action ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) ActionValue ¶ added in v0.4.0
func (c *ControlBase) ActionValue() interface{}
ActionValue returns the control's action value
func (*ControlBase) AddClass ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) AddControls ¶ added in v0.4.0
func (c *ControlBase) AddControls(ctx context.Context, creators ...Creator)
AddControls adds subcontrols to a control using a Create function
func (*ControlBase) AddRelatedRenderScript ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) AddRenderScript ¶ added in v0.4.0
func (c *ControlBase) 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 ControlBase implementations only.
func (*ControlBase) ApplyOptions ¶ added in v0.4.0
func (c *ControlBase) ApplyOptions(ctx context.Context, o ControlOptions)
func (*ControlBase) Attribute ¶ added in v0.4.0
func (c *ControlBase) 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 ControlBase implementation.
func (*ControlBase) Attributes ¶ added in v0.4.0
func (c *ControlBase) Attributes() html.Attributes
Attributes returns a pointer to the attributes of the control. Use this with caution. Some controls setup attributes at initialization time, so you could potentially write over those. Also, if you change attributes during an ajax call, the changes will not be reflected unless you redraw the control. The primary use for this function is to allow controls to set up attributes during initialization.
func (*ControlBase) Child ¶ added in v0.4.0
func (c *ControlBase) Child(id string) ControlI
Child returns the child control with the given id. TODO: This should be a map, both to speed it up, and add the ability to sort it
func (*ControlBase) ChildValidationChanged ¶ added in v0.4.0
func (c *ControlBase) ChildValidationChanged()
ChildValidationChanged is sent by the framework when a child control's validation message has changed. Parent controls can use this to change messages or attributes in response.
func (*ControlBase) Children ¶ added in v0.4.0
func (c *ControlBase) Children() []ControlI
Children returns the child controls of the control.
func (*ControlBase) Cleanup ¶ added in v0.4.0
func (c *ControlBase) Cleanup()
Cleanup is called by the framework when a control is being removed from the page cache. It is an opportunity to remove any potential circular references in your controls that would prevent the garbage collector from removing the control from memory. In particular, references to parent objects would be a problem.
func (*ControlBase) DataConnector ¶ added in v0.4.0
func (c *ControlBase) DataConnector() DataConnector
DataConnector returns the data connector.
func (*ControlBase) Deserialize ¶ added in v0.4.0
func (c *ControlBase) Deserialize(d Decoder) (err error)
Deserialize is called by GobDecode to deserialize the control. It is overridable, and control implementations should call this first before calling their own version. However, after deserialization, the control will not be ready for use, since its parent, form or child controls still need to be deserialized. The Decoded function should be called to fix up the necessary internal pointers.
func (*ControlBase) Draw ¶ added in v0.4.0
Draw renders the control structure into the given buffer.
func (*ControlBase) DrawAjax ¶ added in v0.4.0
func (c *ControlBase) DrawAjax(ctx context.Context, response *Response) (err error)
DrawAjax will be called by the framework during an Ajax rendering of the ControlBase. Every ControlBase gets called. Each ControlBase 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 (*ControlBase) DrawChildren ¶ added in v0.4.0
DrawChildren renders the child controls that have not yet been drawn into the buffer.
func (*ControlBase) DrawInnerHtml ¶ added in v0.4.0
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 (*ControlBase) DrawTag ¶ added in v0.4.0
func (c *ControlBase) DrawTag(ctx context.Context) string
DrawTag is responsible for drawing the ControlBase's tag itself. ControlBase implementations can override this to draw the tag in a different way, or draw more than one tag if drawing a compound control.
func (*ControlBase) DrawTemplate ¶ added in v0.4.0
DrawTemplate is used by the framework to draw the ControlBase 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 (*ControlBase) DrawText ¶ added in v0.4.0
func (c *ControlBase) DrawText(ctx context.Context, buf *bytes.Buffer)
DrawText renders the text of the control, escaping if needed.
func (*ControlBase) DrawingAttributes ¶ added in v0.4.0
func (c *ControlBase) DrawingAttributes(ctx context.Context) 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 ControlBase implementations.
func (*ControlBase) ExecuteWidgetFunction ¶ added in v0.4.0
func (c *ControlBase) ExecuteWidgetFunction(command string, params ...interface{})
ExecuteWidgetFunction will execute the given JavaScript function on the matching client object, with the given parameters. The function is a widget function of the goradd widget wrapper or similar type of object.
func (*ControlBase) FireTestMarker ¶ added in v0.12.0
func (c *ControlBase) FireTestMarker(marker string)
FireTestMarker sends a marker signal to the browser test runner. You would normally send this from some place in your application if you want to wait until your app has gotten to that spot. Call WaitMarker on the test form to wait for the marker.
func (*ControlBase) GT ¶ added in v0.4.0
func (c *ControlBase) GT(message string) string
GT translates strings using the Goradd dictionary.
func (*ControlBase) GetActionScripts ¶ added in v0.4.0
func (c *ControlBase) GetActionScripts(r *Response)
GetActionScripts is an internal function called during drawing to gather up all the event related scripts attached to the control and send them to the response.
func (*ControlBase) GetEvent ¶ added in v0.4.0
func (c *ControlBase) GetEvent(eventName string) *Event
GetEvent returns the event associated with the eventName, which corresponds to the javascript trigger name.
func (*ControlBase) HasAttribute ¶ added in v0.4.0
func (c *ControlBase) HasAttribute(name string) bool
HasAttribute returns true if the control has the indicated custom attribute defined.
func (*ControlBase) HasCallbackAction ¶ added in v0.4.0
func (c *ControlBase) HasCallbackAction(eventName string) bool
HasCallbackAction returns true if one of the actions attached to the given event is a Server action.
func (*ControlBase) HasClass ¶ added in v0.10.0
func (c *ControlBase) HasClass(class string) bool
HasClass returns true if the class has been assigned to the control from the GO side. We do not currently detect class changes done in javascript.
func (*ControlBase) HasServerAction ¶ added in v0.4.0
func (c *ControlBase) HasServerAction(eventName string) bool
HasServerAction returns true if one of the actions attached to the given event is a Server action.
func (*ControlBase) ID ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) Init ¶ added in v0.4.0
func (c *ControlBase) Init(parent ControlI, id string)
Init is used by ControlBase implementations to initialize the standard control structure. You would only call this if you are subclassing one of the standard controls. ControlBase implementations should call this immediately after a control is created. The ControlBase 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 (*ControlBase) IsDisabled ¶ added in v0.4.0
func (c *ControlBase) IsDisabled() bool
IsDisabled returns true if the disabled attribute is true.
func (*ControlBase) IsDisplayed ¶ added in v0.4.0
func (c *ControlBase) IsDisplayed() bool
IsDisplayed returns true if the control will be displayed.
func (*ControlBase) IsOnPage ¶ added in v0.4.0
func (c *ControlBase) IsOnPage() bool
func (*ControlBase) IsRendering ¶ added in v0.4.0
func (c *ControlBase) IsRendering() bool
IsRendering returns true if we are in the process of rendering the control.
func (*ControlBase) IsRequired ¶ added in v0.4.0
func (c *ControlBase) IsRequired() bool
IsRequired returns true if the control requires input from the user to pass validation.
func (*ControlBase) IsVisible ¶ added in v0.4.0
func (c *ControlBase) IsVisible() bool
IsVisible returns whether the control will be drawn.
func (*ControlBase) MarshalJSON ¶ added in v0.4.0
func (c *ControlBase) MarshalJSON() (data []byte, err error)
func (*ControlBase) MarshalState ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) MergeAttributes ¶ added in v0.4.0
func (c *ControlBase) MergeAttributes(a html.Attributes) ControlI
func (*ControlBase) MockFormValue ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) NeedsRefresh ¶ added in v0.12.0
func (c *ControlBase) NeedsRefresh() bool
NeedsRefresh returns true if the control needs to be completely redrawn. Generally you control this by calling Refresh(), but subclasses can implement other ways of detecting this.
func (*ControlBase) Off ¶ added in v0.4.0
func (c *ControlBase) Off()
Off removes all event handlers from the control
func (*ControlBase) On ¶ added in v0.4.0
func (c *ControlBase) On(e *Event, a action.ActionI) ControlI
On adds an event listener to the control that will trigger the given actions. To have a single event fire multiple actions, use action.Group() to combine the actions into one.
func (*ControlBase) Page ¶ added in v0.4.0
func (c *ControlBase) Page() *Page
Page returns the page object associated with the control.
func (*ControlBase) Parent ¶ added in v0.4.0
func (c *ControlBase) Parent() ControlI
Parent returns the parent control of the control. All controls have a parent, except the Form control.
func (*ControlBase) ParentForm ¶ added in v0.4.0
func (c *ControlBase) ParentForm() FormI
ParentForm returns the form object that encloses this control.
func (*ControlBase) PostRender ¶ added in v0.4.0
PostRender is called by the framework at the end of drawing, and is the place where controls do any post-drawing cleanup needed.
func (*ControlBase) PreRender ¶ added in v0.4.0
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 (*ControlBase) PrivateAction ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) ProcessAttributeString ¶ added in v0.7.1
func (c *ControlBase) ProcessAttributeString(s string) ControlI
ProcessAttributeString is used by the drawing template to let you set attributes in the draw tag. Attributes are of the form `name="value"`.
func (*ControlBase) PutCustomScript ¶ added in v0.4.0
func (c *ControlBase) 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 ControlBase implementation does this by calling functions on the response object. This implementation is a stub.
func (*ControlBase) RangeAllChildren ¶ added in v0.4.0
func (c *ControlBase) RangeAllChildren(f func(child ControlI))
RangeAllChildren recursively calls the given function on every child control and subcontrol. It calls the function on the child controls of each control first, and then on the control itself.
func (*ControlBase) RangeSelfAndAllChildren ¶ added in v0.4.0
func (c *ControlBase) RangeSelfAndAllChildren(f func(ctrl ControlI))
RangeSelfAndAllChildren recursively calls the given function on this control and every child control and subcontrol. It calls the function on the child controls of each control first, and then on the control itself.
func (*ControlBase) Refresh ¶ added in v0.4.0
func (c *ControlBase) Refresh()
Refresh will force the control to be completely redrawn on the next update.
func (*ControlBase) RefreshData ¶ added in v0.4.0
func (c *ControlBase) RefreshData(data interface{})
func (*ControlBase) Remove ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) RemoveChild ¶ added in v0.4.0
func (c *ControlBase) RemoveChild(id string)
RemoveChild removes the given child control from both the control and the form.
func (*ControlBase) RemoveChildren ¶ added in v0.4.0
func (c *ControlBase) RemoveChildren()
RemoveChildren removes all the child controls from this control and the form so that the memory manager can delete them.
func (*ControlBase) RemoveClass ¶ added in v0.4.0
func (c *ControlBase) RemoveClass(class string) ControlI
RemoveClass will remove the named class from the control.
func (*ControlBase) RemoveClassesWithPrefix ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) RenderAutoControls ¶ added in v0.4.0
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. ControlBase implementations that need to put these controls in particular locations on the form can override this.
func (*ControlBase) ResetValidation ¶ added in v0.7.0
func (f *ControlBase) ResetValidation()
func (*ControlBase) Restore ¶ added in v0.4.0
func (c *ControlBase) Restore()
Restore is called after the control has been deserialized. It notifies the control tree so that it can restore internal pointers. TODO: Serialization is not yet implemented
func (*ControlBase) SaveState ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) Serialize ¶ added in v0.4.0
func (c *ControlBase) Serialize(e Encoder) (err error)
Serialize is used by the framework to serialize a control to be saved in the pagestate. It is overridable, and control implementations should call this function first before their own serializer.
func (*ControlBase) SetActionValue ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) SetAttribute ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) SetBlockParentValidation ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) SetDataAttribute ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) SetDataConnector ¶ added in v0.4.0
func (c *ControlBase) SetDataConnector(d DataConnector) ControlI
SetDataConnector sets the data connector. The connector must be registered with Gob to be serializable.
func (*ControlBase) SetDisabled ¶ added in v0.4.0
func (c *ControlBase) SetDisabled(d bool)
SetDisable will set the "disabled" attribute of the control.
func (*ControlBase) SetDisplay ¶ added in v0.4.0
func (c *ControlBase) SetDisplay(d string) ControlI
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 (*ControlBase) SetHasNoSpace ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) SetHeightStyle ¶ added in v0.4.0
func (c *ControlBase) SetHeightStyle(h interface{}) ControlI
SetHeightStyle sets the height style property
func (*ControlBase) SetIsRequired ¶ added in v0.4.0
func (c *ControlBase) SetIsRequired(r bool) ControlI
SetIsRequired will set whether the control requires a value from the user. Setting it to true will cause the ControlBase to check this during validation, and show an appropriate error message if the user did not enter a value.
func (*ControlBase) SetParent ¶ added in v0.4.0
func (c *ControlBase) 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 ControlBase from one parent ControlBase to another.
func (*ControlBase) SetShouldAutoRender ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) SetStyle ¶ added in v0.4.0
func (c *ControlBase) SetStyle(name string, value string) ControlI
SetStyle sets a particular property of the style attribute on the control.
func (*ControlBase) SetStyles ¶ added in v0.4.0
func (c *ControlBase) SetStyles(s html.Style)
SetStyles sets the style attribute of the control to the given values.
func (*ControlBase) SetText ¶ added in v0.4.0
func (c *ControlBase) SetText(t string) ControlI
SetText sets the text of the control. Not all controls use this value.
func (*ControlBase) SetTextIsHtml ¶ added in v0.4.0
func (c *ControlBase) SetTextIsHtml(h bool) ControlI
SetTextIsHtml to true to turn off html escaping of the text output.
func (*ControlBase) SetValidationError ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) SetValidationTargets ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) SetValidationType ¶ added in v0.4.0
func (c *ControlBase) SetValidationType(typ ValidationType) ControlI
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 (*ControlBase) SetVisible ¶ added in v0.4.0
func (c *ControlBase) SetVisible(v bool)
SetVisible controls whether the ControlBase 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 (*ControlBase) SetWidthStyle ¶ added in v0.4.0
func (c *ControlBase) SetWidthStyle(w interface{}) ControlI
SetWidthStyle sets the width style property
func (*ControlBase) SetWillBeValidated ¶ added in v0.4.0
func (c *ControlBase) SetWillBeValidated(v bool)
SetWillBeValidated indicates to the wrapper whether to save a spot for a validation message or not.
func (*ControlBase) ShouldAutoRender ¶ added in v0.4.0
func (c *ControlBase) ShouldAutoRender() bool
ShouldAutoRender returns true if the control is set up to auto-render.
func (*ControlBase) T ¶ added in v0.4.0
func (c *ControlBase) 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.SetText(textbox.T("S", i18n.ID("South")));
func (*ControlBase) TPrintf ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) Text ¶ added in v0.4.0
func (c *ControlBase) Text() string
Text returns the text of the control.
func (*ControlBase) TextIsLabel ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) UnmarshalJSON ¶ added in v0.4.0
func (c *ControlBase) UnmarshalJSON(data []byte) (err error)
func (*ControlBase) UnmarshalState ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) UpdateData ¶ added in v0.4.0
func (c *ControlBase) UpdateData(data interface{})
func (*ControlBase) UpdateFormValues ¶ added in v0.4.0
func (c *ControlBase) UpdateFormValues(ctx context.Context)
UpdateFormValues is used by the framework to cause the control to retrieve its values from the form
func (*ControlBase) Validate ¶ added in v0.4.0
func (c *ControlBase) 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 ControlBase implementations. Overriding controls should call the parent version before doing their own validation.
func (*ControlBase) ValidationMessage ¶ added in v0.4.0
func (c *ControlBase) 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 (*ControlBase) ValidationState ¶ added in v0.4.0
func (c *ControlBase) ValidationState() ValidationState
ValidationState returns the current ValidationState value.
func (*ControlBase) ValidationType ¶ added in v0.4.0
func (c *ControlBase) ValidationType(e *Event) ValidationType
ValidationType is an internal function to return the validation type. It allows subclasses to override it.
func (*ControlBase) WasRendered ¶ added in v0.4.0
func (c *ControlBase) WasRendered() bool
WasRendered returns true if the control has been rendered.
func (*ControlBase) WatchChannel ¶ added in v0.4.0
func (c *ControlBase) WatchChannel(ctx context.Context, channel string)
WatchChannel allows you to specify any channel to watch that will cause a redraw
func (*ControlBase) WatchDbRecord ¶ added in v0.4.0
WatchDbRecord will watch a specific record. Specify a table node to watch all fields in the record, or a column node to watch the changes to a particular field of the table.
func (*ControlBase) WatchDbTables ¶ added in v0.4.0
func (c *ControlBase) WatchDbTables(ctx context.Context, nodes ...query.NodeI)
WatchDbTables will add the table nodes to the list of database tables that the control is watching. It also adds all the parents of those nodes. For example, WatchDbTables(ctx, node.Project().Manager()) will watch the project table and the person table.
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) Parent() ControlI Children() []ControlI SetParent(parent ControlI) Remove() RemoveChild(id string) RemoveChildren() Page() *Page ParentForm() FormI Child(string) ControlI RangeAllChildren(func(ControlI)) RangeSelfAndAllChildren(func(ControlI)) SetAttribute(name string, val interface{}) ControlI Attribute(string) string HasAttribute(string) bool ProcessAttributeString(s string) ControlI DrawingAttributes(context.Context) html.Attributes AddClass(class string) ControlI RemoveClass(class string) ControlI HasClass(class string) bool SetStyles(html.Style) SetStyle(name string, value string) ControlI SetWidthStyle(w interface{}) ControlI SetHeightStyle(w interface{}) ControlI Attributes() html.Attributes SetDisplay(d string) ControlI SetDisabled(d bool) IsDisabled() bool PutCustomScript(ctx context.Context, response *Response) TextIsLabel() bool Text() string SetText(t string) ControlI ValidationMessage() string SetValidationError(e string) ResetValidation() WasRendered() bool IsRendering() bool IsVisible() bool SetVisible(bool) IsOnPage() bool Refresh() NeedsRefresh() bool Action(context.Context, ActionParams) PrivateAction(context.Context, ActionParams) SetActionValue(interface{}) ControlI ActionValue() interface{} On(e *Event, a action.ActionI) ControlI Off() WrapEvent(eventName string, selector string, eventJs string, options map[string]interface{}) string HasServerAction(eventName string) bool HasCallbackAction(eventName string) bool // UpdateFormValues is used by the framework to cause the control to retrieve its values from the form UpdateFormValues(context.Context) Validate(ctx context.Context) bool ValidationState() ValidationState ValidationType(*Event) ValidationType SetValidationType(typ ValidationType) ControlI ChildValidationChanged() // 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) // GT translates strings using the Goradd dictionary. GT(format string) string // T translates strings using the application provided dictionary. T(message string, params ...interface{}) string TPrintf(format string, params ...interface{}) string Restore() Cleanup() SetIsRequired(r bool) ControlI Serialize(e Encoder) (err error) Deserialize(d Decoder) (err error) ApplyOptions(ctx context.Context, o ControlOptions) AddControls(ctx context.Context, creators ...Creator) DataConnector() DataConnector SetDataConnector(d DataConnector) ControlI RefreshData(data interface{}) UpdateData(data interface{}) WatchDbTables(ctx context.Context, nodes ...query.NodeI) WatchDbRecord(ctx context.Context, n query.NodeI, pk string) WatchChannel(ctx context.Context, channel string) // contains filtered or unexported methods }
ControlI is the interface that all controls must support. The functions are implemented by the ControlBase methods. See the ControlBase method implementation for a description of each method.
type ControlOptions ¶ added in v0.2.0
type ControlOptions struct { // Attributes will set the attributes of the control. Use DataAttributes to set data attributes, Styles to set styles, and Class to set the class Attributes html.Attributes // Attributes will set the attributes of the control. Use DataAttributes to set data attributes, Styles to set styles, and Class to set the class DataAttributes DataAttributeMap // Styles sets the styles of the control's tag Styles html.Style // Class sets the class of the control's tag. Prefix a class with "+" to add a class, or "-" to remove a class. Class string // IsDisabled initializes the control in the disabled state, with a "disabled" attribute IsDisabled bool // IsRequired is used by the validator. If a value is required, and the control is empty, it will not pass validation. IsRequired bool // IsHidden initializes this control as hidden. A place holder will be sent in the html so that when the control is shown through ajax, we will know where to put it. IsHidden bool // On adds events with actions to the control On EventList // DataConnector is the ViewModel layer that moves data between the control and an attached model. DataConnector DataConnector // WatchedDbTables lets you specify database nodes to watch for changes. When a record in the table is altered, added or deleted, // this control will automatically redraw. To watch a specific record, call WatchDbRecord when you load the control's data. WatchedDbTables []query.NodeI }
ControlOptions are options common to all controls
type ControlTemplateFunc ¶
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 DataAttributeMap ¶ added in v0.2.0
type DataAttributeMap map[string]interface{}
type DataConnector ¶ added in v0.2.0
type DataConnector interface { // Refresh reads from the model, and puts it into the control Refresh(i ControlI, model interface{}) // Update reads data from the control, and puts it into the model Update(i ControlI, model interface{}) }
The DataConnector moves data between the control and the database model. It is a thin view-model controller that can be customized on a per-control basis.
type DataLoader ¶ added in v0.2.0
DataLoader is an optional interface that DataConnectors can use if they need to load data from the database to present a choice of items to the user to select from. The Load method will be called whenever the entire control gets redrawn.
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.
type Decoder ¶
type Decoder interface {
Decode(v interface{}) 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 Encoder ¶
type Encoder interface {
Encode(v interface{}) 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
type ErrorPageFuncType ¶
ErrorPageFuncType 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 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 NewEvent ¶
NewEvent creates an event that triggers on the given javascript event name. Use the builder pattern functions from *Event to add delays, conditions, etc.
func (*Event) ActionValue ¶
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. By default, this will be the value passed in to the event as event data. See on: and trigger: in goradd.js. Example: ActionValue(javascript.JsCode("event.target.id")) will return the target id from the event object passed in to the event handler.
func (*Event) Blocking ¶
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) Bubbles ¶ added in v0.2.0
Bubbles works with a Selector to allow events to come from sub-control of the selected control. The event could be blocked by the sub-control if the subcontrol issues a preventPropagation on the event.
func (*Event) Capture ¶ added in v0.2.0
Capture works with a Selector to allow events to come from a sub-control of the selected control. The event never actually reaches the sub-control for processing, and instead is captured and handled by the selected control.
func (*Event) Condition ¶
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) 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
EventId returns the private event id generated when the event was assigned a control Useful in special situations when drawing a control
func (*Event) HasCallbackAction ¶ added in v0.3.0
HasServerAction returns true if at least one of the event's actions is a server action.
func (*Event) HasServerAction ¶ added in v0.0.3
HasServerAction returns true if at least one of the event's actions is a server action.
func (*Event) PreventBubbling ¶
Call PreventBubbling to cause the event to not bubble to enclosing objects.
func (*Event) PreventingDefault ¶
Call PreventingDefault to cause the event not to do the default action.
func (*Event) Private ¶ added in v0.2.3
Private makes the event private to the control and not removable. This should generally only be used by control implementations to add events that are required by the control and that should not be removed by Off()
func (*Event) Selector ¶
Selector specifies a CSS filter that is used to check for bubbled events. This allows the event to be fired from child controls. By default, the event will not come from sub-controls of the specified child controls. Use Bubbles or Capture to change that.
func (*Event) Terminating ¶
Call Terminating to cause the event not to bubble or do the default action.
func (*Event) Validate ¶
func (e *Event) Validate(v ValidationType) *Event
Validate overrides the controls validation setting just for this event.
func (*Event) ValidationTargets ¶
ValidationTargets overrides the control's validation targets just for this event.
type EventID ¶
type EventID uint16
EventID is a unique id used to specify which event is triggering.
type EventList ¶ added in v0.2.0
EventList is a list of event and action pairs. Use action.Group as the Action to assign multiple actions to an event.
type FastPagestateCache ¶ added in v0.13.2
FastPagestateCache 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 can be used in a production environment if the application is guaranteed to only work on a single machine. If you want scalability, use a serializing page cache that serializes directly to a database that is accessible from all instances of the app.
func NewFastPageCache ¶
func NewFastPageCache(maxEntries int, TTL int64) *FastPagestateCache
NewFastPageCache creates a new FastPagestateCache cache
func (*FastPagestateCache) Get ¶ added in v0.13.2
func (o *FastPagestateCache) Get(pageId string) *Page
Get returns the page based on its page id. If not found, will return null.
func (*FastPagestateCache) Has ¶ added in v0.13.2
func (o *FastPagestateCache) Has(pageId string) bool
Has tests to see if the given page id is in the page cache, without actually loading the page
func (*FastPagestateCache) NewPageID ¶ added in v0.13.2
func (o *FastPagestateCache) NewPageID() string
NewPageID returns a new page id
func (*FastPagestateCache) Set ¶ added in v0.13.2
func (o *FastPagestateCache) 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 FormBase ¶ added in v0.4.0
type FormBase struct { ControlBase // 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 ¶ added in v0.4.0
func (f *FormBase) AddFontAwesome()
AddFontAwesome adds the font-awesome files fo the form
func (*FormBase) AddGoraddFiles ¶ added in v0.4.0
func (f *FormBase) AddGoraddFiles()
AddGoraddFiles adds the various goradd files to the form
func (*FormBase) AddHeadTags ¶ added in v0.4.0
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 ¶ added in v0.4.0
func (f *FormBase) AddJQuery()
AddJQuery adds the jquery javascript to the form
func (*FormBase) AddJQueryUI ¶ added in v0.4.0
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 ¶ added in v0.4.0
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.
The path is either a url, or an internal path to the location of the file in the development environment.
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. You can specify forceHeader and a "defer" attribute to get the effect of loading the javascript in the background. With forceHeader false, 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.
attributes are the attributes that will be included with the script tag, which is useful for things like crossorigin and integrity attributes.
To control the cache-control settings on the file, you should call SetCacheControl.
func (*FormBase) AddMasterJavaScriptFile ¶ added in v0.4.0
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 ¶ added in v0.4.0
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 ¶ added in v0.4.0
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 to an external resource, or a local directory to a resource on disk. Paths must be registered with RegisterAssetDirectory, and will be served from their local location in a development environment, but from the corresponding registered path when deployed.
attributes are the attributes that will be included with the link tag, which is useful for things like crossorigin and integrity attributes.
To control the cache-control settings on the file, you should call SetCacheControl.
func (*FormBase) ChangeLocation ¶ added in v0.4.0
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) CreateControls ¶ added in v0.11.0
CreateControls is a lifecycle function that gets called whenever a page is created. It happens after the Run call. This is the place to add controls to the form
func (*FormBase) Deserialize ¶ added in v0.4.0
func (*FormBase) DisplayAlert ¶ added in v0.4.0
DisplayAlert will display a javascript alert with the given message.
func (*FormBase) Draw ¶ added in v0.4.0
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 ¶ added in v0.4.0
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 ¶ added in v0.4.0
func (f *FormBase) DrawingAttributes(ctx context.Context) html.Attributes
DrawingAttributes returns the attributes to add to the form tag.
func (*FormBase) Exit ¶ added in v0.4.0
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 ¶ added in v0.4.0
Init initializes the form control. Note that ctx might be nil if we are unit testing.
func (*FormBase) LoadControls ¶ added in v0.4.0
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 or session variables.
func (*FormBase) PageDrawingFunction ¶ added in v0.4.0
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 ¶ added in v0.4.0
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) PreRender ¶ added in v0.4.0
PreRender performs setup operations just before drawing.
func (*FormBase) PushLocation ¶ added in v0.4.0
PushLocation pushes the URL that got us to the current page on to the location stack.
func (*FormBase) Response ¶ added in v0.4.0
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 ¶ added in v0.4.0
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.
type FormCreationFunction ¶
type FormI ¶
type FormI interface { ControlI // Init initializes the base structures of the form. Do this before adding controls to the form. // Note that this signature is different than that of the Init function in FormBase. Init(ctx context.Context, id string) PageDrawingFunction() PageDrawFunc AddHeadTags() DrawHeaderTags(ctx context.Context, buf *bytes.Buffer) Response() *Response AddRelatedFiles() AddStyleSheetFile(path string, attributes html.Attributes) AddJavaScriptFile(path string, forceHeader bool, attributes html.Attributes) DisplayAlert(ctx context.Context, msg string) AddJQuery() AddJQueryUI() ChangeLocation(url string) PushLocation(ctx context.Context) PopLocation(ctx context.Context, fallback string) // Lifecycle calls Run(ctx context.Context) error CreateControls(ctx context.Context) LoadControls(ctx context.Context) Exit(ctx context.Context, err error) // contains filtered or unexported methods }
type FrameworkError ¶
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 NewRedirectError ¶ added in v0.12.0
func NewRedirectError(location string) FrameworkError
func (FrameworkError) HttpError ¶ added in v0.13.8
func (e FrameworkError) HttpError() int
HttpError returns the corresponding http error
func (FrameworkError) SetMessage ¶ added in v0.13.8
func (e FrameworkError) SetMessage(msg string) FrameworkError
type GobDeserializer ¶
func (GobDeserializer) Decode ¶
func (e GobDeserializer) Decode(v interface{}) (err error)
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 ¶
func (GobSerializer) Encode ¶
func (e GobSerializer) Encode(v interface{}) (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) SetResponseHeader ¶
SetResponseHeader sets a key-value in the header response.
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 ¶
AddHtmlHeaderTag adds the given tag to the head section of the page.
func (*Page) Cleanup ¶ added in v0.2.0
func (p *Page) Cleanup()
Cleanup is called by the page cache when the page is removed from memory.
func (*Page) ClearResponseHeaders ¶
func (p *Page) ClearResponseHeaders()
ClearResponseHeaders removes all the current response headers.
func (*Page) DrawAjax ¶
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 ¶
DrawHeaderTags draws all the inner html for the head tag
func (*Page) GenerateControlID ¶
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 ¶
GetControl returns the control with the given id. If not found, it panics. Use HasControl to check for existence.
func (*Page) HasControl ¶ added in v0.2.0
func (*Page) HasMetaTag ¶ added in v0.7.0
func (*Page) Init ¶
func (p *Page) Init()
Init initializes the page. Should be called by a form just after creating Page.
func (*Page) LanguageCode ¶
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 (p *Page) PushRedraw() { channel := "form-" + p.stateId if ws.HasChannel(channel) { // If we call this while launching a page, the channel isn't created yet, but the page is going to be drawn, so its ok. ws.SendMessage(channel, map[string]interface{}{"grup": true}) } else { log.FrameworkDebug("Pushing redraw with no channel.") } }
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) MarshalBinary ¶ added in v0.3.0
MarshalBinary is called by the framework to serialize the page state.
func (*Page) MarshalJSON ¶
func (*Page) Restore ¶
func (p *Page) Restore()
Restore is called immediately after the page has been unserialized, to fix up decoded controls.
func (*Page) SetControlIdPrefix ¶
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 ¶
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 ¶
Call SetTitle to set the content of the <title> tag to be output in the head of the page.
func (*Page) StateID ¶
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 ¶
Title returns the content of the <title> tag that will be output in the head of the page.
func (*Page) UnmarshalBinary ¶ added in v0.3.0
func (*Page) UnmarshalJSON ¶
type PageDrawFunc ¶
PageDrawFunc is the type of the page drawing function. This is implemented by the page drawing template.
type PageEncoderI ¶
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 (*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) RegisterForm ¶ added in v0.5.0
func (m *PageManager) RegisterForm(path string, f FormI, id string)
type PageManagerI ¶
type PageManagerI interface { RegisterForm(path string, form FormI, formID string) RunPage(ctx context.Context, buf *bytes.Buffer) (headers map[string]string, httpErrCode int) IsPage(path string) bool }
func GetPageManager ¶
func GetPageManager() PageManagerI
GetPageManager returns the current page manager.
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 )
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 PagestateCacheI ¶ added in v0.13.2
type PagestateCacheI interface { Set(pageId string, page *Page) Get(pageId string) *Page NewPageID() string Has(pageId string) bool }
PagestateCacheI is the page cache interface. The PageCache saves and restores pages in between page accesses by the user.
func GetPagestateCache ¶ added in v0.13.2
func GetPagestateCache() PagestateCacheI
GetPagestateCache returns the page cache. Used internally by goradd.
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.
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 (*Response) CloseWindow ¶
func (r *Response) CloseWindow()
Call CloseWindow to close the current window.
func (*Response) Deserialize ¶ added in v0.3.0
Deserialize unpacks the response from the pagestate. Currently the response is only serialized in the testing framework.
func (*Response) ExecuteControlCommand ¶
func (r *Response) ExecuteControlCommand(controlID string, functionName string, args ...interface{})
ExecuteControlCommand executes the named command on the given control. Possible commands are defined by the goradd widget class in the javascript file.
func (*Response) ExecuteJavaScript ¶
ExecuteJavaScript will execute the given code with the given priority. Note that all javascript code is run in strict mode.
func (*Response) ExecuteJqueryCommand ¶ added in v0.2.0
ExecuteJqueryCommand executes the named jquery command on the given jquery control.
func (*Response) ExecuteJsFunction ¶
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 goradd function on a group of objects defined by a selector.
func (*Response) GetAjaxResponse ¶ added in v0.0.4
GetAjaxResponse returns the JSON for use by the form ajax response. It will also reset the response
func (*Response) JavaScript ¶
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) RemoveClass ¶ added in v0.2.0
func (*Response) Serialize ¶ added in v0.3.0
Serialize encodes the response for the pagestate. Currently, serialization of the response is only used by the testing framework.
func (*Response) SetControlAttribute ¶
SetControlAttribute sets the named html attribute on the control to the given value.
func (*Response) SetControlHtml ¶
SetControlHtml will cause the given control's html to be completely replaced by the given HTML.
func (*Response) SetControlValue ¶
SetControlValue calls the jQuery ".val()" function on the given control, passing it the given value.
func (*Response) SetLocation ¶
Call SetLocation to change the url of the browser.
type Serializable ¶
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 SerializedPagestateCache ¶ added in v0.13.2
SerializedPagestateCache 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.
This also uses an in memory, non-serialized map to keep the pages in memory so that the testing harness can perform browser-based tests. Essentially this cache should only be used for development purposes and not production.
func NewSerializedPageCache ¶
func NewSerializedPageCache(maxEntries int, TTL int64) *SerializedPagestateCache
func (*SerializedPagestateCache) Get ¶ added in v0.13.2
func (o *SerializedPagestateCache) Get(pageId string) *Page
Get returns the page based on its page id. If not found, will return null.
func (*SerializedPagestateCache) Has ¶ added in v0.13.2
func (o *SerializedPagestateCache) Has(pageId string) bool
Has returns true if the page with the given pageId is in the cache.
func (*SerializedPagestateCache) NewPageID ¶ added in v0.13.2
func (o *SerializedPagestateCache) NewPageID() string
NewPageID returns a new page id
func (*SerializedPagestateCache) Set ¶ added in v0.13.2
func (o *SerializedPagestateCache) 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 ¶
StackFrame holds the file, line and function name in a call chain
type TemplateExecuter ¶
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 TestFormI ¶ added in v0.3.0
type TestFormI interface {
NoSerialize() bool
}
This special interface is used by our test harness to prevent the serialization of the test form.
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 )
Source Files ¶
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 |