mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Fixed tristate inputs (used for permissions input)
This commit is contained in:
parent
f06ad01eb2
commit
9ed487c629
7 changed files with 67 additions and 35 deletions
51
assets/js/tristate_checkboxes.js
Normal file
51
assets/js/tristate_checkboxes.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
'use strict';
|
||||
|
||||
import "./lib/jquery.tristate"
|
||||
|
||||
const TristateHelper = class {
|
||||
constructor() {
|
||||
this.registerTriStateCheckboxes();
|
||||
this.registerSubmitHandler();
|
||||
}
|
||||
|
||||
registerSubmitHandler() {
|
||||
document.addEventListener("turbo:submit-start", (e) => {
|
||||
var form = e.detail.formSubmission.formElement;
|
||||
var formData = e.detail.formSubmission.formData;
|
||||
|
||||
var $tristate_checkboxes = $('.tristate:checkbox', form);
|
||||
|
||||
//Iterate over each tristate checkbox in the form and set formData to the correct value
|
||||
$tristate_checkboxes.each(function() {
|
||||
var $checkbox = $(this);
|
||||
var state = $checkbox.tristate('state');
|
||||
|
||||
formData.set($checkbox.attr('name'), state);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
registerTriStateCheckboxes() {
|
||||
//Initialize tristate checkboxes and if needed the multicheckbox functionality
|
||||
document.addEventListener("turbo:load", () => {
|
||||
$(".tristate").tristate( {
|
||||
checked: "true",
|
||||
unchecked: "false",
|
||||
indeterminate: "indeterminate",
|
||||
});
|
||||
|
||||
$('.permission_multicheckbox:checkbox').change(function() {
|
||||
//Find the other checkboxes in this row, and change their value
|
||||
var $row = $(this).parents('tr');
|
||||
|
||||
//@ts-ignore
|
||||
var new_state = $(this).tristate('state');
|
||||
|
||||
//@ts-ignore
|
||||
$('.tristate:checkbox', $row).tristate('state', new_state);
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default new TristateHelper();
|
Loading…
Add table
Add a link
Reference in a new issue