-
Notifications
You must be signed in to change notification settings - Fork 1
/
makeGroups.js
executable file
·138 lines (110 loc) · 2.99 KB
/
makeGroups.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
$( document ).ready(function() {
var areGroupsMade;
$.ajax({
url: "getGroupsMade.php",
async: false,
type: "POST",
data: {authorID: gup("authorID")},
success: function(d){
if(d == 1){
areGroupsMade = true;
}
else areGroupsMade = false;
},
error:function(){
alert("failure");
}
});
if(areGroupsMade){
$("#makeGroupsButton").attr("disabled", true);
//$("#makeGroupsButton").hide();
var adjustment
$("ol.group").sortable({
group: 'simple_with_animation',
pullPlaceholder: false,
// animation on drop
onDrop: function (item, targetContainer, _super) {
var clonedItem = $('<li/>').css({height: 0})
item.before(clonedItem)
clonedItem.animate({'height': item.height()})
item.animate(clonedItem.position(), function () {
clonedItem.detach()
_super(item)
})
},
// set item relative to cursor position
onDragStart: function ($item, container, _super) {
var offset = $item.offset(),
pointer = container.rootGroup.pointer
adjustment = {
left: pointer.left - offset.left,
top: pointer.top - offset.top
}
_super($item, container)
},
onDrag: function ($item, position) {
$item.css({
left: position.left - adjustment.left,
top: position.top - adjustment.top
})
}
})
}
$( "#makeGroupsButton" ).click(function( event ) {
$.ajax({
url: "makeGroup.php",
async: false,
type: "POST",
data: {authorID: gup("authorID")},
success: function(d){
// alert("Groups made!")
},
error:function(){
alert("failure");
}
});
event.preventDefault();
location.reload();
// document.location.href = 'authorResult.php?projectID=' + projectID;
});
$( "#saveAuthorChanges" ).click(function( event ) {
var numGroups;
$.ajax({
url: "getNumGroups.php",
async: false,
type: "POST",
data: {authorID: gup("authorID")},
success: function(d){
numGroups = d;
},
error:function(){
alert("failure");
}
});
// alert(numGroups);
var students = new Array(numGroups);
for(var i = 0; i < numGroups; i++){
students[i] = new Array();
$('#group' + i + ' li').each(function(j, elem) {
students[i].push($(elem).text());
});
}
// alert(students[0]);
$.ajax({
url: "updateGroups.php",
async: false,
type: "POST",
data: {authorID: gup("authorID"), students: JSON.stringify(students)},
success: function(d){
alert("Groups updated!")
// alert(d);
},
error:function(){
alert("failure");
}
});
// event.preventDefault();
// location.reload();
// document.location.href = 'authorResult.php?projectID=' + projectID;
});
});