Sha256: 771e36ac3b08470a0e5106762393bece5f70d420e68501322906fddbaec777cd

Contents?: true

Size: 1.63 KB

Versions: 3

Compression:

Stored size: 1.63 KB

Contents

/**
 * Routing override for Netzke.Base.
 * @class Netzke.Core.Routing
 */
Ext.define('Netzke.Core.Routing', {
  override: 'Netzke.Base',

  netzkeAfterInitComponent: function(){
    if (this.netzkeRoutes) {
      var routes = this.netzkeGetRoutes();
      this.netzkeRouter = Ext.create('Ext.app.Controller', { routes: this.netzkeGetRoutes() });
      this.on('beforedestroy', this.netzkeCleanRoutes, this);

      this.on('render', function(){
        this.netzkeTriggerInitialRoute();
      });
    }

    this.callParent();
  },

  /**
   * Navigate to new hash route.
   * @method netzkeNavigateTo
   * @param route {String} Route
   * @param {Object} [options] Options:
   *   * **append** {Boolean} append to the current route
   *
   * @example
   *
   *     this.netzkeNavigateTo('user/1', {append: true})
   */
  netzkeNavigateTo: function(route, options){
    options = options || {};
    var newRoute = route;
    if (options.append) {
      newRoute = Ext.util.History.getToken() + "/" + newRoute;
    }
    Ext.util.History.add(newRoute);
  },

  // private

  netzkeCleanRoutes: function(){
    this.netzkeRouter.destroy();
  },

  netzkeTriggerInitialRoute: function(){
    var initToken = Ext.util.History.getToken();
    if (initToken) { this.netzkeRouter.redirectTo(initToken, true); }
  },

  netzkeGetRoutes: function(){
    var out = {};
    for (var route in this.netzkeRoutes) {
      var handlerName = this.netzkeRoutes[route],
          handler = this[handlerName];
      if (!handler) Netzke.exception("Route handler " + handlerName + " is not defined");
      out[route] = { action: handler.bind(this) };
    }
    return out;
  }
});

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
netzke-core-6.5.0.0 javascripts/routing.js
netzke-core-6.5.0.0.rc2 javascripts/routing.js
netzke-core-6.5.0.0.rc1 javascripts/routing.js