From 06e4734b0531f64be84038f8188a2cdd9ad5e86d Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Thu, 10 Feb 2011 22:40:16 -0800 Subject: [PATCH] Beefed up event sources: Control over all $.ajax options. Event coloring through options. All event-level options available as "source" options. Event fetching more resilient to errors. --- src/EventManager.js | 207 ++++++++++++++++++++++-------- src/agenda/AgendaEventRenderer.js | 47 +++++-- src/agenda/AgendaView.js | 5 +- src/basic/BasicEventRenderer.js | 2 +- src/common/DayEventRenderer.js | 33 +++-- src/util.js | 63 +++++++++ tests/sources_new.html | 171 ++++++++++++++++++++++++ 7 files changed, 449 insertions(+), 79 deletions(-) create mode 100644 tests/sources_new.html diff --git a/src/EventManager.js b/src/EventManager.js index c99b659..b911830 100644 --- a/src/EventManager.js +++ b/src/EventManager.js @@ -1,7 +1,15 @@ +fc.sourceNormalizers = []; +fc.sourceFetchers = []; + +var ajaxDefaults = { + dataType: 'json', + cache: true // because we are using the cacheParam option (TODO: deprecate) +}; + var eventGUID = 1; -function EventManager(options, sources) { +function EventManager(options, _sources) { var t = this; @@ -24,6 +32,8 @@ function EventManager(options, sources) { // locals + var stickySource = { events: [] }; + var sources = [ stickySource ]; var rangeStart, rangeEnd; var currentFetchID = 0; var pendingSourceCnt = 0; @@ -31,6 +41,11 @@ function EventManager(options, sources) { var cache = []; + for (var i=0; i<_sources.length; i++) { + _addEventSource(_sources[i]); + } + + /* Fetching -----------------------------------------------------------------------------*/ @@ -57,11 +72,13 @@ function EventManager(options, sources) { function fetchEventSource(source, fetchID) { _fetchEventSource(source, function(events) { if (fetchID == currentFetchID) { - for (var i=0; i" + - "" + // good for escaping quotes? - "
" + + function slotSegHtml(event, seg, classes) { + classes = classes.concat(event.className, event.source.className); + var skinCss = getSkinCss(event, opt); + var skinCssAttr = (skinCss ? " style='" + skinCss + "'" : ''); + return "
" + + "" + + "
" + "
" + htmlEscape(formatDates(event.start, event.end, opt('timeFormat'))) + "
" + @@ -293,16 +299,22 @@ function AgendaEventRenderer() { "
" + "
" + "
" + - ((event.editable || event.editable === undefined && opt('editable')) && !opt('disableResizing') && $.fn.resizable ? + ((seg.isEnd && + isEventEditable(event) && + !opt('disableResizing') && // TODO: make like other source properties + $.fn.resizable) + ? "
=
" - : '') + + : + '' + ) + "
"; } function bindDaySeg(event, eventElement, seg) { eventElementHandlers(event, eventElement); - if (event.editable || event.editable === undefined && opt('editable')) { + if (isEventEditable(event)) { draggableDayEvent(event, eventElement, seg.isStart); if (seg.isEnd) { resizableDayEvent(event, eventElement, seg); @@ -313,7 +325,7 @@ function AgendaEventRenderer() { function bindSlotSeg(event, eventElement, seg) { eventElementHandlers(event, eventElement); - if (event.editable || event.editable === undefined && opt('editable')) { + if (isEventEditable(event)) { var timeElement = eventElement.find('span.fc-event-time'); draggableSlotEvent(event, eventElement, timeElement); if (seg.isEnd) { @@ -323,6 +335,11 @@ function AgendaEventRenderer() { } + function isEventEditable(event) { + return firstDefined(event.editable, event.source.editable, opt('editable')); + } + + /* Dragging -----------------------------------------------------------------------------------*/ @@ -330,6 +347,10 @@ function AgendaEventRenderer() { // when event starts out FULL-DAY + // TODO: bug when dragging an event that occupies first day, but is not the event's start (no rounded left side) + + // TODO: bug when dragging from day to slot, outer container doesn't seem to change height + function draggableDayEvent(event, eventElement, isStart) { if (!opt('disableDragging') && eventElement.draggable) { var origWidth; diff --git a/src/agenda/AgendaView.js b/src/agenda/AgendaView.js index 1efee39..952f060 100644 --- a/src/agenda/AgendaView.js +++ b/src/agenda/AgendaView.js @@ -701,10 +701,11 @@ function AgendaView(element, calendar, viewName) { start: startDate, end: endDate, className: [], - editable: false + editable: false, + source: {} }, rect, - 'fc-event fc-event-vert fc-corner-top fc-corner-bottom ' + ['fc-event', 'fc-event-vert', 'fc-corner-top', 'fc-corner-bottom'] )); if ($.browser.msie) { selectionHelper.find('span.fc-event-bg').hide(); // nested opacities mess up in IE, just hide diff --git a/src/basic/BasicEventRenderer.js b/src/basic/BasicEventRenderer.js index a2077db..555c726 100644 --- a/src/basic/BasicEventRenderer.js +++ b/src/basic/BasicEventRenderer.js @@ -77,7 +77,7 @@ function BasicEventRenderer() { function bindDaySeg(event, eventElement, seg) { eventElementHandlers(event, eventElement); - if (event.editable || event.editable === undefined && opt('editable')) { + if (firstDefined(event.editable, event.source.editable, opt('editable'))) { draggableDayEvent(event, eventElement); if (seg.isEnd) { resizableDayEvent(event, eventElement, seg); diff --git a/src/common/DayEventRenderer.js b/src/common/DayEventRenderer.js index 1e5a7a9..1cfac94 100644 --- a/src/common/DayEventRenderer.js +++ b/src/common/DayEventRenderer.js @@ -119,25 +119,26 @@ function DayEventRenderer() { var segCnt=segs.length; var seg; var event; - var className; + var classes; var bounds = allDayBounds(); var minLeft = bounds.left; var maxLeft = bounds.right; var cols = []; // don't really like this system (but have to do this b/c RTL works differently in basic vs agenda) var left; var right; + var skinCss; var html = ''; // calculate desired position/dimensions, create html for (i=0; i" + - "" + + "
" + + "" + (!event.allDay && seg.isStart ? "" + htmlEscape(formatDates(event.start, event.end, opt('timeFormat'))) + @@ -165,9 +173,14 @@ function DayEventRenderer() { :'') + "" + htmlEscape(event.title) + "" + "" + - (seg.isEnd && (event.editable || event.editable === undefined && opt('editable')) && !opt('disableResizing') ? + ((seg.isEnd && + firstDefined(event.editable, event.source.editable, opt('editable')) && + !opt('disableResizing')) // TODO: make this like the other source options + ? "
" - : '') + + : + '' + ) + "
"; seg.left = left; seg.outerWidth = right - left; diff --git a/src/util.js b/src/util.js index d3f1f87..1a6a503 100644 --- a/src/util.js +++ b/src/util.js @@ -1,4 +1,6 @@ +fc.applyAll = applyAll; + /* Event Date Math -----------------------------------------------------------------------------*/ @@ -305,3 +307,64 @@ function setDayID(cell, date) { } +function getSkinCss(event, opt) { + var source = event.source; + var eventColor = event.color; + var sourceColor = source.color; + var optionColor = opt('eventColor'); + var backgroundColor = + event.backgroundColor || + eventColor || + source.backgroundColor || + sourceColor || + opt('eventBackgroundColor') || + optionColor; + var borderColor = + event.borderColor || + eventColor || + source.borderColor || + sourceColor || + opt('eventBorderColor') || + optionColor; + var textColor = + event.textColor || + source.textColor || + opt('textColor'); + var statements = []; + if (backgroundColor) { + statements.push('background-color:' + backgroundColor); + } + if (borderColor) { + statements.push('border-color:' + borderColor); + } + if (textColor) { + statements.push('color:' + textColor); + } + return statements.join(';'); +} + + +function applyAll(functions, thisObj, args) { + if ($.isFunction(functions)) { + functions = [ functions ]; + } + if (functions) { + var i; + var ret; + for (i=0; i + + + + + + + + +
+ +