Skip to content

Commit 9d71ef3

Browse files
committed
Summary: Move select2 field handling to a separate .js file, currently
we only include the select2 things on pages with forms that need it anyway, and this makes it easier to use it in the Secretariat code - Legacy-Id: 8986
1 parent e78637b commit 9d71ef3

13 files changed

Lines changed: 66 additions & 198 deletions

File tree

ietf/secr/templates/drafts/edit.html

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,54 +11,7 @@
1111
<link rel="stylesheet" href="/css/lib/select2.css">
1212
<link rel="stylesheet" href="/css/lib/select2-bootstrap.css">
1313
<script src="/js/lib/select2-3.5.2.min.js"></script>
14-
<script>
15-
// this is copy-pasted from ietf.js, we should include that here too instead of this
16-
$(document).ready(function () {
17-
$(".select2-field").each(function () {
18-
var e = $(this);
19-
if (e.data("ajax-url")) {
20-
var maxEntries = e.data("max-entries");
21-
var multiple = maxEntries != 1;
22-
var prefetched = e.data("pre");
23-
e.select2({
24-
multiple: multiple,
25-
minimumInputLength: 2,
26-
width: "off",
27-
allowClear: true,
28-
maximumSelectionSize: maxEntries,
29-
ajax: {
30-
url: e.data("ajax-url"),
31-
dataType: "json",
32-
quietMillis: 250,
33-
data: function (term, page) {
34-
return {
35-
q: term,
36-
p: page
37-
};
38-
},
39-
results: function (results) {
40-
return {
41-
results: results,
42-
more: results.length == 10
43-
};
44-
}
45-
},
46-
escapeMarkup: function (m) {
47-
return m;
48-
},
49-
initSelection: function (element, cb) {
50-
if (!multiple && prefetched.length > 0)
51-
cb(prefetched[0]);
52-
else
53-
cb(prefetched);
54-
55-
},
56-
dropdownCssClass: "bigdrop"
57-
});
58-
}
59-
});
60-
});
61-
</script>
14+
<script src="/js/select2-field.js"></script>
6215
{% endblock %}
6316

6417
{% block breadcrumbs %}{{ block.super }}

ietf/secr/templates/sreq/edit.html

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,7 @@
99
<link rel="stylesheet" href="/css/lib/select2.css">
1010
<link rel="stylesheet" href="/css/lib/select2-bootstrap.css">
1111
<script src="/js/lib/select2-3.5.2.min.js"></script>
12-
<script>
13-
// this is copy-pasted from ietf.js, we should include that here too instead of this
14-
$(document).ready(function () {
15-
$(".select2-field").each(function () {
16-
var e = $(this);
17-
if (e.data("ajax-url")) {
18-
var maxEntries = e.data("max-entries");
19-
var multiple = maxEntries != 1;
20-
var prefetched = e.data("pre");
21-
e.select2({
22-
multiple: multiple,
23-
minimumInputLength: 2,
24-
width: "off",
25-
allowClear: true,
26-
maximumSelectionSize: maxEntries,
27-
ajax: {
28-
url: e.data("ajax-url"),
29-
dataType: "json",
30-
quietMillis: 250,
31-
data: function (term, page) {
32-
return {
33-
q: term,
34-
p: page
35-
};
36-
},
37-
results: function (results) {
38-
return {
39-
results: results,
40-
more: results.length == 10
41-
};
42-
}
43-
},
44-
escapeMarkup: function (m) {
45-
return m;
46-
},
47-
initSelection: function (element, cb) {
48-
if (!multiple && prefetched.length > 0)
49-
cb(prefetched[0]);
50-
else
51-
cb(prefetched);
52-
53-
},
54-
dropdownCssClass: "bigdrop"
55-
});
56-
}
57-
});
58-
});
59-
</script>
12+
<script src="/js/select2-field.js"></script>
6013
{% endblock %}
6114

6215
{% block breadcrumbs %}{{ block.super }}

ietf/secr/templates/sreq/new.html

Lines changed: 1 addition & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,7 @@
99
<link rel="stylesheet" href="/css/lib/select2.css">
1010
<link rel="stylesheet" href="/css/lib/select2-bootstrap.css">
1111
<script src="/js/lib/select2-3.5.2.min.js"></script>
12-
<script>
13-
// this is copy-pasted from ietf.js, we should include that here too instead of this
14-
$(document).ready(function () {
15-
$(".select2-field").each(function () {
16-
var e = $(this);
17-
if (e.data("ajax-url")) {
18-
var maxEntries = e.data("max-entries");
19-
var multiple = maxEntries != 1;
20-
var prefetched = e.data("pre");
21-
e.select2({
22-
multiple: multiple,
23-
minimumInputLength: 2,
24-
width: "off",
25-
allowClear: true,
26-
maximumSelectionSize: maxEntries,
27-
ajax: {
28-
url: e.data("ajax-url"),
29-
dataType: "json",
30-
quietMillis: 250,
31-
data: function (term, page) {
32-
return {
33-
q: term,
34-
p: page
35-
};
36-
},
37-
results: function (results) {
38-
return {
39-
results: results,
40-
more: results.length == 10
41-
};
42-
}
43-
},
44-
escapeMarkup: function (m) {
45-
return m;
46-
},
47-
initSelection: function (element, cb) {
48-
if (!multiple && prefetched.length > 0)
49-
cb(prefetched[0]);
50-
else
51-
cb(prefetched);
52-
53-
},
54-
dropdownCssClass: "bigdrop"
55-
});
56-
}
57-
});
58-
});
59-
</script>
12+
<script src="/js/select2-field.js"></script>
6013
{% endblock %}
6114

6215
{% block breadcrumbs %}{{ block.super }}

ietf/templates/doc/change_shepherd.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ <h1>Change document shepherd<br><small>{{ doc.name }}-{{ doc.rev }}</small></h1>
3030

3131
{% block js %}
3232
<script src="/js/lib/select2-3.5.2.min.js"></script>
33+
<script src="/js/select2-field.js"></script>
3334
{% endblock %}

ietf/templates/doc/draft/change_replaces.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ <h1>Change documents replaced by<br><small>{{ doc }}</small></h1>
2929

3030
{% block js %}
3131
<script src="/js/lib/select2-3.5.2.min.js"></script>
32+
<script src="/js/select2-field.js"></script>
3233
{% endblock %}

ietf/templates/group/edit.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ <h1>
5252

5353
{% block js %}
5454
<script src="/js/lib/select2-3.5.2.min.js"></script>
55+
<script src="/js/select2-field.js"></script>
5556
<script>
5657
$(document).ready(function () {
5758
$("#id_acronym").closest(".form-group").each(function() {

ietf/templates/group/edit_milestones.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ <h1>{{ title }}</h1>
9494

9595
{% block js %}
9696
<script src="/js/lib/select2-3.5.2.min.js"></script>
97+
<script src="/js/select2-field.js"></script>
9798
<script src="/js/lib/bootstrap-datepicker.js"></script>
9899
<script src="/js/edit-milestones.js"></script>
99100
{% endblock %}

ietf/templates/group/stream_edit.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ <h1>Manage {{ group.name }} RFC stream</h1>
4343

4444
{% block js %}
4545
<script src="/js/lib/select2-3.5.2.min.js"></script>
46+
<script src="/js/select2-field.js"></script>
4647
{% endblock %}

ietf/templates/ipr/details_edit.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ <h2>{% cycle section %}. Other notes</h2>
242242

243243
{% block js %}
244244
<script src="/js/lib/select2-3.5.2.min.js"></script>
245+
<script src="/js/select2-field.js"></script>
245246
<script src="/js/lib/bootstrap-datepicker.js"></script>
246247
<script src="/js/ipr-edit.js"></script>
247248
{% endblock %}

ietf/templates/liaisons/edit.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,6 @@ <h2>{{ fieldset.name }}</h2>
6161
{% block js %}
6262
<script src="/js/lib/bootstrap-datepicker.js"></script>
6363
<script src="/js/lib/select2-3.5.2.min.js"></script>
64+
<script src="/js/select2-field.js"></script>
6465
<script src="/js/liaisons.js"></script>
6566
{% endblock %}

0 commit comments

Comments
 (0)