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
|
<!-- 'Layer dependencies modal' -->
<div id="dependencies_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-hidden="true">
<form id="dependencies_modal_form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3><span id="title"></span> dependencies</h3>
</div>
<div class="modal-body">
<p id="body-text"> <strong id="layer-name"></strong> depends on some layers that are not added to your project. Select the ones you want to add:</p>
<ul class="unstyled" id="dependencies_list">
</ul>
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="submit">Add layers</button>
<button class="btn" type="reset" data-dismiss="modal">Cancel</button>
</div>
</form>
</div>
<script>
function show_layer_deps_modal(projectId, layer, dependencies, title, body, addToProject, successAdd) {
// update layer name
if (title) {
$('#dependencies_modal #title').text(title);
} else {
$('#dependencies_modal #title').text(layer.name);
}
if (body) {
$("#dependencies_modal #body-text").html(body);
} else {
$("#dependencies_modal #layer-name").text(layer.name);
}
var deplistHtml = "";
for (var i = 0; i < dependencies.length; i++) {
deplistHtml += "<li><label class=\"checkbox\"><input name=\"dependencies\" value=\"";
deplistHtml += dependencies[i].id;
deplistHtml +="\" type=\"checkbox\" checked=\"checked\"/>";
deplistHtml += dependencies[i].name;
deplistHtml += "</label></li>";
}
$('#dependencies_list').html(deplistHtml);
var selected = [];
/* -1 is a special dummy Id which we use when the layer isn't yet in the
* system, normally we would add the current layer to the selection.
*/
if (layer.id != -1)
selected.push(layer.id);
var layer_link_list = "<a href='"+layer.url+"'>"+layer.name+"</a>";
$("#dependencies_modal_form").submit(function (e) {
e.preventDefault();
$("input[name='dependencies']:checked").map(function () { selected.push(parseInt($(this).val()))});
if (selected.length > 1) {
tooltipUpdateText = "" + selected.length + " layers added";
} else {
tooltipUpdateText = "1 layer added";
}
for (var i = 0; i < selected.length; i++) {
for (var j = 0; j < dependencies.length; j++) {
if (dependencies[j].id == selected[i]) {
layer_link_list+= ", <a href='"+dependencies[j].layerdetailurl+"'>"+dependencies[j].name+"</a>"
break;
}
}
}
$('#dependencies_modal').modal('hide');
if (addToProject) {
var editProjectUrl = "{% url 'xhr_projectedit' project.id %}";
libtoaster.editProject(editProjectUrl, projectId, { 'layerAdd': selected.join(",") }, function () {
if (successAdd) {
successAdd(selected);
}
}, function () {
console.log ("Adding layers to project failed");
});
} else {
successAdd(selected);
}
});
$('#dependencies_modal').modal('show');
}
</script>
|