New style of URL customization

This commit is contained in:
Olivier Perez 2016-08-04 21:44:31 +02:00
parent 64fe5e0589
commit 9b39dd2fa1
No known key found for this signature in database
GPG Key ID: 3AA3C84A71F35E71
5 changed files with 67 additions and 56 deletions

View File

@ -52,6 +52,12 @@ class Form
*/
public $hidden;
/**
* If true, the author want to customize the URL
* @var boolean
*/
public $use_customized_url;
/**
* If true, a password will be needed to access the poll
* @var boolean
@ -99,4 +105,4 @@ class Form
usort($this->choices, array('Framadate\Choice', 'compare'));
}
}
}

View File

@ -56,8 +56,8 @@ if (isset($_GET['type']) && $_GET['type'] == 'date' ||
$goToStep2 = filter_input(INPUT_POST, GO_TO_STEP_2, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => '/^(date|classic)$/']]);
if ($goToStep2) {
$title = $inputService->filterTitle($_POST['title']);
$customizeId = isset($_POST['customize_id']) ? $inputService->filterBoolean($_POST['customize_id']) : false;
$id = $customizeId == true ? $inputService->filterId($_POST['id']) : null;
$use_customized_url = isset($_POST['use_customized_url']) ? $inputService->filterBoolean($_POST['use_customized_url']) : false;
$customized_url = $use_customized_url == true ? $inputService->filterId($_POST['customized_url']) : null;
$name = $inputService->filterName($_POST['name']);
$mail = $config['use_smtp'] == true ? $inputService->filterMail($_POST['mail']) : null;
$description = $inputService->filterDescription($_POST['description']);
@ -77,10 +77,11 @@ if ($goToStep2) {
$error_on_description = false;
$error_on_password = false;
$error_on_password_repeat = false;
$error_on_id = false;
$error_on_customized_url = false;
$_SESSION['form']->title = $title;
$_SESSION['form']->id = $id;
$_SESSION['form']->id = $customized_url;
$_SESSION['form']->use_customized_url = $use_customized_url;
$_SESSION['form']->admin_name = $name;
$_SESSION['form']->admin_mail = $mail;
$_SESSION['form']->description = $description;
@ -102,12 +103,12 @@ if ($goToStep2) {
$error_on_title = true;
}
if ($customizeId) {
if ($id === false) {
$error_on_id = true;
} else if ($pollRepository->existsById($id)) {
$error_on_id = true;
$error_on_id_msg = __('Error', 'Poll id already used');
if ($use_customized_url) {
if ($customized_url === false) {
$error_on_customized_url = true;
} else if ($pollRepository->existsById($customized_url)) {
$error_on_customized_url = true;
$error_on_customized_url_msg = __('Error', 'Poll id already used');
}
}
@ -134,7 +135,7 @@ if ($goToStep2) {
}
}
if ($title && $name && $email_OK && !$error_on_title && !$error_on_id && !$error_on_description && !$error_on_name
if ($title && $name && $email_OK && !$error_on_title && !$error_on_customized_url && !$error_on_description && !$error_on_name
&& !$error_on_password && !$error_on_password_repeat
) {
@ -172,7 +173,7 @@ $errors = array(
'aria' => '',
'class' => ''
),
'id' => array(
'customized_url' => array(
'msg' => '',
'aria' => '',
'class' => ''
@ -215,10 +216,10 @@ if (!empty($_POST[GO_TO_STEP_2])) {
$errors['title']['msg'] = __('Error', 'Something is wrong with the format');
}
if ($error_on_id) {
$errors['id']['aria'] = 'aria-describeby="poll_comment_error" ';
$errors['id']['class'] = ' has-error';
$errors['id']['msg'] = isset($error_on_id_msg) ? $error_on_id_msg : __('Error', 'Something is wrong with the format');
if ($error_on_customized_url) {
$errors['customized_url']['aria'] = 'aria-describeby="customized_url" ';
$errors['customized_url']['class'] = ' has-error';
$errors['customized_url']['msg'] = isset($error_on_customized_url_msg) ? $error_on_customized_url_msg : __('Error', 'Something is wrong with the format');
}
if ($error_on_description) {
@ -269,7 +270,8 @@ $smarty->assign('goToStep2', GO_TO_STEP_2);
$smarty->assign('poll_type', $poll_type);
$smarty->assign('poll_title', Utils::fromPostOrDefault('title', $_SESSION['form']->title));
$smarty->assign('poll_id', Utils::fromPostOrDefault('id', $_SESSION['form']->id));
$smarty->assign('customized_url', Utils::fromPostOrDefault('customized_url', $_SESSION['form']->id));
$smarty->assign('use_customized_url', Utils::fromPostOrDefault('use_customized_url', $_SESSION['form']->use_customized_url));
$smarty->assign('poll_description', Utils::fromPostOrDefault('description', $_SESSION['form']->description));
$smarty->assign('poll_name', Utils::fromPostOrDefault('name', $_SESSION['form']->admin_name));
$smarty->assign('poll_mail', Utils::fromPostOrDefault('mail', $_SESSION['form']->admin_mail));

View File

@ -34,27 +34,13 @@ $(document).ready(function () {
});
/**
* Enable/Disable custom id options
* Enable/Disable custom url options
*/
var $pollId = $("#poll_id");
var $customizeId = $("#customize_id");
// Init checkbox + input
if (($pollId.val() || $pollId.attr('value') || "").length > 0) {
$customizeId.attr('checked', 'checked');
$pollId.removeAttr("disabled");
}
// Listen for checkbox changes
$customizeId.change(function () {
$("#use_customized_url").change(function () {
if ($(this).prop("checked")) {
$pollId
.removeAttr("disabled")
.val($pollId.attr("tmp") || $pollId.attr('value'));
$("#customized_url_options").removeClass("hidden");
} else {
$pollId
.attr("disabled", "disabled")
.attr("tmp", $pollId.val())
.val("");
$("#customized_url_options").addClass("hidden");
}
});
@ -90,4 +76,4 @@ $(document).ready(function () {
document.getElementById("cookie-warning").setAttribute("style", "");
}
});
});

View File

@ -230,6 +230,7 @@
"Required fields cannot be left blank.": "Merci de remplir les champs obligatoires, marqués d'une *.",
"Poll title": "Titre du sondage",
"Poll id": "Lien du sondage",
"Customize the URL": "Personnaliser le lien",
"Poll id rules": "(peut contenir des lettres, des chiffres et des tirets)",
"Poll id warning": "La modification du lien du sondage peut faciliter l'accès à ce sondage pour des personnes non désirées. Il est recommandé de le protéger par mot de passe.",
"Votes cannot be modified": "Aucun vote ne peut être modifié",

View File

@ -94,34 +94,50 @@
</div>
{/if}
<div class="form-group {$errors['id']['class']}">
{* Poll identifier *}
<div class="form-group {$errors['customized_url']['class']}">
<label for="poll_id" class="col-sm-4 control-label">
{__('Step 1', 'Poll id')}<br/>
<span id="pollIdDesc" class="small">{__('Step 1', 'Poll id rules')}</span>
</label>
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon">
<input id="customize_id" name="customize_id" type="checkbox"/>
</span>
<span class="input-group-addon">
{$SERVER_URL}
</span>
<input id="poll_id" type="text" name="id" class="form-control" {$errors['id']['aria']}
value="{$poll_id|html}" aria-describedBy="pollIdDesc" disabled="disabled" maxlength="64"
pattern="[A-Za-z0-9-]+"/>
<div class="checkbox">
<label>
<input id="use_customized_url" name="use_customized_url" type="checkbox" {if $use_customized_url}checked{/if}/>
{__('Step 1', 'Customize the URL')}
</label>
</div>
<span class="help-block text-warning">{__('Step 1', 'Poll id warning')}</span>
</div>
</div>
{if !empty($errors['id']['msg'])}
<div class="alert alert-danger">
<p id="poll_title_error">
{$errors['id']['msg']}
</p>
<div id="customized_url_options" {if !$use_customized_url}class="hidden"{/if}>
<div class="form-group {$errors['customized_url']['class']}">
<label for="customized_url" class="col-sm-4 control-label">
<span id="pollUrlDesc" class="small">{__('Step 1', 'Poll id rules')}</span>
</label>
<div class="col-sm-8">
<div class="input-group">
<span class="input-group-addon">
{$SERVER_URL}
</span>
<input id="customized_url" type="text" name="customized_url" class="form-control" {$errors['customized_url']['aria']}
value="{$customized_url|html}" aria-describedBy="pollUrlDesc" maxlength="64"
pattern="[A-Za-z0-9-]+"/>
</div>
<span class="help-block text-warning">{__('Step 1', 'Poll id warning')}</span>
</div>
</div>
{/if}
{if !empty($errors['customized_url']['msg'])}
<div class="alert alert-danger">
<p id="poll_customized_url_error">
{$errors['customized_url']['msg']}
</p>
</div>
{/if}
</div>
{* Password *}
<div class="form-group">
<label for="poll_id" class="col-sm-4 control-label">