Sha256: 9bac11e9ddfd154cfb71170e9a89340ae9ab24817a51b3db7624a073198dd526

Contents?: true

Size: 1.4 KB

Versions: 7

Compression:

Stored size: 1.4 KB

Contents

pageflow.linkmapPage.AreasCollection = Backbone.Collection.extend({
  model: pageflow.linkmapPage.Area,

  initialize: function(models, options) {
    this.page = options.page;
    this.defaultPosition = {
      left: 10,
      top: 10
    };

    this.listenTo(this, 'select', this.updateSelectedAttributes);
    this.listenTo(this, 'add', this.updateSelectedAttributes);
  },

  canAddLink: function() {
    return true;
  },

  addLink: function(targetPageId) {
    this.addWithPosition({
      target_type: 'page',
      target_id: targetPageId
    });
  },

  addAudioFile: function(audioFileId) {
    this.addWithPosition({
      target_type: 'audio_file',
      target_id: audioFileId
    });
  },

  addExternalSite: function(siteId) {
    this.addWithPosition({
      target_type: 'external_site',
      target_id: siteId
    });
  },

  addTextOnly: function() {
    this.addWithPosition({
      target_type: 'text_only'
    });
  },

  addWithPosition: function(attributes) {
    var collection = this;

    pageflow.linkmapPage.selectArea(this.page).then(function(positionAttributes) {
      collection.add(_.extend(
        positionAttributes,
        attributes
      ));
    });
  },

  resetSelection: function() {
    this.updateSelectedAttributes(null);
  },

  updateSelectedAttributes: function(selectedArea) {
    this.each(function(area) {
      area.set('selected', area === selectedArea);
    });
  }
});

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pageflow-linkmap-page-1.5.0 app/assets/javascript/pageflow/linkmap_page/editor/collections/areas_collection.js
pageflow-linkmap-page-1.4.0 app/assets/javascript/pageflow/linkmap_page/editor/collections/areas_collection.js
pageflow-linkmap-page-1.3.0 app/assets/javascript/pageflow/linkmap_page/editor/collections/areas_collection.js
pageflow-linkmap-page-1.2.1 app/assets/javascript/pageflow/linkmap_page/editor/collections/areas_collection.js
pageflow-linkmap-page-1.2.0 app/assets/javascript/pageflow/linkmap_page/editor/collections/areas_collection.js
pageflow-linkmap-page-1.1.0 app/assets/javascript/pageflow/linkmap_page/editor/collections/areas_collection.js
pageflow-linkmap-page-1.0.0 app/assets/javascript/pageflow/linkmap_page/editor/collections/areas_collection.js