mirror of
https://github.com/wassname/fullcalendar.git
synced 2026-09-09 11:22:41 +08:00
Rendering resource events now works for slots - all day events still to do
This commit is contained in:
+1
-4
@@ -35,10 +35,7 @@ function Calendar(element, options, eventSources) {
|
||||
var isFetchNeeded = t.isFetchNeeded;
|
||||
var fetchEvents = t.fetchEvents;
|
||||
|
||||
var resourceSources;
|
||||
ResourceManager.call(t, options, resourceSources);
|
||||
//var fetchResources = t.fetchResources;
|
||||
|
||||
ResourceManager.call(t, options);
|
||||
|
||||
// locals
|
||||
var _element = element[0];
|
||||
|
||||
+57
-67
@@ -1,23 +1,16 @@
|
||||
function ResourceManager(options) {
|
||||
var t = this;
|
||||
|
||||
// exports
|
||||
var t = this;
|
||||
// exports
|
||||
t.fetchResources = fetchResources;
|
||||
|
||||
// locals
|
||||
var resources = [];
|
||||
var cache = [];
|
||||
|
||||
_addResourceSources(options.resources);
|
||||
|
||||
/**
|
||||
* ----------------------------------------------------------------
|
||||
* Categorize and add the provided sources
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
function _addResourceSources(sources) {
|
||||
// locals
|
||||
var resourceSources = [];
|
||||
var cache;
|
||||
// initialize the resources.
|
||||
addResourceSources(options.resources);
|
||||
// add the resource sources
|
||||
|
||||
function addResourceSources(sources) {
|
||||
var resource = {};
|
||||
|
||||
if ($.isFunction(sources)) {
|
||||
// is it a function?
|
||||
resource = {
|
||||
@@ -27,100 +20,97 @@ function ResourceManager(options) {
|
||||
} else if (typeof sources == 'string') {
|
||||
// is it a URL string?
|
||||
resource = {
|
||||
url: sources
|
||||
url: sources
|
||||
};
|
||||
resources.push(resource);
|
||||
} else if (typeof sources == 'object') {
|
||||
// is it json object?
|
||||
for (var i=0; i<sources.length; i++) {
|
||||
var s = sources[i];
|
||||
normalizeSource(s);
|
||||
resource = {
|
||||
resources: s
|
||||
};
|
||||
resources.push(resource);
|
||||
for (var i = 0; i < sources.length; i++) {
|
||||
var s = sources[i];
|
||||
normalizeSource(s);
|
||||
resource = {
|
||||
resources: s
|
||||
};
|
||||
resourceSources.push(resource);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* ----------------------------------------------------------------
|
||||
* Fetch resources from source array
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* ----------------------------------------------------------------
|
||||
* Fetch resources from source array
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
function fetchResources(useCache, currentView) {
|
||||
function fetchResources(useCache, currentView) {
|
||||
// if useCache is not defined, default to true
|
||||
useCache = useCache || true;
|
||||
|
||||
if (useCache) {
|
||||
useCache = (typeof useCache !== 'undefined' ? useCache : true);
|
||||
if (cache != undefined && useCache) {
|
||||
// get from cache
|
||||
return cache;
|
||||
} else {
|
||||
// do a fetch resource from source, rebuild cache
|
||||
cache = [];
|
||||
var len = resources.length;
|
||||
var len = resourceSources.length;
|
||||
for (var i = 0; i < len; i++) {
|
||||
var resources = _fetchResourceSource(resources[i], currentView);
|
||||
cache = cache.concat(resources);
|
||||
var resources = fetchResourceSource(resourceSources[i], currentView);
|
||||
cache = cache.concat(resources);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* ----------------------------------------------------------------
|
||||
* Fetch resources from each source. If source is a function, call
|
||||
* the function and return the resource. If source is a URL, get
|
||||
* the data via synchronized ajax call. If the source is an
|
||||
* object, return it as is.
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* ----------------------------------------------------------------
|
||||
* Fetch resources from each source. If source is a function, call
|
||||
* the function and return the resource. If source is a URL, get
|
||||
* the data via synchronized ajax call. If the source is an
|
||||
* object, return it as is.
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
function _fetchResourceSource(source, currentView) {
|
||||
function fetchResourceSource(source, currentView) {
|
||||
var resources = source.resources;
|
||||
|
||||
if (resources) {
|
||||
if ($.isFunction(resources)) {
|
||||
return resources();
|
||||
return resources();
|
||||
}
|
||||
} else {
|
||||
var url = source.url;
|
||||
if (url) {
|
||||
var data={};
|
||||
var data = {};
|
||||
if (typeof currentView === 'object') {
|
||||
var startParam = options.startParam;
|
||||
var endParam = options.endParam;
|
||||
if (startParam) {
|
||||
data[startParam] = Math.round(+currentView.visStart / 1000);
|
||||
data[startParam] = Math.round(+currentView.visStart / 1000);
|
||||
}
|
||||
if (endParam) {
|
||||
data[endParam] = Math.round(+currentView.visEnd / 1000);
|
||||
data[endParam] = Math.round(+currentView.visEnd / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
$.ajax($.extend({}, source, {
|
||||
data: data,
|
||||
dataType: 'json',
|
||||
cache: false,
|
||||
success: function(res) {
|
||||
res = res || [];
|
||||
resources = res;
|
||||
success: function (res) {
|
||||
res = res || [];
|
||||
resources = res;
|
||||
},
|
||||
error: function() {
|
||||
alert("ajax error getting json from "+url);
|
||||
error: function () {
|
||||
alert("ajax error getting json from " + url);
|
||||
},
|
||||
async: false // too much work coordinating callbacks so dumb it down
|
||||
async: false // too much work coordinating callbacks so dumb it down
|
||||
}));
|
||||
}
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
/**
|
||||
* ----------------------------------------------------------------
|
||||
* normalize the source object
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* ----------------------------------------------------------------
|
||||
* normalize the source object
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
function normalizeSource(source) {
|
||||
function normalizeSource(source) {
|
||||
if (source.className) {
|
||||
if (typeof source.className == 'string') {
|
||||
source.className = source.className.split(/\s+/);
|
||||
@@ -129,8 +119,8 @@ function ResourceManager(options) {
|
||||
source.className = [];
|
||||
}
|
||||
var normalizers = fc.sourceNormalizers;
|
||||
for (var i=0; i<normalizers.length; i++) {
|
||||
for (var i = 0; i < normalizers.length; i++) {
|
||||
normalizers[i](source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,40 +1,27 @@
|
||||
|
||||
fcViews.resourceDay = ResourceDayView;
|
||||
|
||||
|
||||
function ResourceDayView(element, calendar) {
|
||||
var t = this;
|
||||
|
||||
|
||||
// exports
|
||||
t.render = render;
|
||||
|
||||
|
||||
// imports
|
||||
ResourceView.call(t, element, calendar, 'resourceDay');
|
||||
var opt = t.opt;
|
||||
var renderResource = t.renderResource;
|
||||
//var skipHiddenDays = t.skipHiddenDays;
|
||||
var formatDate = calendar.formatDate;
|
||||
var getResources = t.getResources;
|
||||
|
||||
function render(date, delta) {
|
||||
var t = this;
|
||||
// exports
|
||||
t.render = render;
|
||||
// imports
|
||||
ResourceView.call(t, element, calendar, 'resourceDay');
|
||||
var opt = t.opt;
|
||||
var renderResource = t.renderResource;
|
||||
//var skipHiddenDays = t.skipHiddenDays;
|
||||
var formatDate = calendar.formatDate;
|
||||
var getResources = t.getResources;
|
||||
|
||||
if (delta) {
|
||||
addDays(date, delta);
|
||||
}
|
||||
//skipHiddenDays(date, delta < 0 ? -1 : 1);
|
||||
|
||||
var start = cloneDate(date, true);
|
||||
var end = addDays(cloneDate(start), 1);
|
||||
|
||||
t.title = formatDate(date, opt('titleFormat'));
|
||||
|
||||
t.start = t.visStart = start;
|
||||
t.end = t.visEnd = end;
|
||||
|
||||
renderResource(getResources.length);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
function render(date, delta) {
|
||||
if (delta) {
|
||||
addDays(date, delta);
|
||||
}
|
||||
//skipHiddenDays(date, delta < 0 ? -1 : 1);
|
||||
var start = cloneDate(date, true);
|
||||
var end = addDays(cloneDate(start), 1);
|
||||
t.title = formatDate(date, opt('titleFormat'));
|
||||
t.start = t.visStart = start;
|
||||
t.end = t.visEnd = end;
|
||||
renderResource(getResources.length);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
+752
-892
File diff suppressed because it is too large
Load Diff
Vendored
BIN
Binary file not shown.
@@ -122,34 +122,34 @@
|
||||
// }
|
||||
// },
|
||||
defaultView: 'resourceDay',
|
||||
resources: [{"id":"resource1","name":"Resource 1"},{"id":"resource2", "name":"Resource 2"}],
|
||||
resources: [{"id":"resource1","name":"Resource 1"},{"id":"resource2", "name":"Resource 2"},{"id":"resource3", "name":"Resource 3"}],
|
||||
events: [
|
||||
{
|
||||
title: 'Lunch 12.15-14.45',
|
||||
title: 'R1-R2: Lunch 12.15-14.45',
|
||||
start: new Date(y, m, d, 12, 15),
|
||||
end: new Date(y, m, d, 14, 45),
|
||||
allDay: false,
|
||||
resource: ['resource1','resource2']
|
||||
},
|
||||
{
|
||||
title: 'Meeting from this day to this +4',
|
||||
title: 'R1: All day',
|
||||
start: new Date(y, m, d, 10, 30),
|
||||
end: new Date(y, m, d, 11, 00),
|
||||
allDay: false,
|
||||
allDay: true,
|
||||
resource: 'resource1'
|
||||
},
|
||||
{
|
||||
title: 'Meeting 11.00',
|
||||
start: new Date(y, m-2, d, 11, 00),
|
||||
allDay: true,
|
||||
title: 'R2: Meeting 11.00',
|
||||
start: new Date(y, m, d, 11, 00),
|
||||
allDay: false,
|
||||
resource: 'resource2'
|
||||
},
|
||||
{
|
||||
title: 'Lunch 12-14',
|
||||
title: 'R1/R2: Lunch 12-14',
|
||||
start: new Date(y, m, d, 12, 0),
|
||||
end: new Date(y, m, d, 14, 0),
|
||||
allDay: false,
|
||||
resource: 'resource1'
|
||||
resource: ['resource1','resource2']
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user