mirror of
https://github.com/Ekokumppanit/Lentolaskuri.git
synced 2026-02-14 09:47:09 +00:00
Initial commit
This commit is contained in:
49
app/scripts/views/route.js
Normal file
49
app/scripts/views/route.js
Normal file
@@ -0,0 +1,49 @@
|
||||
'use strict';
|
||||
|
||||
define([
|
||||
'backbone',
|
||||
'views/leg',
|
||||
'jquery-ui-sortable'
|
||||
], function (Backbone, LegView) {
|
||||
|
||||
var RouteView = Backbone.View.extend({
|
||||
el: '.route',
|
||||
events: {
|
||||
'sortstart': 'sortStart',
|
||||
'sortstop': 'sortStop'
|
||||
},
|
||||
initialize: function () {
|
||||
this.collection.bind('add', this.add, this);
|
||||
this.collection.bind('sort', this.render, this);
|
||||
|
||||
this.$el.sortable({
|
||||
handle: 'div > div',
|
||||
scroll: false,
|
||||
});
|
||||
},
|
||||
sortStart: function () {
|
||||
// fadeOut results
|
||||
},
|
||||
sortStop: function (event, ui) {
|
||||
this.updateSort();
|
||||
// fadeIn results
|
||||
},
|
||||
updateSort: function () {
|
||||
// jQuery UI already updates DOM order,
|
||||
// so we only have to update Backbone collection to match that
|
||||
var self = this;
|
||||
this.$el.find('.leg').each(function (index) {
|
||||
// Get id of model from element
|
||||
var id = $(this).data('id');
|
||||
self.collection.get(id).set('order', index);
|
||||
});
|
||||
this.collection.sort();
|
||||
},
|
||||
add: function (model, collection, options) {
|
||||
var item = new LegView({model: model});
|
||||
this.$el.append(item.render().el);
|
||||
}
|
||||
});
|
||||
|
||||
return RouteView;
|
||||
});
|
||||
Reference in New Issue
Block a user