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
|
/**
* We've clicked the + icon next to a directory. Load up children of this
* directory from the server and display them.
*/
function open_close_branch(path, id) {
var parent = $("#file_" + id);
var children = $("#tree_" + id);
var icon = parent.find(".ui-icon:first");
if (!children.html()) {
parent.addClass("gLoadingSmall");
$.ajax({
url: GET_CHILDREN_URL.replace("__PATH__", path),
success: function(data, textStatus) {
children.html(data);
parent.removeClass("gLoadingSmall");
// Propagate checkbox value
children.find("input[type=checkbox]").attr(
"checked", parent.find("input[type=checkbox]:first").attr("checked"));
}
});
}
children.slideToggle("fast", function() {
if (children.is(":hidden")) {
icon.addClass("ui-icon-plus");
icon.removeClass("ui-icon-minus");
} else {
icon.addClass("ui-icon-minus");
icon.removeClass("ui-icon-plus");
parent.removeClass("gCollapsed");
}
});
}
/**
* We've clicked a checkbox. Propagate the value downwards as necessary.
*/
function click_node(checkbox) {
var parent = $(checkbox).parents("li").get(0);
var checked = $(checkbox).attr("checked");
$(parent).find("input[type=checkbox]").attr("checked", checked);
// @todo if we uncheck all the children for a parent, we should uncheck the
// parent itself, otherwise in the code we'll add the entire parent since if
// we find an album as a leaf, we assume that it's never been expanded in the UI.
if ($("#gServerAddTree").find("input[type=checkbox]").is(":checked")) {
$("#gServerAddAddButton").enable(true);
$("#gServerAddAddButton").removeClass("ui-state-disabled");
} else {
$("#gServerAddAddButton").enable(false);
$("#gServerAddAddButton").addClass("ui-state-disabled");
}
}
function start_add() {
var paths = [];
$.each($("#gServerAdd :checkbox[checked]"), function () {
paths.push(this.value);
});
$.ajax({
url: START_URL,
type: "POST",
async: false,
data: { "paths[]": paths },
dataType: "json",
success: function(data, textStatus) {
$("#gStatus").html(data.status);
$("#gServerAdd .gProgressBar").progressbar("value", data.percent_complete);
setTimeout(function() { run_add(data.url); }, 0);
}
});
return false;
}
function run_add(url) {
$.ajax({
url: url,
async: false,
dataType: "json",
success: function(data, textStatus) {
$("#gStatus").html(data.status);
$("#gServerAdd .gProgressBar").progressbar("value", data.percent_complete);
if (data.done) {
$("#gProgress").slideUp();
} else {
setTimeout(function() { run_add(url); }, 0);
}
}
});
}
|