Commit 79360da2 authored by Carsten  Rose's avatar Carsten Rose
Browse files

#4456 / formModeGlobal=requiredOff - Switches FormElement.mode=required to...

#4456 / formModeGlobal=requiredOff - Switches FormElement.mode=required to 'show' for all FE of the current Form.
parent 27ee7e3b
...@@ -463,7 +463,8 @@ abstract class AbstractBuildForm { ...@@ -463,7 +463,8 @@ abstract class AbstractBuildForm {
// get current data record // get current data record
if ($recordId > 0 && $this->store->getVar('id', STORE_RECORD) === false) { if ($recordId > 0 && $this->store->getVar('id', STORE_RECORD) === false) {
$row = $this->db->sql('SELECT * FROM ' . $this->formSpec[F_TABLE_NAME] . " WHERE id = ?", ROW_EXPECT_1, $tableName = $this->formSpec[F_TABLE_NAME];
$row = $this->db->sql("SELECT * FROM $tableName WHERE id = ?", ROW_EXPECT_1,
array($recordId), "Form '" . $this->formSpec[F_NAME] . "' failed to load record '$recordId' from table '" . array($recordId), "Form '" . $this->formSpec[F_NAME] . "' failed to load record '$recordId' from table '" .
$this->formSpec[F_TABLE_NAME] . "'."); $this->formSpec[F_TABLE_NAME] . "'.");
$this->store->setStore($row, STORE_RECORD); $this->store->setStore($row, STORE_RECORD);
...@@ -488,12 +489,6 @@ abstract class AbstractBuildForm { ...@@ -488,12 +489,6 @@ abstract class AbstractBuildForm {
$debugStack = array(); $debugStack = array();
// Copy global readonly mode.
if ($this->formSpec[F_MODE] == F_MODE_READONLY) {
$fe[FE_MODE] = FE_MODE_READONLY;
$fe[FE_MODE_SQL] = '';
}
// Preparation for Log, Debug // Preparation for Log, Debug
$this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($fe), STORE_SYSTEM); $this->store->setVar(SYSTEM_FORM_ELEMENT, Logger::formatFormElementName($fe), STORE_SYSTEM);
...@@ -514,6 +509,13 @@ abstract class AbstractBuildForm { ...@@ -514,6 +509,13 @@ abstract class AbstractBuildForm {
// Some Defaults // Some Defaults
$formElement = Support::setFeDefaults($formElement, $this->formSpec); $formElement = Support::setFeDefaults($formElement, $this->formSpec);
// // Copy global readonly mode.
// if ($this->formSpec[F_MODE] == F_MODE_READONLY) {
// $fe[FE_MODE] = FE_MODE_READONLY;
// $fe[FE_MODE_SQL] = '';
// }
if ($flagOutput === true) { if ($flagOutput === true) {
$this->fillWrapLabelInputNote($formElement[FE_BS_LABEL_COLUMNS], $formElement[FE_BS_INPUT_COLUMNS], $formElement[FE_BS_NOTE_COLUMNS]); $this->fillWrapLabelInputNote($formElement[FE_BS_LABEL_COLUMNS], $formElement[FE_BS_INPUT_COLUMNS], $formElement[FE_BS_NOTE_COLUMNS]);
} }
...@@ -2468,8 +2470,9 @@ abstract class AbstractBuildForm { ...@@ -2468,8 +2470,9 @@ abstract class AbstractBuildForm {
SIP_RECORD_ID => $targetRecordId, SIP_RECORD_ID => $targetRecordId,
]; ];
if ($formElement[FE_MODE] == FE_MODE_READONLY) { // Inherit current F_MODE
$queryStringArray[F_MODE_GLOBAL] = F_MODE_READONLY; if ($this->formSpec[F_MODE] != '') {
$queryStringArray[F_MODE_GLOBAL] = $this->formSpec[F_MODE];
} }
// Add custom query parameter // Add custom query parameter
......
...@@ -757,6 +757,7 @@ const F_TYPEAHEAD_LDAP_SEARCH_PER_TOKEN = 'typeAheadLdapSearchPerToken'; ...@@ -757,6 +757,7 @@ const F_TYPEAHEAD_LDAP_SEARCH_PER_TOKEN = 'typeAheadLdapSearchPerToken';
const F_MODE = 'mode'; const F_MODE = 'mode';
const F_MODE_READONLY = 'readonly'; const F_MODE_READONLY = 'readonly';
const F_MODE_REQUIRED_OFF = 'requiredOff';
const F_MODE_GLOBAL = 'formModeGlobal'; const F_MODE_GLOBAL = 'formModeGlobal';
const F_SAVE_BUTTON_ACTIVE = 'saveButtonActive'; const F_SAVE_BUTTON_ACTIVE = 'saveButtonActive';
......
...@@ -546,7 +546,8 @@ class QuickFormQuery { ...@@ -546,7 +546,8 @@ class QuickFormQuery {
} }
// Load form // Load form
$form = $this->db->sql("SELECT * FROM Form AS f WHERE f." . F_NAME . " LIKE ? AND f.deleted='no'", ROW_EXPECT_1, $constant = F_NAME; // PhpStorm complains if the constant is directly defined in the string below
$form = $this->db->sql("SELECT * FROM Form AS f WHERE f.$constant LIKE ? AND f.deleted='no'", ROW_EXPECT_1,
[$formName], 'Form not found or multiple forms with the same name.'); [$formName], 'Form not found or multiple forms with the same name.');
$form = $this->modeCleanFormConfig($mode, $form); $form = $this->modeCleanFormConfig($mode, $form);
...@@ -854,8 +855,12 @@ class QuickFormQuery { ...@@ -854,8 +855,12 @@ class QuickFormQuery {
Support::setIfNotSet($formSpec, F_LDAP_USE_BIND_CREDENTIALS, ''); Support::setIfNotSet($formSpec, F_LDAP_USE_BIND_CREDENTIALS, '');
Support::setIfNotSet($formSpec, F_MODE, ''); Support::setIfNotSet($formSpec, F_MODE, '');
if ($formSpec[F_MODE] == '' && $this->store->getVar(F_MODE_GLOBAL, STORE_SIP . STORE_CLIENT, SANITIZE_ALLOW_ALNUMX) == FE_MODE_READONLY) { // In case there is no F_MODE defined on the form, check if there is one in STORE_SIP.
$formSpec[F_MODE] = F_MODE_READONLY; if ($formSpec[F_MODE] == '') {
$formModeGlobal = $this->store->getVar(F_MODE_GLOBAL, STORE_SIP);
if ($formModeGlobal !== false) {
$formSpec[F_MODE] = $formModeGlobal;
}
} }
if ($formSpec[F_MODE] == F_MODE_READONLY) { if ($formSpec[F_MODE] == F_MODE_READONLY) {
......
...@@ -709,6 +709,10 @@ class Support { ...@@ -709,6 +709,10 @@ class Support {
$formElement[FE_MODE] = $formElement[FE_MODE_SQL]; $formElement[FE_MODE] = $formElement[FE_MODE_SQL];
} }
if (isset($formSpec[F_MODE])) {
$formElement[FE_MODE] = self::applyFormModeToFormElement($formElement[FE_MODE], $formSpec[F_MODE]);
}
// Will be used to change dynamicUpdate behaviour // Will be used to change dynamicUpdate behaviour
if (isset($formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE])) { if (isset($formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE])) {
$formElement[FE_FLAG_ROW_OPEN_TAG] = Support::findInSet('row', $formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE]); $formElement[FE_FLAG_ROW_OPEN_TAG] = Support::findInSet('row', $formElement[FE_WRAP_ROW_LABEL_INPUT_NOTE]);
...@@ -721,6 +725,45 @@ class Support { ...@@ -721,6 +725,45 @@ class Support {
return $formElement; return $formElement;
} }
/**
* Depending on $formMode and $feMode, calculate a new $feMode.
* - If $formMode='' : no change.
* - If $formMode=F_MODE_READ_ONLY: set feMode=FE_MODE_READ_ONLY, for all visible elements.
* - If $formMode=F_MODE_REQUIRED_OFF: set feMode=FE_MODE_SHOW, who have have FE_MODE_REQUIRE before.
*
* @param string $feMode FE_MODE_SHOW | FE_MODE_REQUIRED | FE_MODE_READONLY | FE_MODE_HIDDEN |
* @param string $formMode '' | F_MODE_READONLY | F_MODE_REQUIRED_OFF
*
* @return array|string
* @throws CodeException
*/
private function applyFormModeToFormElement($feMode, $formMode) {
if ($formMode == '') {
return $feMode; //no change
}
switch ($feMode) {
case FE_MODE_HIDDEN:
case FE_MODE_READONLY:
break;
case FE_MODE_SHOW:
case FE_MODE_REQUIRED:
if ($formMode == F_MODE_READONLY) {
$feMode = FE_MODE_READONLY;
} elseif ($formMode == F_MODE_REQUIRED_OFF && $feMode = FE_MODE_REQUIRED) {
$feMode = FE_MODE_SHOW;
}
break;
default:
throw new CodeException('Unknown mode: ' . $feMode, ERROR_UNKNOWN_MODE);
}
return $feMode;
}
/** /**
* Looks in $arr if there is an element $index. If not, set it to $value. * Looks in $arr if there is an element $index. If not, set it to $value.
* If $overwriteThis!=false, replace the the original value with $value, if $arr[$index]==$overwriteThis. * If $overwriteThis!=false, replace the the original value with $value, if $arr[$index]==$overwriteThis.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment