Hi,
ich möchte über einen Check-Button im Action-Bereich eines Konfigurationsformulars mein Modul aktiveren oder deaktivieren können.
Eigentlich habe ich es schon fast komplett am laufen, ich bekommen nur die Check-Box im Formular beim Öffnen nicht auf den aktuellen Wert gesetzt.
Hier meine Umsetzung:
in der form.json
...
"actions": [
{
"type":"CheckBox",
"name":"activated",
"caption":"activated",
"value":false,
"onChange":"DBCOCT_SwapModuleStatus($id);"
}
...
public function Create()
...
$this->RegisterAttributeBoolean("activated",false);
...
public function ApplyChanges()
...
// Status der Instanz auf gespeicherten Wert setzen (beim Laden des Moduls)
if ($this->ReadAttributeBoolean("activated")) {
$this->SetModuleActive(true);
}
else {
$this->SetModuleActive(false);
}
...
public function SwapModuleStatus () {
$mystate = $this->GetStatus();
if ($mystate == 104 ) {
$this->SetModuleActive(true);
}
elseif ($mystate == 102 ) {
$this->SetModuleActive(false);
}
}
private function SetModuleActive(bool $state) {
//102 Instanz ist aktiv
//104 Instanz ist inaktiv
$id=$this->InstanceID;
if ($state) {
$this->SetStatus(102);
}
else {
$this->SetStatus(104);
}
$mystate = $this->GetStatus();
if ($mystate == 102 ) {
$this->LogMessage("wieder aktiv",KL_NOTIFY);
$this->WriteAttributeBoolean("activated",true);
$this->UpdateFormField("activated","value",true);
}
else {
$this->LogMessage("nicht mehr aktiv",KL_NOTIFY);
$this->WriteAttributeBoolean("activated",false);
$this->UpdateFormField("activated","value",false);
}
}
Öffne ich das Formular, ist der Button immer auf False
Schalte ich auf „true“, wird der Status der Instanz auf „false“ gesetzt, da er ja zuvor „true“ var (SetModuleActive) und der Button setzt sich wieder auf „false“.
Setze ich den Status bei geöffnetem Formular, funktioniert alles prima. Scheinbar liest das Formular beim Öffnen den Status der Variable „activated“ nicht aus.
Hmm, bin etwas ratlos, hat jemand einen Tip?
Grüße Detlev.