added minTime/maxTime options for agenda views

This commit is contained in:
Adam Shaw 2009-11-29 20:16:47 -08:00
parent e457d4e1dd
commit 32cc6c9744
3 changed files with 45 additions and 10 deletions

View file

@ -71,6 +71,7 @@ function Agenda(element, options, methods) {
tm, firstDay, tm, firstDay,
nwe, // no weekends (int) nwe, // no weekends (int)
rtl, dis, dit, // day index sign / translate rtl, dis, dit, // day index sign / translate
minMinute, maxMinute,
// ... // ...
view = $.extend(this, viewMethods, methods, { view = $.extend(this, viewMethods, methods, {
@ -129,6 +130,8 @@ function Agenda(element, options, methods) {
dis = 1; dis = 1;
dit = 0; dit = 0;
} }
minMinute = parseTime(options.minTime || 0);
maxMinute = parseTime(options.maxTime || 24);
var d0 = rtl ? addDays(cloneDate(view.visEnd), -1) : cloneDate(view.visStart), var d0 = rtl ? addDays(cloneDate(view.visEnd), -1) : cloneDate(view.visStart),
d = cloneDate(d0), d = cloneDate(d0),
@ -172,8 +175,10 @@ function Agenda(element, options, methods) {
// body // body
d = zeroDate(); d = zeroDate();
var maxd = addMinutes(cloneDate(d), maxMinute);
addMinutes(d, minMinute);
s = "<table>"; s = "<table>";
for (i=0; d.getDate() != 2; i++) { for (i=0; d < maxd; i++) {
minutes = d.getMinutes(); minutes = d.getMinutes();
s += "<tr class='" + s += "<tr class='" +
(i==0 ? 'fc-first' : (minutes==0 ? '' : 'fc-minor')) + (i==0 ? 'fc-first' : (minutes==0 ? '' : 'fc-minor')) +
@ -323,7 +328,7 @@ function Agenda(element, options, methods) {
var mins = parseInt(rowMatch[1]) * options.slotMinutes, var mins = parseInt(rowMatch[1]) * options.slotMinutes,
hours = Math.floor(mins/60); hours = Math.floor(mins/60);
date.setHours(hours); date.setHours(hours);
date.setMinutes(mins % 60); date.setMinutes(mins%60 + minMinute);
view.trigger('dayClick', this, date, false, ev); view.trigger('dayClick', this, date, false, ev);
}else{ }else{
view.trigger('dayClick', this, date, true, ev); view.trigger('dayClick', this, date, true, ev);
@ -367,17 +372,15 @@ function Agenda(element, options, methods) {
function compileSlotSegs(events) { function compileSlotSegs(events) {
var d1 = cloneDate(view.visStart), var d = addMinutes(cloneDate(view.visStart), minMinute),
d2 = addDays(cloneDate(d1), 1),
levels, levels,
segCols = [], segCols = [],
i=0; i=0;
for (; i<colCnt; i++) { for (; i<colCnt; i++) {
levels = stackSegs(view.sliceSegs(events, d1, d2)); levels = stackSegs(view.sliceSegs(events, d, addMinutes(cloneDate(d), maxMinute-minMinute)));
countForwardSegs(levels); countForwardSegs(levels);
segCols.push(levels); segCols.push(levels);
addDays(d1, 1); addDays(d, 1, true);
addDays(d2, 1);
} }
return segCols; return segCols;
} }
@ -661,6 +664,7 @@ function Agenda(element, options, methods) {
allDay ? 0 : // minute delta allDay ? 0 : // minute delta
Math.round((eventElement.offset().top - bodyContent.offset().top) / slotHeight) Math.round((eventElement.offset().top - bodyContent.offset().top) / slotHeight)
* options.slotMinutes * options.slotMinutes
+ minMinute
- (event.start.getHours() * 60 + event.start.getMinutes()), - (event.start.getHours() * 60 + event.start.getMinutes()),
allDay, ev, ui allDay, ev, ui
); );
@ -844,12 +848,16 @@ function Agenda(element, options, methods) {
// get the Y coordinate of the given time on the given day (both Date objects) // get the Y coordinate of the given time on the given day (both Date objects)
function timePosition(day, time) { function timePosition(day, time) { // both date object. day holds 00:00 of current day
if (time > day && time.getDay() != day.getDay()) { day = cloneDate(day, true);
if (time < addMinutes(cloneDate(day), minMinute)) {
return 0;
}
if (time >= addMinutes(cloneDate(day), maxMinute)) {
return bodyContent.height(); return bodyContent.height();
} }
var slotMinutes = options.slotMinutes, var slotMinutes = options.slotMinutes,
minutes = time.getHours()*60 + time.getMinutes(), minutes = time.getHours()*60 + time.getMinutes() - minMinute,
slotI = Math.floor(minutes / slotMinutes), slotI = Math.floor(minutes / slotMinutes),
tr = body.find('tr:eq(' + slotI + ')'), tr = body.find('tr:eq(' + slotI + ')'),
td = tr.find('td'), td = tr.find('td'),

View file

@ -128,6 +128,26 @@ var parseISO8601 = fc.parseISO8601 = function(s, ignoreTimezone) {
return new Date(Number(date) + (offset * 60 * 1000)); return new Date(Number(date) + (offset * 60 * 1000));
} }
var parseTime = fc.parseTime = function(s) { // returns minutes since start of day
if (typeof s == 'number') { // an hour
return s * 60;
}
if (typeof s == 'object') { // a Date object
return s.getHours() * 60 + s.getMinutes();
}
var m = s.match(/(\d+)(?::(\d+))?\s*(\w+)?/);
if (m) {
var h = parseInt(m[1]);
if (m[3]) {
h %= 12;
if (m[3].toLowerCase().charAt(0) == 'p') {
h += 12;
}
}
return h * 60 + (m[2] ? parseInt(m[2]) : 0);
}
};
/* Date Formatting /* Date Formatting

View file

@ -69,6 +69,13 @@
timeFormat: "h(:mm)[T]{ - h(:mm)T}", timeFormat: "h(:mm)[T]{ - h(:mm)T}",
//timeFormat: { agendaWeek: "'YO'" }, //timeFormat: { agendaWeek: "'YO'" },
minTime: 5,
maxTime: '10:45pm',
//dayClick: function(date) {
// console.log(date);
//},
//isRTL: true,
events: [ events: [
{ {
title: 'All Day Event', title: 'All Day Event',