Constructor
new BaseController(params, navSection)
Parameters:
Name | Type | Description |
---|---|---|
params |
url.URLSearchParams |
URL parameters from the UI. These usually come from a query string attached to the href attribute of a link or button. |
navSection |
string |
The section of DART's top navigation bar that should be highlighted when this controller renders a page. For example, when rendering AppSetting pages, the "Settings" section of the top nav bar should be active. |
- Source:
Members
alertCssClass :string
Controllers may optionally set this before redirecting to control the appearance of the optional alertMessage. The value can be any valid Bootstrap 4 alert class. The most common values will be "alert-success" and "alert-danger".
- Default Value:
-
- "alert-success"
- Source:
alertMessage :string
Controllers may optionally set this before redirecting, to make an alert message appear on the top of the destination page. For example, after successfully submitting a form, a controller typically redirects to the list page with an alert message at the top saying the data was saved.
- Source:
formClass :Form
This is the name of the form class that can render a form for this controller's model. For example, the AppSettingController will have formClass AppSettingForm. This must be set by the child class.
formTemplate :handlebars.Template
This is the template that renders this controller's form. Templates are properties of the Template object. This property must be set by the child class.
listTemplate :handlebars.Template
This is the template that renders this controller's object list. Templates are properties of the Template object. This property must be set by the child class.
model :PersistentObject|object
This is the model which the controller represents. For example, The AppSettingController renders forms and lists for the AppSetting model. This must be set by the child class.
- Source:
nameProperty :string
The name property of this template's model. This is used when ordering lists of objects by name. For example, the nameProperty for model BagItProfile or AppSetting would be "name".
navSection :string
The name of the nav section to highlight when this controller renders a page. Valid values include any names you see on DART's top nav bar, including "Dashboard", "Settings", "Jobs" and "Help".
- Source:
params :url.URLSearchParams
A url.URLSearchParams object containing parameters that the controller will need to render the display. For forms, the only required param is usually "id", which is the UUID of the object to be edited. For lists, this typically includes limit, offset, orderBy, and sortDirection.
- Source:
redirected :boolean
This property will be set to true if the controller that was originally called redirected to a new controller.
- Default Value:
-
- false
- Source:
typeMap :object.<string, string>
The typeMap describes how values in this.params should be converted, if they do need to be converted. Because url.URLSearchParams are always either strings or arrays of strings, we sometimes need to convert them to numbers or booleans before we can use them. For example, a controller that lists a number of objects needs the "limit" param to be converted from string "20" to number 20.
typeMap key is the param name and value is the data type.
The typeMap currently supports types "string", "boolean", and "number" (no dates yet). Each controller sets its own typeMap as necessary.
- Source:
Methods
containerContent(html)
The sets the content of the main page container to the html you pass in.
Parameters:
Name | Type | Description |
---|---|---|
html |
string |
HTML content to render in the page's main container. |
destroy()
This deletes an object from the database, after prompting the user to confirm they really want to delete it.
edit()
This displays a HTML form with pre-filled values, so a user can edit an existing object.
list()
This displays a list of all instances of an object type from the local database. It works with params limit, offset, orderBy, and sortDirection, which are passed into the constructor in the params object.
modalContent(title, body)
This sets the title and body of the modal popup window.
Parameters:
Name | Type | Description |
---|---|---|
title |
string |
The title of the modal popup. |
body |
string |
The HTML content of the modal popup. |
new()
This displays a blank form that allows a user to create a new instance of an object.
noContent()
Controller methods call this when they do not want to render any new content.
openExternal()
This opens a URL in an external browser window, using the user's default web browser.
The URL comes the value of the "url" param in the params object that was passed in to this object's constructor. Derived classes can also call this.params.set('url', '...value...') before calling this method.
paramsToHash()
Converts URLSearchParams to a simple hash with correct data types. The data types are specified in each controller's typeMap, which can specify that certain params be converted to numbers or booleans.
postRenderCallback(fnName)
This is to be defined by derived classes as necessary. It does nothing in the base class, but derived classes can use it to attach event handlers to HTML elements that have just been rendered.
Parameters:
Name | Type | Description |
---|---|---|
fnName |
string |
The name of the function that was called in the original request. The postRenderCallback may include logic to perform different actions based on what the user initially requested. For example, you may want to attach one set of event handlers after rendering Controller.new() and a different set after rendering Controller.update(). |
redirect(controllerName, fnName, params)
This redirects to a new URL that will call the function fnName on the controller controllerName with the specified params. Use this only when redirecting to an entirely new controller.
This changes the page URL, causing the RequestHandler to parse and route the new request.
Parameters:
Name | Type | Description |
---|---|---|
controllerName |
string |
The name of the controller you want to redirect to. |
fnName |
string |
The name of the function on the new controller that should process the request. |
params |
URLSearchParams |
The URL query parameters to pass into the constructor of the controller you are redirecting to. |
update()
This handles the submission of a form, saving an object to the local database if it's valid, or highlighting errors on the form if the object is not valid.