-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
886 lines (745 loc) · 27.4 KB
/
Copy pathindex.html
File metadata and controls
886 lines (745 loc) · 27.4 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
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
<!DOCTYPE html>
<html>
<head>
<title>Maker Hub Equipment and Expertise Reservation System</title>
<base target="_top">
<?!= include("STYLESHEET"); ?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.5/jquery.fullpage.min.css" />
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.19.1/moment-with-locales.min.js"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.6.2/fullcalendar.min.js"
crossorigin="anonymous"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/3.6.2/fullcalendar.min.css" rel="stylesheet">
<link href="https://cdn.rawgit.com/xdan/datetimepicker/74389996/build/jquery.datetimepicker.min.css" rel="stylesheet">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullPage.js/2.9.5/jquery.fullpage.min.js"></script>
<script src="https://cdn.rawgit.com/thanashyam/2309671/raw/5168575d69cd84588c52aa183dbfb3d932b9d4f9/jquery.md5.js"></script>
<script src="https://cdn.rawgit.com/xdan/datetimepicker/74389996/build/jquery.datetimepicker.full.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="currentUserDisplay"><b>Logged in user</b>
<span class="currentUserNetid">Anonymous</span> :
<span class="currentUserName">Unknown User</span>
<!-- <span class="currentUserAccessLevel">Open Hours Only</span> -->
</div>
<div class="clientEnter"><b>Serving User:</b>
<input size="10" id="clientNetIdEnter" name="clientNetId" placeholder="Net ID"/>
<button class="clientLookup">Lookup</button>
<img src="https://loading.io/spinners/gears/lg.dual-gear-loading-icon.gif" width="32" class="clientLoadingGif" style="display:none;">
</div>
<div class="clientDisplay"><b>Serving:</b>
<span class="clientNetid">Anonymous</span> :
<span class="clientUserName">Unknown User</span> : Access
<span class="clientUserAccessLevel">Unknown</span>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div id="accordion" role="tablist">
<div class="card">
<div class="card-header" role="tab" id="headingOne">
<h5 class="mb-0">
<a class="collapsed" data-toggle="collapse" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
Reserve equipment
</a>
</h5>
</div>
<div id="collapseOne" class="collapse" role="tabpanel" aria-labelledby="headingOne">
<div class="card-body">
<ul class="equipment_list">
</ul>
</div>
</div>
<div class="card-header" role="tab" id="headingReservationUI_e">
<h5 class="mb-0">
<a class="collapsed" data-toggle="collapse" href="#collapseReservationUI_e" aria-expanded="false" aria-controls="collapseReservationUI_e">
<!-- Reservation UI-->
</a>
</h5>
</div>
<div id="collapseReservationUI_e" class="collapse" role="tabpanel" aria-labelledby="headingReservationUI_s">
<div class="card-body">
<B>Reservation for:</b> <span class="equipmentToReserveName"></span><BR/>
<span class="ifAccessClosedHours notes">Because you have keycode access to the Maker Hub, you can reserve equipment for any time the library is open.</span>
<span class="ifNotAccessClosedHours notes">As a visitor, you can reserve equipment for hours the Maker Hub is open. Reservations for 3D Printers must START during open hours.</span>
<BR>
<b>From:</b> <input id="equipmentReservationStartTime" type="text">
<BR>
<b>To:</b> <input id="equipmentReservationEndTime" type="text">
<br>
<button id="createEquipmentReservation">Create Reservation</button>
</div>
</div>
</div>
<div class="card">
<div class="card-header" role="tab" id="headingTwo">
<h5 class="mb-0">
<a class="collapsed" data-toggle="collapse" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Reserve an expert
</a>
</h5>
</div>
<div id="collapseTwo" class="collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="card-body">
<ul class="merit_badge_list">
</ul>
</div>
</div>
</div>
</div>
</div>
<div class="col-md-8">
<div id="calendar">
</div>
</div>
</div>
<div class="row">
<div>
<pre class="event">
</pre>
</div>
</div>
</div>
<script>
// link: https://script.google.com/a/georgetown.edu/macros/s/AKfycbz9xcx_m-6LEez8cUlR59q4E-f4pnSMz1JwqFHZS_Rr/dev
var timezone = "local";
var defaultView= "agendaDay";
var curView = defaultView;
// refactor out
var staffMeritBadges = {};
var meritBadgeList = {};
var scheduleWithDeets = {};
// end refactor out
var calendarStartDate = false;
var calendarEndDate = false;
var selectedBadgeName = false;
var selectedBadgeScriptName = false;
var staffScheduleEventsFiltered = false;
var selectedReservationEquipmentName = false;
var selectedReservationEquipmentCategory = false;
var staffScheduleCalendarName = "Maker Hub Staff and Volunteer Schedule";
var staffScheduleEvents = false;
var equipmentReservationCalendarName = "";
var equipmentReservationEvents = false;
var staffConsultationCalendarName = "Georgetown Maker Hub Staff Consultation Calendar";
var staffConsultationEvents = false;
var staffAvailabilityEvents = false;
var meritBadgeIconList = false;
var staffChecklist = false;
var equipmentList = false;
var openHours = false;
var currentUser = {
isStaff : false,
accessClosedHours : false
}
var clientUser = {
isStaff : false,
accessClosedHours : false
}
var defaultClientUser = clientUser;
function gotCurrentUserNetId(netId){
$(".currentUserNetid").text(netId);
currentUser.netid = netId;
google.script.run.withSuccessHandler(function(data){
currentUser = data;
console.log("got user data");
console.log(currentUser);
if(currentUser.role && currentUser.role.trim() != "" && currentUser.role.toLowerCase() != "visitor"){
if(currentUser.role.toLowerCase() == "staff" ||
currentUser.role.toLowerCase() == "volunteer" ||
currentUser.role.toLowerCase() == "manager"){
currentUser.isStaff = true;
}
currentUser.accessClosedHours = true;
}
$(".currentUserName").text(currentUser.name);
$(".currentUserAccessLevel").text(currentUser.accessClosedHours ? "All Hours" : "Open Hours Only");
}).getUserTableDataFromNetId(netId);
}
function eventCreated(event){
console.log(event);
$(".event").text(JSON.stringify(event, null, ' '));
}
function clientLookupClicked(){
$(".clientLoadingGif").show();
clientNetId = $("#clientNetIdEnter").val();
console.log("clicked" + clientNetId);
clientUser = defaultClientUser;
google.script.run.withSuccessHandler(function(data){
clientUser = data;
console.log("got user data");
console.log(clientUser);
if(clientUser.role && clientUser.role.trim() != "" && clientUser.role.toLowerCase() != "visitor"){
if(clientUser.role.toLowerCase() == "staff" ||
clientUser.role.toLowerCase() == "volunteer" ||
clientUser.role.toLowerCase() == "manager"){
clientUser.isStaff = true;
}
clientUser.accessClosedHours = true;
}
$(".clientUserName").text(clientUser.name ? clientUser.name : "Unknown");
$(".clientNetid").text(clientUser.netid ? clientUser.netid : "Anonymous");
$(".clientUserAccessLevel").text(clientUser.accessClosedHours ? "All Hours" : "Open Hours Only");
$(".clientLoadingGif").hide();
if(clientUser.accessClosedHours){
$(".ifAccessClosedHours").show();
$(".ifNotAccessClosedHours").hide();
}else{
$(".ifAccessClosedHours").hide();
$(".ifNotAccessClosedHours").show();
}
}).getUserTableDataFromNetId(clientNetId);
}
// Get Data
// events
function getStaffScheduleEvents(startDate, endDate, callback){
console.log("start " + startDate.toString());
console.log("end " + endDate.toString());
google.script.run
.withFailureHandler(function(error){console.log(error);})
.withSuccessHandler(function(data){
console.log("got sse data");
console.log(data);
staffScheduleEvents = data;
if(callback){callback();}
}).getStaffScheduleEvents(startDate.toString(), endDate.toString());
}
function getStaffConsultationEvents(startDate, endDate, callback){
console.log("start " + startDate.toString());
console.log("end " + endDate.toString());
google.script.run
.withFailureHandler(function(error){console.log(error);})
.withSuccessHandler(function(data){
console.log("got sce data");
console.log(data);
staffConsultationEvents = data;
if(callback){callback();}
}).getStaffConsultationEvents(startDate.toString(), endDate.toString());
}
function getEquipmentReservationEvents(startDate, endDate, callback){
console.log("start " + startDate.toString());
console.log("end " + endDate.toString());
google.script.run
.withFailureHandler(function(error){console.log(error);})
.withSuccessHandler(function(data){
equipmentReservationEvents = data;
if(callback){callback();}
}).getEquipmentReservationEvents(startDate.toString(), endDate.toString());
}
// get other data
function getMeritBadgeIconList(callback){
google.script.run
.withFailureHandler(function(error){console.log(error);})
.withSuccessHandler(function(data){
meritBadgeIconList = data;
if(callback){callback();}
}).getMeritBadgeIconList();
}
function getStaffChecklist(callback){
google.script.run
.withFailureHandler(function(error){console.log(error);})
.withSuccessHandler(function(data){
staffChecklist = data;
if(callback){callback();}
}).getStaffChecklist();
}
function getOpenHours(callback){
google.script.run
.withFailureHandler(function(error){console.log(error);})
.withSuccessHandler(function(data){
openHours = data;
if(callback){callback();}
}).getOpenHours();
}
function getEquipmentList(callback){
google.script.run
.withFailureHandler(function(error){console.log(error);})
.withSuccessHandler(function(data){
equipmentList = data;
if(callback){callback();}
}).getEquipmentList();
}
// data munging
function reconcileStaffScheduleAndConsultations(callback){
// this involves some processing, splitting up staff availability events based on current consultation events.
staffAvailabilityEvents = {};
// look through staff consultation events,
// find all staff schedule events with same person
$.each(staffConsultationEvents, function(key, event){
var consultEventStart = new moment(event.startTime);
var consultEventEnd = new moment(event.endTime);
var staffEmail = event.guestList[0].email;
/*
staffEmail = "ahd48@georgetown.edu";
staffEmail = "da606@georgetown.edu";
staffEmail = "nbm28@georgetown.edu";
*/
var staffEvents = staffScheduleEvents.filter(function(a){
return a.guestList[0].email == staffEmail;
});
$.each(staffEvents, function(index, schedEvent){
var schedEventStart = new moment(schedEvent.startTime);
var schedEventEnd = new moment(schedEvent.endTime);
// compare dates
var overlap = false;
if(consultEventStart.unix() > schedEventStart.unix() && consultEventEnd.unix() < schedEventEnd.unix()){
overlap = "split";
}
if(consultEventStart.unix() <= schedEventStart.unix() && consultEventEnd.unix() < schedEventEnd.unix() && consultEventEnd.unix() > schedEventStart.unix() ){
overlap = "beginning";
}
if(consultEventStart.unix() > schedEventStart.unix() && consultEventStart.unix() < schedEventEnd.unix() && consultEventEnd.unix() >= schedEventEnd.unix() ){
overlap = "end";
}
if(consultEventStart.unix() <= schedEventStart.unix() && consultEventEnd.unix() >= schedEventEnd.unix()){
overlap = "total";
}
if(overlap == "beginning"){
// change start time of sched event to be same as end time of consult event
schedEvent.startTime = event.endTime;
}
if(overlap == "end"){
// change endTime of sched event to be same as start time of consult event
schedEvent.endTime = event.startTime;
}
if(overlap == "split"){
// we need to copy the sched event, then edit the dates
var newEvent = JSON.parse(JSON.stringify(schedEvent));
newEvent.startTime = event.endTime;
schedEvent.endTime = event.startTime;
staffScheduleEvents.push(newEvent);
}
if(overlap == "total"){
// we delete the entire event
schedEvent.deleteme = true;
}
});
});
staffScheduleEvents = staffScheduleEvents.filter(function(a){
return(!a.deleteme);
});
if (callback){
callback();
}
}
// filter staff schedule events based on requested badges and staff expertise
function filterStaffScheduleEventsbyBadges(callback){
console.log("filtering");
if(!selectedBadgeName){
staffScheduleEventsFiltered = true;
if(callback){
callback();
}
return;
}
var badgeNames = Object.keys(meritBadgeIconList);
var newEvents = staffScheduleEvents.filter(function(event){
try{
var staffId = event.guestList[0].email.split("@")[0];
console.log(staffId);
// get merit badges this person has.
var staffData = staffChecklist.checklistData.data.filter(function(a){
return a.NetId == staffId;
})[0];
var showhide = "hide";
$.each(meritBadgeIconList, function(badgeName){
if(staffData[badgeName]){
if(selectedBadgeName == badgeName){
showhide = "show";
}
}
});
if(showhide == "hide"){
return false;
}else{
return true;
}
}catch(e){
console.log("error in eventRendered loop: " + e);
}
});
staffScheduleEvents = newEvents;
staffScheduleEventsFiltered = true;
if(callback){
callback();
}
}
// render Data
function renderEvents(){
showEvents(staffScheduleEvents);
showEvents(equipmentReservationEvents);
showEvents(staffConsultationEvents);
showEvents(staffAvailabilityEvents);
}
function showMeritBadgeList(){
$.each(meritBadgeIconList, function(key, badge){
(function(_key, _badge){
var badgeElem = $("<li data-badgename='"+key+"' class='clickable'>"+key+"</li>").appendTo(".merit_badge_list");
$(badgeElem).click(function(event){
meritBadgeClicked(_key, _badge, event);
});
})(key, badge);
});
}
function showEquipmentList(){
$.each(equipmentList, function(cat_key, cat){
var cat_elem = $("<li data-category='"+cat_key+"'><span class='cat_name'>"+cat_key+"</span></li>").appendTo(".equipment_list");
var item_list = $("<ul></ul>").appendTo(cat_elem);
$.each(cat.items, function(item_name, item_data){
(function(_item_name, _item_list){
var item_elem = $("<li class='clickable' data-item='"+_item_name+"'>"+_item_name+"</li>").appendTo(_item_list);
$(item_elem).click(function(event){equipmentClicked(event);});
})(item_name, item_list);
});
});
}
function showEvents(events){
console.log("showEvents");
console.log(events);
$.each(events, function(key, event){
console.log(event);
var revent = {
id : event.id,
title: event.title,
start : event.startTime,
calendarName : event.calendarName,
end : event.endTime,
guestList : event.guestList,
staffId: event.staffId
};
console.log("showing event");
console.log(revent);
$("#calendar").fullCalendar('renderEvent', revent);
});
console.log($("#calendar"));
}
// UI interactions
var currentMeritBadgeClicked = false;
function meritBadgeClicked(name, badge, event){
console.log("meritBadgeClicked");
if(name == currentMeritBadgeClicked){
return;
}
currentMeritBadgeClicked = name;
var badgeScriptName = "badge_"+name.replace(/[^a-zA-Z]/g,"");
selectedBadgeName = name;
selectedBadgeScriptName = badgeScriptName;
console.log(name);
console.log(badgeScriptName);
console.log(badge);
console.log(event);
calendarNewRender();
}
function equipmentClicked(event){
console.log("equipmentClicked");
console.log(event);
var item_name = $(event.target).data("item");
var category = $(event.target).parent().parent().data("category");
selectedReservationEquipmentName = item_name;
selectedReservationEquipmentCategory = category;
console.log(category + " : " + item_name);
$("#collapseOne").collapse("hide");
$("#collapseReservationUI_e").collapse("show");
/*
Here let's have the UI that handles making an equipment reservation
*/
$("#createEquipmentReservation").prop("disabled", true);
var maybeEnableButton = function(){
console.log("maybe");
var startTouched = $('#equipmentReservationStartTime').data('touched');
var endTouched = $('#equipmentReservationEndTime').data('touched');
console.log(startTouched);
console.log(endTouched);
if(startTouched && endTouched){
var startdate = $('#equipmentReservationStartTime').datetimepicker('getValue');
var enddate = $('#equipmentReservationEndTime').datetimepicker('getValue');
if(startdate < enddate){
console.log("dates ok");
$("#createEquipmentReservation").prop("disabled", false);
}else{
console.log("dates in wrong order");
}
}
};
$("#equipmentReservationStartTime").change(function(){
$(this).data("touched", true);
maybeEnableButton()
});
$("#equipmentReservationEndTime").change(function(){
$(this).data("touched", true);
maybeEnableButton()
});
$("#createEquipmentReservation").click(function(){
console.log("creating reservation");
var startdate = $('#equipmentReservationStartTime').datetimepicker('getValue');
var enddate = $('#equipmentReservationEndTime').datetimepicker('getValue');
console.log(startdate);
console.log(enddate);
console.log(clientUser.netid);
console.log(selectedReservationEquipmentCategory);
console.log(selectedReservationEquipmentName);
});
$(".equipmentToReserveName").text(category + " : " + item_name);
}
function calendarNewRender(view, element){
//console.log(view.start.format('MMMM Do YYYY, h:mm:ss a'));
//console.log(view.end.format('MMMM Do YYYY, h:mm:ss a'));
// then get all the events in the time frame.
//console.log(element);
console.log("calendarNewRender");
$('#calendar').fullCalendar('removeEvents');
staffScheduleEvents = false;
equipmentReservationEvents = false;
staffConsultationEvents = false;
staffAvailabilityEvents = false;
staffScheduleEventsFiltered = false;
calendarStartDate = $('#calendar').fullCalendar('getDate');
calendarEndDate = $('#calendar').fullCalendar('getDate');
// adjust the reservation date window here as well, somehow...
console.log("curDate is " + calendarStartDate.format());
calendarEndDate.endOf("day");
calendarStartDate.startOf("day");
if(curView == "agendaDay"){
calendarEndDate.endOf("day");
calendarStartDate.startOf("day");
}
console.log("starrt");
console.log(calendarStartDate.toString());
console.log(calendarEndDate.toString());
getStaffConsultationEvents(calendarStartDate, calendarEndDate, maybeReconcileDates);
getStaffScheduleEvents(calendarStartDate, calendarEndDate, maybeReconcileDates);
getEquipmentReservationEvents(calendarStartDate, calendarEndDate, maybeShowEvents);
}
function eventRendered(event, element){
console.log("event rendered");
console.log(staffChecklist);
// $(element).append("<span>"+event.calendarName+"<span>");
if(event.calendarName == staffScheduleCalendarName){
var badgeNames = Object.keys(meritBadgeIconList);
try{
var staffId = event.guestList[0].email.split("@")[0];
console.log(staffId);
// get merit badges this person has.
var staffData = staffChecklist.checklistData.data.filter(function(a){
return a.NetId == staffId;
})[0];
var badgeNames = [];
var badgeScriptNames = [];
$.each(meritBadgeIconList, function(badgeName){
if(staffData[badgeName]){
badgeNames.push(badgeName);
badgeScriptNames.push("badge_"+badgeName.replace(/[^a-zA-Z]/g,""));
}
});
console.log(staffData);
console.log(badgeScriptNames);
$(element).append("<span class='merit-badge-list'>"+badgeNames.join(", ")+"</span>");
$(element).addClass(badgeScriptNames.join(" "));
$(element).addClass("badgedEvent");
}catch(e){
console.log("error in eventRendered loop: " + e);
}
}
if(event.calendarName == staffConsultationCalendarName){
}
if(event.calendarName == equipmentReservationCalendarName){
}
if(event.staffId){
}
}
// controls
function maybeReconcileDates(){
console.log("maybe reconcile?");
if(staffScheduleEvents && staffConsultationEvents && staffChecklist){
filterStaffScheduleEventsbyBadges(maybeShowEvents);
reconcileStaffScheduleAndConsultations(maybeShowEvents);
}else{
console.log(staffScheduleEvents);
console.log(staffConsultationEvents);
}
}
function maybeShowEvents(){
console.log("maybe?");
if(staffScheduleEvents &&
equipmentReservationEvents &&
staffConsultationEvents &&
staffAvailabilityEvents &&
meritBadgeIconList &&
staffScheduleEventsFiltered &&
staffChecklist){
console.log("will show events");
renderEvents();
}else{
console.log(staffScheduleEvents);
console.log(equipmentReservationEvents);
console.log(staffConsultationEvents);
console.log(staffAvailabilityEvents);
console.log(meritBadgeIconList);
console.log(staffChecklist);
}
}
// startup functions
function setupCalendarView(){
console.log("setupCalendarView");
$('#calendar').fullCalendar({
// put your options and callbacks here
viewRender : calendarNewRender,
defaultView: defaultView,
scrollTime : "11:00",
eventRender : eventRendered,
timezone : timezone
});
}
function setupDateTimePickers(){
var maxMinTimeLogic = function(seldate, context, _this){
var minTime = new Date();
minTime.setMinutes(0);
var maxTime = new Date();
maxTime.setMinutes(0);
var setMin = 0;
var setMax = 0;
console.log(clientUser);
if(clientUser.accessClosedHours ||
(context == "end" && selectedReservationEquipmentCategory && selectedReservationEquipmentCategory.match(/3D Printer/))){
console.log("open access");
setMin = minTime.setHours(0);
maxTime.setMinutes(59);
setMax = maxTime.setHours(23);
}else{
// get this days open hours:
var thisDate = new Date(seldate);
var dow = thisDate.getDay();
if(dow != 0){
console.log(openHours);
var keys = Object.keys(openHours);
var todayHoursIndex = keys.filter(function(day){
if(openHours[day].index == dow){
return true;
}
})[0];
var todayHours = openHours[todayHoursIndex];
setMin = minTime.setHours(todayHours.openHour);
maxTime.setMinutes(01)
setMax = maxTime.setHours(todayHours.closeHour);
}
}
console.log(seldate);
_this.setOptions({minTime:setMin, maxTime:setMax});
};
$("#equipmentReservationStartTime").datetimepicker({
step: 15,
allowBlank: true,
onSelectDate: function(seldate){
maxMinTimeLogic(seldate, "start", this)
},
onShow: function(seldate){
console.log("onshow");
maxMinTimeLogic(seldate, "start", this)
},
onClose: function(seldate){
console.log("close");
console.log(seldate);
},
validateOnBlur : false,
todayButton : true,
format: 'm/d/y g:i A',
formatTime: 'g:i A'
});
$("#equipmentReservationEndTime").datetimepicker({
step: 15,
allowBlank: true,
onSelectDate: function(seldate){
maxMinTimeLogic(seldate, "end", this)
},
onShow: function(seldate){
console.log("onshow");
maxMinTimeLogic(seldate, "end", this)
},
validateOnBlur : false,
todayButton : true,
format: 'm/d/y g:i A',
formatTime: 'g:i A'
});
}
$(function() {
moment().format();
// see https://fullcalendar.io/docs/utilities/Moment/
// see https://fullcalendar.io/docs/
google.script.run.withSuccessHandler(gotCurrentUserNetId).getNetId();
$(".clientLookup").click(clientLookupClicked);
$('#clientNetIdEnter').keydown(function (e){
if(e.keyCode == 13){
clientLookupClicked();
}
});
if(clientUser.accessClosedHours){
$(".ifAccessClosedHours").show();
$(".ifNotAccessClosedHours").hide();
}else{
$(".ifAccessClosedHours").hide();
$(".ifNotAccessClosedHours").show();
}
/*
google.script.run
.withSuccessHandler(eventCreated)
.withFailureHandler(function(error){console.log(error);})
.createStaffConsultationEvent(
"November 7, 2017, 18:00 ",
"November 7, 2017, 20:00 ",
"new title", "This is the description", ['dhu3']);
*/
//$('.collapse').collapse()
getOpenHours();
setupDateTimePickers();
getMeritBadgeIconList(showMeritBadgeList);
getEquipmentList(showEquipmentList);
getStaffChecklist(maybeShowEvents);
setupCalendarView();
});
// deprecate:
function processStaffScheduleByMeritBadges(startDate, endDate){
console.log("asking for badge schedule");
var gotStaffSchedulesByMeritBadge = function(data){
staffMeritBadges = {};
scheduleWithDeets = {};
var allEvents = {};
console.log("got staff schedules w/ badges");
console.log(data);
$.each(data, function(meritBadge, staffs){
$.each(staffs, function(staffId, deets){
if(!staffMeritBadges[staffId]){
staffMeritBadges[staffId] = {};
}
staffMeritBadges[staffId][meritBadge] = deets;
$.each(deets.schedule, function(index, event){
scheduleWithDeets[event.id] = {event : event, deets: deets};
event.staffId = staffId;
allEvents[event.id] = event ;
console.log(event);
});
// add meritBadgeImage to event
});
});
console.log(allEvents);
console.log(scheduleWithDeets);
console.log(staffMeritBadges);
showEvents(allEvents);
}
google.script.run
.withFailureHandler(function(error){console.log(error);})
.withSuccessHandler(gotStaffSchedulesByMeritBadge).organizeStaffByMeritBadges(startDate.toString(), endDate.toString());
}
</script>
</body>
</html>