Sha256: 02d8709df5e60250c16db81b25ace0503ad0f02bc831ebc8b12812dade0a8783
Contents?: true
Size: 1.2 KB
Versions: 6
Compression:
Stored size: 1.2 KB
Contents
pageflow.Chapter = Backbone.Model.extend({ modelName: 'chapter', paramRoot: 'chapter', mixins: [pageflow.failureTracking, pageflow.delayedDestroying], initialize: function(attributes, options) { this.pages = new pageflow.SubsetCollection({ parent: pageflow.pages, parentModel: this, filter: function(item) { return item.get('chapter_id') === attributes.id; }, comparator: function(item) { return item.get('position'); } }); this.pages.each(function(page) { page.chapter = this; }, this); this.listenTo(this, 'change:title', function() { this.save(); }); this.listenTo(this.pages, 'add', function(model) { model.chapter = this; }); this.listenTo(this.pages, 'remove', function(model) { model.chapter = null; }); this.listenTo(this, 'destroy', function() { this.pages.clear(); }); return attributes; }, urlRoot: function() { return this.isNew() ? this.collection.url() : '/chapters'; }, addPage: function() { this.pages.create({ chapter_id: this.get('id'), position: this.pages.length }); }, destroy: function() { this.destroyWithDelay(); } });
Version data entries
6 entries across 6 versions & 1 rubygems