From 8595e0c5dbd124f1ce31ea3e0b23ffd44944df7f Mon Sep 17 00:00:00 2001 From: Carsten Rose <carsten.rose@math.uzh.ch> Date: Fri, 29 Apr 2016 15:06:08 +0200 Subject: [PATCH] #1931 - Form: FE 'subrecord' zeigt keinen 'new' Button an wenn es keine Subrecords gibt. UsersManual/index.rst: more details to 'Type: subrecord' AbstracctBuildForm.php: check if there are no subrecords. No subrecors mean: display only the 'new' button. prepareSubrecord() returns now 'true' even if there are no subrecords. --- extension/Documentation/UsersManual/Index.rst | 7 ++-- extension/qfq/qfq/AbstractBuildForm.php | 33 +++++++++++-------- extension/qfq/qfq/Evaluate.php | 2 +- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/extension/Documentation/UsersManual/Index.rst b/extension/Documentation/UsersManual/Index.rst index d405105b5..215bd8dc0 100644 --- a/extension/Documentation/UsersManual/Index.rst +++ b/extension/Documentation/UsersManual/Index.rst @@ -788,7 +788,8 @@ Type: subrecord # Notice the **exclamation mark** after '{{' - this is necessary to return an array of elements, instead of a single string. - * Exactly one column 'id' has to exist; it specifies the primary record for the target form. + * Exactly one column 'id' has to exist; it specifies the primary record for the target form. If the column 'id' should + not be shown to the user, it's ok to hide the columen by name it '_id'. * Columnname: *<title>[|<number>][|width=<number>][|nostrip][|icon][|url][|mailto]* @@ -806,8 +807,10 @@ Type: subrecord 'checked.png' AS 'Status\|icon', email AS 'mailto', CONCAT(homepage, '\|Homepage') AS 'url' ... * Special column name: *_rowClass* - * Defines CSS class name(s) which will be rendered in the *<tr class="<_rowClass>">*. + + * Define CSS class name(s) which will be rendered in the *<tr class="<_rowClass>">* of the subrecord table. * By using Bootstrap, the following predefined classes are available: + * Text color: *text-muted|text-primary|text-success|text-info|text-warning|text-danger* (http://getbootstrap.com/css/#helper-classes) * Row background: *active|success|info|warning|danger* (http://getbootstrap.com/css/#tables-contextual-classes) diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php index 2bf7ce98f..bb71a4a7f 100644 --- a/extension/qfq/qfq/AbstractBuildForm.php +++ b/extension/qfq/qfq/AbstractBuildForm.php @@ -1208,6 +1208,7 @@ abstract class AbstractBuildForm { $flagEdit = false; $flagDelete = false; $linkNew = ''; + $control = array(); $primaryRecord = $this->store->getStore(STORE_RECORD); @@ -1227,17 +1228,21 @@ abstract class AbstractBuildForm { } } - // construct column attributes - $control = $this->getSubrecordColumnControl(array_keys($formElement['sql1'][0])); + $columns = $linkNew; + + if (isset($formElement['sql1'][0])) { + // construct column attributes + $control = $this->getSubrecordColumnControl(array_keys($formElement['sql1'][0])); + + // Skip '_rowClass': should not be shown in the title. + if (isset($control['title'][FE_SUBRECORD_ROW_CLASS])) { + unset($control['title'][FE_SUBRECORD_ROW_CLASS]); + } - // Skip class control column - if (isset($control['title'][FE_SUBRECORD_ROW_CLASS])) { - unset($control['title'][FE_SUBRECORD_ROW_CLASS]); + // Subrecord: Column titles + $columns .= '<th>' . implode('</th><th>', $control['title']) . '</th>'; } - // Subrecord: Column titles - $columns = $linkNew; - $columns .= '<th>' . implode('</th><th>', $control['title']) . '</th>'; if ($flagDelete) $columns .= '<th></th>'; @@ -1263,10 +1268,6 @@ abstract class AbstractBuildForm { } if ($flagDelete) { -// $rowHtml .= Support::wrapTag('<td>', $this->createDeleteLink($targetTableName, $row['id'], $this->symbol[SYMBOL_DELETE], 'Delete', $this->showDebugInfo)); -// $this->createDeleteLink($targetTableName, $row['id'], $this->symbol[SYMBOL_DELETE], 'Delete', $this->showDebugInfo) - - // <button type="button" class="record-delete" data-sip={{SIP}}><span class="glyphicon glyphicon-trash"></span></button> $s = $this->createDeleteUrl($targetTableName, $row['id'], RETURN_SIP); $rowHtml .= Support::wrapTag('<td>', Support::wrapTag("<button type='button' class='record-delete' data-sip='$s'>", '<span class="glyphicon glyphicon-trash"></span>')); } @@ -1280,6 +1281,10 @@ abstract class AbstractBuildForm { } /** + * Prepare Subrecord: + * - check if the current record has an recordId>0. If not, subrecord can't be edited. Return a message. + * - check if there is an SELECT statement for the subrecords. + * * @param $formElement * @param $primaryRecord * @param $rcText @@ -1301,14 +1306,14 @@ abstract class AbstractBuildForm { // No records? if (count($formElement['sql1']) == 0) { $rcText = ''; - return false; + return true; } if (!isset($formElement['sql1'][0][$nameColumnId])) $nameColumnId = '_id'; if (!isset($formElement['sql1'][0][$nameColumnId])) { - throw new UserFormException('Missing column \'id\' (or "@_id") in \'sql1\' Query', ERROR_DB_MISSING_COLUMN_ID); + throw new UserFormException('Missing column \'id\' (or "_id") in \'sql1\' Query', ERROR_DB_MISSING_COLUMN_ID); } return true; diff --git a/extension/qfq/qfq/Evaluate.php b/extension/qfq/qfq/Evaluate.php index 2b230d6e3..3d815149a 100644 --- a/extension/qfq/qfq/Evaluate.php +++ b/extension/qfq/qfq/Evaluate.php @@ -60,7 +60,7 @@ class Evaluate { } /** - * Recursive evaluation of 'line'. Constant string, Variables or SQL Query or all of them. + * Recursive evaluation of 'line'. Constant string, Variables or SQL Query or all of them. All queries will be fired. * * Token to replace have to be enclosed by '{{' and '}}' * -- GitLab