Docs Help

Terms, Icons, and Labels

Many classes have shortcut names used when creating (instantiating) a class with a configuration object. The shortcut name is referred to as an alias (or xtype if the class extends Ext.Component). The alias/xtype is listed next to the class name of applicable classes for quick reference.

Access Levels

Framework classes or their members may be specified as private or protected. Else, the class / member is public. Public, protected, and private are access descriptors used to convey how and when the class or class member should be used.

Member Types

Member Syntax

Below is an example class member that we can disect to show the syntax of a class member (the lookupComponent method as viewed from the Ext.button.Button class in this case).

lookupComponent ( item ) : Ext.Component
protected

Called when a raw config object is added to this container either during initialization of the items config, or when new items are added), or {@link #insert inserted.

This method converts the passed object into an instanced child component.

This may be overridden in subclasses when special processing needs to be applied to child creation.

Parameters

item :  Object

The config object being added.

Returns
Ext.Component

The component to be added.

Let's look at each part of the member row:

Member Flags

The API documentation uses a number of flags to further commnicate the class member's function and intent. The label may be represented by a text label, an abbreviation, or an icon.

Class Icons

- Indicates a framework class

- A singleton framework class. *See the singleton flag for more information

- A component-type framework class (any class within the Ext JS framework that extends Ext.Component)

- Indicates that the class, member, or guide is new in the currently viewed version

Member Icons

- Indicates a class member of type config

- Indicates a class member of type property

- Indicates a class member of type method

- Indicates a class member of type event

- Indicates a class member of type theme variable

- Indicates a class member of type theme mixin

- Indicates that the class, member, or guide is new in the currently viewed version

Class Member Quick-Nav Menu

Just below the class name on an API doc page is a row of buttons corresponding to the types of members owned by the current class. Each button shows a count of members by type (this count is updated as filters are applied). Clicking the button will navigate you to that member section. Hovering over the member-type button will reveal a popup menu of all members of that type for quick navigation.

Getter and Setter Methods

Getting and setter methods that correlate to a class config option will show up in the methods section as well as in the configs section of both the API doc and the member-type menus just beneath the config they work with. The getter and setter method documentation will be found in the config row for easy reference.

History Bar

Your page history is kept in localstorage and displayed (using the available real estate) just below the top title bar. By default, the only search results shown are the pages matching the product / version you're currently viewing. You can expand what is displayed by clicking on the button on the right-hand side of the history bar and choosing the "All" radio option. This will show all recent pages in the history bar for all products / versions.

Within the history config menu you will also see a listing of your recent page visits. The results are filtered by the "Current Product / Version" and "All" radio options. Clicking on the button will clear the history bar as well as the history kept in local storage.

If "All" is selected in the history config menu the checkbox option for "Show product details in the history bar" will be enabled. When checked, the product/version for each historic page will show alongside the page name in the history bar. Hovering the cursor over the page names in the history bar will also show the product/version as a tooltip.

Search and Filters

Both API docs and guides can be searched for using the search field at the top of the page.

On API doc pages there is also a filter input field that filters the member rows using the filter string. In addition to filtering by string you can filter the class members by access level, inheritance, and read only. This is done using the checkboxes at the top of the page.

The checkbox at the bottom of the API class navigation tree filters the class list to include or exclude private classes.

Clicking on an empty search field will show your last 10 searches for quick navigation.

API Doc Class Metadata

Each API doc page (with the exception of Javascript primitives pages) has a menu view of metadata relating to that class. This metadata view will have one or more of the following:

Expanding and Collapsing Examples and Class Members

Runnable examples (Fiddles) are expanded on a page by default. You can collapse and expand example code blocks individually using the arrow on the top-left of the code block. You can also toggle the collapse state of all examples using the toggle button on the top-right of the page. The toggle-all state will be remembered between page loads.

Class members are collapsed on a page by default. You can expand and collapse members using the arrow icon on the left of the member row or globally using the expand / collapse all toggle button top-right.

Desktop -vs- Mobile View

Viewing the docs on narrower screens or browsers will result in a view optimized for a smaller form factor. The primary differences between the desktop and "mobile" view are:

Viewing the Class Source

The class source can be viewed by clicking on the class name at the top of an API doc page. The source for class members can be viewed by clicking on the "view source" link on the right-hand side of the member row.

Sencha Touch 2.4


top

Using Device Profiles

Today's mobile web applications are expected to work on a wide variety of devices, spanning from the smallest mobile phones to the largest tablets. These devices have a wide range of screen resolutions and are used in different ways. People tend to use phone apps while out of the house to rapidly gather some information or to perform some action - often in a very short time. Tablet apps are more likely to be used for longer periods of time, usually within the home or somewhere else where they can sit for a long time.

All of this means that people expect different app experiences on different devices. However, much of your application logic and assets can be shared between the different experiences. Writing separate apps for each platform is time consuming, error-prone and plain boring. Thankfully, Device Profiles give us a simple way to share between device types as much code as needed, while making it easy to customize behavior, appearance, and workflows for each device.

Setting Up Profiles

Device Profiles exist within the context of an Application, for example if we wanted to create an email app with phone and tablet profiles, we could define our app.js shown in the following code sample (see the Intro to Apps guide if this is not familiar):

Ext.application({
    name: 'Mail',

    profiles: ['Phone', 'Tablet']
});

Since we did not give our Application a launch function, at the moment it is only going to load those two Profiles. By convention, it expects to find them in app/profile/Phone.js and app/profile/Tablet.js. The following code shows the Phone profile:

Ext.define('Mail.profile.Phone', {
    extend: 'Ext.app.Profile',

    config: {
        name: 'Phone',
        views: ['Main']
    },

    isActive: function() {
        return Ext.os.is('Phone');
    }
});

The Tablet profile follows the same pattern. In the Phone profile we only supplied three pieces of information - the Profile name, the optional set of additional views to load when this Profile is activated, and an isActive function.

The isActive function determines if a given profile should be active on the device your app runs on. By far the most common approach is to create profiles for Phone and Tablet, using the built-in Ext.os.is method (e.g. Ext.os.is(Phone). You can write any code you like in the isActive function, as long as it always returns true or false for the device it is running on.

Determining the Active Profile

Once the Profiles have been loaded, their isActive functions are called in turn. The first one that return true is the Profile that the Application boots with. This Profile is then set to the Application's currentProfile, and the Application prepares to load all of its dependencies - the models, views, controllers, and other classes that constitute the app. It does this by combining its own dependencies with those specified in the active profile.

For example, let us amend our previous Application so that it loads its own Models and Views:

Ext.application({
    name: 'Mail',

    profiles: ['Phone', 'Tablet'],

    models: ['User'],
    views: ['Navigation', 'Login']
});

Finally, when we load the app on a phone, the Phone profile is activated and the application loads the following files:

  • app/model/User.js
  • app/view/Navigation.js
  • app/view/Login.js
  • app/view/phone/Main.js

The first three items are specified in the Application itself - the User model plus the Navigation and Login views. The fourth item is specified by the Phone Profile and follows a special form. By convention, classes that are specific to a Profile are expected to be defined in a subdirectory with the same name as the Profile. For example, the 'Main' view specified in the Phone Profile is loaded from app/view/phone/Main.js, whereas if we had defined 'Main' in the Application, it would be loaded from app/view/Main.js.

The same applies to all models, views, controllers, and stores loaded in a Profile. This is important as it enables you to easily share behavior, view logic, and more between profiles (see the specializing views and controllers sections below). If you need to load classes that do not comply with this convention, you can specify the full class name instead:

Ext.define('Mail.profile.Phone', {
    extend: 'Ext.app.Profile',

    config: {
        name: 'Phone',
        views: ['Main', 'Mail.view.SpecialView'],
        models: ['Mail.model.Message']
    },

    isActive: function() {
        return Ext.os.is('Phone');
    }
});

As evident from this example, you can mix and match fully-qualified class names (e.g. 'Mail.view.SomeView') and relatively specified class names (e.g. 'Main', which becomes 'Mail.view.phone.Main'). Be aware that all models, views, controllers, and stores specified for a Profile are treated this way. This means if there are Models or Stores that you want to load for Tablets only, but do not want to create classes like Mail.model.tablet.User, you should specify the fully-qualified class names instead (e.g. Mail.model.User in this case).

The Launch Process

The launch process using Profiles is almost exactly the same as that without using Profiles. Profile-based apps have a 3-stage launch process; after all of the dependencies have been loaded, the following happens:

  1. Controllers are instantiated; each Controller's init function is called
  2. The Profile's launch function is called
  3. The Application's launch function is called.

When using Profiles it is common to use the Profile launch functions to create the app's initial UI. In many cases this means the Application's launch function is completely removed, as the initial UI is usually different in each Profile (you can still specify an Application-wide launch function for setting up items such as analytics or other profile- agnostic setup).

A typical Profile launch function might look like in the following sample:

Ext.define('Mail.profile.Phone', {
    extend: 'Ext.app.Profile',

    config: {
        name: 'Phone',
        views: ['Main']
    },

    isActive: function() {
        return Ext.os.is('Phone');
    },

    launch: function() {
        Ext.create('Mail.view.phone.Main');
    }
});

Note that both Profile and Application launch functions are optional - if you do not define them, they are not called.

Specializing Views

Most of the specialization implemented by a Profile occurs in the Views and the Controllers. Let us assume that we have the following tablet Profile:

Ext.define('Mail.profile.Tablet', {
    extend: 'Ext.app.Profile',

    config: {
        views: ['Main']
    },

    launch: function() {
        Ext.create('Mail.view.tablet.Main');
    }
});

When this app boots on a tablet device, the file app/views/tablet/Main.js is loaded as usual. The following code sample is the content of the app/views/tablet/Main.js file:

Ext.define('Mail.view.tablet.Main', {
    extend: 'Mail.view.Main',

    config: {
        title: 'Tablet-specific version'
    }
});

Usually, when we define a view class we extend one of Sencha Touch's built in views, but in the previous example we extend Mail.view.Main, one of our own views. The following code sample illustrates how Mail.view.Main looks like:

Ext.define('Mail.view.Main', {
    extend: 'Ext.Panel',

    config: {
        title: 'Generic version',
        html: 'This is the main screen'
    }
});

We thus have a superclass (Mail.view.Main) and a Profile-specific subclass (Mail.view.tablet.Main), which can customize any aspect of the superclass. In this case we change the title of the Main view from "Generic version" to "Tablet-specific version" in our subclass, so that is what we see when the app loads.

Since these are normal classes, it is easy to customize almost any part of the superclass using the flexible config system. For example, assuming that we also have a phone version of the app, we could customize its version of the Main view as follows (app/view/phone/Main.js):

Ext.define('Mail.view.phone.Main', {
    extend: 'Mail.view.Main',

    config: {
        title: 'Phone-specific version',

        items: [
            {
                xtype: 'button',
                text: 'This is a phone...'
            }
        ]
    }
});

Sharing Sub-Views

While the previous example is useful, it is more common to share certain pieces of views and stitch them together in different ways for different profiles. For example, imagine an email app where the tablet UI is a split screen with a message list on the left and the current message loaded on the right. The Phone version is the exact same message list and a similar message view, but this time in a card layout, since there is not enough screen space to display both views simultaneously.

To achieve this we have to create the two shared sub-views - the message list and the message viewer. In each case we have left the class config out for brevity:

Ext.define('Mail.view.MessageList', {
    extend: 'Ext.List',
    xtype: 'messagelist'

    // config goes here...
});

And the Message Viewer:

Ext.define('Mail.view.MessageViewer', {
    extend: 'Ext.Panel',
    xtype: 'messageviewer'

    // config goes here...
});

Eventually, in order to achieve the target layout that contains two views, the tablet Main view might use the following code :

Ext.define('Mail.view.tablet.Main', {
    extend: 'Ext.Container',

    config: {
        layout: 'fit',
        items: [
            {
                xtype: 'messagelist',
                width: 200,
                docked: 'left'
            },
            {
                xtype: 'messageviewer'
            }
        ]
    }
});

This creates a 200px wide messagelist on the left, and uses the rest of the device's screen space to show the message viewer. Now let us assume we wanted to achieve the Phone layout:

Ext.define('Mail.view.phone.Main', {
    extend: 'Ext.Container',

    config: {
        layout: 'card',
        items: [
            {
                xtype: 'messagelist'
            },
            {
                xtype: 'messageviewer'
            }
        ]
    }
});

In this case we use a Container with a card layout (a layout that only shows one item at a time), and put both the list and the viewer into it. In this case we still need to add in some logic that tells the Container to show the messageviewer when a message in the list is tapped on, but we have easily reused our two sub-views in different configurations based on the currently loaded Profile.

Similar to the previous example, we have the option to customize the two shared views for each Profile - for example we could create the Mail.view.phone.MessageViewer and the Mail.view.tablet.MessageViewer subclasses, both of which extend the Mail.view.MessageViewer superclass. This enables us to again share a lot of view code between those classes, while presenting customizations appropriate for the actual device used.

Specializing Controllers

Similar to Views, many applications have some Controller logic that can be shared across multiple Profiles. In the case of Profiles, the most important differences are usually workflow-related. For example, an app's tablet profile may allow you to complete a workflow on a single page, whereas the phone profile presents a multi-page wizard.

In the following example we have a simple Phone profile that loads a view called Main and a controller called Messages. As before, this app loads app/view/phone/Main.js and app/controller/phone/Messages.js:

Ext.define('Mail.profile.Phone', {
    extend: 'Ext.app.Profile',

    config: {
        views: ['Main'],
        controllers: ['Messages']
    },

    launch: function() {
        Ext.create('Mail.view.phone.Main');
    }
});

Since we already know that our phone and tablet-specific controllers share most of their functionality, we create a controller superclass in app/controller/Messages.js:

Ext.define('Mail.controller.Messages', {
    extend: 'Ext.app.Controller',

    config: {
        refs: {
            viewer: 'messageviewer',
            messageList: 'messagelist'
        },
        control: {
            messageList: {
                itemtap: 'loadMessage'
            }
        }
    },

    loadMessage: function(item) {
        this.getViewer().load(item);
    }
});

The Controller from the previous example performs three operations:

  1. Sets up refs referencing views that we care about.
  2. Listens for the itemtap event on the message list and calls the loadMessage() function when itemtap is fired.
  3. Loads the selected message item into the Viewer when loadMessage() is called.

We can now create the phone-specific Controller as follows:

Ext.define('Mail.controller.phone.Messages', {
    extend: 'Mail.controller.Messages',

    config: {
        refs: {
            main: '#mainPanel'
        }
    },

    loadMessage: function(item) {
        this.callParent(arguments);
        this.getMain().setActiveItem(1);
    }
});

This code extends the Messages superclass controller and provides the following functionality:

  1. Adds another ref for the phone UI's main panel 2. Extends the loadMessage function to perform the original logic and then sets the main panel's active item to the message viewer.

The entire superclass configuration is inherited by the subclass that extends it. In the case of duplicated configs such as refs, the configuration is merged, so the phone Messages controller class has three refs - main, viewer, and messageList. As with any class that extends another class, we can use callParent to extend an existing function in the superclass.

Remember that the Mail.controller.Messages superclass is not declared as a dependency by either the Application or the Profile. It it automatically loaded because our Mail.controller.phone.Messages controller extends it.

What Code to Share

In the previous example we were able to share some (but not all) of our refs. We were also able to share the single event that we listen for by using the Controller's control config. Generally speaking, the more an app diverges between profiles, the fewer refs and control configs you will be able to share.

One Controller config that should be shared across profiles is routes. These config maps URLs to Controller actions and provides back button support and deep linking. It is important to keep the routes config in the superclass, because the same URL should map to the same content regardless of the device.

For example, if a friend is using the phone version of your app and sends you a link to the app page she is currently on, you should be able to tap that link on your tablet device and see the tablet-specific view for that URL. Keeping all routes in the superclass enables you to keep a consistent URL structure that works regardless of device.

Specializing Models

Models are customized per Profile less frequently than Controllers and Views, so that do not usually require a subclass. In this case we only specify the fully qualified class names for models:

Ext.define('Mail.profile.Tablet', {
    extend: 'Ext.app.Profile',

    config: {
        models: ['Mail.model.Group']
    }
});

Sencha Touch 2.4