From 2310333f8d0e219c9a01e0b2ac13bcf60ba576e5 Mon Sep 17 00:00:00 2001
From: Thomas Citharel <tcit@tcit.fr>
Date: Tue, 20 Feb 2018 11:55:14 +0100
Subject: [PATCH] Adds some comments to understand the logic

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
---
 adminstuds.php  | 21 ++++++++++++++++++---
 js/app/studs.js | 14 ++++++++++----
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/adminstuds.php b/adminstuds.php
index b642d845..0d030590 100644
--- a/adminstuds.php
+++ b/adminstuds.php
@@ -149,14 +149,29 @@ if (isset($_POST['update_poll_info'])) {
         }
     } elseif ($field === 'password') {
         $password = isset($_POST['password']) ? $_POST['password'] : null;
+
+        /**
+         * Did the user choose results to be publicly visible ?
+         */
         $resultsPubliclyVisible = isset($_POST['resultsPubliclyVisible']) ? $inputService->filterBoolean($_POST['resultsPubliclyVisible']) : false;
+        /**
+         * If there's one, save the password
+         */
         if (!empty($password)) {
             $poll->password_hash =  PasswordHasher::hash($password);
             $updated = true;
         }
-	if ($poll->password_hash === null || $poll->hidden === true){
-	    $poll->results_publicly_visible = false;
-	}
+
+        /**
+         * If not pasword was set and the poll should be hidden, hide the results
+         */
+        if ($poll->password_hash === null || $poll->hidden === true) {
+            $poll->results_publicly_visible = false;
+        }
+
+        /**
+         * We don't have a password, the poll is hidden and we change the results public visibility
+         */
         if ($resultsPubliclyVisible !== $poll->results_publicly_visible && $poll->password_hash !== null && $poll->hidden === false) {
             $poll->results_publicly_visible = $resultsPubliclyVisible;
             $updated = true;
diff --git a/js/app/studs.js b/js/app/studs.js
index 9ee66961..7ebef8c1 100644
--- a/js/app/studs.js
+++ b/js/app/studs.js
@@ -103,8 +103,14 @@ $(document).ready(function () {
         return false;
     });
 
-	$('#password').on('keyup change', function () {
-		if($('#password').val() && !($('#hidden').attr('checked'))){$('#resultsPubliclyVisible').removeAttr('disabled');}
-		else {$('#resultsPubliclyVisible').attr('disabled','disabled');};
-	});
+    /**
+     * Disable view public results option when there's a password and the poll is not hidden
+     */
+    $('#password').on('keyup change', function () {
+        if($('#password').val() && !($('#hidden').attr('checked'))){
+            $('#resultsPubliclyVisible').removeAttr('disabled');
+        } else {
+            $('#resultsPubliclyVisible').attr('disabled','disabled');
+        }
+    });
 });
-- 
GitLab