2023-05-17 21:19:14 +02:00
|
|
|
/*eslint no-var: "error" */
|
|
|
|
/*eslint no-unused-vars: "off" */
|
|
|
|
/*eslint linebreak-style: "off" */
|
|
|
|
/*eslint no-trailing-spaces: "off" */
|
|
|
|
/*eslint-env es6*/
|
|
|
|
// Put this file in path/to/plugin/amd/src
|
|
|
|
// You can call it anything you like
|
|
|
|
|
|
|
|
import {get_string,get_strings} from 'core/str';
|
|
|
|
import {call} from 'core/ajax';
|
|
|
|
import Debugger from './debugger';
|
|
|
|
|
|
|
|
import {load_strings} from './string-helper';
|
|
|
|
|
|
|
|
let debug = new Debugger("treestudyplan-config-grades");
|
|
|
|
|
|
|
|
/*
|
|
|
|
let strings = load_strings({
|
|
|
|
studyplan: {
|
|
|
|
studyplan_select_placeholder: 'studyplan_select_placeholder',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize grade cfg page
|
|
|
|
*/
|
|
|
|
export function init() {
|
|
|
|
{ const
|
|
|
|
intRx = /\d/,
|
|
|
|
integerChange = (event) => {
|
|
|
|
if ( (event.key.length > 1) || intRx.test(event.key)
|
2023-09-08 12:47:29 +02:00
|
|
|
) {
|
|
|
|
return;
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
};
|
2023-09-08 12:47:29 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
for (let input of document.querySelectorAll( 'input[type="number"][step="1"][min="0"]' )){
|
|
|
|
input.addEventListener("keydown", integerChange);
|
2023-09-08 12:47:29 +02:00
|
|
|
}
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
{ const
|
|
|
|
decimal= /^[0-9]*?\.[0-9]*?$/,
|
|
|
|
intRx = /\d/,
|
|
|
|
floatChange = (event) => {
|
|
|
|
if ( (event.key.length > 1) || ( (event.key === ".") && (!event.currentTarget.value.match(decimal)) )
|
|
|
|
|| intRx.test(event.key)
|
2023-09-08 12:47:29 +02:00
|
|
|
) {
|
|
|
|
return;
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
};
|
2023-09-08 12:47:29 +02:00
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
for (let input of document.querySelectorAll( 'input[type="number"][min="0"]:not([step])' )){
|
|
|
|
input.addEventListener("keydown", floatChange);
|
2023-09-08 12:47:29 +02:00
|
|
|
}
|
2023-05-17 21:19:14 +02:00
|
|
|
for (let input of document.querySelectorAll( 'input[type="text"].float' )){
|
|
|
|
input.addEventListener("keydown", floatChange);
|
2023-09-08 12:47:29 +02:00
|
|
|
}
|
|
|
|
|
2023-05-17 21:19:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|