allow ViewOptionHashes for selectable options, fixed new selectable bugs

This commit is contained in:
Adam Shaw 2010-07-03 18:00:38 -07:00
parent 1f02eb5f91
commit 6f4ab74340
5 changed files with 41 additions and 21 deletions

View file

@ -19,7 +19,7 @@ setDefaults({
maxTime: 24
});
views.agendaWeek = function(element, options) {
views.agendaWeek = function(element, options, viewName) {
return new Agenda(element, options, {
render: function(date, delta) {
if (delta) {
@ -46,10 +46,10 @@ views.agendaWeek = function(element, options) {
this.option('columnFormat')
);
}
});
}, viewName);
};
views.agendaDay = function(element, options) {
views.agendaDay = function(element, options, viewName) {
return new Agenda(element, options, {
render: function(date, delta) {
if (delta) {
@ -66,10 +66,10 @@ views.agendaDay = function(element, options) {
this.option('columnFormat')
);
}
});
}, viewName);
};
function Agenda(element, options, methods) {
function Agenda(element, options, methods, viewName) {
var head, body, bodyContent, bodyTable, bg,
colCnt,
@ -111,6 +111,7 @@ function Agenda(element, options, methods) {
return addMinutes(start, options.defaultEventMinutes);
}
});
view.name = viewName;
view.init(element, options);
@ -965,16 +966,17 @@ function Agenda(element, options, methods) {
var selected = false;
var daySelectionMousedown = selection_dayMousedown(
view, hoverListener, cellDate, renderDayOverlay, clearOverlay, reportSelection, unselect
view, hoverListener, cellDate, cellIsAllDay, renderDayOverlay, clearOverlay, reportSelection, unselect
);
function slotSelectionMousedown(ev) {
if (view.option('selectable')) {
unselect();
var _mousedownElement = this;
var dates;
hoverListener.start(function(cell, origCell) {
clearSelection();
if (cell && cell.col == origCell.col) {
if (cell && cell.col == origCell.col && !cellIsAllDay(cell)) {
var d1 = cellDate(origCell);
var d2 = cellDate(cell);
dates = [
@ -988,9 +990,12 @@ function Agenda(element, options, methods) {
dates = null;
}
}, ev);
$(document).one('mouseup', function() {
$(document).one('mouseup', function(ev) {
hoverListener.stop();
if (dates) {
if (+dates[0] == +dates[1]) {
view.trigger('dayClick', _mousedownElement, dates[0], false, ev);
}
reportSelection(dates[0], dates[3], false);
}
});

View file

@ -6,7 +6,7 @@ setDefaults({
weekMode: 'fixed'
});
views.month = function(element, options) {
views.month = function(element, options, viewName) {
return new Grid(element, options, {
render: function(date, delta) {
if (delta) {
@ -46,10 +46,10 @@ views.month = function(element, options) {
true
);
}
});
}, viewName);
};
views.basicWeek = function(element, options) {
views.basicWeek = function(element, options, viewName) {
return new Grid(element, options, {
render: function(date, delta) {
if (delta) {
@ -77,10 +77,10 @@ views.basicWeek = function(element, options) {
false
);
}
});
}, viewName);
};
views.basicDay = function(element, options) {
views.basicDay = function(element, options, viewName) {
return new Grid(element, options, {
render: function(date, delta) {
if (delta) {
@ -98,7 +98,7 @@ views.basicDay = function(element, options) {
false
);
}
});
}, viewName);
};
@ -107,7 +107,7 @@ views.basicDay = function(element, options) {
var tdHeightBug;
function Grid(element, options, methods) {
function Grid(element, options, methods, viewName) {
var tm, firstDay,
nwe, // no weekends (int)
@ -135,6 +135,7 @@ function Grid(element, options, methods) {
return cloneDate(event.start);
}
});
view.name = viewName;
view.init(element, options);
@ -528,7 +529,7 @@ function Grid(element, options, methods) {
var selected = false;
var selectionMousedown = selection_dayMousedown(
view, hoverListener, cellDate, renderDayOverlay, clearOverlay, reportSelection, unselect
view, hoverListener, cellDate, function(){return true}, renderDayOverlay, clearOverlay, reportSelection, unselect
);
view.select = function(startDate, endDate, allDay) {

View file

@ -215,7 +215,8 @@ $.fn.fullCalendar = function(options) {
newViewElement = absoluteViewElement =
$("<div class='fc-view fc-view-" + v + "' style='position:absolute'/>")
.appendTo(content),
options
options,
v // the view's name
);
}
@ -225,7 +226,7 @@ $.fn.fullCalendar = function(options) {
header.find('div.fc-button-' + v).addClass(tm + '-state-active');
}
view.name = viewName = v;
viewName = v;
render(); // after height has been set, will make absoluteViewElement's position=relative, then set to null
content.css('overflow', '');
if (oldView) {

View file

@ -1,19 +1,26 @@
function selection_dayMousedown(view, hoverListener, cellDate, renderSelection, clearSelection, reportSelection, unselect) {
function selection_dayMousedown(view, hoverListener, cellDate, cellIsAllDay, renderSelection, clearSelection, reportSelection, unselect) {
return function(ev) {
if (view.option('selectable')) {
unselect();
var _mousedownElement = this;
var dates;
hoverListener.start(function(cell, origCell) {
clearSelection();
if (cell) {
if (cell && cellIsAllDay(cell)) {
dates = [ cellDate(origCell), cellDate(cell) ].sort(cmp);
renderSelection(dates[0], addDays(cloneDate(dates[1]), 1), true);
}else{
dates = null;
}
}, ev);
$(document).one('mouseup', function(ev) {
if (hoverListener.stop()) { // over a cell?
hoverListener.stop();
if (dates) {
if (+dates[0] == +dates[1]) {
view.trigger('dayClick', _mousedownElement, dates[0], true, ev);
}
reportSelection(dates[0], dates[1], true);
}
});

View file

@ -26,6 +26,12 @@
//weekends: false,
//allDaySlot: false,
selectable: true,
/*
selectable: {
month: false,
agenda: true
},
*/
//selectHelper: true,
/*
selectHelper: function(start, end) {