Sha256: dbd5eed8c3e4d2121f283737ed68cf49ecb22c8a10181e49a6fe675d4023a76b

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

// This is our connection to the Asset library.
slices.AssetCollection = Backbone.Collection.extend({

  model: slices.Asset,

  url: '/admin/assets',

  initialize: function() {
    this.bind('add', this.afterAdd);
    this.bind('remove', this.afterRemove);
  },

  // This request responds with a page worth of results in `items`.
  parse: function(response) {
    this.currentPage = response.current_page;
    this.perPage = response.per_page;
    this.totalEntries = response.total_entries
    this.totalPages = response.total_pages;
    return response.items;
  },

  // Returns true if there are more pages in the current criteria.
  hasMorePages: function() {
    return this.currentPage < this.totalPages;
  },

  // After an asset is added, we need to update the non-standard
  // totalEntries count.
  afterAdd: function() {
    this.totalEntires += 1;
    this.totalPages = Math.ceil(this.totalEntries / this.perPage);
  },

  // Similarly, we need to update the count on remove.
  afterRemove: function() {
    this.totalEntries -= 1;
    this.totalPages = Math.ceil(this.totalEntries / this.perPage);
  }

});

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
slices-2.0.2 app/assets/javascripts/slices/app/models/asset_collection.js
slices-2.0.1 app/assets/javascripts/slices/app/models/asset_collection.js
slices-2.0.0 app/assets/javascripts/slices/app/models/asset_collection.js
slices-1.0.5 app/assets/javascripts/slices/app/models/asset_collection.js
slices-1.0.4 app/assets/javascripts/slices/app/models/asset_collection.js
slices-1.0.3 app/assets/javascripts/slices/app/models/asset_collection.js
slices-1.0.2 app/assets/javascripts/slices/app/models/asset_collection.js
slices-1.0.1 app/assets/javascripts/slices/app/models/asset_collection.js
slices-1.0.0 app/assets/javascripts/slices/app/models/asset_collection.js