-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
73 lines (59 loc) · 2.18 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
'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();
}
}
function toggle_selfinstall() {
let selfinstall_select = $('#batch_connect_session_context_jupyter_install');
if(selfinstall_select.prop("checked")) {
toggle_visibility_of_form_group('#batch_connect_session_context_auto_modules_JupyterLab', false);
toggle_visibility_of_form_group('#batch_connect_session_context_jupyter_envtype', true);
toggle_visibility_of_form_group('#batch_connect_session_context_env_path', true);
} else {
toggle_visibility_of_form_group('#batch_connect_session_context_auto_modules_JupyterLab', true);
toggle_visibility_of_form_group('#batch_connect_session_context_auto_modules_Python', false);
toggle_visibility_of_form_group('#batch_connect_session_context_jupyter_envtype', false);
toggle_visibility_of_form_group('#batch_connect_session_context_env_path', false);
}
}
function set_selfinstall_change_handler() {
let jupyter_install = $('#batch_connect_session_context_jupyter_install');
jupyter_install.change(selfinstall_change_handler);
}
function selfinstall_change_handler() {
toggle_selfinstall();
}
function set_envtype_change_handler() {
let envtype = $('#batch_connect_session_context_jupyter_envtype');
envtype.change(envtype_change_handler);
}
function envtype_change_handler() {
toggle_envtype();
}
function toggle_envtype() {
let envtype_select = $('#batch_connect_session_context_jupyter_envtype');
if(envtype_select.val() == "0") { /* Python venv */
toggle_visibility_of_form_group('#batch_connect_session_context_auto_modules_Python', true);
}
if(envtype_select.val() == "1") { /* Conda env */
toggle_visibility_of_form_group('#batch_connect_session_context_auto_modules_Python', false);
}
}
$(document).ready(function() {
toggle_selfinstall();
toggle_envtype();
set_selfinstall_change_handler();
set_envtype_change_handler();
});