Add subtasks drag and drop

This commit is contained in:
Frederic Guillot
2016-02-19 22:59:47 -05:00
parent 270e0835b2
commit de4519fa2c
16 changed files with 217 additions and 205 deletions

View File

@@ -8,7 +8,7 @@ function App() {
this.popover = new Popover(this);
this.task = new Task();
this.project = new Project();
this.subtask = new Subtask();
this.subtask = new Subtask(this);
this.file = new FileUpload(this);
this.keyboardShortcuts();
this.chosen();

View File

@@ -1,7 +1,12 @@
function Subtask() {
function Subtask(app) {
this.app = app;
}
Subtask.prototype.listen = function() {
var self = this;
this.dragAndDrop();
$(document).on("click", ".subtask-toggle-status", function(e) {
e.preventDefault();
var el = $(this);
@@ -15,6 +20,8 @@ Subtask.prototype.listen = function() {
} else {
el.replaceWith(data);
}
self.dragAndDrop();
}
});
});
@@ -28,7 +35,60 @@ Subtask.prototype.listen = function() {
url: el.attr("href"),
success: function(data) {
$(".subtasks-table").replaceWith(data);
self.dragAndDrop();
}
});
});
};
Subtask.prototype.dragAndDrop = function() {
var self = this;
$(".draggable-row-handle").mouseenter(function() {
$(this).parent().parent().addClass("draggable-item-hover");
}).mouseleave(function() {
$(this).parent().parent().removeClass("draggable-item-hover");
});
$(".subtasks-table tbody").sortable({
forcePlaceholderSize: true,
handle: "td:first i",
helper: function(e, ui) {
ui.children().each(function() {
$(this).width($(this).width());
});
return ui;
},
stop: function(event, ui) {
var subtask = ui.item;
subtask.removeClass("draggable-item-selected");
self.savePosition(subtask.data("subtask-id"), subtask.index() + 1);
},
start: function(event, ui) {
ui.item.addClass("draggable-item-selected");
}
}).disableSelection();
};
Subtask.prototype.savePosition = function(subtaskId, position) {
var url = $(".subtasks-table").data("save-position-url");
var self = this;
this.app.showLoadingIcon();
$.ajax({
cache: false,
url: url,
contentType: "application/json",
type: "POST",
processData: false,
data: JSON.stringify({
"subtask_id": subtaskId,
"position": position
}),
complete: function() {
self.app.hideLoadingIcon();
}
});
};