forked from OSC/bc_osc_jupyter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
108 lines (91 loc) · 2.52 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
'use strict'
/**
* Clamp between two numbers
*
* @param {number} min The minimum
* @param {number} max The maximum
* @param {number} val The value to clamp
*/
function clamp(min, max, val) {
return Math.min(max, Math.max(min, val));
}
/**
* Fix num cores, allowing blanks to remain
*/
function fix_num_cores() {
let node_type_input = $('#batch_connect_session_context_node_type');
let num_cores_input = $('#batch_connect_session_context_num_cores');
if(num_cores_input.val() === '') {
return;
}
set_ppn_by_node_type(node_type_input, num_cores_input);
}
/**
* Sets the ppn by node type.
*
* @param {element} node_type_input The node type input
* @param {element} num_cores_input The number cores input
*/
function set_ppn_by_node_type(node_type_input, num_cores_input) {
let data = node_type_input.find(':selected').data();
num_cores_input.attr('max', data.maxPpn);
num_cores_input.attr('min', data.minPpn);
// Clamp value between min and max
num_cores_input.val(
clamp(data.minPpn, data.maxPpn, num_cores_input.val())
);
}
/**
* Toggle the visibilty of a form group
*
* @param {string} form_id The form identifier
* @param {boolean} show Whether to show or hide
*/
function toggle_visibilty_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 visibilty of the CUDA select
*
* Looking for the value of data-can-show-cuda
*/
function toggle_cuda_version_visibility() {
let node_type_input = $('#batch_connect_session_context_node_type');
// Allow for cuda_version control not existing
if ( ! ($('#batch_connect_session_context_cuda_version').length > 0) ) {
return;
}
toggle_visibilty_of_form_group(
'#batch_connect_session_context_cuda_version',
node_type_input.find(':selected').data('can-show-cuda')
);
}
/**
* Sets the change handler for the node_type select.
*/
function set_node_type_change_handler() {
let node_type_input = $('#batch_connect_session_context_node_type');
node_type_input.change(node_type_change_hander);
}
/**
* Update UI when node_type changes
*/
function node_type_change_hander() {
fix_num_cores();
toggle_cuda_version_visibility();
}
/**
* Main
*/
// Set controls to align with the values of the last session context
fix_num_cores();
toggle_cuda_version_visibility();
// Install event handlers
set_node_type_change_handler();