Sha256: 3364c195e90dfd33cfc67a02bf7df862d3e50b625bdcd59cb02a35e7fc6a9351

Contents?: true

Size: 1.85 KB

Versions: 12

Compression:

Stored size: 1.85 KB

Contents

/**
 * Base class for input views that reference models.
 *
 * @class
 * @memberof module:pageflow/editor
 */
pageflow.ReferenceInputView = Backbone.Marionette.ItemView.extend(
/** @lends module:pageflow/editor.pageflow.ReferenceInputView# */{

  mixins: [pageflow.inputView],

  template: 'pageflow/editor/templates/inputs/reference',
  className: 'reference_input',

  ui: {
    title: '.title',
    unsetButton: '.unset',
    buttons: 'button'
  },

  events: {
    'click .choose': function() {
      var view = this;

      this.choose().then(function(site) {
        view.model.set(view.options.propertyName, site.get('perma_id'));
      });

      return false;
    },

    'click .unset': function() {
      this.model.unset(this.options.propertyName);
      return false;
    }
  },

  initialize: function() {
    this.listenTo(this.model, 'change:' + this.options.propertyName, this.update);
  },

  onRender: function() {
    this.update();
    this.listenTo(this.model, 'change:' + this.options.propertyName, this.update);
  },

  choose: function() {
    throw 'Not implemented: Override ReferenceInputView#choose to return a promise';
  },

  getTarget: function() {
    throw 'Not implemented: Override ReferenceInputView#getTarget';
  },

  createThumbnailView: function(target) {
    return new pageflow.ModelThumbnailView({
      model: target
    });
  },

  update: function() {
    var target = this.getTarget(this.model.get(this.options.propertyName));

    this.ui.title.text(target ? target.title() : I18n.t('pageflow.editor.views.inputs.reference_input_view.none'));
    this.ui.unsetButton.toggle(!!target);

    this.updateDisabledAttribute(this.ui.buttons);

    if (this.thumbnailView) {
      this.thumbnailView.close();
    }

    this.thumbnailView = this.subview(this.createThumbnailView(target));

    this.ui.title.before(this.thumbnailView.el);
  }
});

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pageflow-12.0.4 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.3 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.2 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.1 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.0 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.0.rc7 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.0.rc6 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.0.rc5 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.0.rc4 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.0.rc3 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.0.rc2 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js
pageflow-12.0.0.rc1 app/assets/javascripts/pageflow/editor/views/inputs/reference_input_view.js