Adds some comments to understand the logic

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-02-20 11:55:14 +01:00
parent e9deb8d22e
commit 2310333f8d
2 changed files with 28 additions and 7 deletions

View File

@ -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;

View File

@ -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');
}
});
});