forked from kchomacau/timetable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
2254 lines (1824 loc) · 56.6 KB
/
script.js
File metadata and controls
2254 lines (1824 loc) · 56.6 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
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var timetable = document.getElementById("timetable");
var template = timetable.innerHTML;
var finding_period = false;
var course_code_length = 8;
var course_sec_length = 3;
var default_block = {bg: "#d9d9d9", col: "#888888"}
// String.prototype.cleanup = function() {
// return this.toLowerCase().replace(/[^a-z]+/g, "");
// }
function checkTextOverflow(){
var spans = document.querySelectorAll(".day-col a span.text-marq");
var margin_px = 5;
var px_per_frame = 1;
for(var span of spans) {
var col_width = $(span.parentElement).width();
if((span.offsetWidth - 2) < col_width) {
$(span).removeClass("text-marq");
continue;
}
// if(span.innerHTML.length > 19) {
// should run
var left = margin_px;
if(span.style.left) {
left = (parseInt(span.style.left) - px_per_frame);
}
if(left < (col_width - margin_px - span.offsetWidth)) {
left = margin_px;
}
span.style.left = left + 'px';
// span.style.marginLeft = left < margin_px ? 0 : ((margin_px - left) + 'px');
span.style.visibility = (left === margin_px) ? 'hidden' : '';
// }
}
}
function isLab(obj) {
// if this session is a Lab class
if (obj.type ==="Lab") {
var countLab = 0;
// loop through courses list
for(var course of courses_info) {
// find Lab for this course
if(course.code === obj.code && course.type === "Lab") {
countLab++;
// if more than one, then OK.
if(countLab > 1){
break;
}
}
}
return (countLab > 1);
}
else {
return false;
}
}
function match_course(content, with_section){
if(with_section===true){
return content.match(/[A-Za-z]{4}[0-9]{3,4}((\/[0-9]{3})*)?( )?(\([0-9]{3}\))?/g);
}
return null; // content.match(/[A-Za-z]{4}[0-9]{3,4}[^\n]*/g);
}
function match_course_with_index(content) {
var result = [];
var regex = /[A-Za-z]{4}[0-9]{3,4}[^\n]*/g;
while((match = regex.exec(content)) !== null) {
result.push({
index: match.index,
info: match[0]
});
}
return result;
}
var courses = [
];
var allCourseMode = false;
var used_colors = {};
if(localStorage["coursesJson"]){
var tmp_courses = JSON.parse(localStorage["coursesJson"]);
var error_courses = [];
var looked_courses = [];
courses = [];
for(var i=0; i<tmp_courses.length; i++){
var this_courseCode = tmp_courses[i].code;
if(looked_courses.indexOf(this_courseCode)>-1){
continue;
}
looked_courses.push(this_courseCode);
var found = false;
for(var j=0; j<courses_info.length; j++){
if(courses_info[j].code === this_courseCode){
found = true;
var skipThisSection = false;
for(var k=0; k<tmp_courses.length; k++) {
if(tmp_courses[k].code === this_courseCode && tmp_courses[k].isRemoved) {
if(isLab(courses_info[j])
&& courses_info[j].start === tmp_courses[k].start
&& courses_info[j].day === tmp_courses[k].day) {
skipThisSection = true;
}
}
}
if(skipThisSection) {
var cloneObj = JSON.parse(JSON.stringify(courses_info[j]));
cloneObj.isRemoved = true;
courses.push(cloneObj);
}
else {
courses.push(courses_info[j]);
}
}
}
if(found === false && this_courseCode.trim() !== ""){
error_courses.push(this_courseCode);
}
}
if(error_courses.length > 0){
window.setTimeout(function(){
alert("以下課程可能已被取消或更改:" + error_courses.join(", "));
},1000);
}
}
var totalHeight = 600;
var lineHeight = 12;
var dayName = ["SUN","MON","TUE","WED","THU","FRI","SAT"];
var dayDisp = [
"日(Sun)",
"一(Mon)",
"二(Tue)",
"三(Wed)",
"四(Thu)",
"五(Fri)",
"六(Sat)"
];
var errorDiv = document.getElementById("error");
var courseListDiv = document.getElementById("courselist");
var earliest = undefined;
var latest = undefined;
var heightOf1Min = 0;
var wrapper = document.getElementById("wrapper");
wrapper.style.height = (totalHeight + 60) + "px";
var hasUrlParam = false;
var versions = [];
var cur_ver = -1;
var max_ver = cur_ver;
Object.size = function(obj) {
var size = 0, key;
for (key in obj) {
if(obj[key] !== undefined){
size++;
}
}
return size;
};
var studyPlanDiv = document.getElementById("study-plan");
var studyPlanLink = document.getElementById("studyplan-link");
studyPlanLink.style.display = "none";
var profBtn = 0;
var searched_umacinfo = {};
var studyPlanHeader = "<b><i class=\"fa fa-list-alt\" aria-hidden=\"true\"></i> 可選擇的課程列表 Available Courses List</b>";
var allSlotItems = [];
var blackListSlot = [];
var selectedCourseCount = 0;
function getSelectedCourseCodeList(){
var arr = [];
for(var i=0; i<courses.length; i++){
if(arr.indexOf(courses[i].code)===-1){
arr.push(courses[i].code);
}
}
return arr;
}
// function lockScrollToggle(){
// var body = document.getElementById("body");
// if(body.className === ""){
// body.className = "lockScreen";
// }
// else{
// body.className = "";
// }
// }
function changeValue(courseCode){
document.getElementById("coursename").value = courseCode;
return true;
}
var urlParam = window.location.search;
if(urlParam.indexOf("course=") > -1){
var courseCode_param = urlParam.substr(urlParam.indexOf("course=")+7, course_code_length);
changeValue(courseCode_param);
add(courseCode_param);
hasUrlParam = true;
}
// function lockToggle(){
// if(localStorage["lockMode"] && localStorage["lockMode"]==="lock"){
// localStorage["lockMode"] = "unlock";
// }
// else{
// localStorage["lockMode"] = "lock";
// }
// genIt(null, null, true);
// }
function convertToStamp(t){
return (parseInt(t.substr(0,2)) * 60) + (parseInt(t.substr(3,2)) * 1);
}
function convertToDisp(t){
if(t == '') {
return t;
}
var time = convertToStamp(t);
var hour = parseInt(time/60);
var min = parseInt(time % 60);
if(min < 10) {
min = '0' + min
}
return hour + ":" + min;
}
function addToScreen(target, el, i){
window.setTimeout(function(){
target.appendChild(el);
}, i);
}
var elCollection = [];
// var lastClick = {
// id: '',
// hash: ''
// };
function genIt(courses_list, no_scroll, is_ctrlZ){
if(no_scroll && no_scroll===true){
// window.scrollTo(0,0);
// document.getElementById("courses-list").scrollTop = document.getElementById("isw-form").offsetTop;
}
else{
// var target = 0;
// if(studyPlanDiv.innerHTML !== ""){
// target = studyPlanDiv.offsetTop;
// }
// window.scrollTo(0,document.getElementById("wrapper").offsetTop);
// document.getElementById("courses-list").scrollTop = target;
window.scrollTo(0,document.getElementById("wrapper").offsetTop);
}
courseListDiv.innerHTML = "";
// courses = courses.sort(function(a,b){return a.code > b.code});
var used_colors_list = used_colors;
if(!courses_list){
courses_list = courses;
allCourseMode = false;
document.getElementById("courses-list").className = "active";
}
else{
allCourseMode = true;
document.getElementById("courses-list").className = "inactive";
for(var i=courses.length-1; i>=0; i--){
courses_list.unshift(courses[i]);
}
}
// if(
// allCourseMode===true ||
// (localStorage["lockMode"] && localStorage["lockMode"]==="lock")
// ){
// document.getElementById("overlay").className = "lock";
// document.getElementById("lock").className = "lock";
// localStorage["lockMode"] = "lock";
// // document.getElementById("lock").innerHTML = "按此解鎖 Click to unlock<br><small>解鎖後,您將可以從課程表中刪除科目<br>Unlock to remove course(s) from timetable.</small>";
// }
// else{
// document.getElementById("overlay").className = "unlock";
// document.getElementById("lock").className = "unlock";
// // document.getElementById("lock").innerHTML = "按此鎖定 Click to lock<br><small>鎖定課程表能避免誤刪課程<br>Lock to protect course(s) from removing.</small>";
// }
earliest = undefined;
latest = undefined;
timetable.innerHTML = template;
document.getElementById("morning").style.height = 0 + "px";
document.getElementById("night").style.height = 0 + "px";
document.getElementById("afternoon").style.height = 0 + "px";
elCollection = [];
prettified = false;
// save divs used in timetable rendering, for giving indent.
var day = document.querySelectorAll(".col");
for(var i=0; i<day.length; i++){
day[i].style.height = totalHeight + 'px';
elCollection[i] = [];
}
if(allCourseMode===false && !is_ctrlZ){
cur_ver++;
max_ver = cur_ver;
versions[cur_ver] = JSON.stringify(courses_list);
}
if(cur_ver===0){
document.getElementById("undo").className = "styled hidden";
}
else{
document.getElementById("undo").className = "styled";
}
if(cur_ver===max_ver){
document.getElementById("redo").className = "styled hidden";
}
else{
document.getElementById("redo").className = "styled";
}
// dont print same section twice.
var check_block_repeat = [];
for(var i=courses_list.length-1; i>=0; i--){
var ths_json = JSON.stringify(courses_list[i]);
if(check_block_repeat.indexOf(ths_json)===-1){
check_block_repeat.push(ths_json);
}
else{
courses_list.splice(i, 1, {});
}
}
for(var i=0; i<courses_list.length; i++){
if(!courses_list[i].code || courses_list[i].isRemoved){
continue;
}
var starttime;
var endtime;
if(!courses_list[i].startStamp){
courses_list[i].startStamp = convertToStamp(courses_list[i].start);
}
if(!courses_list[i].endStamp){
courses_list[i].endStamp = convertToStamp(courses_list[i].end);
}
starttime = courses_list[i].startStamp;
endtime = courses_list[i].endStamp;
if(!earliest || earliest > starttime){
earliest = starttime;
}
if(!latest || latest < endtime){
latest = endtime;
}
}
if(earliest === undefined){
earliest = 11.5*60;
latest = 16.5*60;
}
else{
if(earliest > (9*60 + 30)){
earliest -= 30;
}
if(latest < (18*60)){
latest += 30;
}
if(earliest > (12.5 * 60)){
earliest = (12.5 * 60);
}
if(latest < (15.5 * 60)){
latest = (15.5 * 60);
}
}
heightOf1Min = totalHeight / (latest - earliest);
timetable.className = (
(allCourseMode===true) ? "adding-course" : "selected-course"
);
var renderGap = 5;
for(var i=0; i<courses_list.length; i++){
if(!courses_list[i].code || courses_list[i].isRemoved){
continue;
}
var tmpLineHeight = lineHeight;
var weekday = dayName.indexOf(courses_list[i].day);
if(weekday > -1){
if(allCourseMode === true){
var basicHTML = courses_list[i].code + "<br>" + courses_list[i].start + "-" + courses_list[i].end + "<br>" + courses_list[i].venue;
// var prevFound = false;
// for(var k=0; k<i; k++){
// if(
// (courses_list[k].start === courses_list[i].start) &&
// (courses_list[k].end === courses_list[i].end) &&
// (courses_list[k].day === courses_list[i].day)
// ){
// if(courses_list[i].code !== courses_list[k].code){
// var div = document.getElementById(courses_list[k].code + "-" +courses_list[k].start + "-" +courses_list[k].end + "-" +courses_list[k].day);
// div.innerHTML += "<hr>" + basicHTML;
// }
// prevFound = true;
// break;
// }
// }
// if(prevFound === true){
// continue;
// }
}
var thisIsLab = isLab(courses_list[i]);
var div = document.createElement("a");
var this_id = courses_list[i].code + "-" +courses_list[i].start + "-" +courses_list[i].end + "-" +courses_list[i].day;
if(allCourseMode === false){
if (thisIsLab) {
div.href = "javascript:removeSection(" + i + ")";
// div.className = "lab";
// console.log(i);
}
else {
div.href = "javascript:deleteIt('" + courses_list[i].code + "')";
}
}
else{
div.href = "javascript:filterIt(" + weekday + "," + elCollection[weekday].length + ")";
}
div.style.top = parseInt((courses_list[i].startStamp - earliest) * heightOf1Min) + "px";
var divHeight = ((courses_list[i].endStamp - courses_list[i].startStamp) * heightOf1Min - 12);
div.style.height = parseInt(divHeight) + "px";
var paddingTop = (divHeight - (tmpLineHeight*4)) / 2;
if(allCourseMode === false){
var basicHTML = courses_list[i].code + "<br><span class=\"text-marq\">" + courses_list[i].name + "</span><br>" + courses_list[i].venue + "<br>" + courses_list[i].start + "-" + courses_list[i].end;
if(thisIsLab) {
basicHTML += '[Lab]';
}
if(paddingTop > 0){
div.innerHTML = basicHTML;
}
else{
tmpLineHeight = 12;
var paddingTop = (divHeight - (tmpLineHeight*2)) / 2;
div.innerHTML = courses_list[i].code + "<br>@" + courses_list[i].start + '/' + courses_list[i].venue;
}
}
else{
tmpLineHeight = 9;
var paddingTop = 7;
div.innerHTML = basicHTML;
div.id = this_id;
}
var background = undefined;
if(used_colors_list[courses_list[i].code]){
background = used_colors_list[courses_list[i].code];
}
else if(allCourseMode === false){
for(var k=0; k<colors.length; k++){
var used = false;
for(var h in used_colors_list){
if(colors[k] === used_colors_list[h]){
used = true;
break;
}
}
if(used === false){
break;
}
}
background = colors[k];
used_colors_list[courses_list[i].code] = colors[k];
}
if(background === undefined){
background = default_block.bg;
div.style.color = default_block.col;
}
div.style.borderColor = background;
div.style.lineHeight = tmpLineHeight + "px";
if(allCourseMode === false){
var span = document.createElement("span");
span.className = "cross";
span.innerHTML = "×";
span.style.height = tmpLineHeight + "px";
div.appendChild(span);
var span = document.createElement("span");
span.className = "alt-text";
span.innerHTML = thisIsLab ? "[Lab]" : courses_list[i].code;
span.style.height = tmpLineHeight + "px";
div.appendChild(span);
}
var bgDiv = document.createElement("div");
bgDiv.className = "background";
bgDiv.style.backgroundColor = background;
bgDiv.style.zIndex = -1;
// var altText = document.createElement("div");
// altText.className = "alt";
// altText.innerHTML = basicHTML;
// Calculate indent.
var top = parseInt(div.style.top);
var height = parseInt(divHeight);
var bottom = top + height;
var left = 0;
for(var thisEC=0; thisEC<elCollection[weekday].length; thisEC++) {
var el = elCollection[weekday][thisEC];
if(el.top <= bottom && el.bottom >= top) {
if(el.left >= left) {
left = el.left + 21;
}
// if(el.paddingTop >= paddingTop){
// if(el.paddingTop < height/3*2) {
// paddingTop = el.paddingTop + 3;
// }
// else{
// paddingTop += 3;
// }
// }
}
}
if(paddingTop > 0){
div.style.paddingTop = parseInt(paddingTop) + "px";
div.style.height = parseInt(divHeight - paddingTop) + "px";
}
else{
div.style.paddingTop = "0px";
}
if(left > 90) {
left = 90;
}
elCollection[weekday].push({
code: courses_list[i].code,
background: background,
top: top,
paddingTop: paddingTop,
bottom: bottom,
left: left
});
div.style.left = left + 'px';
div.appendChild(bgDiv);
// div.appendChild(altText);
addToScreen(day[weekday], div, i*renderGap);
}
}
var returnAt = (i+1) * renderGap;
var morning_height = 0;
var night_height = 0;
if(earliest < (13*60)){
morning_height = (13*60 - earliest);
}
if(latest > (18*60)){
night_height = (latest - 18*60);
}
if(morning_height < 1){
morning_height = 0;
}
else{
morning_height = morning_height * heightOf1Min + (lineHeight/2);
}
night_height = night_height * heightOf1Min - (lineHeight/2);
document.getElementById("morning").style.height = morning_height + "px";
document.getElementById("morning").style.lineHeight = morning_height + "px";
if(morning_height < 48){
document.getElementById("morning").style.lineHeight = 1 + "px";
}
if(night_height < 30){
night_height = 0;
}
document.getElementById("night").style.height = night_height + "px";
document.getElementById("night").style.lineHeight = night_height + "px";
var afternoon_height = totalHeight - night_height - morning_height;
morning_height += 35;
document.getElementById("afternoon").style.top = morning_height + "px";
document.getElementById("afternoon").style.height = afternoon_height + "px";
document.getElementById("afternoon").style.lineHeight = afternoon_height + "px";
for(var i=earliest; i<latest; i+=30){
var stampTop = ((i - earliest) * heightOf1Min - (lineHeight/2));
var stamp = document.createElement("div");
stamp.style.height = (heightOf1Min * 30) + "px";
stamp.style.top = stampTop + "px";
var hour = parseInt(i/60);
var min = (i - (hour*60));
if(min < 10){
min = '0' + min;
}
stamp.innerHTML = hour + ":" + min;
day[0].appendChild(stamp);
}
var previousCourse = "";
// if(allCourseMode===true){
// var div_umacinfo = document.getElementById("umacinfo");
// div_umacinfo.className = "";
// div_umacinfo.innerHTML = "";
// var ccode = document.getElementById("coursename").value;
// if(window.jQuery){
// $.get(
// "umac_info.php",
// {course: ccode},
// function(data){
// div_umacinfo.className = "umac-info";
// div_umacinfo.innerHTML = data.replace(/style="[^"]*"/g, "");
// }
// );
// }
// }
// for(var i=courses_list.length-1; i>=0; i--){
for(var i=0; i<courses_list.length; i++){
if(!courses_list[i].code || courses_list[i].isRemoved){
continue;
}
if(courses_list[i].code !== previousCourse){
previousCourse = courses_list[i].code;
var li = document.createElement("li");
var no_remark = courses_list[i].remark.replace(/\s/g, "")==="";
var no_dept = (courses_list[i].host && (courses_list[i].host.replace(/\s/g, "")===""));
li.innerHTML = '<h3><span style="background:' + used_colors_list[courses_list[i].code] + '"></span>' + courses_list[i].code + "</h3>" +
"<p>" + courses_list[i].name + "</p>" +
"<ul id='" + courses_list[i].code + "'></ul>" +
((courses_list[i].prof.replace(/\s/g, "")==="")
? ""
: "<p><u>講師 Lecturer</u><br>" + courses_list[i].prof + "</p>") +
((no_dept && no_remark)
? ''
: '<p><u>備註 Remark</u>' +
(no_dept
? ''
: '<br>Host by ' + courses_list[i].host + '; ') +
(no_remark
? ''
: courses_list[i].remark.replace(/\n/g, "<br>")) +
'</p>'
) +
'<a href="javascript:add(\'' +courses_list[i].code+ '\')" class="add">加入 Add</a><a href="javascript:deleteIt(\'' +courses_list[i].code+ '\')" class="del">刪除 Delete</a>';
if(allCourseMode===true){
var current_course_code_list = getSelectedCourseCodeList();
// if(current_course_code_list.indexOf(courses_list[i].code)!==-1){
if(i < courses.length){
li.className = "inactive";
}
else{
li.className = "inlist";
}
}
// courseListDiv.insertBefore(li, courseListDiv.querySelector("li"));
courseListDiv.appendChild(li);
}
var dayIndex = dayName.indexOf(courses_list[i].day);
if(dayIndex > -1){
var ths = courses_list[i];
var ths_id = ths.code + '-' + ths.day + '-' + ths.startStamp + '-' + ths.endStamp;
if(!document.getElementById(ths_id)){
ul = document.getElementById(ths.code);
var li_el = document.createElement("li");
li_el.id = ths_id;
if (allCourseMode!==true && isLab(ths)) {
var btnColor = used_colors_list[courses_list[i].code];
if(!btnColor) {
btnColor = "#607d8b";
}
li_el.className = "no-dots";
li_el.innerHTML += "<a href=\"javascript:removeSection("+i+")\" class=\"course-hide\" style=\"color: " + btnColor + "\"><i class=\"fa fa-trash-o\" title=\"Hide\"></i></a>";
}
li_el.innerHTML += "<b>" + dayDisp[dayIndex] + " " + ths.start + "-" + ths.end + "</b><br>"+ ths.venue + (ths.type==='Lecture' ? '' : "(" + ths.type + ")");
// console.log(ths.code);
for(var ix in courses){
var oppose = courses[ix];
if(oppose.isRemoved) {
continue;
}
if(
oppose.code !== ths.code
&& oppose.day === ths.day
&& (
(oppose.startStamp <= ths.startStamp && oppose.endStamp >= ths.startStamp)
|| (oppose.startStamp <= ths.endStamp && oppose.endStamp >= ths.endStamp)
|| (oppose.startStamp >= ths.startStamp && oppose.endStamp <= ths.endStamp)
)
){
li_el.innerHTML += "<br><span class=\"warning\">與" + oppose.code + "衝突</span>";
}
// console.log(oppose.code, ths.code);
}
ul.appendChild(li_el);
}
}
}
if(allCourseMode === false){
localStorage["coursesJson"] = JSON.stringify(courses_list);
used_colors = used_colors_list;
}
var als_count = 0;
var als = document.querySelectorAll("#courselist li.inlist ul");
if(als.length===0) {
als = document.querySelectorAll("#courselist li ul");
}
for(var i=0; i<als.length; i++) {
if(als[i].innerHTML === ''){
als_count++;
}
}
var als_total = als.length;
if(als_count > 0) {
var als_text_chi, als_text_eng, als_text_eng_count;
als_text_eng_count = 's are ';
if(als_count === als_total) {
als_text_chi = '全部課程';
als_text_eng = 'All';
}
else{
als_text_chi = als_total + '個課程中有' + als_count + '個';
als_text_eng = als_count + ' of ' + als_total;
if(als_count===1){
als_text_eng_count = ' is ';
}
}
alert('所選的' + als_text_chi + '未有上課時間 / ' + als_text_eng + ' selected course' + als_text_eng_count+ 'unscheduled.')
}
// if(callback_function) {
// window.setTimeout(callback_function, returnAt);
// }
if(finding_period===true){
return find_period(true);
}
return true;
}
function print_error(msg, code){
var span_id_str = " class='others'";
if(code){
span_id_str = ' class="'+code+'"';
}
if(errorDiv.innerHTML.indexOf(msg) === -1){
errorDiv.innerHTML += "<span" + span_id_str + ">" + msg + "</span>";
}
window.scrollTo(0,document.getElementById("table-top").offsetTop);
document.getElementById("courses-list").scrollTop = 0;
}
function removeError(code){
// remove specific error.
if(code){
var er = document.querySelectorAll("." + code);
for(var el=0; el<er.length; el++){
errorDiv.removeChild(er[el]);
}
}
// remove other error => keep COURSE ERROR.
var er = document.querySelectorAll(".others");
for(var el=0; el<er.length; el++){
errorDiv.removeChild(er[el]);
}
}
var courses_list_tmp = [];
var prettified = false;
function removeElement(element) {
element.parentNode.removeChild(element);
}
function prettifyDisp(day, elCollectionIndex){
prettified = true;
var weekday = document.querySelectorAll(".col");
var baseClass = "col day-col";
for(var i=1; i<weekday.length; i++) {
if(i !== day) {
// removeElement(weekday[i]);
weekday[i].className = baseClass + " other-col";
weekday[i].style.width = "40px";
}
else{
if(weekday[i].className.indexOf("active-col") !== -1){
// user clicked on the active day, should return add.
return add(elCollection[i][elCollectionIndex].code);
}
weekday[i].style.width = "580px"; // 825 - 245
weekday[i].className = baseClass + " active-col";
}
}
return prettifyDisp_proc(elCollection[day]);
}
function prettifyDisp_proc(elCollection){
var other_els = document.querySelectorAll(".col.day-col.other-col a");
for(var i=0; i<other_els.length; i++) {
// other_els[i].href = "javascript:void(0)";
other_els[i].style.left = "0px";
other_els[i].style.width = "auto";
}
var total_width = parseInt(document.querySelector(".col.day-col.active-col").style.width);
var margins_width = 12; // course-block margin width
var solvedConflicts = [];
var els = document.querySelectorAll(".col.day-col.active-col a");
for(var ths_i=0; ths_i<elCollection.length; ths_i++) {
if(solvedConflicts.indexOf(ths_i) > -1){
continue;
}
var conflicts = [];
var ths = elCollection[ths_i];
for(var tht_i=ths_i+1; tht_i<elCollection.length; tht_i++) {
var tht = elCollection[tht_i];
if(tht.top <= ths.bottom && tht.bottom >= ths.top) {
conflicts.push(tht_i);
solvedConflicts.push(tht_i);
}
}
if(conflicts.length > 0) {
conflicts.unshift(ths_i);
// console.log(total_width, total_width / conflicts.length);
var el_margin = 8;
var el_total_width = parseInt((total_width - el_margin) / conflicts.length * 10) / 10;
var el_width = el_total_width - margins_width - 1;
for(var i=0; i<conflicts.length; i++) {
els[conflicts[i]].style.width = (el_width + el_margin) + "px";
els[conflicts[i]].style.left = (el_total_width * i) + "px";
// console.log(els[conflicts[i]], conflicts[i], el_width, (el_total_width * i));
}
}
}
}
function filterIt(day, elCollectionIndex) {
if(prettified === false){
var this_course_el = elCollection[day][elCollectionIndex];
var coursecode = this_course_el.code;
var this_cl_tmp = [coursecode];
// Day by day
// for(var day=0; day<elCollection.length; day++) {
// courses in one day
// for(var i=0; i<elCollection[day].length; i++) {
// if course found
// if(elCollection[day][i].code === coursecode) {
// find conflict courses.
for(var j=0; j<elCollection[day].length; j++) {
// avoid same course
if(j !== elCollectionIndex) {
var thisC = elCollection[day][elCollectionIndex];
var thatC = elCollection[day][j];
if(thatC.bottom >= thisC.top && thatC.top <= thisC.bottom && thatC.background === default_block.bg) {
// overlap
if(this_cl_tmp.indexOf(thatC.code) === -1) {
this_cl_tmp.push(thatC.code);
break;
}
}
}
}
// }
// }
// }
if(this_cl_tmp.length === 1){
return add(coursecode);
}
}
// for(var i = courses_list_tmp.length-1; i>=0; i-- ){
// if(this_cl_tmp.indexOf(courses_list_tmp[i].code) === -1) {
// courses_list_tmp.splice(i,1);
// }
// }
// return genIt(courses_list_tmp);
return prettifyDisp(day, elCollectionIndex);
// var this_hash = day +"#" + elCollectionIndex;
// if(lastClick.hash===this_hash){
// return add(coursecode);
// }
// var shouldQuit = (lastClick.id === this_id);
// lastClick.id = this_id;
// lastClick.hash = this_hash;
// if(shouldQuit===true) {
// return prettifyDisp();
// }
}
function look(coursecode, is_error, is_importing){
// var courses_list_current = getSelectedCourseCodeList();
courses_list_tmp = [];
for(var i=0; i<courses_info.length; i++){
// console.log(courses_info[i].code.substr(0,course_code_length), coursecode);