This commit is contained in:
2025-04-11 22:57:23 +02:00
parent 1f38807599
commit a1b24ba466
4 changed files with 345 additions and 19 deletions

View File

@@ -490,4 +490,22 @@
.row:after {
clear: both;
}
.handle {
width: 6px;
background: #333;
position: absolute;
top: 0;
bottom: 0;
cursor: ew-resize;
z-index: 20;
}
.handle-left {
left: 0;
}
.handle-right {
right: 0;
}

View File

@@ -22,7 +22,8 @@
onItemClick: function (data) { return; },
onAddClick: function (data) { return; },
onRender: function() { return; },
scrollToToday: true
scrollToToday: true,
saveEndpoint: null
};
/**
@@ -940,6 +941,66 @@
e.stopPropagation();
settings.onItemClick($(this).data("dataObj"));
});
bar.append('<div class="handle handle-left"></div><div class="handle handle-right"></div>');
let isDragging = false;
let dragType = null;
let startX = 0;
let originalLeft = 0;
let originalWidth = 0;
bar.find('.handle').on('mousedown', function(e) {
e.stopPropagation();
isDragging = true;
dragType = $(this).hasClass('handle-left') ? 'left' : 'right';
startX = e.pageX;
originalLeft = bar.position().left;
originalWidth = bar.width();
$(document).on('mousemove.barDrag', function(e) {
if (!isDragging) return;
let delta = e.pageX - startX;
if (dragType === 'left') {
let newLeft = originalLeft + delta;
let newWidth = originalWidth - delta;
if (newWidth > 10) {
bar.css({ left: newLeft + 'px', width: newWidth + 'px' });
}
} else if (dragType === 'right') {
let newWidth = originalWidth + delta;
if (newWidth > 10) {
bar.css({ width: newWidth + 'px' });
}
}
});
$(document).on('mouseup.barDrag', function() {
if (isDragging) {
isDragging = false;
$(document).off('.barDrag');
// Oblicz nową datę z `left` i `width`
const cellSize = tools.getCellSize();
const newFromOffset = bar.position().left;
const newToOffset = newFromOffset + bar.width();
const ganttEl = bar.closest(".fn-gantt").parent()[0];
const fromTime = tools.getDateFromOffset(newFromOffset, ganttEl);
const toTime = tools.getDateFromOffset(newToOffset, ganttEl);
const data = bar.data("dataObj");
// Tutaj można wysłać AJAX
$.post(settings.saveEndpoint, {
from: fromTime.toISOString(),
to: toTime.toISOString()
});
console.log("Zmieniono daty:", fromTime, toTime);
}
});
});
return bar;
},
@@ -1441,7 +1502,12 @@
}
return maxDate;
},
getDateFromOffset: function(offsetPx, element) {
const step = settings.scale === "hours" ? 3600000 * element.scaleStep : 86400000; // godziny lub dni
const startDate = element.dateStart.getTime();
const index = Math.floor(offsetPx / tools.getCellSize());
return new Date(startDate + index * step);
},
// Return the minimum available date in data depending on the scale
getMinDate: function (element) {
var minDate = null;