Commit 9f211b8d authored by alexandre's avatar alexandre

Sortable seems to work!

parent d71cb34a
...@@ -70,15 +70,25 @@ window.W = window.W || {}; ...@@ -70,15 +70,25 @@ window.W = window.W || {};
// console.log("relocated"); // console.log("relocated");
// console.log(this.model, index) // console.log(this.model, index)
// } // }
'relocate': 'relocate',
'relocateChild': 'relocateChild'
}, },
triggers: { // Triggered by jquery nested sortable when the item is
'foobar': 'foobar' relocate: function(event, index) {
var parentItem = this.$el.parent().closest("li");
parentItem.trigger('relocateChild', [this.model, index]);
return false;
}, },
onFoobar: function(view, event) { // Triggered by a subline view beeing relocated
console.log(view.model); relocateChild: function(event, model, index) {
console.log(view.model.get("parent")); model.get("parent").get("sublines").remove(model);
this.model.get("sublines").add(model, {at: index});
return false;
}, },
effaceAxe: function(e) { effaceAxe: function(e) {
...@@ -628,27 +638,6 @@ window.W = window.W || {}; ...@@ -628,27 +638,6 @@ window.W = window.W || {};
return false; return false;
}, },
// This event is triggered during sorting, but only when the DOM
// position has changed.
// onSortchange: function(view, event, ui) {
// console.log("changed")
// },
// onSortout: function(view, event, ui) {
// console.log("sorted out")
// },
// onSortupdate: function(view, event, ui) {
// console.log("updated")
// },
// onRelocate: function(view, event, ui) {
// console.log("relocated")
// console.log(view)
// console.log(event)
// console.log(ui)
// },
onSave: function(view, event) { onSave: function(view, event) {
// console.log("ok"); // console.log("ok");
this.model.save(); this.model.save();
...@@ -673,33 +662,18 @@ window.W = window.W || {}; ...@@ -673,33 +662,18 @@ window.W = window.W || {};
isAllowed: function(placeholder, placeholderParent, currentItem) { isAllowed: function(placeholder, placeholderParent, currentItem) {
return true; return true;
}, },
start: function(e, ui) {
console.log("current index", ui.item.index());
console.log("current parent", $(ui.item).closest("li"))
},
update: function(e, ui) {
console.log("current index", ui.item.index());
console.log("current parent", $(ui.item).closest("li"))
},
// change: function(event, ui) {
// // console.log("***");
// console.log("change");
// // console.log(event);
// // console.log(ui);
// },
relocate: function(event, ui) { relocate: function(event, ui) {
ui.item.trigger('foobar'); /*
// console.log(ui.item); * When the sort action is over:
// console.log(firstRegion.$el.nestedSortable('toArray')); * 1. trigger an event "relocate" on the item beeing sorted, along with its index
// console.log(firstRegion.$el.nestedSortable('toHierarchy')); * 2. listen and catch event "relocate" on the view that is responsible for the item
// console.log("***"); * 3. trigger an event "relocateChild" on the parent element, along with the index, and the item model
// console.log("relocate"); * 4. listen and catch event "relocateChild" on the view that is responsible for the parent item
// console.log(event); * 5. console.log that
// console.log(ui); * console.log("stop");
// ui.item.trigger('relocate', ui.item.index()); * ui.item.trigger("drop", ui.item.index());
// console.log("<<<"); */
// console.log(ui.item.parentItem); ui.item.trigger("relocate", ui.item.index());
// console.log(">>>");
}, },
}); });
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment