Sha256: b1fb3c82ec3b6ad31e3b9462886e9f572971d598bec001e2c0f56f7dabc524af

Contents?: true

Size: 969 Bytes

Versions: 12

Compression:

Stored size: 969 Bytes

Contents

pageflow.orderedCollection = {
  initialize: function() {
    this.listenTo(this, 'remove', function() {
      this.consolidatePositions();
      this.saveOrder();
    });
  },

  consolidatePositions: function() {
    this.each(function(item, index) {
      item.set('position', index);
    });
  },

  saveOrder: function() {
    var parentModel = this.parentModel;
    var collection = this;

    if (collection.isEmpty()) {
      return $.Deferred().resolve().promise();
    }

    return Backbone.sync('patch', parentModel, {
      url: collection.url() + '/order',
      attrs: {ids: collection.pluck('id')},

      success: function(response) {
        parentModel.trigger('sync', parentModel, response, {});
        parentModel.trigger('sync:order', parentModel, response, {});
      },

      error: function(jqXHR,  textStatus, errorThrown) {
        pageflow.editor.failures.add(new pageflow.OrderingFailure(parentModel, collection));
      }
    });
  }
};

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
pageflow-0.9.2 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.9.1 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.9.0 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.8.2 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.8.1 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.8.0 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.7.2 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.7.1 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.7.0 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.6.0 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.5.0 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js
pageflow-0.4.0 app/assets/javascripts/pageflow/editor/collections/mixins/ordered_collection.js