-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrade.js
1772 lines (1689 loc) · 58.2 KB
/
grade.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
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
// Global variables
var currScan = null;
var examlist = [];
var selectedExam = null;
// Uploading tools
var Upload = function (file, tool, input, exam) {
this.file = file;
this.tool = tool;
this.exam = exam;
this.input = input;
};
Upload.prototype.getType = function() {
return this.file.type;
};
Upload.prototype.getSize = function() {
return this.file.size;
};
Upload.prototype.getName = function() {
return this.file.name;
};
Upload.prototype.doUpload = function () {
var that = this;
var formData = new FormData();
// add assoc key values, this will be posts values
formData.append("uploads", this.file, this.getName());
formData.append("go", "upload");
formData.append("tool", this.tool);
formData.append("input", this.input);
formData.append("evid", this.exam[0]);
$.ajax({
type: "POST",
url: "grade.php",
xhr: function () {
var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) {
myXhr.upload.addEventListener('progress', that.progressHandling, false);
}
return myXhr;
},
success: function (data) {
// your callback here
$('#uploadstatus').append("Successfully uploaded: " + that.getName());
$('#uploadstatus').append("<br/>");
$('#uploadstatus').append(data);
},
error: function (error) {
// handle error
$('#uploadstatus').append("Error in Uploading: " + that.getName());
$('#uploadstatus').append("<br/>");
},
async: true,
data: formData,
cache: false,
contentType: false,
processData: false,
timeout: 60000
});
};
Upload.prototype.progressHandling = function (event) {
var percent = 0;
var position = event.loaded || event.position;
var total = event.total;
var progress_bar_id = "#progress-wrp";
if (event.lengthComputable) {
percent = Math.ceil(position / total * 100);
}
// update progressbars classes so it fits your code
$(progress_bar_id + " .progress-bar").css("width", +percent + "%");
$(progress_bar_id + " .status").text(percent + "%");
};
function callUpload() {
var files = $('#selectedfile')[0].files;
var tool = $('#select-tools').val();
var input = $('#inputtext').val();
if (/^admin/.test(input) && (tool == "Roster" || tool == "Upload Scans")) {
for (var i = 0; i < files.length; i++) {
var upload = new Upload(files[i], tool, input, selectedExam);
// maby check size or type here with upload.getSize() and upload.getType()
// execute upload
upload.doUpload();
}
}
return false;
}
function callClear() {
//$('#inputtext').val("");
$('#uploadstatus').html("");
var percent = 0;
var progress_bar_id = "#progress-wrp";
$(progress_bar_id + " .progress-bar").css("width", +percent + "%");
$(progress_bar_id + " .status").text(percent + "%");
}
var ident = function (d) { return d; };
function ShowID(tool, exam) {
this.tool = tool;
this.exam = exam;
this.fc = null;
this.img = null;
this.tselIndex = null;
this.currPage = 1;
}
(function() {
/***************bootstrap modal helper class *************/
var Modal = function (options) {
var $this = this;
options = options ? options : {};
$this.options = {};
$this.options.header = options.header !== undefined ? options.header : false;
$this.options.footer = options.footer !== undefined ? options.footer : false;
$this.options.closeButton = options.closeButton !== undefined ? options.closeButton : true;
$this.options.footerCloseButton = options.footerCloseButton !== undefined ? options.footerCloseButton : false;
$this.options.id = options.id !== undefined ? options.id : "myModal";
/**
* Append modal window html to body
*/
$this.createModal = function () {
$('body').append('<div id="' + $this.options.id + '" class="modal fade"></div>');
$($this.selector).append('<div class="modal-dialog custom-modal"><div class="modal-content"></div></div>');
var win = $('.modal-content', $this.selector);
if ($this.options.header) {
win.append('<div class="modal-header"><h4 class="modal-title" lang="de"></h4></div>');
if ($this.options.closeButton) {
win.find('.modal-header').prepend('<button type="button" class="close" data-dismiss="modal">×</button>');
}
}
win.append('<div class="modal-body"></div>');
if ($this.options.footer) {
win.append('<div class="modal-footer"></div>');
if ($this.options.footerCloseButton) {
win.find('.modal-footer').append('<a data-dismiss="modal" href="#" class="btn btn-default" lang="de">' + $this.options.footerCloseButton + '</a>');
}
}
$($this.selector).on('hidden.bs.modal', function (e) {
$($this.selector).remove();
});
};
/**
* Set header text. It makes sense only if the options.header is logical true.
* @param {String} html New header text.
*/
$this.setHeader = function (html) {
$this.window.find('.modal-title').html(html);
};
/**
* Set body HTML.
* @param {String} html New body HTML
*/
$this.setBody = function (html) {
$this.window.find('.modal-body').html(html);
};
/**
* Set footer HTML.
* @param {String} html New footer HTML
*/
$this.setFooter = function (html) {
$this.window.find('.modal-footer').html(html);
};
/**
* Return window body element.
* @returns {jQuery} The body element
*/
$this.getBody = function () {
return $this.window.find('.modal-body');
};
/**
* Show modal window
*/
$this.show = function () {
$this.window.modal('show');
};
/**
* Hide modal window
*/
$this.hide = function () {
$this.window.modal('hide');
};
/**
* Toggle modal window
*/
$this.toggle = function () {
$this.window.modal('toggle');
};
$this.selector = "#" + $this.options.id;
if (!$($this.selector).length) {
$this.createModal();
}
$this.window = $($this.selector);
$this.setHeader($this.options.header);
};
/************** END HELPER CLASS ******************/
fabric.util.object.extend(fabric.Object.prototype, {
annStr: "Unknown",
annPts: 0,
annPage: -1 });
const STATE_IDLE = 'idle';
const STATE_PANNING = 'panning';
fabric.Canvas.prototype.toggleDragMode = function(dragMode) {
// Remember the previous X and Y coordinates for delta calculations
let stx;
let sty;
// Keep track of the state
let state = STATE_IDLE;
var zoomLevel = 0;
var zoomLevelMin = 0;
var zoomLevelMax = 4;
var canvas = this;
// We're entering dragmode
if (dragMode) {
// Discard any active object
this.discardActiveObject();
// Set the cursor to 'move'
this.defaultCursor = 'move';
// Loop over all objects and disable events / selectable. We remember its value in a temp variable stored on each object
this.forEachObject(function(object) {
object.prevEvented = object.evented;
object.prevSelectable = object.selectable;
object.evented = false;
object.selectable = false;
});
// Remove selection ability on the canvas
this.selection = false;
// touch
this.on('touch:gesture', function(e) {
// Handle zoom only if 2 fingers are touching the screen
if (e.e.touches && e.e.touches.length == 2) {
// Calculate delta from start scale
var delta = e.self.scale;
console.log("touch " + delta);
// Zoom to pinch point
if (delta != 0) {
var pointer = canvas.getPointer(e.e, true);
var point = new fabric.Point(pointer.x, pointer.y);
if (delta > 1) {
if (zoomLevel < zoomLevelMax) {
zoomLevel++;
canvas.zoomToPoint(point, Math.pow(2, zoomLevel));
}
} else if (delta < 1) {
if (zoomLevel > zoomLevelMin) {
zoomLevel--;
canvas.zoomToPoint(point, Math.pow(2, zoomLevel));
}
}
}
}
return false;
});
// When MouseUp fires, we set the state to idle
this.on('mouse:up', function(e) {
state = STATE_IDLE;
});
// When MouseDown fires, we set the state to panning
this.on('mouse:down', (e) => {
state = STATE_PANNING;
var mouse = canvas.getPointer(e.e, true);
stx = mouse.x;
sty = mouse.y;
});
// When the mouse moves, and we're panning (mouse down), we continue
this.on('mouse:move', (e) => {
if (state === STATE_PANNING && e && e.e) {
// Calculate deltas
let deltaX = 0;
let deltaY = 0;
var mouse = canvas.getPointer(e.e, true);
if (stx) {
deltaX = mouse.x - stx;
}
if (sty) {
deltaY = mouse.y - sty;
}
// Update the last X and Y values
stx = mouse.x;
sty = mouse.y;
let delta = new fabric.Point(deltaX, deltaY);
canvas.relativePan(delta);
canvas.trigger('moved');
}
});
$(this.wrapperEl).on('mousewheel', function (options) {
var delta = options.originalEvent.wheelDelta;
if (delta != 0) {
var pointer = canvas.getPointer(options.e, true);
var point = new fabric.Point(pointer.x, pointer.y);
if (delta > 0) {
if (zoomLevel < zoomLevelMax) {
zoomLevel++;
canvas.zoomToPoint(point, Math.pow(2, zoomLevel));
}
} else if (delta < 0) {
if (zoomLevel > zoomLevelMin) {
zoomLevel--;
canvas.zoomToPoint(point, Math.pow(2, zoomLevel));
}
}
}
return false;
});
} else {
$(this.wrapperEl).on('mousewheel', function () { return false; });
// When we exit dragmode, we restore the previous values on all objects
this.forEachObject(function(object) {
object.evented = (object.prevEvented !== undefined) ? object.prevEvented : object.evented;
object.selectable = (object.prevSelectable !== undefined) ? object.prevSelectable : object.selectable;
});
// Reset the cursor
this.defaultCursor = 'default';
// Remove the event listeners
this.off('mouse:up');
this.off('mouse:down');
this.off('mouse:move');
// Restore selection ability on the canvas
this.selection = true;
}
};
ShowID.prototype.init_vars = function() {
this.fc = null;
this.img = null;
this.rect = null;
this.startDrawing = false;
this.started = false;
this.stx = 0;
this.sty = 0;
this.dType = null;
this.currTData = null;
this.currRData = null;
this.data = null;
this.igrade = null;
this.rlist = null;
this.graders = null;
}
ShowID.prototype.addAnnotation = function(obj) {
var curr = this;
curr.fc.add(obj);
curr.callUpdate();
}
ShowID.prototype.removeAnnotation = function(obj) {
var curr = this;
curr.fc.remove(obj);
curr.callUpdate();
}
ShowID.prototype.hasPages = function() {
var curr = this;
return curr.data && curr.data.length > 0;
}
ShowID.prototype.init = function(input) {
var curr = this;
curr.init_vars();
curr.input = input;
d3.json("grade.php?go=getPages&input=" + input +
"&evid=" + curr.exam[0],
function (data) {
curr.data = data;
d3.select("#templateContainer").html("");
var dinfo = d3.select("#templateContainer").append("div")
.attr("id", "docinfo")
.attr("style", "display:inline-block");
d3.select("#templateContainer").append("text")
.html(" | Enable Pan and Zoom ");
d3.select("#templateContainer").append("input")
.attr("type", "checkbox").attr("id", "enablePanZoom")
.on("change", function (e) {
if (curr.fc) {
if (d3.select("#enablePanZoom").property("checked")){
curr.fc.toggleDragMode(true);
}
else {
curr.fc.toggleDragMode(false);
}
}
});
var reftable = d3.select("#templateContainer").append("table")
.attr("id", "ptable").attr("border", 0);
var ctable = d3.select("#templateContainer").append("table")
.attr("id", "ctable").attr("border", 0);
var ctr = ctable.append("tr");
var ctd1 = ctr.append("td").attr("align", "left")
.attr("valign", "top");
var ctd2 = ctr.append("td").attr("align", "left")
.attr("valign", "top");
var imgc = ctd1.append("div").attr("style",
"margin: 0 auto; width:850px;height:1100px");
var stn = ctd2.append("div").attr("id", "nameinfo");
var st = ctd2.append("div").attr("id", "objlist");
var c = imgc
.append("canvas").attr("id", "imgCanvas").attr("width", "850px")
.attr("height", "1100px");
var canvas = new fabric.Canvas('imgCanvas');
curr.fc = canvas;
if (data && data.length > 0) {
var index = curr.currPage - 1;
var info = data[index][0] + "/" + data[index][5];
d3.select("#docinfo").text(info);
var url = "grade.php?go=getImage&input=" +
data[curr.currPage - 1][4] + "&evid=" + curr.exam[0];
fabric.Image.fromURL(url, function(oImg) {
// scale image down, and flip it, before adding it onto canvas
oImg.scale(0.5);
oImg.hasControls = false;
oImg.lockMovementX = false;
oImg.lockMovementY = false;
oImg.lockRotation = oImg.lockScalingX = oImg.lockScalingY = false;
oImg.selectable = false;
canvas.add(oImg);
curr.img = oImg;
curr.callLoad();
});
}
canvas.selection=false;
var dataLen = 0;
if (data && data.length > 0) {
dataLen = data.length;
}
var idx = $.map($(Array(dataLen + 5)),function(v, i) { return i; });
var pages = reftable.append("tr").selectAll("td").data(idx)
.enter().append("td").html(function (d) {
if (d == 0) { return "Pages:"; }
else if (d == dataLen + 1) { return "Name"; }
else if (d == dataLen + 2) { return "Region"; }
else if (d == dataLen + 3) { return "ZoomIn"; }
else if (d == dataLen + 4) { return "ZoomOut"; }
else {
return data[d - 1][1]; } })
.style("width", "50px").style("text-align", "center")
.on('mouseover', function(){
d3.select(this).style('background-color', 'gray');})
.on('mouseout', function(){
d3.select(this).style('background-color', 'white');})
.on("click", function(d) {
var obj = d3.select(this).data();
if (curr.img && obj[0] > 0 && obj[0] < dataLen + 1) {
var url = "grade.php?go=getImage&input=" +
data[obj[0] - 1][4] + "&evid=" + curr.exam[0];
curr.img.setSrc(url, function (d) {
curr.currPage = obj[0];
curr.hideObjects();
canvas.renderAll();
});
}
else if (obj[0] == dataLen + 1) {
curr.startDrawing = true;
curr.dType = "Name";
}
else if (obj[0] == dataLen + 2) {
curr.startDrawing = true;
curr.dType = "Region";
}
else if (obj[0] == dataLen + 3) { curr.zoomIn(); }
else if (obj[0] == dataLen + 4) { curr.zoomOut(); }
});
if (curr.hasPages()) {
curr.addEvents();
curr.showName(data[0][3]);
curr.displayRubric();
//curr.panZoom();
}
});
}
ShowID.prototype.getFCobject = function() {
var curr = this;
var canvas = curr.fc;
var index = 0;
if (curr.tool == "Match") {
var objs = curr.fc.getObjects();
for (var i =0; i < objs.length; i++) {
if (objs[i].get('annStr') == "Name") {
return objs[i];
}
}
}
if (curr.currTData) {
index = curr.currTData[0] + 1;
}
if (index < canvas.size()) {
var obj = canvas.item(index);
return obj;
}
return null;
}
ShowID.prototype.zoomIn = function() {
var curr = this;
var canvas = curr.fc;
if (curr.tool == "Grade" || curr.tool == "View") {
var zoomLevel = canvas.getZoom();
if (zoomLevel < 16) {
var obj = curr.getFCobject();
if (obj) {
var point = obj.getCenterPoint();
canvas.zoomToPoint(point, zoomLevel * 2);
}
else {
canvas.setZoom(zoomLevel * 2);
}
canvas.renderAll();
}
}
}
ShowID.prototype.zoomOut = function() {
var curr = this;
var canvas = curr.fc;
if (curr.tool == "Grade" || curr.tool == "View") {
var zoomLevel = canvas.getZoom();
if (zoomLevel > 1) {
var obj = curr.getFCobject();
if (obj) {
var point = obj.getCenterPoint();
canvas.zoomToPoint(point, zoomLevel * 0.5);
}
else {
canvas.setZoom(zoomLevel * 0.5);
}
canvas.renderAll();
}
}
}
ShowID.prototype.panZoom = function() {
var curr = this;
var canvas = curr.fc;
if (curr.tool == "Grade" || curr.tool == "View") {
canvas.toggleDragMode(true);
}
}
ShowID.prototype.saveRubric = function() {
var curr = this;
if (curr.tool != "Grade") {
return;
}
var tdata = curr.currTData;
var res = [];
for (var i = 0; i < tdata[4].length; i++) {
res.push([tdata[0], tdata[4][i][0], tdata[4][i][1], tdata[4][i][2],
tdata[4][i][3], tdata[4][i][4]]);
}
var input = encodeURIComponent(JSON.stringify(res));
$.ajax({type: 'POST',
data: {go: "saveRubric", input: input,
evid: curr.exam[0]},
url: "grade.php",
success: function(d) {
var st = JSON.parse(d);
if (st && st[0] == 1) {
d3.select("#gradeStatus").append("br");
d3.select("#gradeStatus").append("span").html(st[1]);
d3.select("#gradeStatus").append("text").html("√");
}
if (st && st[0] == 0) {
d3.select("#gradeStatus").append("br");
d3.select("#gradeStatus").append("span")
.attr("class", "errorInfo").html(st[1]);
}
}
});
}
ShowID.prototype.updateGraders = function() {
var curr = this;
if (curr.tool != "Grade") {
return;
}
var login = getUserLoginData();
var res = [];
if (curr.graders) {
res = curr.graders.split(',');
}
var found = false;
for (var i = 0; i < res.length; i++) {
if (res[i] == login[3]) {
found = true;
break;
}
}
if (!found) {
res.push(login[3]);
}
curr.graders = res.join(",");
}
ShowID.prototype.saveGrade = function() {
var curr = this;
if (curr.tool != "Grade") {
return;
}
curr.updateGraders();
curr.updateGradeInfo();
var tdata = curr.currTData;
var notes = d3.select("#inotes").property('value');
notes = notes.replace("'", "-");
var res = [[curr.data[0][0], tdata[0], notes, curr.igrade,
curr.rlist, curr.graders]];
var input = encodeURIComponent(JSON.stringify(res));
$.ajax({type: 'POST',
data: {go: "saveGrade", input: input,
evid: curr.exam[0]},
url: "grade.php",
success: function(d) {
var st = JSON.parse(d);
if (st && st[0] == 1) {
d3.select("#gradeStatus").append("br");
d3.select("#gradeStatus").append("span").html(st[1]);
d3.select("#gradeStatus").append("text").html("√");
}
if (st && st[0] == 0) {
d3.select("#gradeStatus").append("br");
d3.select("#gradeStatus").append("span")
.attr("class", "errorInfo").html(st[1]);
}
}
});
}
ShowID.prototype.saveReGrade = function() {
var curr = this;
if (curr.tool != "View") {
return;
}
var tdata = curr.currTData;
var notes = d3.select("#iregradenotes").property('value');
if(notes.trim()=="") {
d3.select("#regradeStatus").append("br");
d3.select("#regradeStatus").append("span")
.attr("class", "errorInfo").html("No input specified");
return;
}
notes = notes.replace("'", "-");
var rdata = [[curr.data[0][0], tdata[0], notes]];
curr.currRData = rdata;
var res = rdata;
var input = encodeURIComponent(JSON.stringify(res));
$.ajax({type: 'POST',
data: {go: "saveReGrade", input: input,
evid: curr.exam[0]},
url: "grade.php",
success: function(d) {
var st = JSON.parse(d);
if (st && st[0] == 1) {
d3.select("#regradeStatus").append("br");
d3.select("#regradeStatus").append("span").html(st[1]);
d3.select("#regradeStatus").append("text").html("√");
}
if (st && st[0] == 0) {
d3.select("#regradeStatus").append("br");
d3.select("#regradeStatus").append("span")
.attr("class", "errorInfo").html(st[1]);
}
}
});
}
ShowID.prototype.saveTotal = function() {
var curr = this;
if (curr.tool != "Grade") {
return;
}
$.ajax({type: 'POST',
data: {go: "saveTotal", scanid: curr.data[0][0],
evid: curr.exam[0]},
url: "grade.php",
success: function(d) {
var st = JSON.parse(d);
if (st && st[0] == 1) {
d3.select("#gradeStatus").append("br");
d3.select("#gradeStatus").append("span").html(st[1]);
d3.select("#gradeStatus").append("text").html("√");
}
if (st && st[0] == 0) {
d3.select("#gradeStatus").append("br");
d3.select("#gradeStatus").append("span")
.attr("class", "errorInfo").html(st[1]);
}
}
});
}
ShowID.prototype.updateTotalGradeInfo = function() {
var curr = this;
d3.json("grade.php?go=getTotal&scanid=" + curr.data[0][0] +
"&evid=" + curr.exam[0],
function (data) {
d3.select("#itotal").html( parseFloat(data[0]).toFixed(3)
+ "/" + parseFloat(data[1]).toFixed(3) );
});
}
ShowID.prototype.updateGradeInfo = function() {
var curr = this;
d3.select("#igrade").html("Grade : " +
parseFloat(curr.igrade).toFixed(3));
if (curr.tool != "Grade") {
return;
}
if (curr.graders && curr.graders != "") {
d3.select("#igrade").append("span").html(" Graders : " + curr.graders);
}
}
ShowID.prototype.calculateGrade = function() {
var curr = this;
if (curr.tool != "Grade") {
return;
}
var tdata = curr.currTData;
var maxp = tdata[2];
var total = maxp;
var ototal = null;
var rlist = "";
var tsel = d3.select("#irlist").selectAll("tr")
.each(function (d, i) {
var ch = d3.select(this).select("input.rcheckbox").node().checked;
var m = d3.select(this).select("input.mpbox").node().value;
var g = d3.select(this).select("input.gbox").node().value;
tdata[4][i][2] = g;
if (ch) {
total = total + m * g;
rlist = rlist + i + "x" + m + ",";
if (tdata[4][i][3] == "o") {
ototal = m * g;
}
}
});
if (total < 0) { total = 0; }
if (ototal != null) { total = ototal; }
curr.igrade = total;
curr.rlist = rlist;
curr.updateGradeInfo();
}
ShowID.prototype.updateRubric = function() {
var curr = this;
if (curr.tool != "Grade" && curr.tool != "View") {
return;
}
var tdata = curr.currTData;
d3.select("#irlist").html("");
var tbl = d3.select("#irlist").append("table").attr("border", 0);
var cells = tbl.selectAll("tr").data(tdata[4]).enter()
.append("tr").append("td");
cells.append("input").attr("type", "checkbox")
.attr("class", "rcheckbox")
.on("change", function (e) {
curr.calculateGrade();
});
cells.append("span").html(" ");
if (curr.tool == "View") {
cells.append("span")
.attr("class", "mpbox")
.text(function (d) { return 1;});
cells.append("span").html("  x  ");
cells.append("span")
.attr("class", "gbox")
.text(function (d) { return d[2];});
cells.append("span").html(" ");
cells.append("span").html(function (d) {return d[1];})
}
if (curr.tool == "Grade") {
cells.append("input").attr("type", "text")
.attr("class", "mpbox")
.attr("style", 'width: 15px;margin:unset;padding:unset')
.attr("value", function (d) { return 1;});
cells.append("span").html("  x  ");
cells.append("input").attr("type", "text")
.attr("class", "gbox")
.attr("style", 'width: 30px;margin:unset;padding:unset')
.attr("value", function (d) { return d[2];});
cells.append("span").html(" ");
cells.append("span").html(function (d) {return d[1];})
.each(function (d) {
var cell = d3.select(this);
var obj = d3.select(this.parentNode).data();
$(cell.node()).editable({
type: 'textarea',
rows: 3,
defaultValue: 'Unknown',
success: function(response, newValue) {
obj[0][1] = newValue;
}
});
});
}
d3.select("#irlist").append("br");
d3.select("#irlist").append("textarea").attr("rows", "3")
.attr("id", "inotes");
d3.select("#irlist").append("br");
if (curr.tool == "Grade") {
d3.select("#irlist").append("button").text("C")
.on("click", function (e) {
d3.select("#irlist").selectAll("tr")
.filter(function (d, i) { return i == 0; })
.select("input.rcheckbox").property("checked", true);
d3.select("#gradeStatus").html("√");
curr.calculateGrade();
curr.saveGrade();
var obj = d3.select("#tsel").node().options;
obj.selectedIndex++;
if (obj.selectedIndex == -1) {
obj.selectedIndex = 0;
}
curr.gradeOneRegion();
});
d3.select("#irlist").append("button").text("I")
.on("click", function (e) {
d3.select("#irlist").selectAll("tr")
.filter(function (d, i) { return i == 1; })
.select("input.rcheckbox").property("checked", true);
d3.select("#gradeStatus").html("√");
curr.calculateGrade();
curr.saveGrade();
var obj = d3.select("#tsel").node().options;
obj.selectedIndex++;
if (obj.selectedIndex == -1) {
obj.selectedIndex = 0;
}
curr.gradeOneRegion();
});
d3.select("#irlist").append("button").text("PS")
.on("click", function (e) { callPrev(); return false; });
var cell1 = d3.select("#irlist").append("input").attr("type", "button")
.attr("value", "Submit");
d3.select("#irlist").append("button").text("NS")
.on("click", function (e) { callNext(); return false; });
var cell3 = d3.select("#irlist").append("span")
.attr("id", "gradeStatus");
cell1.on("click", function (e) {
// Submit grades
d3.select("#gradeStatus").html("√");
curr.calculateGrade();
curr.saveRubric();
curr.saveGrade();
curr.saveTotal();
curr.updateTotalGradeInfo();
});
}
if (tdata.length == 6) {
curr.igrade = tdata[5][1];
curr.rlist = tdata[5][2];
curr.graders = tdata[5][3];
curr.updateGradeInfo();
d3.select("#inotes").property("value", tdata[5][0]);
var res = curr.rlist.split(',');
var arr = [];
for (var i = 0; i < tdata[4].length; i++) {
arr[i] = [0, 1];
}
for (var i = 0; i < res.length; i++) {
var l = res[i].split('x');
if (l.length == 2) {
arr[l[0]] = [1, l[1]];
}
}
d3.select("#irlist").selectAll("tr").each(function (d, i) {
if (arr[i][0] == 1) {
d3.select(this).select("input.rcheckbox").property("checked", true);
d3.select(this).select("input.mpbox").property("value", arr[i][1]);
d3.select(this).select("span.mpbox").text(arr[i][1]);
}
});
}
if (curr.tool == "View") {
d3.select("#irlist").selectAll("input")
.each(function (d, i) {
d3.select(this).property("disabled", "disabled");
});
d3.select("#inotes").property("disabled", "disabled");
}
curr.calculateGrade();
}
ShowID.prototype.updateRegrade = function() {
var curr = this;
if (curr.tool != "Grade" && curr.tool != "View") {
return;
}
var rdata = curr.currRData;
var cell = d3.select("#regradenotes");
cell.html("Regrade:");
cell.append("br");
cell.append("textarea").attr("rows", "3")
.attr("id", "iregradenotes");
cell.append("br");
if (rdata && rdata.length > 0) {
d3.select("#iregradenotes").property("value", rdata[0][2]);
}
if (curr.tool == "View") {
var cell1 = cell.append("input").attr("type", "button")
.attr("value", "Request Regrade");
var cell3 = cell.append("span")
.attr("id", "regradeStatus");
cell1.on("click", function (e) {
// Submit grades
d3.select("#regradeStatus").html("√");
curr.saveReGrade();
});
}
if (curr.tool == "Grade") {
d3.select("#iregradenotes").property("disabled", "disabled");
}
}
ShowID.prototype.gradeOneRegion = function(tdata) {
var curr = this;
if (curr.tool != "Grade" && curr.tool != "View") {
return;
}
if (tdata == null) {
var tsel = d3.select("#tsel").selectAll("option")
.filter(function (d, i) {
return this.selected;
});
tdata = tsel.data()[0];
var obj = d3.select("#tsel").node().options;
curr.tselIndex = obj.selectedIndex;
if (curr.tselIndex == -1) {
tdata = null;
}
}
if (tdata == null) {
return;
}
curr.currTData = tdata;
curr.igrade = null;
curr.rlist = null;
curr.graders = null;
if (curr.img && curr.currPage != tdata[3]) {
var url = "grade.php?go=getImage&input=" + curr.data[tdata[3] - 1][4] +
"&evid=" + curr.exam[0];
curr.img.setSrc(url, function (d) {
curr.currPage = tdata[3];
curr.hideObjects();
curr.fc.renderAll();
});
}
d3.select("#rlist").html(tdata[1] + " - [" + tdata[2] + "]   ");
if (curr.tool == "Grade") {
d3.select("#rlist").append("span").html("(+)")
.on('mouseover', function(){
d3.select(this).style('background-color', 'gray');})
.on('mouseout', function(){
d3.select(this).style('background-color', 'white');})
.on("click", function(e) {
if (!tdata[4]) { tdata[4] = []; }
var login = getUserLoginData();
tdata[4].push([tdata[4].length, "New rubric - edit", 0, "add",
login[3]]);
curr.updateRubric();
});
}
d3.select("#rlist").append("div").attr("id", "irlist");
d3.json("grade.php?go=getRubric&scanid=" + curr.data[0][0] +
"&templateid=" + tdata[0] + "&evid=" + curr.exam[0],
function (data) {
curr.currTData = tdata = data[0];
curr.updateRubric();
});