Observable Application
Package: | Ext |
Defined In: | Application.js |
Class: | Application |
Extends: | Observable |
Represents a Sencha Application. Most Applications consist of at least the application's name and a launch function:
new Ext.Application({
name: 'MyApp',
launch: function() {
this.viewport = new Ext.Panel({
fullscreen: true,
id : 'mainPanel',
layout: 'card',
items : [
{
html: 'Welcome to My App!'
}
]
});
}
});
Instantiating a new application automatically creates a global variable using the configured name property and sets up namespaces for views, stores, models and controllers within the app:
//this code is run internally automatically when creating the app
Ext.ns('MyApp', 'MyApp.views', 'MyApp.stores', 'MyApp.models', 'MyApp.controllers');
The launch function usually creates the Application's Viewport and runs any actions the Application needs to perform when it boots up. The launch function is only expected to be run once.
Routes and history support
Sencha Applications provide in-app deep linking and history support, allowing your users both to use the back button inside your application and to refresh the page and come back to the same screen even after navigating. In-app history support relies on the Routing engine, which maps urls to controller/action pairs. Here's an example route definition:
//Note the # in the url examples below
Ext.Router.draw(function(map) {
//maps the url http://mydomain.com/#dashboard to the home controller's index action
map.connect('dashboard', {controller: 'home', action: 'index'});
//fallback route - would match routes like http://mydomain.com/#users/list to the 'users' controller's
//'list' action
map.connect(':controller/:action');
});
If you generated your Sencha app using the Sencha Command application generator script, you'll see this file is already present in your application's app/routes.js file. History-driven apps can specify the defaultUrl configuration option, which will dispatch to that url if no url is currently set:
new Ext.Application({
name: 'MyApp',
defaultUrl: 'dashboard'
});
Application profiles
Applications support multiple app profiles and reconfigure itself accordingly. Here we set up an Application with 3 profiles - one if the device is a phone, one for tablets in landscape orientation and one for tablets in portrait orientation:
new Ext.Application({
name: 'MyApp',
profiles: {
phone: function() {
return Ext.is.Phone;
},
tabletPortrait: function() {
return Ext.is.Tablet && Ext.orientation == 'portrait';
},
tabletLandscape: function() {
return Ext.is.Tablet && Ext.orientation == 'landscape';
}
}
});
When the Application checks its list of profiles, the first function that returns true becomes the current profile. The Application will normally automatically detect when a profile change has occurred (e.g. if a tablet is rotated from portrait to landscape mode) and fire the profilechange event. It will also by default inform all Components on the page that the current profile has changed by calling their setProfile functions. The setProfile function is left as an empty function for you to implement if your component needs to react to different device/application profiles.
The current profile can be found using getProfile. If the Application does not correctly detect device profile changes, calling the determineProfile function will force it to re-check.
Config Options | Defined By | |
---|---|---|
autoUpdateComponentProfiles : Boolean If true, automatically calls Ext.Component.setProfile on
all components whenever a application/device profile change ... If true, automatically calls Ext.Component.setProfile on
all components whenever a application/device profile change is detected (defaults to true) | Application | |
defaultUrl : String When the app is first loaded, this url will be redirected to. Defaults to undefined | Application | |
listeners : Object A config object containing one or more event handlers to be added to this
object during initialization. This should ... A config object containing one or more event handlers to be added to this object during initialization. This should be a valid listeners config object as specified in the addListener example for attaching multiple handlers at once. DOM events from ExtJs Components While some ExtJs Component classes export selected DOM events (e.g. "click", "mouseover" etc), this
is usually only done when extra value can be added. For example the DataView's
| Observable | |
loadMaskFadeDuration : Number The number of milliseconds the load mask takes to fade out. Defaults to 1000 | Application | |
loadMaskRemoveDuration : Number The number of milliseconds until the load mask is removed after starting the
fadeout. Defaults to 1050. | Application | |
name : String The name of the Application. This should be the same as the single global variable that the
application uses, and sho... The name of the Application. This should be the same as the single global variable that the
application uses, and should not contain spaces | Application | |
profiles : Object A set of named profile specifications that this application supports. See the intro
docs for an example | Application | |
scope : Object The scope to execute the launch function in. Defaults to the Application
instance. | Application | |
setProfilesOnLaunch : Boolean If true, determines the current application profile on launch and calls
updateComponentProfiles. Defaults to true | Application | |
useHistory : Boolean True to automatically set up Ext.History support (defaults to true) | Application | |
useLoadMask : Boolean/String True to automatically remove an application loading mask when the
DOM is ready. If set to true, this expects a div c... True to automatically remove an application loading mask when the
DOM is ready. If set to true, this expects a div called "loading-mask" to be present in the body.
Pass the id of some other DOM node if using a custom loading mask element. Defaults to false. | Application |
Method | Defined By | |
---|---|---|
addEvents( Object|String o , string Optional. )
:
voidAdds the specified events to the list of events which this Observable may fire. Adds the specified events to the list of events which this Observable may fire. Parameters:
| Observable | |
addListener( String eventName , Function handler , [Object scope ], [Object options ] )
:
voidAppends an event handler to this object. Appends an event handler to this object. Parameters:
| Observable | |
addManagedListener( Observable|Element item , Object|String ename , Function fn , Object scope , Object opt )
:
voidAdds listeners to any Observable object (or Element) which are automatically removed when this Component
is destroyed... Adds listeners to any Observable object (or Element) which are automatically removed when this Component is destroyed. Parameters:
| Observable | |
clearListeners()
:
void Removes all listeners for this object including the managed listeners Removes all listeners for this object including the managed listeners Parameters:
| Observable | |
clearManagedListeners()
:
void Removes all managed listeners for this object. Removes all managed listeners for this object. Parameters:
| Observable | |
determineProfile( Boolean silent )
:
voidCalls each configured profile function, marking the first one that returns true as the current
application profile. F... Calls each configured profile function, marking the first one that returns true as the current
application profile. Fires the 'beforeprofilechange' and 'profilechange' events if the profile has changed Parameters:
| Application | |
dispatch( Object options )
:
BooleanDispatches to a given controller/action combo with optional arguments. Dispatches to a given controller/action combo with optional arguments. Parameters:
| Application | |
enableBubble( String/Array events )
:
voidEnables events fired by this Observable to bubble up an owner hierarchy by calling
this.getBubbleTarget() if present.... Enables events fired by this Observable to bubble up an owner hierarchy by calling
This is commonly used by Ext.Components to bubble events to owner Containers. See Ext.Component.getBubbleTarget. The default implementation in Ext.Component returns the Component's immediate owner. But if a known target is required, this can be overridden to access the required target more quickly. Example:
Parameters:
| Observable | |
fireEvent( String eventName , Object... args )
:
BooleanFires the specified event with the passed parameters (minus the event name).
An event may be set to bubble up an Obse... Fires the specified event with the passed parameters (minus the event name). An event may be set to bubble up an Observable parent hierarchy (See Ext.Component.getBubbleTarget) by calling enableBubble. Parameters:
| Observable | |
getProfile()
:
String Gets the name of the currently-detected application profile Gets the name of the currently-detected application profile Parameters:
| Application | |
hasListener( String eventName )
:
BooleanChecks to see if this object has any listeners for a specified event Checks to see if this object has any listeners for a specified event Parameters:
| Observable | |
launch( String profile )
:
BooleanCalled automatically when the page has completely loaded. This is an empty function that should be
overridden by each... Called automatically when the page has completely loaded. This is an empty function that should be
overridden by each application that needs to take action on page load Parameters:
| Application | |
on( String eventName , Function handler , [Object scope ], [Object options ] )
:
voidAppends an event handler to this object (shorthand for addListener.) Appends an event handler to this object (shorthand for addListener.) Parameters:
| Observable | |
relayEvents( Object o , Array events )
:
voidRelays selected events from the specified Observable as if the events were fired by this. Relays selected events from the specified Observable as if the events were fired by this. Parameters:
| Observable | |
removeListener( String eventName , Function handler , [Object scope ] )
:
voidRemoves an event handler. Removes an event handler. Parameters:
| Observable | |
removeManagedListener( Observable|Element item , Object|String ename , Function fn , Object scope )
:
voidRemoves listeners that were added by the mon method. Removes listeners that were added by the mon method. Parameters:
| Observable | |
resumeEvents()
:
void Resume firing events. (see suspendEvents)
If events were suspended using the queueSuspended parameter, then all
event... Resume firing events. (see suspendEvents)
If events were suspended using the queueSuspended parameter, then all
events fired during event suspension will be sent to any listeners now. Parameters:
| Observable | |
suspendEvents( Boolean queueSuspended )
:
voidSuspend the firing of all events. (see resumeEvents) Suspend the firing of all events. (see resumeEvents) Parameters:
| Observable | |
un( String eventName , Function handler , [Object scope ] )
:
voidRemoves an event handler (shorthand for removeListener.) Removes an event handler (shorthand for removeListener.) Parameters:
| Observable |
Event | Defined By | |
---|---|---|
beforeprofilechange :
( String profile , String oldProfile )
Fires when a change in Application profile has been detected, but before any action is taken to
update the applicati... Fires when a change in Application profile has been detected, but before any action is taken to
update the application's components about the change. Return false from any listener to cancel the
automatic updating of application components (see autoUpdateComponentProfiles) Listeners will be called with the following arguments:
| Application | |
launch :
( Ext.Application app )
Fires when the application is launched Fires when the application is launched Listeners will be called with the following arguments:
| Application | |
profilechange :
( String profile , String oldProfile )
Fires when a change in Applicatino profile has been detected and the application's components have
already been infor... Fires when a change in Applicatino profile has been detected and the application's components have
already been informed. Listeners can perform additional processing here if required Listeners will be called with the following arguments:
| Application |