-
Notifications
You must be signed in to change notification settings - Fork 16
/
fullCalendarUrweb.js
230 lines (196 loc) · 6.72 KB
/
fullCalendarUrweb.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
function uw_fullcalendar_refresh(cal) {
t = cal.view.type;
if (cal.view.type == 'timeGridWeek')
cal.changeView('timeGridDay');
else
cal.changeView('timeGridWeek');
cal.changeView(t);
}
function fctimein(tm) {
return Math.round(tm / 1000);
}
function fctimeout(tm) {
return tm.getTime() * 1000;
}
function uw_fullcalendar_replace(id, settings) {
var node = document.getElementById(id);
if (node) {
var props = {
plugins: [ 'interaction', 'dayGrid', 'timeGrid' ],
header: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
editable: settings["_OnDrop"] != null,
defaultView: 'timeGridWeek',
navLinks: true,
selectable: settings["_OnSelect"] != null,
selectMirror: settings["_OnSelect"] != null,
// minTime: "06:00:00",
allDaySlot: settings["_AllDaySlot"],
nowIndicator: true
};
if (settings["_SlotDuration"])
props.slotDuration = settings["_SlotDuration"];
if (settings["_SnapDuration"])
props.snapDuration = settings["_SnapDuration"];
if (settings["_DefaultDate"])
props.defaultDate = fctimein(settings["_DefaultDate"]);
if (settings["_OnSelect"])
props.select = function(arg) {
execF(execF(execF(settings["_OnSelect"],
fctimeout(arg.start)),
fctimeout(arg.end)),
null);
};
if (settings["_OnDrop"])
props.eventDrop = function(arg) {
execF(execF(execF(settings["_OnDrop"],
arg.oldEvent),
arg.event),
null);
};
if (settings["_Content"])
props.eventRender = function(arg) {
if (arg.isMirror)
return;
if (arg.event.rendering && arg.event.title)
arg.el.innerText = arg.event.title;
var r = execF(execF(settings["_Content"], arg.event), null);
var cls = {v : null};
var html = flatten(cls, r["_Header"]);
var span = document.createElement("span");
span.closures = cls.v;
span.innerHTML = html;
var node = arg.el.querySelector('.fc-time');
if (node) {
node.appendChild(span);
runScripts(span);
}
cls = {v : null};
html = flatten(cls, r["_Body"]);
span = document.createElement("span");
span.closures = cls.v;
span.innerHTML = html;
node = arg.el.querySelector('.fc-content');
if (node) {
node.appendChild(span);
runScripts(span);
}
};
else
props.eventRender = function(arg) {
if (arg.event.rendering && arg.event.title)
arg.el.innerText = arg.event.title;
}
var cal = new FullCalendar.Calendar(node, props);
cal.render();
var setSize = function() {
if ($(node).is(':visible'))
uw_fullcalendar_refresh(cal);
else
window.setTimeout(setSize, 500);
};
setSize();
return cal;
} else er("FullCalendar: couldn't find location of calendar");
}
function fceventin(data) {
var edata = {allDay: data["_AllDay"],
start: fctimein(data["_Start"]),
title : data["_Title"]};
if (data["_Id"]) edata.id = data["_Id"];
if (data["_End"]) edata.end = fctimein(data["_End"]);
if (data["_Rendering"] != "Normal") {
if (data["_Rendering"] == "Background")
edata.rendering = "background";
else
edata.rendering = "inverse-background";
}
return edata;
}
var fctextcolor_cache_valid = false;
var fctextcolor_cache = null;
function fctextcolor() {
if (fctextcolor_cache_valid)
return fctextcolor_cache;
fctextcolor_cache_valid = true;
var styleSheets = window.document.styleSheets;
for (var i = 0; i < styleSheets.length; i++) {
var classes = null;
try {
classes = styleSheets[i].rules || styleSheets[i].cssRules;
} catch (e) { }
if (!classes)
continue;
for (var x = 0; x < classes.length; x++) {
if (classes[x].selectorText == '.fc-text-color') {
fctextcolor_cache = classes[x].style.color;
return fctextcolor_cache;
}
}
}
}
function fceventpost(data, ev) {
if (data["_TextColor"])
listen(data["_TextColor"],
function(v) { ev.setProp('textColor', v || fctextcolor()); });
else
ev.setProp('textColor', fctextcolor());
if (data["_BackgroundColor"]) listen(data["_BackgroundColor"],
function(v) { ev.setProp('backgroundColor', v); });
}
function fceventpostCopout(data, dataOut) {
if (data["_TextColor"])
dataOut['textColor'] = scur(data["_TextColor"]) || fctextcolor();
else
dataOut['textColor'] = fctextcolor();
if (data["_BackgroundColor"])
dataOut['backgroundColor'] = scur(data["_BackgroundColor"]);
}
function uw_fullcalendar_events(cal) {
var out = null, evs = cal.getEvents();
for (var i = evs.length - 1; i >= 0; --i)
out = {"_1": evs[i], "_2": out};
return out;
}
function uw_fullcalendar_addEvent(cal, data) {
var ev = cal.addEvent(fceventin(data));
fceventpost(data, ev);
return ev;
}
function uw_fullcalendar_addEvents(cal, datas) {
var evs = [];
for (; datas; datas = datas["_2"]) {
var data = datas["_1"];
var dataOut = fceventin(data);
fceventpostCopout(data, dataOut);
evs.push(dataOut);
}
cal.addEventSource(evs);
return null;
}
function uw_fullcalendar_removeEvent(ev) {
ev.remove();
}
function uw_fullcalendar_eventStart(ev) {
return fctimeout(ev.start);
}
function uw_fullcalendar_eventTitle(ev) {
return ev.title;
}
function uw_fullcalendar_eventRendering(ev) {
return (ev.rendering == "background" ? "Background"
: ev.rendering == "inverse-background" ? "InverseBackground"
: "Normal");
}
function uw_fullcalendar_eventId(ev) {
return ev.id;
}
function uw_fullcalendar_getEventById(cal, id) {
return cal.getEventById(id);
}
function uw_fullcalendar_unselect(cal) {
cal.unselect();
}