Commit b7c61b61 authored by Carsten  Rose's avatar Carsten Rose

multiSql selects no records: a) customizable message, b) throw error on save().

parent 32f0413a
Pipeline #2466 passed with stages
in 2 minutes and 50 seconds
......@@ -4354,14 +4354,25 @@ Multi Form
----------
`Multi Forms` are like a regular form with the difference that the shown FormElements are repeated for *each* selected record
(defined by `multiformSql`).
(defined by `multiSql`).
+------------------+----------------------------------+------------------------------------------------+
| Name | | |
+==================+==================================+================================================+
| multiSql | {{!SELECT id, name FROM Person}} | Query to select MulitForm records |
+------------------+----------------------------------+------------------------------------------------+
| multiMgsNoRecord | Default: No data | Message shown if `multiSql` selects no records |
+------------------+----------------------------------+------------------------------------------------+
The Form is shown as a HTML table.
* `multiFormSql`: Selects the records where the defined FormElements will work on each.
* `multiSql`: Selects the records where the defined FormElements will work on each.
* A uniq column 'id' or '_id' (not shown) is mandatory and has to reflect an existing record id in table `primary table`.
* Additional columns, defined in `multiFormSql`, will be shown on the form in the same line, before the FormElements.
* Additional columns, defined in `multiSql`, will be shown on the form in the same line, before the FormElements.
`
Simple
......@@ -4374,7 +4385,7 @@ General:
Form:
* Per row, the STORE_RECORD is filled with the whole record of the primary table, referenced
by `multiFormSql.id`.
by `multiSql.id`.
FormElement:
......@@ -4385,8 +4396,9 @@ FormElement:
Advanced
========
* The FormElement.name do not have to be a column of the primary table.
* The insert/update/delete SQL statement (of each non-primary table column) has to be individually defined.
* The `FormElement.name` do not have to be a column of the primary table.
* If `FormElement.name` is not a column of the primary table, the insert/update/delete SQL statement has to be
extra defined.
.. _multiple-languages:
......
......@@ -221,8 +221,7 @@ abstract class AbstractBuildForm {
// No rows: nothing to do.
if (empty($parentRecords)) {
//TODO Meldung konfigurierbar machen.
return 'No data';
return $this->formSpec[F_MULTI_MSG_NO_RECORD];
}
// Check for 'id' or '_id' as column name
......
......@@ -1040,6 +1040,8 @@ const F_ORDER_COLUMN = 'orderColumn';
const F_ORDER_COLUMN_NAME = 'ord';
const F_SHOW_ID_IN_FORM_TITLE = SYSTEM_SHOW_ID_IN_FORM_TITLE;
const F_MULTI_MSG_NO_RECORD = 'multiMsgNoRecord';
const F_MULTI_MSG_NO_RECORD_TEXT = 'No data';
const F_REST_SQL_LIST = 'restSqlList';
const F_REST_SQL_DATA = 'restSqlData';
......
......@@ -1438,6 +1438,7 @@ class QuickFormQuery {
Support::setIfNotSet($formSpec, F_ENTER_AS_SUBMIT, $this->store->getVar(SYSTEM_ENTER_AS_SUBMIT, STORE_SYSTEM));
Support::setIfNotSet($formSpec, F_SESSION_TIMEOUT_SECONDS, $this->store->getVar(SYSTEM_SESSION_TIMEOUT_SECONDS, STORE_SYSTEM));
Support::setIfNotSet($formSpec, F_FE_REQUIRED_POSITION, F_FE_REQUIRED_POSITION_LABEL_RIGHT);
Support::setIfNotSet($formSpec, F_MULTI_MSG_NO_RECORD, F_MULTI_MSG_NO_RECORD_TEXT);
// In case there is no F_MODE defined on the form, check if there is one in STORE_SIP.
if ($formSpec[F_MODE] == '') {
......
......@@ -75,11 +75,11 @@ class Save {
public function process() {
$rc = 0;
if ($this->formSpec[F_MULTI_SQL] !== '') {
$rc = $this->saveMultiForm();
} else {
if ($this->formSpec[F_MULTI_SQL] == '') {
$recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP . STORE_ZERO);
$rc = $this->elements($recordId);
} else {
$rc = $this->saveMultiForm();
}
return $rc;
......@@ -96,10 +96,12 @@ class Save {
$parentRecords = $this->evaluate->parse($this->formSpec[F_MULTI_SQL], ROW_REGULAR);
// No rows: nothing to do.
// No rows: This must be an error, cause MultiForms must have at least one record.
if (empty($parentRecords)) {
//TODO Meldung konfigurierbar machen.
return 'No data';
throw new \UserFormException(
json_encode([ERROR_MESSAGE_TO_USER => $this->formSpec[F_MULTI_MSG_NO_RECORD],
ERROR_MESSAGE_TO_DEVELOPER => 'Query selects no records: ' . $this->formSpec[F_MULTI_SQL]]),
ERROR_MISSING_EXPECT_RECORDS);
}
// Check for 'id' or '_id' as column name
......
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