-
Notifications
You must be signed in to change notification settings - Fork 0
/
form.js
112 lines (99 loc) · 2.91 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
'use strict'
/**
* Fix num cores, allowing blanks to remain
*/
function fix_num_cores() {
let node_type_input = $('#batch_connect_session_context_node_type');
let node_type = node_type_input.val();
let num_cores_input = $('#num_cores');
if(num_cores_input.val() === '') {
return;
}
if(node_type === 'hugemem') {
set_ppn_owens_hugemem(num_cores_input);
} else {
set_ppn_owens_regular(num_cores_input);
}
}
/**
* Sets the PPN limits available for Owens hugemem nodes.
*
* hugemem reservations are always assigned the full node
*
* @param {element} num_cores_input The input for num_cores
*/
function set_ppn_owens_hugemem(num_cores_input) {
const NUM_CORES = 48;
num_cores_input.attr('max', NUM_CORES);
num_cores_input.attr('min', NUM_CORES);
num_cores_input.val(NUM_CORES);
}
/**
* Sets the PPN limits available for non hugemem Owens nodes.
*
* @param {element} num_cores_input The input for num_cores
*/
function set_ppn_owens_regular(num_cores_input) {
const NUM_CORES = 28;
num_cores_input.attr('max', NUM_CORES);
num_cores_input.attr('min', 0);
num_cores_input.val(Math.min(NUM_CORES, 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 license fields
*
* Academic: hidden
* Commercial: visible
*/
function toggle_license_field_visibility() {
let user_license_provider = $("#batch_connect_session_context_user_license_provider");
toggle_visibilty_of_form_group(
'#batch_connect_session_context_extern_license_server',
user_license_provider.val() === 'external'
);
toggle_visibilty_of_form_group(
'#batch_connect_session_context_extern_license_file',
user_license_provider.val() === 'external'
);
}
/**
* 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_input, fix_num_cores);
}
/**
* Sets the change handler for the user_is_commercial_user select.
*/
function set_user_license_provider_change_handler() {
let user_license_provider = $("#batch_connect_session_context_user_license_provider");
user_license_provider.change(toggle_license_field_visibility);
}
/**
* Install event handlers
*/
$(document).ready(function() {
// Set the max value to be what was set in the last session
fix_num_cores();
// Ensure that fields are shown or hidden based on what was set in the last session
toggle_license_field_visibility();
set_node_type_change_handler();
set_user_license_provider_change_handler();
});