I really need your help with this one. I've been trying so hard to get this right but I just can't do it..
jsfiddle: http://jsfiddle.net/5Vyq8/13/
js-code:
$(document).ready(function () {
// Treetable
$("table").treetable({
expandable: true,
initialState: "expanded",
expanderTemplate: "<a href='#'> </a>",
indent: 24,
column: 0
});
// Draggable
$("table .draggable").draggable({
opacity: .75,
refreshPositions: true,
revert: "invalid",
revertDuration: 300,
scroll: true,
delay: 100,
cursor: 'move'
});
//Droppable
$("table tbody tr").each(function () {
$(this).droppable({
accept: ".draggable",
hoverClass: "append-to-task",
over: function (e, ui) {
// add class 'accept-incoming-task' to the row under after 1 second
},
out: function () {
},
drop: function (e, ui) {
var droppedEl = ui.draggable;
// Adds the task as the first child to dropped row
$("table").treetable("move", droppedEl.data("ttId"), $(this).data("ttId"));
},
});
});
});
What I'm trying to achieve is this:
I appriciate your time and help.
I managed to solve this at last! Here's the solution:
$(document).ready(function () {
// Treetable
$("table").treetable({
expandable: true,
initialState: "expanded",
expanderTemplate: "<a href='#'> </a>",
indent: 24,
column: 0
});
// Draggable
$("table .draggable").draggable({
opacity: .75,
refreshPositions: true,
revert: "invalid",
revertDuration: 300,
scroll: true,
delay: 100,
cursor: 'move'
});
//Droppable
var hoverTimeout;
$("table tbody tr").each(function () {
var that=this;
$(this).droppable({
accept: ".draggable",
hoverClass: "append-to-task",
over: function (e, ui) {
clearTimeout(hoverTimeout);
$('.accept-incoming-task').removeClass('accept-incoming-task');
// add class 'accept-incoming-task' to the row under after 1 second
hoverTimeout = setTimeout(function(){
$(that).addClass("accept-incoming-task");
}, 1000);
},
out: function () {
},
drop: function (e, ui) {
$('.accept-incoming-task').removeClass('accept-incoming-task');
var droppedEl = ui.draggable;
// Adds the task as the first child to dropped row
$("table").treetable("move", droppedEl.data("ttId"), $(this).data("ttId"));
},
});
});
});
Fiddle: http://jsfiddle.net/7yEaU/2/