From 781c09a5e025a3d6263ca45679302be13a05a1b7 Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Tue, 31 Jan 2017 22:34:05 +0100
Subject: [PATCH] AbstractBuildForm.php, BuildFormBootstrap.php,
 BuildFormTable.php, Constants.php, QuickFormQuery.php, Index.rst: Implemented
 Paramater 'extraDeleteForm' for 'forms' and 'subrecords'. Doku update.

---
 extension/Documentation/UsersManual/Index.rst | 22 +++++++++++++++++++
 extension/qfq/qfq/AbstractBuildForm.php       | 10 ++++++---
 extension/qfq/qfq/BuildFormBootstrap.php      |  8 ++-----
 extension/qfq/qfq/BuildFormTable.php          |  2 +-
 extension/qfq/qfq/Constants.php               |  2 ++
 extension/qfq/qfq/QuickFormQuery.php          |  6 ++++-
 6 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/extension/Documentation/UsersManual/Index.rst b/extension/Documentation/UsersManual/Index.rst
index 2ed0d3d4d..9d45c5b2d 100644
--- a/extension/Documentation/UsersManual/Index.rst
+++ b/extension/Documentation/UsersManual/Index.rst
@@ -557,6 +557,8 @@ parameter
 +------------------------+--------+----------------------------------------------------------------------------------------------------------+
 | submitButtonText       | string | Show save button, with the <submitButtonText> at the bottom of the form                                  |
 +------------------------+--------+----------------------------------------------------------------------------------------------------------+
+| extraDeleteForm        | string | Name of a form which specifies how to delete the primary record and optional slave records               |
++------------------------+--------+----------------------------------------------------------------------------------------------------------+
 
 * Example:
 
@@ -611,6 +613,25 @@ classBody
 * Predefined background colors: `qfq-color-white`, `qfq-color-grey-1` (dark), `qfq-color-grey-2` (light),
   `qfq-color-blue-1` (dark), `qfq-color-blue-2`. (light)
 
+submitButtonText
+''''''''''''''''
+
+If specified and non empty, display a regular submit button at the bottom of the page with the given text.
+This gives the form a ordinary HTML-form look'n' feel. With this option, the standard buttons on the top right border
+should be hided to not confuse the user.
+
+extraDeleteForm
+'''''''''''''''
+
+Depending on the database definition, it might be necessary to delete the primary record *and* corresponding slave records.
+To not repeat such 'slave record delete definition', an 'extraDeleteForm' could be specified. If the user open's a record
+in a form and clicks on the 'delete' button, a defined 'extraDeleteForm'-form will be used to delete primary and slave
+records instead of using the current form.
+E.g. if there are multiple different forms to work on the same table, all of theses forms might reference to the same
+'extraDeleteForm'-form. This simplifies the maintenance.
+
+The 'extraDeleteForm' parameter might be specified for a 'form' and/or for 'subrecords'
+
 FormElements
 ------------
 * Each *form* contains one or more *FormElement*.
@@ -1048,6 +1069,7 @@ will be rendered inside the form as a HTML table.
   * *form*: Target form, e.g. *form=person*
   * *page*: Target page with detail form. If none specified, use the current page.
   * *title*: Title displayed over the table in the current form.
+  * *extraDeleteForm*: Optional. The per row delete Button will reference such form (for deleting) instead of *form* (default).
   * *detail*: Mapping of values from the primary form to the target form (defined via `form=...`).
 
     * Syntax::
diff --git a/extension/qfq/qfq/AbstractBuildForm.php b/extension/qfq/qfq/AbstractBuildForm.php
index b93838ac3..218cf93ea 100644
--- a/extension/qfq/qfq/AbstractBuildForm.php
+++ b/extension/qfq/qfq/AbstractBuildForm.php
@@ -1403,6 +1403,9 @@ abstract class AbstractBuildForm {
 
         if (isset($formElement[SUBRECORD_PARAMETER_FORM])) {
 
+            Support::setIfNotSet($formElement, F_EXTRA_DELETE_FORM, '');
+            $formElement[F_FINAL_DELETE_FORM] = $formElement[F_EXTRA_DELETE_FORM] != '' ? $formElement[F_EXTRA_DELETE_FORM] : $formElement[SUBRECORD_PARAMETER_FORM];
+
             $linkNew = Support::wrapTag('<th>', $this->createFormLink($formElement, 0, $primaryRecord, $this->symbol[SYMBOL_NEW], 'New'));
 
             // Decode settings in subrecordOption
@@ -1423,8 +1426,9 @@ abstract class AbstractBuildForm {
             $columns .= '<th>' . implode('</th><th>', $control['title']) . '</th>';
         }
 
-        if ($flagDelete)
+        if ($flagDelete) {
             $columns .= '<th></th>';
+        }
 
         // Table head
         $html = Support::wrapTag('<tr>', $columns);
@@ -1449,12 +1453,12 @@ abstract class AbstractBuildForm {
                 $toolTip = 'Delete';
 
                 if ($this->showDebugInfo) {
-                    $toolTip .= PHP_EOL . "form = '" . $this->formSpec[F_NAME] . "'" . PHP_EOL . "r = '" . $row[$nameColumnId] . "'";
+                    $toolTip .= PHP_EOL . "form = '" . $formElement[F_FINAL_DELETE_FORM] . "'" . PHP_EOL . "r = '" . $row[$nameColumnId] . "'";
                 }
 
 //                $buttonDelete = $this->buildButtonCode('delete-button', $toolTip, GLYPH_ICON_DELETE, $disabled);
 
-                $s = $this->createDeleteUrl($formElement[SUBRECORD_PARAMETER_FORM], '', $row[$nameColumnId], RETURN_SIP);
+                $s = $this->createDeleteUrl($formElement[F_FINAL_DELETE_FORM], '', $row[$nameColumnId], RETURN_SIP);
 //                $rowHtml .= Support::wrapTag('<td>', Support::wrapTag("<button type='button' class='record-delete btn btn-default' data-sip='$s'>", '<span class="glyphicon ' . GLYPH_ICON_DELETE . '"></span>'));
                 $rowHtml .= Support::wrapTag('<td>', Support::wrapTag("<button type='button' class='record-delete btn btn-default' data-sip='$s' " . Support::doAttribute('title', $toolTip) . ">", '<span class="glyphicon ' . GLYPH_ICON_DELETE . '"></span>'));
 
diff --git a/extension/qfq/qfq/BuildFormBootstrap.php b/extension/qfq/qfq/BuildFormBootstrap.php
index fbc07e0ab..5e3e999af 100644
--- a/extension/qfq/qfq/BuildFormBootstrap.php
+++ b/extension/qfq/qfq/BuildFormBootstrap.php
@@ -158,10 +158,6 @@ class BuildFormBootstrap extends AbstractBuildForm {
         if (Support::findInSet(FORM_BUTTON_CLOSE, $this->formSpec['showButton'])) {
             $toolTip = 'Close';
 
-            if ($this->showDebugInfo) {
-                $toolTip .= PHP_EOL . "table = '" . $this->formSpec[F_TABLE_NAME] . "'" . PHP_EOL . "r = '" . $recordId . "'";
-            }
-
             $buttonClose = $this->buildButtonCode('close-button', 'Close', GLYPH_ICON_CLOSE);
         }
 
@@ -170,7 +166,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
             $toolTip = 'Delete';
 
             if ($this->showDebugInfo && $recordId > 0) {
-                $toolTip .= PHP_EOL . "form = '" . $this->formSpec[F_NAME] . "'" . PHP_EOL . "r = '" . $recordId . "'";
+                $toolTip .= PHP_EOL . "form = '" . $this->formSpec[F_FINAL_DELETE_FORM] . "'" . PHP_EOL . "r = '" . $recordId . "'";
             }
             $disabled = ($recordId > 0) ? '' : 'disabled';
 
@@ -345,7 +341,7 @@ class BuildFormBootstrap extends AbstractBuildForm {
         $tabId = $this->getTabId();
 
         if (0 < ($recordId = $this->store->getVar(SIP_RECORD_ID, STORE_SIP))) {
-            $deleteUrl = $this->createDeleteUrl($this->formSpec[F_NAME], '', $recordId);
+            $deleteUrl = $this->createDeleteUrl($this->formSpec[F_FINAL_DELETE_FORM], '', $recordId);
         }
 
         $actionUpload = FILE_ACTION . '=' . FILE_ACTION_UPLOAD;
diff --git a/extension/qfq/qfq/BuildFormTable.php b/extension/qfq/qfq/BuildFormTable.php
index 47b0997b7..4149457d7 100644
--- a/extension/qfq/qfq/BuildFormTable.php
+++ b/extension/qfq/qfq/BuildFormTable.php
@@ -77,7 +77,7 @@ class BuildFormTable extends AbstractBuildForm {
         $formEditUrl = $this->createFormEditUrl();
         $html .= "<p><a " . Support::doAttribute('href', $formEditUrl) . ">Edit</a><small>[$sipParamString]</small></p>";
 
-        $deleteUrl = $this->createDeleteUrl($this->formSpec[F_NAME], '', $this->store->getVar(SIP_RECORD_ID, STORE_SIP));
+        $deleteUrl = $this->createDeleteUrl($this->formSpec[F_FINAL_DELETE_FORM], '', $this->store->getVar(SIP_RECORD_ID, STORE_SIP));
         $html .= "<p><a " . Support::doAttribute('href', $deleteUrl) . ">Delete</a>";
 
         $html .= $this->wrapItem(WRAP_SETUP_TITLE, $this->formSpec['title'], true);
diff --git a/extension/qfq/qfq/Constants.php b/extension/qfq/qfq/Constants.php
index 444951bbf..2e354adf6 100644
--- a/extension/qfq/qfq/Constants.php
+++ b/extension/qfq/qfq/Constants.php
@@ -445,6 +445,8 @@ const GLYPH_ICON_CLOSE = 'glyphicon-remove';
 const F_NAME = 'name';
 const F_TABLE_NAME = 'tableName';
 const F_REQUIRED_PARAMETER = 'requiredParameter';
+const F_EXTRA_DELETE_FORM = 'extraDeleteForm';
+const F_FINAL_DELETE_FORM = 'finalDeleteForm';
 
 const F_SUBMIT_BUTTON_TEXT = 'submitButtonText';
 
diff --git a/extension/qfq/qfq/QuickFormQuery.php b/extension/qfq/qfq/QuickFormQuery.php
index be437ca65..e9f28171b 100644
--- a/extension/qfq/qfq/QuickFormQuery.php
+++ b/extension/qfq/qfq/QuickFormQuery.php
@@ -233,7 +233,7 @@ class QuickFormQuery {
             $sipFound = $this->validateForm($foundInStore, $formMode);
 
         } else {
-            // FORM_DELETE without a form definition: Fake the form wiht only a tableName.
+            // FORM_DELETE without a form definition: Fake the form with only a tableName.
             $table = $this->store->getVar(SIP_TABLE, STORE_SIP);
             if ($table === false) {
                 throw new UserFormException("No 'form' and no 'table' definition found.", ERROR_MISSING_VALUE);
@@ -388,6 +388,10 @@ class QuickFormQuery {
         Support::setIfNotSet($this->formSpec, F_BS_NOTE_COLUMNS, 3, '');
 
         Support::setIfNotSet($this->formSpec, F_SUBMIT_BUTTON_TEXT, '');
+        Support::setIfNotSet($this->formSpec, F_EXTRA_DELETE_FORM, '');
+
+        // Set F_FINAL_DELETE_FORM
+        $this->formSpec[F_FINAL_DELETE_FORM] = $this->formSpec[F_EXTRA_DELETE_FORM] != '' ? $this->formSpec[F_EXTRA_DELETE_FORM] : $this->formSpec[F_NAME];
 
         // Take default from config.ini
         $class = $this->store->getVar(SYSTEM_CSS_CLASS_QFQ_FORM_PILL, STORE_SYSTEM);
-- 
GitLab