Sha256: 10e68080dc3f84fae8981b66440d4693725929d8a93739cc0c624989b8a2b363

Contents?: true

Size: 1.01 KB

Versions: 58

Compression:

Stored size: 1.01 KB

Contents

pageflow.orderedCollection = {
  initialize: function() {
    if (this.autoConsolidatePositions !== false) {
      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('update', 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

58 entries across 58 versions & 1 rubygems

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