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
137 lines (124 loc) · 5.19 KB
/
ipr-edit.js
File metadata and controls
137 lines (124 loc) · 5.19 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
$(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);
// Manage fields that depend on the Blanket IPR Disclosure choice
const blanketCheckbox = document.getElementById('id_is_blanket_disclosure')
if (blanketCheckbox) {
const patentDetailInputs = [
// The ids are from the HolderIprDisclosureForm and its base form class,
// intentionally excluding patent_notes because it's never required
'id_patent_number',
'id_patent_inventor',
'id_patent_title',
'id_patent_date'
].map((id) => document.getElementById(id))
const patentDetailRowDivs = patentDetailInputs.map(
(elt) => elt.closest('div.row')
)
const royaltyFreeLicensingRadio = document.querySelector(
'#id_licensing input[value="royalty-free"]'
)
let lastSelectedLicensingRadio
const otherLicensingRadios = document.querySelectorAll(
'#id_licensing input:not([value="royalty-free"])'
)
const handleBlanketCheckboxChange = () => {
const isBlanket = blanketCheckbox.checked
// Update required fields
for (elt of patentDetailInputs) {
// disable the input element
elt.required = !isBlanket
}
for (elt of patentDetailRowDivs) {
// update the styling on the row that indicates required field
if (isBlanket) {
elt.classList.remove('required')
} else {
elt.classList.add('required')
}
}
// Update licensing selection
if (isBlanket) {
lastSelectedLicensingRadio = document.querySelector(
'#id_licensing input:checked'
)
royaltyFreeLicensingRadio.checked = true
otherLicensingRadios
.forEach(
(elt) => elt.setAttribute('disabled', '')
)
} else {
royaltyFreeLicensingRadio.checked = false
if (lastSelectedLicensingRadio) {
lastSelectedLicensingRadio.checked = true
}
otherLicensingRadios
.forEach(
(elt) => elt.removeAttribute('disabled')
)
}
}
handleBlanketCheckboxChange()
blanketCheckbox.addEventListener(
'change',
(evt) => handleBlanketCheckboxChange()
)
}
});