-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
284 lines (248 loc) · 7.6 KB
/
form.js
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
'use strict'
/**
* Toggle the visibilty of a form group
*
* @param {string} form_id The form identifier
* @param {boolean} show Whether to show or hide
*/
function toggle_visibility_of_form_group(form_id, show) {
let form_element = $(form_id);
let parent = form_element.parent();
if(show) {
parent.show();
} else {
form_element.val('');
parent.hide();
}
}
/**
* Toggle the visibility of the jupyterlab check-box
*
* Looking for the value of data-has-jupyterlab
*/
function toggle_jupyterlab_switch_visibility() {
let custom_environment_input = $('#batch_connect_session_context_custom_environment');
// Allow for jupyter_swtich control not existing
if ( ! ($('#batch_connect_session_context_jupyterlab_switch').length > 0) ) {
return;
}
toggle_visibility_of_form_group(
'#batch_connect_session_context_jupyterlab_switch',
custom_environment_input.find(':selected').data('has-jupyterlab')
);
}
/**
* Toggle the visibility of the gpu_type and gpu_devel_type selects
*/
function toggle_gpu_type_visibility() {
// return if no partitions
if ( ! ($('#batch_connect_session_context_partitions').length > 0) ) {
return;
}
let partition_input = $('#batch_connect_session_context_partitions');
let gpu_type_input = $('#batch_connect_session_context_gpu_type');
let gpu_devel_type_input = $('#batch_connect_session_context_gpu_devel_type');
if ( gpu_devel_type_input.length > 0 ) {
if ( partition_input[0].value === "gpu_devel" ){
toggle_visibility_of_form_group(gpu_devel_type_input, 1);
}else{
toggle_visibility_of_form_group(gpu_devel_type_input, 0);
gpu_devel_type_input.val('');
}
}
if ( gpu_type_input.length > 0 ) {
if ( partition_input[0].value === "gpu" ){
toggle_visibility_of_form_group(gpu_type_input, 1);
}else{
toggle_visibility_of_form_group(gpu_type_input, 0);
gpu_type_input.val('');
}
}
/*
*/
/*
if ( partition_input[0].value === "gpu_devel" ){
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_devel_type', 1
);
}else{
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_devel_type', 0
);
}
if ( partition_input[0].value === "gpu" ){
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_type', 1
);
}else{
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_type', 0
);
}
if ( partition_input[0].value.match("gpu_devel") != null ){
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_devel_type', 1
);
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_type', 0
);
}else if ( partition_input[0].value.match("gpu") != null ){
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_devel_type', 0
);
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_type', 1
);
}
else{
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_devel_type', 0
);
toggle_visibility_of_form_group(
'#batch_connect_session_context_gpu_type', 0
);
}
*/
}
/**
* Toggle the visibility of the num_gpu select
*
* Looking for the value of data-has-gpu from partition to toggle on/off num_gpu
*/
function toggle_num_gpu_visibility() {
// return if no partitions
if ( ! ($('#batch_connect_session_context_partitions').length > 0) ) {
return;
}
// return if no num_gpu
if ( ! ($('#batch_connect_session_context_num_gpu').length > 0) ) {
return;
}
let partition_input = $('#batch_connect_session_context_partitions');
let num_gpu_input = $('#batch_connect_session_context_num_gpu');
if ( partition_input[0].value.match("gpu") != null ){
num_gpu_input.attr('min', 1);
num_gpu_input.val('1');
}
else{
num_gpu_input.attr('min', 0);
num_gpu_input.val('');
}
toggle_visibility_of_form_group(
'#batch_connect_session_context_num_gpu',
partition_input.find(':selected').data('has-gpu')
);
}
/**
* set max hours for seleted partition
*/
function fix_num_hours() {
if ( ! ($('#batch_connect_session_context_bc_num_hours').length > 0) ) {
return;
}
let partition_input = $('#batch_connect_session_context_partitions');
let num_hours_input = $('#batch_connect_session_context_bc_num_hours');
num_hours_input.attr('max', partition_input.find(':selected').data('max-hours'));
}
/**
* toggle on/off additional user input options
*/
function toggle_advanced_options_visibility() {
// return if no advaned_options
if ( ! ($('#batch_connect_session_context_advanced_options').length > 0) ) {
return;
}
var advanced_options = document.getElementById("batch_connect_session_context_advanced_options");
if ($('#batch_connect_session_context_bc_account').length > 0) {
toggle_visibility_of_form_group(
'#batch_connect_session_context_bc_account',
advanced_options.checked
);
}
if ($('#batch_connect_session_context_module_collection').length > 0) {
toggle_visibility_of_form_group(
'#batch_connect_session_context_module_collection',
advanced_options.checked
);
}
/*
if ($('#batch_connect_session_context_additional_modules').length > 0) {
toggle_visibility_of_form_group(
'#batch_connect_session_context_additional_modules',
advanced_options.checked
);
}
*/
if ($('#batch_connect_session_context_advanced_job_options').length > 0) {
toggle_visibility_of_form_group(
'#batch_connect_session_context_advanced_job_options',
advanced_options.checked
);
}
if ($('#batch_connect_session_context_java_opts').length > 0) {
toggle_visibility_of_form_group(
'#batch_connect_session_context_java_opts',
advanced_options.checked
);
}
if ($('#batch_connect_session_context_conda_env').length > 0) {
toggle_visibility_of_form_group(
'#batch_connect_session_context_conda_env',
advanced_options.checked
);
}
if ($('#batch_connect_session_context_glibc').length > 0) {
toggle_visibility_of_form_group(
'#batch_connect_session_context_glibc',
advanced_options.checked
);
}
if ($('#batch_connect_session_context_user_defined_envs').length > 0) {
toggle_visibility_of_form_group(
'#batch_connect_session_context_user_defined_envs',
advanced_options.checked
);
}
}
/**
* Sets the change handler for the custom_environment select.
*/
function set_custom_environment_change_handler() {
let custom_environment_input = $('#batch_connect_session_context_custom_environment');
custom_environment_input.change(custom_environment_change_handler);
}
function set_partition_change_handler() {
let partition_input = $('#batch_connect_session_context_partitions');
partition_input.change(partition_change_handler);
}
function set_advanced_options_handler() {
let advanced_input = $('#batch_connect_session_context_advanced_options');
advanced_input.change(advanced_options_handler);
}
/**
* Update UI when custom_environment changes
*/
function custom_environment_change_handler() {
toggle_jupyterlab_switch_visibility();
}
function partition_change_handler() {
toggle_num_gpu_visibility();
toggle_gpu_type_visibility();
fix_num_hours();
}
function advanced_options_handler() {
toggle_advanced_options_visibility();
}
/**
* Main
*/
// Set controls to align with the values of the last session context
toggle_jupyterlab_switch_visibility();
toggle_num_gpu_visibility();
toggle_gpu_type_visibility();
fix_num_hours();
toggle_advanced_options_visibility();
// Install event handlers
set_custom_environment_change_handler();
set_partition_change_handler();
set_advanced_options_handler();