Sha256: cb83db362a690abd281dc29a21ab20dc3eabf249b39826bd2c808de78f86c45b

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

(function(Paloma){

  var Engine = function(config){
    this.factory = config.factory;
    this._request = null;
  };

  Engine.prototype.start = function(){
    // Do not execute if there is no request available.
    if ( !this._request ) return;

    // Do not execute if already executed.
    //
    // This happens when using turbolinks,
    // if a page using js(false) is rendered
    // after a page with executed js, then the
    // previous js will be executed again.
    if ( this._request.executed ) return;

    var resource = this._request['controller'],
        Controller = this.factory.get(resource);

    if (!Controller){
      return Paloma.warn('Paloma: undefined controller -> ' + resource);
    }

    var controller = new Controller( this._request['params'] ),
        action = this._request['action'],
        params = this._request['params'];

    if (!controller[action]){
      return Paloma.warn('Paloma: undefined action <' + action +
        '> for <' + resource + '> controller');
    }


    Paloma.log('Paloma: Execute ' + resource + '#' + action + ' with');
    Paloma.log(params);

    controller[ this._request['action'] ]();

    this._request.executed = true;
  };


  //
  // options:
  //  resource
  //  action
  //  params
  //  id
  //
  Engine.prototype.setRequest = function(options){
    this._request = {
      id: options.id,
      controller: options.resource,
      action: options.action,
      params: options.params,
      executed: false
    };
  };


  Engine.prototype.getRequest = function(key){
    return (!key ? this._request : this._request[key]);
  };


  Paloma.Engine = Engine;

})(window.Paloma);

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
paloma-4.2.1 vendor/assets/javascripts/paloma/engine.js
paloma-4.2.0 vendor/assets/javascripts/paloma/engine.js
paloma-4.1.2 vendor/assets/javascripts/paloma/engine.js