-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.js
193 lines (163 loc) · 5 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
'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 num_gpu select
*
* Looking for the value of data-has-gpu from partition
*/
function toggle_num_gpu_visibility() {
// 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
);
}
}
/**
* 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();
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();
fix_num_hours();
toggle_advanced_options_visibility();
// Install event handlers
set_custom_environment_change_handler();
set_partition_change_handler();
set_advanced_options_handler();