Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions dahu/core/app/scripts/behaviors/workspace/actions/sortable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Created by coutinju on 6/14/15.
*/

define([
'backbone.marionette'
], function(
Marionette
) {
/**
* Sortable behavior for composite views.
*/
return Marionette.Behavior.extend({
/*
* When the view is empty this.view.$childViewContainer is undefined.
* We need to check if the behavior is defined because it might be
* the first childView to be added in the childViewContainer.
*/
onChildviewDomRefresh: function() {
// Either childViewContainer is defined or not
var list = this.view.$childViewContainer || this.$el;

if(list.attr("sortable"))
return;

var collection = this.view.collection;

// Make the list sortable
list.sortable({
update: function(event, ui) {
// Get an attached model
var model = collection.get(ui.item.data('backbone-cid'));

// On the quiet remove it from the collection
collection.remove(model, {silent:true});

//And sneakily add it to the necessary index
collection.add(model, {at:ui.item.index(), silent:true});
}
});
},

onAddChild: function(view) {
/*
* We add as attribute the cid attribute of backbone to identify
* each view when the user drags and drops it.
*/
view.$el.attr('data-backbone-cid', view.model.cid);
}
});
});
18 changes: 15 additions & 3 deletions dahu/core/app/scripts/views/filmstrip/screens.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ define([
'handlebars',
'backbone.marionette',
// views
'views/filmstrip/screen'
'views/filmstrip/screen',
// behaviors
'behaviors/workspace/actions/sortable'
], function(
Handlebars, Marionette,
Handlebars,
Marionette,
// views
FilmstripScreenView){
FilmstripScreenView,
// behaviors
SortableBehavior
) {

/**
* Filmstrip screen view
Expand All @@ -27,6 +33,12 @@ define([
this.collection = this.screencast.model.get('screens');
},

behaviors: {
SortableBehavior: {
behaviorClass: SortableBehavior
}
},

/**
* Redefinition of methods to take into consideration the new parameter
* item in getItemView, that we redefined in FilmStripScreenView.
Expand Down
10 changes: 10 additions & 0 deletions dahu/core/app/scripts/views/workspace/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ define([
'views/workspace/actions/action',
// templates
'text!templates/views/workspace/actions.html',
// behaviors
'behaviors/workspace/actions/sortable',
//modules
'modules/utils/exceptions'
], function(
Expand All @@ -34,6 +36,8 @@ define([
ActionView,
// templates
actionsTemplate,
// behaviors
SortableBehavior,
//modules
Exceptions
) {
Expand Down Expand Up @@ -64,6 +68,12 @@ define([

},

behaviors: {
SortableBehavior: {
behaviorClass: SortableBehavior
}
},

onAddChild: function(viewInstance) {
this.scrollOnAction(viewInstance);
},
Expand Down