Sha256: 6333346a8196572ce4e999c828414e9fd50f73fa6fce35354b377c2fae5218fe

Contents?: true

Size: 1.43 KB

Versions: 46

Compression:

Stored size: 1.43 KB

Contents

pageflow.WidgetTypes = pageflow.Object.extend({
  initialize: function() {
    this._clientSideConfigs = {};
    this._optionalRoles = {};
  },

  register: function(name, config) {
    if (this._setup) {
      throw 'Widget types already set up. Register widget types before initializers run.';
    }

    this._clientSideConfigs[name] = config;
  },

  setup: function(serverSideConfigsByRole) {
    this._setup = true;
    this._widgetTypesByName = {};

    var roles = _.keys(serverSideConfigsByRole);

    this._widgetTypesByRole = roles.reduce(_.bind(function(result, role) {
      result[role] = serverSideConfigsByRole[role].map(_.bind(function(serverSideConfig) {
        var clientSideConfig = this._clientSideConfigs[serverSideConfig.name] || {};
        var widgetType = new pageflow.WidgetType(serverSideConfig, clientSideConfig);

        this._widgetTypesByName[serverSideConfig.name] = widgetType;
        return widgetType;
      }, this));

      return result;
    }, this), {});
  },

  findAllByRole: function(role) {
    return this._widgetTypesByRole[role] || [];
  },

  findByName: function(name) {
    if (!this._widgetTypesByName[name]) {
      throw('Could not find widget type with name "' + name +'"');
    }

    return this._widgetTypesByName[name];
  },

  registerRole: function(role, options) {
    this._optionalRoles[role] = options.isOptional;
  },

  isOptional: function(role) {
    return !!this._optionalRoles[role];
  }
});

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
pageflow-14.5.2 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-15.0.2 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-15.0.1 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-15.0.0 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.5.1 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.5.0 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-15.0.0.rc2 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-15.0.0.rc1 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-15.0.0.beta4 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-15.0.0.beta3 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.4.0 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-15.0.0.beta2 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-15.0.0.beta1 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.3.0 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.2.1 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.2.0 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.1.1 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.1.0 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.0.0 app/assets/javascripts/pageflow/editor/api/widget_types.js
pageflow-14.0.0.rc2 app/assets/javascripts/pageflow/editor/api/widget_types.js