Sha256: 0115b06604509589b13e7824ea43fa8797094615a4ef570c4a8c57c19ab55103
Contents?: true
Size: 1.43 KB
Versions: 76
Compression:
Stored size: 1.43 KB
Contents
pageflow.SortableCollectionView = pageflow.CollectionView.extend({ render: function() { pageflow.CollectionView.prototype.render.call(this); this.$el.sortable({ connectWith: this.options.connectWith, placeholder: 'sortable-placeholder', forcePlaceholderSize: true, delay: 200, update: _.bind(function(event, ui) { if (ui.item.parent().is(this.el)) { this.updateOrder(); } }, this), receive: _.bind(function(event, ui) { var view = ui.item.data('view'); this.reindexPositions(); this.itemViews.add(view); this.collection.add(view.model); }, this), remove: _.bind(function(event, ui) { var view = ui.item.data('view'); this.itemViews.remove(view); this.collection.remove(view.model); }, this) }); return this; }, addItem: function(item) { if (!this.itemViews.findByModel(item)) { pageflow.CollectionView.prototype.addItem.call(this, item); } }, removeItem: function(item) { if (this.itemViews.findByModel(item)) { pageflow.CollectionView.prototype.removeItem.call(this, item); } }, updateOrder: function() { this.reindexPositions(); this.collection.sort(); this.collection.saveOrder(); }, reindexPositions: function() { this.$el.children().each(function(index) { $(this).data('view').model.set('position', index); }); } });
Version data entries
76 entries across 76 versions & 1 rubygems