forked from cbsandeep10/IMathAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoveitem.js
More file actions
executable file
·99 lines (95 loc) · 2.4 KB
/
moveitem.js
File metadata and controls
executable file
·99 lines (95 loc) · 2.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
$(function() {
//if we're moving a block, don't list it in destination blocks
moveItemAddBlockOptions(blockinfo, "0", item.match(/B/)?item.substr(1):null, "");
$("#blockselect").val(block);
$("#blockselect").on('change', function() {
moveItemAddBlockItems($(this).val());
});
moveItemAddBlockItems(block);
});
//skip is block ID or null
function moveItemAddBlockOptions(arr,parent,skip,pre) {
var blockref;
if (parent=="0") {
$("#blockselect").append($('<option>', {
value: "0",
text: _("Main Course Page")
}));
}
for (var i=0;i<arr.length;i++) {
if (typeof arr[i] === 'object') {
//is a block
blockref = parent+'-'+(i+1);
if (arr[i]['id']==skip) {continue;}
$("#blockselect").append($('<option>', {
value: blockref,
text: pre+arr[i]['name']
}));
moveItemAddBlockOptions(arr[i]['items'], blockref, skip, "- "+pre);
}
}
}
function moveItemAddBlockItems(block) {
var i,blockref;
var parts = block.split(/-/);
var thisitems = blockinfo.slice();
if (parts.length>1) {
for (i=1;i<parts.length;i++) {
thisitems = thisitems[parts[i]-1]['items'].slice();
}
}
$("#itemselect").find("option").remove();
$("#itemselect").append($('<option>', {
value: 'top',
text: (parts.length>1)?_("Top of the Block"):_("Top of the Page")
}));
var index = 0; var selectedindex = 0;
for (i=0;i<thisitems.length;i++) {
if (typeof thisitems[i] === 'object') {
//is a block
if (item != 'B'+thisitems[i]['id']) { //skip if this is the item we're moving
$("#itemselect").append($('<option>', {
value: 'B'+thisitems[i]['id'],
text: thisitems[i]['name']
}));
index++;
} else {
selectedindex = index;
}
} else {
if (item != thisitems[i]) { //skip if this is the item we're moving
$("#itemselect").append($('<option>', {
value: thisitems[i],
text: iteminfo[thisitems[i]][1]
}));
index++;
} else {
selectedindex = index;
}
}
}
document.getElementById("itemselect").selectedIndex = selectedindex;
}
function moveitem() {
var data = {
item: item,
block: block,
newblock: $("#blockselect").val(),
moveafter: $("#itemselect").val()
};
$.ajax({
type: "POST",
url: imasroot+"/course/moveitem.php?cid="+cid,
data: data,
dataType: "html"
}).done(function(data) {
if (data=="OK") {
window.parent.location.reload();
} else {
$("#error").append(data);
}
});
}
function cancelmove() {
window.parent.GB_hide();
}