mirror of
https://github.com/wassname/fullcalendar.git
synced 2026-06-27 16:10:13 +08:00
Merge pull request #23 from KirkeWeb/resourceView
Adds resourceFilter option
This commit is contained in:
+110
-61
@@ -1,9 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset='utf-8' />
|
||||
<link href='../dist/fullcalendar.css' rel='stylesheet' />
|
||||
<link href='../dist/fullcalendar.print.css' rel='stylesheet' media='print' />
|
||||
<meta charset='utf-8'/>
|
||||
<link href='../dist/fullcalendar.css' rel='stylesheet'/>
|
||||
<link href='../dist/fullcalendar.print.css' rel='stylesheet' media='print'/>
|
||||
<style type="text/css">
|
||||
body {
|
||||
margin: 5px;
|
||||
@@ -13,6 +13,19 @@
|
||||
background-color: #ffffff;
|
||||
}
|
||||
|
||||
form {
|
||||
background-color: #444;
|
||||
color: #fff;
|
||||
width: 500px;
|
||||
margin: auto;
|
||||
white-space: pre-line;
|
||||
padding: 15px 30px;
|
||||
}
|
||||
|
||||
input {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.red {
|
||||
background-color: rgb(255, 190, 190);
|
||||
}
|
||||
@@ -23,7 +36,7 @@
|
||||
<script src='../dist/fullcalendar.js'></script>
|
||||
<script>
|
||||
|
||||
$(document).ready(function() {
|
||||
$(document).ready(function () {
|
||||
var date = new Date();
|
||||
var d = date.getDate();
|
||||
var m = date.getMonth();
|
||||
@@ -38,70 +51,95 @@
|
||||
defaultView: 'resourceDay',
|
||||
editable: true,
|
||||
droppable: true,
|
||||
resources: [{
|
||||
'id': 'resource1',
|
||||
'name': 'Resource 1'
|
||||
}, {
|
||||
'id': 'resource2',
|
||||
'name': 'Resource 2'
|
||||
}, {
|
||||
'id': 'resource3',
|
||||
'name': 'Resource 3',
|
||||
'className': ['red']
|
||||
}],
|
||||
events: [{
|
||||
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,
|
||||
resources: ['resource1', 'resource2']
|
||||
}, {
|
||||
title: 'R1: All day',
|
||||
start: new Date(y, m, d, 10, 30),
|
||||
end: new Date(y, m, d, 11, 0),
|
||||
allDay: true,
|
||||
resources: 'resource1'
|
||||
}, {
|
||||
title: 'R2: Meeting 11.00',
|
||||
start: new Date(y, m, d, 11, 0),
|
||||
allDay: true,
|
||||
resources: 'resource2'
|
||||
}, {
|
||||
title: 'R1/R2: Lunch 12-14',
|
||||
start: new Date(y, m, d, 12, 0),
|
||||
end: new Date(y, m, d, 14, 0),
|
||||
allDay: false,
|
||||
resources: ['resource1', 'resource2']
|
||||
}, {
|
||||
id: 777,
|
||||
title: 'Lunch',
|
||||
start: new Date(y, m, d, 12, 0),
|
||||
end: new Date(y, m, d, 14, 0),
|
||||
allDay: false,
|
||||
resources: ['resource1']
|
||||
}, {
|
||||
id: 999,
|
||||
title: 'Repeating Event',
|
||||
start: new Date(y, m, d - 3, 16, 0),
|
||||
allDay: false,
|
||||
resources: 'resource2'
|
||||
}, {
|
||||
id: 999,
|
||||
title: 'Repeating Event',
|
||||
start: new Date(y, m, d + 4, 16, 0),
|
||||
allDay: false,
|
||||
resources: 'resource2'
|
||||
}],
|
||||
resources: [
|
||||
{
|
||||
'id': 'resource1',
|
||||
'name': 'Resource 1'
|
||||
},
|
||||
{
|
||||
'id': 'resource2',
|
||||
'name': 'Resource 2'
|
||||
},
|
||||
{
|
||||
'id': 'resource3',
|
||||
'name': 'Resource 3',
|
||||
'className': ['red']
|
||||
}
|
||||
],
|
||||
resourceFilter: function (resource) {
|
||||
var active = $("input").map(function(){
|
||||
return this.checked ? this.name : null;
|
||||
}).get();
|
||||
return $.inArray(resource.id, active) > -1;
|
||||
},
|
||||
events: [
|
||||
{
|
||||
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,
|
||||
resources: ['resource1', 'resource2']
|
||||
},
|
||||
{
|
||||
title: 'R1: All day',
|
||||
start: new Date(y, m, d, 10, 30),
|
||||
end: new Date(y, m, d, 11, 0),
|
||||
allDay: true,
|
||||
resources: 'resource1'
|
||||
},
|
||||
{
|
||||
title: 'R2: Meeting 11.00',
|
||||
start: new Date(y, m, d, 11, 0),
|
||||
allDay: true,
|
||||
resources: 'resource2'
|
||||
},
|
||||
{
|
||||
title: 'R1/R2: Lunch 12-14',
|
||||
start: new Date(y, m, d, 12, 0),
|
||||
end: new Date(y, m, d, 14, 0),
|
||||
allDay: false,
|
||||
resources: ['resource1', 'resource2']
|
||||
},
|
||||
{
|
||||
id: 777,
|
||||
title: 'R1: Lunch',
|
||||
start: new Date(y, m, d, 12, 0),
|
||||
end: new Date(y, m, d, 14, 0),
|
||||
allDay: false,
|
||||
resources: ['resource1']
|
||||
},
|
||||
{
|
||||
title: 'R3: Breakfast',
|
||||
start: new Date(y, m, d, 8, 0),
|
||||
end: new Date(y, m, d, 8, 30),
|
||||
allDay: false,
|
||||
resources: ['resource3']
|
||||
},
|
||||
{
|
||||
id: 999,
|
||||
title: 'Repeating Event',
|
||||
start: new Date(y, m, d - 3, 16, 0),
|
||||
allDay: false,
|
||||
resources: 'resource2'
|
||||
},
|
||||
{
|
||||
id: 999,
|
||||
title: 'Repeating Event',
|
||||
start: new Date(y, m, d + 4, 16, 0),
|
||||
allDay: false,
|
||||
resources: 'resource2'
|
||||
}
|
||||
],
|
||||
// the 'ev' parameter is the mouse event rather than the resource 'event'
|
||||
// the ev.data is the resource column clicked upon
|
||||
selectable: true,
|
||||
selectHelper: true,
|
||||
select: function(start, end, ev) {
|
||||
select: function (start, end, ev) {
|
||||
console.log(start);
|
||||
console.log(end);
|
||||
console.log(ev.data); // resources
|
||||
},
|
||||
eventClick: function(event) {
|
||||
eventClick: function (event) {
|
||||
console.log(event);
|
||||
},
|
||||
eventDrop: function (event, delta, revertFunc) {
|
||||
@@ -110,13 +148,19 @@
|
||||
});
|
||||
});
|
||||
|
||||
$(document).ready(function() {
|
||||
$('input:checkbox').change(function(){
|
||||
$('#calendar').fullCalendar('render');
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
<style>
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
|
||||
font-family: "Lucida Grande", Helvetica, Arial, Verdana, sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
@@ -128,7 +172,12 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<form>Select the resources you wanna filter:
|
||||
|
||||
<input name="resource1" type="checkbox" checked /> Resource 1
|
||||
<input name="resource2" type="checkbox" /> Resource 2
|
||||
<input name="resource3" type="checkbox" checked /> Resource 3
|
||||
</form>
|
||||
<div id='calendar'></div>
|
||||
|
||||
</body>
|
||||
|
||||
Vendored
+9
-5
@@ -2024,12 +2024,10 @@ function ResourceManager(options) {
|
||||
*/
|
||||
|
||||
function fetchResources(useCache, currentView) {
|
||||
var cache;
|
||||
// if useCache is not defined, default to true
|
||||
useCache = (typeof useCache !== 'undefined' ? useCache : true);
|
||||
if (cache !== undefined && useCache) {
|
||||
// get from cache
|
||||
return cache;
|
||||
} else {
|
||||
if (!useCache || cache === undefined) {
|
||||
// do a fetch resource from source, rebuild cache
|
||||
cache = [];
|
||||
var len = resourceSources.length;
|
||||
@@ -2037,8 +2035,13 @@ function ResourceManager(options) {
|
||||
var resources = fetchResourceSource(resourceSources[i], currentView);
|
||||
cache = cache.concat(resources);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
if($.isFunction(options.resourceFilter)) {
|
||||
return $.grep(cache, options.resourceFilter);
|
||||
}
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2108,6 +2111,7 @@ function ResourceManager(options) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
;;
|
||||
|
||||
fc.applyAll = applyAll;
|
||||
|
||||
Vendored
+2
-2
File diff suppressed because one or more lines are too long
@@ -48,12 +48,10 @@ function ResourceManager(options) {
|
||||
*/
|
||||
|
||||
function fetchResources(useCache, currentView) {
|
||||
var cache;
|
||||
// if useCache is not defined, default to true
|
||||
useCache = (typeof useCache !== 'undefined' ? useCache : true);
|
||||
if (cache !== undefined && useCache) {
|
||||
// get from cache
|
||||
return cache;
|
||||
} else {
|
||||
if (!useCache || cache === undefined) {
|
||||
// do a fetch resource from source, rebuild cache
|
||||
cache = [];
|
||||
var len = resourceSources.length;
|
||||
@@ -61,8 +59,13 @@ function ResourceManager(options) {
|
||||
var resources = fetchResourceSource(resourceSources[i], currentView);
|
||||
cache = cache.concat(resources);
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
if($.isFunction(options.resourceFilter)) {
|
||||
return $.grep(cache, options.resourceFilter);
|
||||
}
|
||||
|
||||
return cache;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,4 +134,4 @@ function ResourceManager(options) {
|
||||
normalizers[i](source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user