forked from ietf-tools/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_request.js
More file actions
167 lines (145 loc) · 5.2 KB
/
session_request.js
File metadata and controls
167 lines (145 loc) · 5.2 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright The IETF Trust 2015-2025, All Rights Reserved
/* global alert */
var ietf_sessions; // public interface
(function() {
'use strict';
function get_formset_management_data(prefix) {
return {
total_forms: document.getElementById('id_' + prefix + '-TOTAL_FORMS').value,
};
}
function update_session_form_visibility(session_num, is_visible) {
const elt = document.getElementById('session_row_' + session_num);
if (elt) {
elt.hidden = !is_visible;
elt.querySelector('[name$="DELETE"]').value = is_visible ? '' : 'on';
}
}
function have_additional_session() {
const elt = document.getElementById('id_third_session');
return elt && elt.checked;
}
function update_for_num_sessions(val) {
const total_forms = get_formset_management_data('session_set').total_forms;
val = Number(val);
if (have_additional_session()) {
val++;
}
for (let i=0; i < total_forms; i++) {
update_session_form_visibility(i, i < val);
}
const only_one_session = (val === 1);
if (document.form_post.session_time_relation) {
document.form_post.session_time_relation.disabled = only_one_session;
document.form_post.session_time_relation.closest('div.row').hidden = only_one_session;
}
if (document.form_post.joint_for_session) {
document.form_post.joint_for_session.disabled = only_one_session;
}
const third_session_row = document.getElementById('third_session_row');
if (third_session_row) {
third_session_row.hidden = val < 2;
}
}
function delete_last_joint_with_groups () {
var b = document.form_post.joint_with_groups.value;
var temp = b.split(' ');
temp.pop();
b = temp.join(' ');
document.form_post.joint_with_groups.value = b;
document.form_post.joint_with_groups_selector.selectedIndex=0;
}
/*******************************************************************/
// WG constraint UI support
// get the constraint field element for a given slug
function constraint_field(slug) {
return document.getElementById('id_constraint_' + slug);
}
// get the wg selection element for a given slug
function constraint_selector(slug) {
return document.getElementById('id_wg_selector_' + slug);
}
/**
* Handler for constraint select input 'change' event
*/
function wg_constraint_selector_changed() {
let slug = this.getAttribute('data-slug');
let cfield = constraint_field(slug);
// add selected value to constraint_field
cfield.value += ' ' + this.options[this.selectedIndex].value;
}
/**
* Remove the last group in a WG constraint field
*
* @param slug ConstraintName slug
*/
function delete_last_wg_constraint(slug) {
let cfield = constraint_field(slug);
if (cfield) {
var b = cfield.value;
var temp = b.split(' ');
temp.pop();
b = temp.join(' ');
cfield.value = b;
constraint_selector(slug).selectedIndex = 0;
}
}
/**
* Handle click event on a WG constraint's delete button
*
* @param slug ConstraintName slug
*/
function delete_wg_constraint_clicked(slug) {
delete_last_wg_constraint(slug);
}
/**
* Handler for the change event on the session count select or 'third session' checkbox
*/
function handle_num_session_change(event) {
const num_select_value = Number(event.target.value);
if (num_select_value !== 2) {
if (document.form_post.third_session) {
document.form_post.third_session.checked = false;
}
}
update_for_num_sessions(num_select_value);
}
function handle_third_session_change(event) {
const num_select_value = Number(document.getElementById('id_num_session').value);
if (num_select_value === 2) {
update_for_num_sessions(num_select_value);
} else {
event.target.checked = false;
}
}
function wg_constraint_delete_clicked(event) {
const constraint_name = event.currentTarget.dataset.constraint_name;
delete_last_wg_constraint(constraint_name);
}
/* Initialization */
function on_load() {
// Attach event handler to session count select
const num_session_select = document.getElementById('id_num_session');
num_session_select.addEventListener('change', handle_num_session_change);
const third_session_input = document.getElementById('id_third_session');
if (third_session_input) {
third_session_input.addEventListener('change', handle_third_session_change);
}
update_for_num_sessions(num_session_select.value);
// Attach event handlers to constraint selectors
let selectors = document.getElementsByClassName('wg_constraint_selector');
for (let index = 0; index < selectors.length; index++) {
selectors[index].addEventListener('change', wg_constraint_selector_changed, false)
}
// Attach event handler to constraint delete buttons
document.querySelectorAll('.wg_constraint_delete')
.forEach(btn => btn.addEventListener('click', wg_constraint_delete_clicked));
}
// initialize after page loads
window.addEventListener('load', on_load, false);
// expose public interface methods
ietf_sessions = {
delete_last_joint_with_groups: delete_last_joint_with_groups,
delete_wg_constraint_clicked: delete_wg_constraint_clicked
}
})();