forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipr-edit.js
More file actions
55 lines (43 loc) · 1.68 KB
/
ipr-edit.js
File metadata and controls
55 lines (43 loc) · 1.68 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
$(document).ready(function() {
var form = $(".ipr-form");
var template = form.find('.draft-row.template');
var templateData = template.clone();
$('.draft-add-row').click(function() {
var el = template.clone(true);
var totalField = $('#id_iprdocrel_set-TOTAL_FORMS');
var total = +totalField.val();
el.find(':input').each(function() {
var name = $(this).attr('name').replace('-' + (total-1) + '-','-' + total + '-');
var id = 'id_' + name;
$(this).attr({'name': name, 'id': id}).val('');
});
el.find('label').each(function() {
var newFor = $(this).attr('for').replace('-' + (total-1) + '-','-' + total + '-');
$(this).attr('for', newFor);
});
++total;
totalField.val(total);
template.before(el);
el.removeClass("template");
el.find(".select2-field").each(function () {
setupSelect2Field($(this));
});
});
function updateRevisions() {
var selectbox = $(this).find('[name$="document"]');
if (selectbox.val()) {
var name = selectbox.select2("data").text;
if (name.toLowerCase().substring(0, 3) == "rfc")
$(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
setTimeout(function () {
form.find(".draft-row").each(updateRevisions);
}, 10);
});