Fix to all day select dates

This commit is contained in:
sean kenny
2014-07-24 14:04:28 +01:00
parent 1287de3851
commit 189105eec5
2 changed files with 48 additions and 24 deletions
+41 -21
View File
@@ -56,7 +56,7 @@ function ResourceView(element, calendar, viewName) {
t.reportDayClick = reportDayClick; // selection mousedown hack
t.dragStart = dragStart;
t.dragStop = dragStop;
t.getResources = calendar.fetchResources;
t.getResources = calendar.fetchResources;
// imports
View.call(t, element, calendar, viewName);
@@ -69,7 +69,6 @@ function ResourceView(element, calendar, viewName) {
var clearOverlays = t.clearOverlays;
var reportSelection = t.reportSelection;
var unselect = t.unselect;
var daySelectionMousedown = t.daySelectionMousedown;
var slotSegHtml = t.slotSegHtml;
var cellToDate = t.cellToDate;
var dateToCell = t.dateToCell;
@@ -549,7 +548,7 @@ function ResourceView(element, calendar, viewName) {
var date = cellToDate(0, 0);
var rowMatch = this.parentNode.className.match(/fc-slot(\d+)/); // TODO: maybe use data
ev.data = resources()[col];
ev.data = resources()[col];
if (rowMatch) {
var mins = parseInt(rowMatch[1]) * opt('slotMinutes');
@@ -570,25 +569,13 @@ function ResourceView(element, calendar, viewName) {
// TODO: should be consolidated with BasicView's methods
function renderDayOverlay(overlayStart, overlayEnd, refreshCoordinateGrid) { // overlayEnd is exclusive
function renderDayOverlay(overlayStart, overlayEnd, refreshCoordinateGrid, col) { // overlayEnd is exclusive
var allDayRow = 0;
if (refreshCoordinateGrid) {
coordinateGrid.build();
}
var segments = rangeToSegments(overlayStart, overlayEnd);
for (var i=0; i<segments.length; i++) {
var segment = segments[i];
dayBind(
renderCellOverlay(
segment.row,
segment.leftCol,
segment.row,
segment.rightCol
)
);
}
dayBind(renderCellOverlay(allDayRow, col, allDayRow, col));
}
@@ -755,10 +742,10 @@ function ResourceView(element, calendar, viewName) {
}
function renderSelection(startDate, endDate, allDay) { // only for all-day
function renderSelection(startDate, endDate, allDay, col) { // only for all-day
if (allDay) {
if (opt('allDaySlot')) {
renderDayOverlay(startDate, addDays(cloneDate(endDate), 1), true);
renderDayOverlay(startDate, endDate, true, col);
}
}else{
renderSlotSelection(startDate, endDate);
@@ -825,7 +812,40 @@ function ResourceView(element, calendar, viewName) {
}
}
function daySelectionMousedown(ev) {
var cellToDate = t.cellToDate;
var getIsCellAllDay = t.getIsCellAllDay;
var hoverListener = t.getHoverListener();
var reportDayClick = t.reportDayClick; // this is hacky and sort of weird
var col;
if (ev.which == 1 && opt('selectable')) { // which==1 means left mouse button
unselect(ev);
var _mousedownElement = this;
var dates;
hoverListener.start(function(cell, origCell) { // TODO: maybe put cellToDate/getIsCellAllDay info in cell
clearSelection();
if (cell && getIsCellAllDay(cell)) {
col = cell.col;
dates = [ realCellToDate(origCell), realCellToDate(cell) ].sort(dateCompare);
renderSelection(dates[0], dates[1], true, col);
}else{
dates = null;
}
}, ev);
$(document).one('mouseup', function(ev) {
hoverListener.stop();
if (dates) {
if (+dates[0] == +dates[1]) {
reportDayClick(dates[0], true, ev);
}
ev.data = resources()[col];
reportSelection(dates[0], dates[1], true, ev);
}
});
}
}
// select on the calendar somewhere
function slotSelectionMousedown(ev) {
if (ev.which == 1 && opt('selectable')) { // ev.which==1 means left mouse button
unselect(ev);
+7 -3
View File
@@ -74,7 +74,7 @@
$('#calendar').fullCalendar({
//When you click and select a time range show up the modal, with date,
//start and end time fields populated (Didn´t add fields).
select: function(start, end, allDay, ev) {
select: function(start, end, allDay, ev, resources) {
console.log(start);
console.log(ev.data);
},
@@ -99,10 +99,14 @@
center: 'title',
right: 'agendaWeek, agendaDay, resourceDay'
},
allDaySlot: false,
editable: true,
eventDrop: function (event, delta, revertFunc) {
console.log(event.resources);
},
allDaySlot: true,
selectable: true,
selectHelper: true,
editable: true,
droppable: true,
snapMinutes: 5,
slotMinutes: 15,