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
This commit is contained in:
parent
e78637b9fc
commit
9d71ef3179
|
@ -11,54 +11,7 @@
|
|||
<link rel="stylesheet" href="/css/lib/select2.css">
|
||||
<link rel="stylesheet" href="/css/lib/select2-bootstrap.css">
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script>
|
||||
// this is copy-pasted from ietf.js, we should include that here too instead of this
|
||||
$(document).ready(function () {
|
||||
$(".select2-field").each(function () {
|
||||
var e = $(this);
|
||||
if (e.data("ajax-url")) {
|
||||
var maxEntries = e.data("max-entries");
|
||||
var multiple = maxEntries != 1;
|
||||
var prefetched = e.data("pre");
|
||||
e.select2({
|
||||
multiple: multiple,
|
||||
minimumInputLength: 2,
|
||||
width: "off",
|
||||
allowClear: true,
|
||||
maximumSelectionSize: maxEntries,
|
||||
ajax: {
|
||||
url: e.data("ajax-url"),
|
||||
dataType: "json",
|
||||
quietMillis: 250,
|
||||
data: function (term, page) {
|
||||
return {
|
||||
q: term,
|
||||
p: page
|
||||
};
|
||||
},
|
||||
results: function (results) {
|
||||
return {
|
||||
results: results,
|
||||
more: results.length == 10
|
||||
};
|
||||
}
|
||||
},
|
||||
escapeMarkup: function (m) {
|
||||
return m;
|
||||
},
|
||||
initSelection: function (element, cb) {
|
||||
if (!multiple && prefetched.length > 0)
|
||||
cb(prefetched[0]);
|
||||
else
|
||||
cb(prefetched);
|
||||
|
||||
},
|
||||
dropdownCssClass: "bigdrop"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumbs %}{{ block.super }}
|
||||
|
|
|
@ -9,54 +9,7 @@
|
|||
<link rel="stylesheet" href="/css/lib/select2.css">
|
||||
<link rel="stylesheet" href="/css/lib/select2-bootstrap.css">
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script>
|
||||
// this is copy-pasted from ietf.js, we should include that here too instead of this
|
||||
$(document).ready(function () {
|
||||
$(".select2-field").each(function () {
|
||||
var e = $(this);
|
||||
if (e.data("ajax-url")) {
|
||||
var maxEntries = e.data("max-entries");
|
||||
var multiple = maxEntries != 1;
|
||||
var prefetched = e.data("pre");
|
||||
e.select2({
|
||||
multiple: multiple,
|
||||
minimumInputLength: 2,
|
||||
width: "off",
|
||||
allowClear: true,
|
||||
maximumSelectionSize: maxEntries,
|
||||
ajax: {
|
||||
url: e.data("ajax-url"),
|
||||
dataType: "json",
|
||||
quietMillis: 250,
|
||||
data: function (term, page) {
|
||||
return {
|
||||
q: term,
|
||||
p: page
|
||||
};
|
||||
},
|
||||
results: function (results) {
|
||||
return {
|
||||
results: results,
|
||||
more: results.length == 10
|
||||
};
|
||||
}
|
||||
},
|
||||
escapeMarkup: function (m) {
|
||||
return m;
|
||||
},
|
||||
initSelection: function (element, cb) {
|
||||
if (!multiple && prefetched.length > 0)
|
||||
cb(prefetched[0]);
|
||||
else
|
||||
cb(prefetched);
|
||||
|
||||
},
|
||||
dropdownCssClass: "bigdrop"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumbs %}{{ block.super }}
|
||||
|
|
|
@ -9,54 +9,7 @@
|
|||
<link rel="stylesheet" href="/css/lib/select2.css">
|
||||
<link rel="stylesheet" href="/css/lib/select2-bootstrap.css">
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script>
|
||||
// this is copy-pasted from ietf.js, we should include that here too instead of this
|
||||
$(document).ready(function () {
|
||||
$(".select2-field").each(function () {
|
||||
var e = $(this);
|
||||
if (e.data("ajax-url")) {
|
||||
var maxEntries = e.data("max-entries");
|
||||
var multiple = maxEntries != 1;
|
||||
var prefetched = e.data("pre");
|
||||
e.select2({
|
||||
multiple: multiple,
|
||||
minimumInputLength: 2,
|
||||
width: "off",
|
||||
allowClear: true,
|
||||
maximumSelectionSize: maxEntries,
|
||||
ajax: {
|
||||
url: e.data("ajax-url"),
|
||||
dataType: "json",
|
||||
quietMillis: 250,
|
||||
data: function (term, page) {
|
||||
return {
|
||||
q: term,
|
||||
p: page
|
||||
};
|
||||
},
|
||||
results: function (results) {
|
||||
return {
|
||||
results: results,
|
||||
more: results.length == 10
|
||||
};
|
||||
}
|
||||
},
|
||||
escapeMarkup: function (m) {
|
||||
return m;
|
||||
},
|
||||
initSelection: function (element, cb) {
|
||||
if (!multiple && prefetched.length > 0)
|
||||
cb(prefetched[0]);
|
||||
else
|
||||
cb(prefetched);
|
||||
|
||||
},
|
||||
dropdownCssClass: "bigdrop"
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
{% endblock %}
|
||||
|
||||
{% block breadcrumbs %}{{ block.super }}
|
||||
|
|
|
@ -30,4 +30,5 @@
|
|||
|
||||
{% block js %}
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -29,4 +29,5 @@
|
|||
|
||||
{% block js %}
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -52,6 +52,7 @@ so. New accounts can be <a href="{% url "create_account" %}">created here</a>.</
|
|||
|
||||
{% block js %}
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$("#id_acronym").closest(".form-group").each(function() {
|
||||
|
|
|
@ -94,6 +94,7 @@
|
|||
|
||||
{% block js %}
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
<script src="/js/lib/bootstrap-datepicker.js"></script>
|
||||
<script src="/js/edit-milestones.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -43,4 +43,5 @@
|
|||
|
||||
{% block js %}
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -242,6 +242,7 @@
|
|||
|
||||
{% block js %}
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
<script src="/js/lib/bootstrap-datepicker.js"></script>
|
||||
<script src="/js/ipr-edit.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -61,5 +61,6 @@
|
|||
{% block js %}
|
||||
<script src="/js/lib/bootstrap-datepicker.js"></script>
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
<script src="/js/liaisons.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -28,4 +28,5 @@
|
|||
|
||||
{% block content_end %}
|
||||
<script src="/js/lib/select2-3.5.2.min.js"></script>
|
||||
<script src="/js/select2-field.js"></script>
|
||||
{% endblock %}
|
||||
|
|
|
@ -206,60 +206,6 @@ $(".snippet .show-all").click(function () {
|
|||
// }
|
||||
// });
|
||||
|
||||
function setupSelect2Field(e) {
|
||||
var url = e.data("ajax-url");
|
||||
if (!url)
|
||||
return;
|
||||
|
||||
var maxEntries = e.data("max-entries");
|
||||
var multiple = maxEntries != 1;
|
||||
var prefetched = e.data("pre");
|
||||
e.select2({
|
||||
multiple: multiple,
|
||||
minimumInputLength: 2,
|
||||
width: "off",
|
||||
allowClear: true,
|
||||
maximumSelectionSize: maxEntries,
|
||||
ajax: {
|
||||
url: url,
|
||||
dataType: "json",
|
||||
quietMillis: 250,
|
||||
data: function (term, page) {
|
||||
return {
|
||||
q: term,
|
||||
p: page
|
||||
};
|
||||
},
|
||||
results: function (results) {
|
||||
return {
|
||||
results: results,
|
||||
more: results.length == 10
|
||||
};
|
||||
}
|
||||
},
|
||||
escapeMarkup: function (m) {
|
||||
return m;
|
||||
},
|
||||
initSelection: function (element, cb) {
|
||||
if (!multiple && prefetched.length > 0)
|
||||
cb(prefetched[0]);
|
||||
else
|
||||
cb(prefetched);
|
||||
|
||||
},
|
||||
dropdownCssClass: "bigdrop"
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$(".select2-field").each(function () {
|
||||
if ($(this).closest(".template").length > 0)
|
||||
return;
|
||||
|
||||
setupSelect2Field($(this));
|
||||
});
|
||||
});
|
||||
|
||||
// Use the Bootstrap3 tooltip plugin for all elements with a title attribute
|
||||
$('[title][title!=""]').tooltip();
|
||||
|
||||
|
|
55
static/js/select2-field.js
Normal file
55
static/js/select2-field.js
Normal file
|
@ -0,0 +1,55 @@
|
|||
// currently we only include select2 CSS/JS on those pages where forms
|
||||
// need it, so the generic setup code here is also kept separate
|
||||
function setupSelect2Field(e) {
|
||||
var url = e.data("ajax-url");
|
||||
if (!url)
|
||||
return;
|
||||
|
||||
var maxEntries = e.data("max-entries");
|
||||
var multiple = maxEntries != 1;
|
||||
var prefetched = e.data("pre");
|
||||
e.select2({
|
||||
multiple: multiple,
|
||||
minimumInputLength: 2,
|
||||
width: "off",
|
||||
allowClear: true,
|
||||
maximumSelectionSize: maxEntries,
|
||||
ajax: {
|
||||
url: url,
|
||||
dataType: "json",
|
||||
quietMillis: 250,
|
||||
data: function (term, page) {
|
||||
return {
|
||||
q: term,
|
||||
p: page
|
||||
};
|
||||
},
|
||||
results: function (results) {
|
||||
return {
|
||||
results: results,
|
||||
more: results.length == 10
|
||||
};
|
||||
}
|
||||
},
|
||||
escapeMarkup: function (m) {
|
||||
return m;
|
||||
},
|
||||
initSelection: function (element, cb) {
|
||||
if (!multiple && prefetched.length > 0)
|
||||
cb(prefetched[0]);
|
||||
else
|
||||
cb(prefetched);
|
||||
|
||||
},
|
||||
dropdownCssClass: "bigdrop"
|
||||
});
|
||||
}
|
||||
|
||||
$(document).ready(function () {
|
||||
$(".select2-field").each(function () {
|
||||
if ($(this).closest(".template").length > 0)
|
||||
return;
|
||||
|
||||
setupSelect2Field($(this));
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue