Calendar.js
9.08 KB
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import React from 'react';
import {
Row,
Col,
ButtonGroup,
Button,
} from 'reactstrap';
import 'fullcalendar/dist/fullcalendar';
import 'jquery-ui/ui/widgets/draggable';
import moment from 'moment/moment';
import $ from 'jquery';
import s from './Calendar.module.scss';
import Widget from '../../../../components/Widget';
class Calendar extends React.Component {
constructor(props) {
super(props);
this.state = {
calendarView: 'month',
currentMonth: moment().format('MMM YYYY'),
currentDay: moment().format('dddd'),
};
const date = new Date();
const d = date.getDate();
const m = date.getMonth();
const y = date.getFullYear();
this.calendarOptions = {
header: {
left: '',
center: '',
right: '',
},
events: [
{
title: 'All Day Event',
start: new Date(y, m, 1),
backgroundColor: '#79A5F0',
textColor: '#fff',
description: 'Will be busy throughout the whole day',
},
{
title: 'Long Event',
start: new Date(y, m, d + 5),
end: new Date(y, m, d + 7),
description: 'This conference should be worse visiting',
},
{
id: 999,
title: 'Blah Blah Car',
start: new Date(y, m, d - 3, 16, 0),
allDay: false,
description: 'Agree with this guy on arrival time',
},
{
id: 1000,
title: 'Buy this template',
start: new Date(y, m, d + 3, 12, 0),
allDay: false,
backgroundColor: '#555',
textColor: '#fff',
description: 'Make sure everything is consistent first',
},
{
title: 'Got to school',
start: new Date(y, m, d + 16, 12, 0),
end: new Date(y, m, d + 16, 13, 0),
backgroundColor: '#64bd63',
textColor: '#fff',
description: 'Time to go back',
},
{
title: 'Study some Node',
start: new Date(y, m, d + 18, 12, 0),
end: new Date(y, m, d + 18, 13, 0),
backgroundColor: '#79A5F0',
textColor: '#fff',
description: 'Node.js is a platform built ' +
'on Chrome\'s JavaScript runtime for easily' +
' building fast, scalable network applications.' +
' Node.js uses an event-driven, non-blocking' +
' I/O model that makes it lightweight and' +
' efficient, perfect for data-intensive real-time' +
' applications that run across distributed devices.',
},
{
title: 'Click for Flatlogic',
start: new Date(y, m, 28),
end: new Date(y, m, 29),
url: 'http://flatlogic.com/',
backgroundColor: '#e5603b',
textColor: '#fff',
description: 'Creative solutions',
},
],
selectable: true,
selectHelper: true,
select: (start, end, allDay) => {
this.createEvent = () => {
const title = this.event.title;
if (title) {
this.$calendar.fullCalendar('renderEvent',
{
title,
start,
end,
allDay,
backgroundColor: '#64bd63',
textColor: '#fff',
},
true, // make the event "stick"
);
}
this.$calendar.fullCalendar('unselect');
$('#create-event-modal').modal('hide');
};
$('#create-event-modal').modal('show');
},
eventClick: (event) => {
this.event = event;
$('#show-event-modal').modal('show');
},
editable: true,
droppable: true,
drop: (dateItem, event) => { // this function is called when something is dropped
// retrieve the dropped element's stored Event Object
const originalEventObject = {
// use the element's text as the event title
title: $.trim($(event.target).text()),
};
// we need to copy it, so that multiple events don't have a reference to the same object
const copiedEventObject = $.extend({}, originalEventObject);
// assign it the date that was reported
copiedEventObject.start = dateItem;
copiedEventObject.allDay = !dateItem.hasTime();
const $categoryClass = $(event.target).data('event-class');
if ($categoryClass) {
copiedEventObject.className = [$categoryClass];
}
// render the event on the calendar
// the last `true` argument determines if
// the event 'sticks'
// http://arshaw.com/fullcalendar/docs/event_rendering/renderEvent/)
this.$calendar.fullCalendar('renderEvent', copiedEventObject, true);
$(event.target).remove();
},
};
this.dragOptions = { zIndex: 999, revert: true, revertDuration: 0 };
this.prev = this.prev.bind(this);
this.next = this.next.bind(this);
this.today = this.today.bind(this);
this.changeView = this.changeView.bind(this);
this.getCurrentMonth = this.getCurrentMonth.bind(this);
this.getCurrentDay = this.getCurrentDay.bind(this);
}
componentDidMount() {
this.$calendar = $('#calendar');
this.$calendar.fullCalendar(this.calendarOptions);
$('.draggable').draggable(this.dragOptions);
}
getCurrentMonth() {
return moment(this.$calendar.fullCalendar('getDate')).format('MMM YYYY');
}
getCurrentDay() {
return moment(this.$calendar.fullCalendar('getDate')).format('dddd');
}
prev() {
this.$calendar.fullCalendar('prev');
}
next() {
this.$calendar.fullCalendar('next');
}
today() {
this.$calendar.fullCalendar('today');
}
changeView(view) {
this.$calendar.fullCalendar('changeView', view);
this.setState({ calendarView: view });
}
render() {
return (
<div className={s.root}>
<Row>
<Col lg={4} xs={12} md={6}>
<ol className="breadcrumb">
<li className="breadcrumb-item">YOU ARE HERE</li>
<li className="breadcrumb-item active">Calendar</li>
</ol>
<h1 className="page-title">
{this.state.currentMonth} - <span className="fw-semi-bold">{this.state.currentDay}</span>
</h1>
<h3>Draggable <span className="fw-semi-bold">Events</span></h3>
<p>Just drap and drop events from there directly into the calendar.</p>
<div className="calendar-external-events mb-lg">
<div className="external-event draggable" data-event-class="bg-success text-white">
<i className="fa fa-circle fa-fw text-success ml-xs mr-xs" />
Make a tea
</div>
<div className="external-event draggable" data-event-class="bg-warning text-white">
<i className="fa fa-circle fa-fw text-warning ml-xs mr-xs" />
Open windows
</div>
<div className="external-event draggable" data-event-class="bg-gray text-white">
<i className="fa fa-circle-o fa-fw text-gray-light ml-xs mr-xs" />
Some stuff
</div>
<div className="external-event draggable" data-event-class="bg-danger text-white">
<i className="fa fa-square fa-fw text-danger ml-xs mr-xs" />
Study UX engineering
</div>
<div className="external-event draggable" data-event-class="bg-gray text-white">
<i className="fa fa-circle-o fa-fw text-gray-light ml-xs mr-xs" />
Another stuff
</div>
</div>
</Col>
<Col md={6} lg={8} xs={12}>
<Widget>
<Row className="calendar-controls">
<Col md={3}>
<ButtonGroup className="mr-sm">
<Button color="default" onClick={this.prev}>
<i className="fa fa-angle-left" />
</Button>
<Button color="default" onClick={this.next}>
<i className="fa fa-angle-right" />
</Button>
</ButtonGroup>
</Col>
<Col md={9} className="calendar-controls text-right">
<ButtonGroup>
<Button
color="default" onClick={() => this.changeView('month')}
active={this.state.calendarView === 'month'}
>Month</Button>
<Button
color="default" onClick={() => this.changeView('agendaWeek')}
active={this.state.calendarView === 'agendaWeek'}
>Week</Button>
<Button
color="default" onClick={() => this.changeView('agendaDay')}
active={this.state.calendarView === 'agendaDay'}
>Day</Button>
</ButtonGroup>
</Col>
</Row>
<div id="calendar" className="calendar" />
</Widget>
</Col>
</Row>
</div>
);
}
}
export default Calendar;