BaseController Class
The base controller provides functions for the majority of the heavy lifing for a controller. It accepts and provides access to extending controllers for items such as the request, response, session, etc.
Constructor
BaseController
()
Item Index
Methods
- apiResponse static
- checkForFormRefill
- displayErrorOrSuccessCallback
- formError
- getContentSanitizationRules static deprecated
- getDefaultSanitizationRules static deprecated
- getJSONPostParams deprecated
- getPageName
- getPostData
- getPostParams
- getSanitizationRules
- getServiceContext
- getTemplateServiceInstance
- hasRequiredParams
- init
- initSync
- onLocalizedAlternateFlagFound
- redirect
- requiresClientLocalization
- requiresClientLocalizationCallback
- sanitize static deprecated
- sanitizeObject
- setFormFieldValues
- setPageName
Properties
- activeTheme
- ALERT_PATTERN static
- API_FAILURE static
- API_SUCCESS static
- body
- context
- ENCODING_MAPPING static
- FORM_REFILL_PATTERN static
- localizationService deprecated
- ls
- pageName
- pathVars
- query
- referer deprecated
- req
- reqHandler
- res
- session
- ts
Methods
apiResponse
()
String
static
Generates an generic API response object
Returns:
JSON
checkForFormRefill
-
result
-
cb
Parameters:
-
result
String -
cb
Function
displayErrorOrSuccessCallback
-
flag
-
cb
Parameters:
-
flag
String -
cb
Function
formError
-
message
-
redirectLocation
-
cb
Parameters:
-
message
StringThe error message to be displayed
-
redirectLocation
String -
cb
Function
getContentSanitizationRules
()
deprecated
static
The sanitization rules that apply to Pages and Articles
getDefaultSanitizationRules
()
deprecated
static
getJSONPostParams
-
cb
Parses the incoming payload of a request as JSON formatted data.
Parameters:
-
cb
Function
getPageName
()
String
Provides a page title. This is picked up by the template engine when the ^page_name^ key is found in a template.
Returns:
The page title
getPostData
-
cb
Parameters:
-
cb
Function
getPostParams
-
cb
Parameters:
-
cb
Function
getSanitizationRules
()
Object
Returns:
getServiceContext
()
Object
Retrieves a context object that contains the necessary information for service prototypes
Returns:
getTemplateServiceInstance
-
props
Creates a TemplateService instance
Parameters:
-
props
Object
Returns:
hasRequiredParams
-
queryObject
-
requiredParameters
Parameters:
-
queryObject
Object -
requiredParameters
Array
init
-
props
-
cb
Responsible for initializing a controller. Properties from the RequestHandler are passed down so that the controller has complete access to a variety of request specified properties. By default the function transfers the options over to instance variables that can be access during rendering. In addition, the function sets up the template service along with a set of local flags:
- locale - The selected locale for the request (NOTE: this may not match the requested language if not supported)
- error_success - An alert box if one was registered by the controller
- page_name - The title of the page
- localization_script - Includes the localization script so that it can be used client side
- analytics - Inserts the necessary javascript for analytics providers
Parameters:
-
props
ObjectThe properties needed to initialize the controller
-
request_handler
RequestHandler -
request
RequestThe incoming request
-
response
ResponseThe outgoing response
-
session
ObjectThe session object
-
localization_service
LocalizationThe localization service instance for the request
-
path_vars
ObjectThe path variables associated with the URL for the request
-
query
ObjectThe query string variables associated with the URL for the request
-
-
cb
FunctionA callback that takes a single optional argument: cb(Error)
initSync
-
context
Provides a synchronous function means to initialize a controller. It is meant to be called from the "init" function called by the request handler.
Parameters:
-
context
ObjectSee "init" for more details on properties
onLocalizedAlternateFlagFound
-
routeLocalized
-
cb
Parameters:
-
routeLocalized
Boolean -
cb
Function
redirect
-
location
-
cb
Redirects a request to a different location
Parameters:
-
location
String -
cb
Function
requiresClientLocalization
()
Boolean
Returns:
requiresClientLocalizationCallback
-
flag
-
cb
Parameters:
-
flag
String -
cb
Function
sanitize
-
value
-
[config]
Parameters:
-
value
String -
[config]
Object optional
sanitizeObject
-
obj
Sanitizes an object. This function is handy for incoming post objects. It iterates over each field. If the field is a string value it will be sanitized based on the default sanitization rules (BaseController.getDefaultSanitizationRules) or those provided by the call to BaseController.getSanitizationRules.
Parameters:
-
obj
Object
setFormFieldValues
-
post
Parameters:
-
post
Object
setPageName
-
pageName
Sets the page title
Parameters:
-
pageName
StringThe desired page title
Properties
activeTheme
String
ALERT_PATTERN
String
private
static
The snippet of HTML that will display an alert box
API_FAILURE
Integer
static
The code for a failed API call
API_SUCCESS
Integer
static
The code for a successful API call
body
Object | Null
The deserialized body of the request. This field is only ever populted if the executing route specifies the "request_body" attribute and provides valid MIME types that map to a registered body parser
context
Req: Request, session: object, ls: Localization, ts: TemplateService, site: string, hostname: string, activeTheme: string, onlyThisSite: boolean, siteObj: object
ENCODING_MAPPING
Object
private
static
A mapping that converts the HTTP standard for content-type encoding and what the Buffer prototype expects
FORM_REFILL_PATTERN
String
private
static
The snippet of JS code that will ensure that a form is refilled with values from the post
pageName
String
The title of the view to be rendered, if there is a view
pathVars
Object
The hash of key/value pairs that represent the variables passed in the route path
query
Object
The hash of key/value pairs that represent the variables passed as query string parameters
referer
String
deprecated
The referring URL
req
Request
The current request object
res
Response
The current response object
session
Object
The session object that represents the calling entity