-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootstrapFullCalendarPlugin.js
320 lines (283 loc) · 13.5 KB
/
bootstrapFullCalendarPlugin.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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
var fullCalendar = fullCalendar || {};
(function ($) {
"use strict";
fullCalendar.onSharepointReady = function () {
var showPopup = null;
if (showPopup == null)
showPopup = SP.UI.ModalDialog.showWaitScreenWithNoClose('Working on it...');
fullCalendar.loadCalendar($);
setTimeout(function () {
if (showPopup != null)
showPopup.close();
showPopup = null;
}, 1500);
};
fullCalendar.loadCalendar = function ($) {
var jsonData = fullCalendar.loadDataFromList('Calendar');
console.info(jsonData);
var options = {
events_source: function () {
return jsonData;
},
view: 'month',
tmpl_path: '/sites/PSSPEARDEV/SiteAssets/js/tmpls/',
tmpl_cache: false,
day: new Date().format('yyyy-MM-dd'),
onAfterEventsLoad: function (events) {
if (!events) {
return;
}
var list = $('#eventlist');
list.html('');
$.each(events, function (key, val) {
$(document.createElement('li'))
.html('<a href="' + val.url + '">' + val.title + '</a>')
.appendTo(list);
});
},
onAfterViewLoad: function (view) {
$('.page-header h3').text(this.getTitle());
$('.btn-group button').removeClass('active');
$('button[data-calendar-view="' + view + '"]').addClass('active');
},
classes: {
months: {
general: 'label'
}
}
};
var calendar;
$.getScript('../SiteAssets/js/calendar.js', function () {
calendar = $('#calendar').calendar(options);
$('.btn-group button[data-calendar-nav]').each(function () {
var $this = $(this);
$this.click(function (evt) {
evt.preventDefault();
calendar.navigate($this.data('calendar-nav'));
});
});
$('.btn-group button[data-calendar-view]').each(function () {
var $this = $(this);
$this.click(function (evt) {
evt.preventDefault();
calendar.view($this.data('calendar-view'));
});
});
$('#first_day').change(function () {
var value = $(this).val();
value = value.length ? parseInt(value) : null;
calendar.setOptions({
first_day: value
});
calendar.view();
});
$('#language').change(function () {
calendar.setLanguage($(this).val());
calendar.view();
});
$('#events-in-modal').change(function () {
var val = $(this).is(':checked') ? $(this).val() : null;
calendar.setOptions({
modal: val
});
});
$('#format-12-hours').change(function () {
var val = $(this).is(':checked') ? true : false;
calendar.setOptions({
format12: val
});
calendar.view();
});
$('#show_wbn').change(function () {
var val = $(this).is(':checked') ? true : false;
calendar.setOptions({
display_week_numbers: val
});
calendar.view();
});
$('#show_wb').change(function () {
var val = $(this).is(':checked') ? true : false;
calendar.setOptions({
weekbox: val
});
calendar.view();
});
$('#events-modal .modal-header, #events-modal .modal-footer').click(function (e) {
//e.preventDefault();
//e.stopPropagation();
});
});
};
fullCalendar.createJSONForCalendar = function (jsonData) {
//Ashish
//Fetch Category Data
var eventClasses = {};
fullCalendar.getListDataByFilter("Events-Category Master LIst", { $select: "Title,fullCalendarEventClass" }).success(function (data) {
//eventCategory = data.d.results;
$(".legendUl").empty();
$(data.d.results).each(function (i, o) {
var eventClass = "";
if (o.fullCalendarEventClass) {
eventClass = "event-" + o.fullCalendarEventClass.replace(/ /g, '').toLowerCase();
}
eventClasses[o.Title] = eventClass;
if ($('.legendUl .' + eventClass).length == 0)
$(".legendUl").append($('<li><span class="circleLegendOne ' + eventClass + '"></span><label class="label-legend">' + o.Title + '</label></li>'));
else {
var legendLabel = $('.legendUl .' + eventClass).next();
legendLabel.text(legendLabel.text() + ', ' + o.Title);
}
})
}).fail(function (error) {
console.error(error);
});
var sourceJSON = [],
displayMode = 'Display',
sourceUrl = encodeURIComponent(window.location.href);
if (typeof (sessionStorage["Admin"]) === "undefined" || typeof (sessionStorage["Event Admin"]) === "undefined") {
JCICommon.verifyCurrentUserGroup("Admin");
JCICommon.verifyCurrentUserGroup("Event Admin");
}
if (sessionStorage["Admin"] === "Yes" || sessionStorage["Event Admin"] === "Yes") {
displayMode = 'Edit';
}
for (var i = 0; i < jsonData.length; i++) {
var Id = parseInt(jsonData[i]['Id']),
Title = jsonData[i]['Title'],
startDate = jsonData[i]['EventDate'],
endDate = jsonData[i]['EndDate'],
category = jsonData[i]['fullCalendarEventsCategory']['Title'],
_startDate = new Date(startDate),
_endDate = new Date(endDate),
eventClass = eventClasses[category],
newJSON = [],
linkUrl = "../SitePages/Add%20Event.aspx?LID=" + Id + "&Form=" + displayMode + "&Source=" + sourceUrl;
//if (category === 'Meeting' || category === 'Work hours' || category === 'Business')
// eventClass = 'event-important'
//else if (category === 'Get-together' || category === 'Gifts' || category === 'Birthday' || category === 'Anniversary')
// eventClass = 'event-special'
//else if (category === 'Holiday')
// eventClass = 'event-success'
newJSON = { 'id': Id, 'title': Title, 'url': linkUrl, 'class': eventClass, 'start': _startDate.getTime(), 'end': _endDate.getTime() }
sourceJSON.push(newJSON);
}
return sourceJSON;
}
fullCalendar.loadDataFromList = function (listTitle) {
var Category = GetUrlKeyValue('c');
var StartDate = GetUrlKeyValue('d');
var FilterField1 = GetUrlKeyValue('FilterField1');
var FilterField2 = GetUrlKeyValue('FilterField2');
if (FilterField1) {
if (FilterField1 == "fullCalendarEventsCategory")
Category = GetUrlKeyValue('FilterValue1');
if (FilterField1 == "EventDate")
StartDate = GetUrlKeyValue('FilterValue1');
}
if (FilterField2) {
if (FilterField2 == "fullCalendarEventsCategory")
Category = GetUrlKeyValue('FilterValue2');
if (FilterField2 == "EventDate")
StartDate = GetUrlKeyValue('FilterValue2');
}
//console.log(Category + "\n" + StartDate);
var jsonData,
filterJSON = {
$select: 'Id,Title,fullCalendarEventsCategory/Title,fullCalendarEventsCategory/Id,EventDate,EndDate,ParticipantsPicker/Id,ParticipantsPicker/Title,Author/Id,Author/Title',
$expand: 'ParticipantsPicker,Author,fullCalendarEventsCategory'
},
filter = '( (ParticipantsPicker/Id eq ' + _spPageContextInfo.userId + ' or Author/Id eq ' + _spPageContextInfo.userId + ')';
if (!SP.ScriptUtility.isNullOrEmptyString(Category)) {
filter += "and fullCalendarEventsCategory/Title eq '" + Category + "'"
}
if (!SP.ScriptUtility.isNullOrEmptyString(filter)) {
filter += " )"
filterJSON['$filter'] = filter
}
fullCalendar.getListDataByFilter(listTitle, filterJSON)
.success(function (data) {
console.info(data);
jsonData = data.d.results
if (!SP.ScriptUtility.isNullOrEmptyString(StartDate)) {
jsonData = fullCalendar.filterJSONByDate(jsonData, StartDate)
}
})
.fail(function (error) {
console.error(error);
fullCalendar.errorNotify(listTitle, 'Error Occurred while fetching the data from ' + listTitle);
})
return fullCalendar.createJSONForCalendar(jsonData);
}
fullCalendar.filterJSONByDate = function (jsonData, filteredDate) {
var _filteredDate = new Date(filteredDate),
newJSONData = $(jsonData).filter(function (index, value) {
return (new Date(value['EventDate']) >= _filteredDate)
})
return newJSONData;
}
fullCalendar.errorNotify = function (messageTitle, message) {
try {
var notificationData = new SPStatusNotificationData("", STSHtmlEncode(message), "../SiteAssets/images/error_notify.png", null),
notification = new SPNotification(SPNotifications.ContainerID.Status, STSHtmlEncode(messageTitle), false, null, null, notificationData);
notification.Show(false);
} catch (e) {
console.error(e);
}
}
fullCalendar.successNotify = function (messageTitle, message) {
try {
var notificationData = new SPStatusNotificationData("", STSHtmlEncode(message), "../SiteAssets/images/success_notify.png", null),
notification = new SPNotification(SPNotifications.ContainerID.Status, STSHtmlEncode(messageTitle), false, null, null, notificationData);
notification.Show(false);
} catch (e) {
console.error(e);
}
}
$(document).ready(function () {
SP.SOD.loadMultiple(['sp.js', 'sp.ui.dialog.js'], fullCalendar.onSharepointReady);
// if (typeof (sessionStorage["Admin"]) === "undefined" ||
// typeof (sessionStorage["HR Scorecard Admin"]) === "undefined" ||
// typeof (sessionStorage["HR Scorecard User"]) === "undefined" ||
// typeof (sessionStorage["Document User"]) === "undefined" ||
// typeof (sessionStorage["Document Admin"]) === "undefined" ||
// typeof (sessionStorage["Task User"]) === "undefined" ||
// typeof (sessionStorage["Task Admin"]) === "undefined" ||
// typeof (sessionStorage["Event User"]) === "undefined" ||
// typeof (sessionStorage["Event Admin"]) === "undefined") {
// JCICommon.verifyCurrentUserGroup("Admin");
// JCICommon.verifyCurrentUserGroup("HR Scorecard Admin");
// JCICommon.verifyCurrentUserGroup("HR Scorecard User");
// JCICommon.verifyCurrentUserGroup("Document User");
// JCICommon.verifyCurrentUserGroup("Document Admin");
// JCICommon.verifyCurrentUserGroup("Task User");
// JCICommon.verifyCurrentUserGroup("Task Admin");
// JCICommon.verifyCurrentUserGroup("Event User");
// JCICommon.verifyCurrentUserGroup("Event Admin");
// }
if (sessionStorage["Admin"] != "Yes") {
$('.ms-core-sideNavBox-removeLeftMargin').find('a[href*="/Users.aspx"]').hide();
$('.ms-core-sideNavBox-removeLeftMargin').find('a[href*="/Admin.aspx"]').hide();
}
if (!(sessionStorage['Admin'] === 'Yes' ||
sessionStorage['HR Scorecard Admin'] === 'Yes' ||
sessionStorage['HR Scorecard User'] === 'Yes')) {
$('.ms-core-sideNavBox-removeLeftMargin').find('a[href*="/HRScorecard.aspx"]').hide();
}
if (!(sessionStorage['Admin'] === 'Yes' ||
sessionStorage['Task User'] === 'Yes' ||
sessionStorage['Task Admin'] === 'Yes')) {
$('.ms-core-sideNavBox-removeLeftMargin').find('a[href*="/TasksPage.aspx"]').hide();
}
if (!(sessionStorage['Admin'] === 'Yes' ||
sessionStorage['Event User'] === 'Yes' ||
sessionStorage['Event Admin'] === 'Yes')) {
$('.ms-core-sideNavBox-removeLeftMargin').find('a[href*="/Events.aspx"]').hide();
}
if (!(sessionStorage['Admin'] === 'Yes' ||
sessionStorage['Document User'] === 'Yes' ||
sessionStorage['Document Admin'] === 'Yes')) {
$('.ms-core-sideNavBox-removeLeftMargin').find('a[href*="/Document Category.aspx"]').hide();
}
$('.menu-item-text:contains("Recycle Bin")').remove();
})
})(jQuery);