From 4645df03702390e4857d0896e45aa63e38a4bc4d Mon Sep 17 00:00:00 2001
From: Carsten  Rose <carsten.rose@math.uzh.ch>
Date: Sun, 20 Jan 2019 12:56:31 +0100
Subject: [PATCH] Fixes #7684. Optional hide second button (cancel) in
 link/question alerts.

---
 extension/Documentation/Manual.rst    | 2 +-
 extension/Source/core/report/Link.php | 6 ++++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/extension/Documentation/Manual.rst b/extension/Documentation/Manual.rst
index 3d2993b9f..6d897625a 100644
--- a/extension/Documentation/Manual.rst
+++ b/extension/Documentation/Manual.rst
@@ -5616,7 +5616,7 @@ Question
 +----------------------+--------------------------------------------------------------------------------------------------------------------------+
 | Positive button text | Default: 'Ok'                                                                                                            |
 +----------------------+--------------------------------------------------------------------------------------------------------------------------+
-| Negative button text | Default: 'Cancel'                                                                                                        |
+| Negative button text | Default: 'Cancel'. To hide the second button: '-'                                                                        |
 +----------------------+--------------------------------------------------------------------------------------------------------------------------+
 | Timeout in seconds   | 0: no timeout, >0: after the specified time in seconds, the alert will dissapear and behaves like 'negative answer'      |
 +----------------------+--------------------------------------------------------------------------------------------------------------------------+
diff --git a/extension/Source/core/report/Link.php b/extension/Source/core/report/Link.php
index 32b33b410..3b5d2e29b 100644
--- a/extension/Source/core/report/Link.php
+++ b/extension/Source/core/report/Link.php
@@ -1094,14 +1094,16 @@ class Link {
         $level = ($arr[QUESTION_INDEX_LEVEL] === '') ? DEFAULT_QUESTION_LEVEL : $arr[QUESTION_INDEX_LEVEL];
         $ok = ($arr[QUESTION_INDEX_BUTTON_OK] === '') ? 'Ok' : $arr[QUESTION_INDEX_BUTTON_OK];
         $cancel = ($arr[QUESTION_INDEX_BUTTON_FALSE] === '') ? 'Cancel' : $arr[QUESTION_INDEX_BUTTON_FALSE];
+        $cancel = ($cancel=='-') ? '': ", { label: '$cancel',eventName: 'cancel'}";
+
         $timeout = ($arr[QUESTION_INDEX_TIMEOUT] === '') ? '0' : $arr[QUESTION_INDEX_TIMEOUT] * 1000;
         $flagModalStatus = ($arr[QUESTION_INDEX_FLAG_MODAL] === '') ? '1' : $arr[QUESTION_INDEX_FLAG_MODAL];
         $flagModal = ($flagModalStatus === "1") ? 'true' : 'false';
 
         $js = <<<EOF
 var alert = new QfqNS.Alert({ message: '$text', type: '$level', modal: $flagModal, timeout: $timeout, buttons: [
-    { label: '$ok', eventName: 'ok' },
-    { label: '$cancel',eventName: 'cancel'}
+    { label: '$ok', eventName: 'ok' }
+    $cancel
 ] } );
 alert.on('alert.ok', function() {
   window.location = $('#$id').attr('href');
-- 
GitLab