summaryrefslogtreecommitdiff
path: root/assets/js/components/subtask-drag-and-drop.js
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2017-03-19 16:45:32 -0400
committerFrederic Guillot <fred@kanboard.net>2017-03-19 16:45:32 -0400
commitd915c2a96b0cbb54b9949cc04495d156e1f89332 (patch)
tree93f31d3de295c0f6cfc7c3a3bdf20cb8d7e7922a /assets/js/components/subtask-drag-and-drop.js
parent5b7ed28ba1a47a5c4312017a86fb811e14c0285a (diff)
Improve subtask toggle
Diffstat (limited to 'assets/js/components/subtask-drag-and-drop.js')
-rw-r--r--assets/js/components/subtask-drag-and-drop.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/assets/js/components/subtask-drag-and-drop.js b/assets/js/components/subtask-drag-and-drop.js
new file mode 100644
index 00000000..f704376a
--- /dev/null
+++ b/assets/js/components/subtask-drag-and-drop.js
@@ -0,0 +1,44 @@
+KB.on('dom.ready', function() {
+
+ function savePosition(subtaskId, position) {
+ var url = $(".subtasks-table").data("save-position-url");
+
+ $.ajax({
+ cache: false,
+ url: url,
+ contentType: "application/json",
+ type: "POST",
+ processData: false,
+ data: JSON.stringify({
+ "subtask_id": subtaskId,
+ "position": position
+ })
+ });
+ }
+
+ $(".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");
+ savePosition(subtask.data("subtask-id"), subtask.index() + 1);
+ },
+ start: function(event, ui) {
+ ui.item.addClass("draggable-item-selected");
+ }
+ }).disableSelection();
+});