/** * @author Ed Spencer * @class Ext.util.Router * @extends Ext.util.Observable * @ignore */ Ext.util.Router = Ext.extend(Ext.util.Observable, { constructor: function(config) { config = config || {}; Ext.apply(this, config, { defaults: { action: 'index' } }); this.routes = []; Ext.util.Router.superclass.constructor.call(this, config); },
/** * Connects a url-based route to a controller/action pair plus additional params * @param {String} url The url to recognize */ connect: function(url, params) { params = Ext.apply({url: url}, params || {}, this.defaults); var route = new Ext.util.Route(params); this.routes.push(route); return route; },
/** * Recognizes a url string connected to the Router, return the controller/action pair plus any additional * config associated with it * @param {String} url The url to recognize * @return {Object/undefined} If the url was recognized, the controller and action to call, else undefined */ recognize: function(url) { var routes = this.routes, length = routes.length, i, result; for (i = 0; i < length; i++) { result = routes[i].recognize(url); if (result != undefined) { return result; } } return undefined; },
/** * Convenience method which just calls the supplied function with the Router instance. Example usage:

Ext.Router.draw(function(map) {
    map.connect('activate/:token', {controller: 'users', action: 'activate'});
    map.connect('home',            {controller: 'index', action: 'home'});
});
* @param {Function} fn The fn to call */ draw: function(fn) { fn.call(this, this); } }); Ext.Router = new Ext.util.Router();