From 9b39dd2fa1d7b73fc516b256b9d4a7e59ebb532b Mon Sep 17 00:00:00 2001 From: Olivier Perez Date: Thu, 4 Aug 2016 21:44:31 +0200 Subject: [PATCH] New style of URL customization --- app/classes/Framadate/Form.php | 8 ++++- create_poll.php | 36 ++++++++++++----------- js/app/create_poll.js | 24 ++++----------- locale/fr.json | 1 + tpl/create_poll.tpl | 54 ++++++++++++++++++++++------------ 5 files changed, 67 insertions(+), 56 deletions(-) diff --git a/app/classes/Framadate/Form.php b/app/classes/Framadate/Form.php index 52437e5..f8620de 100644 --- a/app/classes/Framadate/Form.php +++ b/app/classes/Framadate/Form.php @@ -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')); } -} \ No newline at end of file +} diff --git a/create_poll.php b/create_poll.php index f90562f..24bf5c1 100644 --- a/create_poll.php +++ b/create_poll.php @@ -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)); diff --git a/js/app/create_poll.js b/js/app/create_poll.js index 601fd7c..d708726 100644 --- a/js/app/create_poll.js +++ b/js/app/create_poll.js @@ -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", ""); } -}); \ No newline at end of file +}); diff --git a/locale/fr.json b/locale/fr.json index 21279eb..d5dae19 100644 --- a/locale/fr.json +++ b/locale/fr.json @@ -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é", diff --git a/tpl/create_poll.tpl b/tpl/create_poll.tpl index 0f28f7e..f773e2e 100644 --- a/tpl/create_poll.tpl +++ b/tpl/create_poll.tpl @@ -94,34 +94,50 @@ {/if} -
+ {* Poll identifier *} + +
-
- - - - - {$SERVER_URL} - - +
+
- {__('Step 1', 'Poll id warning')}
- {if !empty($errors['id']['msg'])} -
-

- {$errors['id']['msg']} -

+
+
+ + +
+
+ + {$SERVER_URL} + + +
+ {__('Step 1', 'Poll id warning')} +
- {/if} + {if !empty($errors['customized_url']['msg'])} +
+

+ {$errors['customized_url']['msg']} +

+
+ {/if} +
+ + {* Password *}