fixes some of the apply/reset/edit semantics

This commit is contained in:
wall_e committed 2026-10-22 15:44:42 +02:00
1 parent 0cc5a826a2
commit 338e48afe5
1 file changed
+32 -21
+32 -21
View File
@@ -81,7 +81,7 @@ export function init(instrODB) {
document.getElementById("selectTDC").addEventListener("click", display_config);
document.getElementById("saveTDC").addEventListener("click", save_config);
document.getElementById("loadV1190").addEventListener("click", display_v1190);
document.getElementById("editTDC").addEventListener("click", () => edit_config());
document.getElementById("editTDC").addEventListener("click", () => edit_config(!isEditing));
document.getElementById("resetTDC").addEventListener("click", init_config);
document.getElementById("loadTDC").addEventListener("click", () => apply_last_config(instrODB_local));
document.getElementById("tdc_DatWindow_button").addEventListener("click", change_data_window);
@@ -92,6 +92,12 @@ export function init(instrODB) {
disable_by_run_status
);
warn_colour_on_edit();
watch_odb(
"/Equipment/TDC/Settings/SettingsFile",
warn_colour_on_edit
);
document
.getElementById("tdc_Pre_Pileup_Window")
.addEventListener("change", updatePrePileupWindow);
@@ -103,6 +109,7 @@ export function init(instrODB) {
//global variables;
let gTDCbrowsed = false;
let gTDClastLoadfileName = "";
let isEditing = false;
//custom style:
var readTDC_css = `
@@ -305,10 +312,6 @@ function on_load() {
// Hide all the space holders.
set_class_visibility("tdcNewVal_General", "hidden");
// Disable the 'Apply' and 'Reset'-button.
//document.getElementById("loadTDC").disabled = true;
//document.getElementById("resetTDC").disabled = true;
}
function init_config() {
@@ -316,6 +319,7 @@ function init_config() {
gTDCbrowsed = false;
gTDClastLoadfileName = "";
edit_config(false); //disable editing.
disable_by_run_status();
}
/* Toggle button states depending on experiment status*/
@@ -323,12 +327,12 @@ function disable_by_run_status() {
mjsonrpc_db_get_value("/Runinfo/State").then((rpc) => {
const runStopped = rpc.result.data[0] == 1;
//Enable only if Run stopped
if (runStopped) {
if (runStopped && !gTDCbrowsed) {
enable_class("stoppedEditable", "enable", "");
} else {
enable_class("stoppedEditable", "disable", "Stop run to edit.");
//disable element editing
edit_config(false);
enable_class("stoppedEditable", "disable", "Stop run to edit.");
}
// Check if browsing a TDC file:
if (gTDCbrowsed) {
@@ -339,8 +343,10 @@ function disable_by_run_status() {
//special case: loading a new file needs stopped and browsed:
if (gTDCbrowsed && runStopped) {
enable_class("loadTDC", "enable", "");
document.getElementById("resetTDC").disabled = false;
} else {
enable_class("loadTDC", "disable", "Stop run and load a file..");
document.getElementById("resetTDC").disabled = true;
}
});
}
@@ -349,7 +355,9 @@ function disable_by_run_status() {
/*
Function to enable browser editing of the TDC configuration.
*/
function edit_config(enable = true) {
function edit_config(enable) {
isEditing = enable;
// Find all elements with the tdc_editable class
const cl_elements = document.querySelectorAll(".tdc_editable");
cl_elements.forEach((element) => {
@@ -370,18 +378,22 @@ function edit_config(enable = true) {
if (enable == true) {
modbset(instrODB_local.tdcSettingsDir + 'SettingsFile', "Manually edited. Please save!");
}
//set a red background color in editing mode:
const odb_fileName = document.getElementById("TDC_ODB_FILENAME"); //current fileName (should be fine without a promise.)
document.querySelectorAll(".tdc_filename").forEach((element) => {
// somebody could have forgotten saving the changes:
if (enable == true || odb_fileName.value == "Manually edited. Please save!") {
element.style.backgroundColor = "red";
} else {
element.style.backgroundColor = "";
}
});
}
function warn_colour_on_edit() {
mjsonrpc_db_get_value("/Equipment/TDC/Settings/SettingsFile").then((rpc) => {
const odb_fileName = rpc.result.data[0];
//set a red background color in editing mode:
document.querySelectorAll(".tdc_filename").forEach((element) => {
// somebody could have forgotten saving the changes:
if (odb_fileName === "Manually edited. Please save!") {
element.style.backgroundColor = "red";
} else {
element.style.backgroundColor = "";
}
});
});
}
/*
@@ -557,10 +569,9 @@ function apply_last_config() {
if (extension == "v1190") {
load_v1190(gTDClastLoadfileName, apply_new_config);
return;
} else {
load_config(gTDClastLoadfileName, apply_new_config);
}
load_config(gTDClastLoadfileName, apply_new_config);
}
/**