forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipr-edit.js
More file actions
72 lines (61 loc) · 2.43 KB
/
ipr-edit.js
File metadata and controls
72 lines (61 loc) · 2.43 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
$(document)
.ready(function () {
var form = $(".ipr-form");
$('.draft-add-row')
.on("click", function () {
var template = form.find('.draft-row.template');
var el = template.clone(true)
.removeClass("template d-none");
var totalField = $('#id_iprdocrel_set-TOTAL_FORMS');
var total = +totalField.val();
el.find("*[for*=iprdocrel], *[id*=iprdocrel], *[name*=iprdocrel]")
.not(".d-none")
.each(function () {
var x = $(this);
["for", "id", "name"].forEach(function (at) {
var val = x.attr(at);
if (val && val.match("iprdocrel")) {
x.attr(at, val.replace('__prefix__', total.toString()));
}
});
});
++total;
totalField.val(total);
template.before(el);
el.find('.select2-field').each((index, element) => setupSelect2Field($(element)));
});
function updateRevisions() {
if ($(this)
.hasClass("template"))
return;
var selectbox = $(this)
.find('[name$="document"]');
if (selectbox.val()) {
var name = selectbox.select2("data")[0]
.text;
var prefix = name.toLowerCase()
.substring(0, 3);
if (prefix == "rfc" || prefix == "bcp" || prefix == "std")
$(this)
.find('[name$=revisions]')
.val("")
.hide();
else
$(this)
.find('[name$=revisions]')
.show();
}
}
form.on("change", ".select2-field", function () {
$(this)
.closest(".draft-row")
.each(updateRevisions);
});
// add a little bit of delay to let the select2 box have time to do its magic
// FIXME: this should be done after a select2 event fires!
// See https://select2.org/programmatic-control/events
setTimeout(function () {
form.find(".draft-row")
.each(updateRevisions);
}, 10);
});