new View/AlertView()
Base class for alerts.
Extend this class to provide custom alert behavior:
const AlertView = require('view/alert-view');
const TemplateManager = require('view/template');
let PortalAlertView = AlertView.extend({
initialize: function(options) {
AlertView.prototype.initialize.call(this, options);
// You may override and/or pre-compile alert template
this.tpl = 'my-alert';
TemplateManager.compile('my-alert', 'handlebars code...');
},
render: function(options) {
// Provide your custom rendering logic.
// For example, switch between different templates
this.tpl = 'alert2';
AlertView.prototype.render.call(this, options);
},
close: function() {
// Provide your custom dismiss logic: animation, fade effects, etc.
}
});
Extends
Members
-
collection :Data/BeanCollection
-
Reference to the collection this component is bound to.
Type:
- Inherited From:
-
context :Core/Context
-
Reference to the context (required).
Type:
- Inherited From:
-
meta :Object
-
Component metadata (optional).
Type:
- Object
- Inherited From:
-
model :Data/Bean
-
Reference to the model this component is bound to.
Type:
- Inherited From:
-
module :string
-
Module name (optional).
Type:
- string
- Inherited From:
-
options :Object
-
Backbone view options.
Type:
- Object
- Inherited From:
- Deprecated:
-
- Deprecated since 7.8.0 since this is no longer supported by Backbone.
-
tpl :string
-
The default alert template.
Type:
- string
Methods
-
<protected> _dispose()
-
Disposes this component.
This method:
- unbinds this component from model and collection
- removes all event callbacks registered within this component
- removes this component from the DOM
Override this method to provide custom logic:
const ViewManager = require('view/view-manager'); ViewManager.views.MyView = ViewManager.View.extend({ _dispose: function() { // Perform custom clean-up. For example, clear timeout handlers, etc. ... // Call super ViewManager.View.prototype._dispose.call(this); } });
- Inherited From:
-
<protected> _hide()
-
Override this method to provide custom show logic.
- Inherited From:
-
<protected> _render()
-
Renders this component.
Override this method to provide custom logic. The default implementation does nothing. See
Backbone.View#render
for details. The convention is for #_render to always returnthis
.- Inherited From:
Returns:
Instance of this component.
- Type
- View/Component
-
<protected> _show()
-
Override this method to provide custom show logic.
- Inherited From:
-
<protected> _super(method [, args])
-
Retrieves and invokes parent prototype functions.
Requires a method parameter to function. The method called should be named the same as the function being called from.
Examples:
- Good:
({ initialize: function(options) { // extend the base meta with some custom meta options.meta = _.extend({}, myMeta, options.meta || {}); // Only call parent initialize from initialize this._super('initialize', [options]); this.buildFoo(options); } });
- Bad:
({ initialize: function(options) { // extend the base meta with some custom meta options.meta = _.extend({}, myMeta, options.meta || {}); // Calling a function like buildFoo from initialize is incorrect. Should call directly on this this._super('buildFoo',[options]); } });
Parameters:
Name Type Argument Description method
string The name of the method to call (e.g.
initialize
,_renderHtml
).args
Array <optional>
Arguments to pass to the parent method.
- Inherited From:
Returns:
The result of invoking the parent method.
- Type
- *
-
<protected> _wrapInitialize(options)
-
Wraps the initialize method to delegate the events on the element, after it initializes.
Parameters:
Name Type Description options
Object The Backbone.View initialization options.
- Inherited From:
-
before(name, callback [, context])
-
Adds a callback/hook to be fired before an action is taken. If that callback returns
false
, the action should not be taken.The following example binds a callback function and passes the scope from the view component to use in that callback:
model.before('save', this.doSomethingBeforeSave, this);
Multiple space-separated event names can be bound to a single callback:
view.before('save dispose', this.callback, this);
This method also supports an event map syntax, as an alternative to positional arguments:
this.before({ render: this.doSomethingBeforeRender, dispose: this.doSomethingBeforeDispose, });
Parameters:
Name Type Argument Description name
string | Object Event(s) to trigger before. Accepts multiple space-separated event names or an event map.
callback
function Function to be called.
context
Object <optional>
Value to be assigned to
this
when the callback is fired.- Inherited From:
- Mixes In:
Returns:
Instance of this class.
- Type
- Object
-
<abstract> bindDataChange()
-
Binds data changes to this component.
- Inherited From:
-
closestComponent(name)
-
Traverses upwards from the current component to find the first component that matches the name.
The default implementation does nothing. See View/Layout#closestComponent, View/View#closestComponent and View/Field#closestComponent methods.
Parameters:
Name Type Description name
string The name of the component to find.
- Inherited From:
Returns:
The component or
undefined
if not found.- Type
- View/Component
-
constructor(options)
-
Constructor for sidecar components, currently used to define the order of event delegation on this component's events, after Backbone changed the order in which events are delegated from 0.9.10 to 1.2.0. Also temporarily defines #options on the component, as Backbone no longer does this by default.
Parameters:
Name Type Description options
Object The
Backbone.View
initialization options.- Inherited From:
Returns:
The created
Backbone.View
.- Type
- Backbone.View
-
delegateEvents()
-
Proxies the parent method on
Backbone.View
, but only called after this view instance initializes.- Inherited From:
Returns:
Instance of this component.
- Type
- View/Component
-
dispose()
-
Disposes a component.
Once the component gets disposed it can not be rendered. Do not override this method. Instead override View/Component#_dispose method if you need custom disposal logic.
- Inherited From:
-
getPlaceholder()
-
Gets the HTML placeholder for this component.
- Inherited From:
Returns:
HTML placeholder to be used in a Handlebars template.
- Type
- Handlebars.SafeString
-
hide()
-
Pass through function to jQuery's hide to hide view.
- Inherited From:
Returns:
false
if the BeforeEvent forhide
fails;undefined
otherwise.- Type
- boolean | undefined
-
initialize(options)
-
Initializes this component.
Parameters:
Name Type Description options
Object The
Backbone.View
initialization options.Properties
Name Type Argument Description context
Core/Context Reference to the context.
meta
Object <optional>
Component metadata.
module
string <optional>
Module name.
model
Data/Bean <optional>
Reference to the model this component is bound to.
collection
Data/BeanCollection <optional>
Reference to the collection this component is bound to.
- Inherited From:
-
isVisible()
-
Checks if this component is visible on the page.
- Inherited From:
Returns:
true
if this component is visible on the page;false
otherwise.- Type
- boolean
-
loadData()
-
Fetches data for layout's model or collection.
The default implementation does nothing. See View/Layout#loadData and View/View#loadData methods.
- Inherited From:
-
offBefore( [name] [, callback] [, context])
-
Removes a previously-bound callback function from a before event.
If no context is given, all of the versions of the callback with different contexts will be removed:
this.offBefore('render', this.onRenderBefore);
If no callback is given, all callbacks for the before event will be removed:
this.offBefore('render');
If no event is specified, all callbacks for all before events will be removed from the object:
this.offBefore();
Parameters:
Name Type Argument Description name
string <optional>
Event(s) to remove the listeners for.
callback
function <optional>
Callback to remove specifically for a given event.
context
Object <optional>
Context to use when determining which callback to remove.
- Inherited From:
- Mixes In:
Returns:
Instance of this class.
- Type
- Object
-
render()
-
Renders an alert.
The method executes a pre-compiled template and replaces the inner HTML of this view root DOM element. Additionally,
alert-[level]
class is added to the root element.- Overrides:
-
setTemplateOption(key, option)
-
Sets template option.
If the given option already exists it is augmented by the value of the given
option
parameter.See the Handlebars.js documentation for details.
Parameters:
Name Type Description key
string Option key.
option
Object Option value.
- Inherited From:
-
show()
-
Pass through function to jQuery's show to show view.
- Inherited From:
Returns:
false
if the BeforeEvent forshow
fails;undefined
otherwise.- Type
- boolean | undefined
-
toString()
-
Gets a string representation of this component.
- Inherited From:
Returns:
String representation of this component.
- Type
- string
-
triggerBefore(name)
-
Triggers the before callback for the given event
name
or list of events.The following example triggers the callback bound to the before
save
event given:this.triggerBefore('save');
Multiple events can be triggered as well:
this.triggerBefore('save render dispose');
Custom arguments (e.g.
a
,b
,c
) can be passed to the callback:this.triggerBefore('save', a, b, c);
Parameters:
Name Type Description name
string The before event(s) to trigger.
- Inherited From:
- Mixes In:
Returns:
Returns
true
if the event should be triggered,false
otherwise.- Type
- boolean
-
unbind()
-
Removes all event callbacks registered within this component and undelegates Backbone events.
Override this method to provide custom logic.
- Inherited From:
-
unbindData()
-
Removes this component's event handlers from model and collection.
Performs the opposite of what View/Component#bindDataChange method does.
Override this method to provide custom logic.
- Inherited From:
-
updateVisibleState(visible)
-
Updates this component's visibility state.
Note: This does not show/hide the component. Please use View/Component#show and View/Component#hide to do this.
Parameters:
Name Type Description visible
boolean Visibility state of this component.
- Inherited From: