forked from geekbrit/ResCal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrc_resource.js
executable file
·78 lines (61 loc) · 1.86 KB
/
rc_resource.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
// Resource Class
// --------------
// Calendars are associated with one or more resources
// When a Calendar is rendered, it retrieves a list of Events from each
// associated Resource for each timeslot being rendered.
//
// Usage Models:
// 1: transient data initialized from static array loaded from server on startup
// 2: live Ajax retrieval / storage
// 3: live Ajax + localStorage for offline working
//--- TEST DATA -------------------------------------------------------
var init_resource = {
Room1:{title:"Orca",capacity:250,location:"Rochester North"},
Room2:{title:"Narwhal",capacity:50,location:"Rochester North"},
Room3:{title:"Walrus",capacity:500,location:"Rochester East"},
};
var init_resource_events = {
Room1:[0,1,2,3],
Room2:[4,5,6,7],
Room3:[8,9,10,11]
}
//--- END TEST DATA ---------------------------------------------------
//--- Application-specific event acceptance criteria
//--- Example - reject events if the resource does not have the required capacity
var resource_reject_event = function( event, t ){
if( event.attendance > t.attr.capacity ) {
return "This room does not have the capacity required for the event ("
+event.attendance+")";
}
else {
return false;
}
}
function Resource( resource_id, init_mode ) {
var t = this;
t.eventpool = [];
t.id = resource_id;
// initialization
switch( init_mode )
{
case 'localtest': {
t.attr = init_resource[resource_id];
t.eventpool = init_resource_events[resource_id];
break;
}
default: alert("unrecognized Resource initialization mode");
}
t.AddEvent = function( event ){
if( reason = resource_reject_event( Events[event], t ) ) {
}
else {
if( -1 == t.eventpool.indexOf(event) ){
insertIntoSortedList(event,t.eventpool,function(a,b){a.start-b.start})
}
}
}
t.MoveEvent = function( event, destination ){
}
return t;
}