From b66a47ef6718113df0dbd0040b15cfc436fc2ed5 Mon Sep 17 00:00:00 2001 From: Antonin Date: Thu, 26 Mar 2015 16:33:11 +0100 Subject: [PATCH] Added simple javascript check for the name. - The goal here is to prevent the losing of the choices by having a bad name. - This is a POC, there is probably some cleaning before merge --- adminstuds.php | 2 ++ js/app/studs.js | 21 +++++++++++++++++++++ studs.php | 2 ++ tpl/head.tpl | 2 ++ tpl/part/vote_table_classic.tpl | 2 +- tpl/part/vote_table_date.tpl | 2 +- tpl/studs.tpl | 18 +++++++++++++++--- 7 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 js/app/studs.js diff --git a/adminstuds.php b/adminstuds.php index a26bbd2..e613d51 100644 --- a/adminstuds.php +++ b/adminstuds.php @@ -373,5 +373,7 @@ $smarty->assign('comments', $comments); $smarty->assign('editingVoteId', $editingVoteId); $smarty->assign('message', $message); $smarty->assign('admin', true); +$smarty->assign('parameter_name_regex', NAME_REGEX); +$smarty->assign('parameter_name_error', _('Name is incorrect.')); $smarty->display('studs.tpl'); \ No newline at end of file diff --git a/js/app/studs.js b/js/app/studs.js new file mode 100644 index 0000000..7a32203 --- /dev/null +++ b/js/app/studs.js @@ -0,0 +1,21 @@ +$(document).ready(function() { + + $("#poll_form").submit(function( event ) { + var name = $("#name").val(); + var regexContent = $("#parameter_name_regex").text().split("/"); + var regex = new RegExp(regexContent[1], regexContent[2]); + if (name.length == 0 || !regex.test(name)) { + event.preventDefault(); + var errorMessage = $("#parameter_name_error").text(); + var addedDiv = ""; + $("#message-container").empty(); + $("#message-container").append(addedDiv); + $('html, body').animate({ + scrollTop: $("#message-container").offset().top + }, 750); + } + }); + +}); \ No newline at end of file diff --git a/studs.php b/studs.php index 281fdc9..1bfbb52 100644 --- a/studs.php +++ b/studs.php @@ -202,5 +202,7 @@ $smarty->assign('comments', $comments); $smarty->assign('editingVoteId', $editingVoteId); $smarty->assign('message', $message); $smarty->assign('admin', false); +$smarty->assign('parameter_name_regex', NAME_REGEX); +$smarty->assign('parameter_name_error', _('Name is incorrect.')); $smarty->display('studs.tpl'); diff --git a/tpl/head.tpl b/tpl/head.tpl index 3b8bbac..401a271 100644 --- a/tpl/head.tpl +++ b/tpl/head.tpl @@ -24,6 +24,8 @@ {/if} + {block name="header"}{/block} +
\ No newline at end of file diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index e36559d..ab0a652 100644 --- a/tpl/part/vote_table_classic.tpl +++ b/tpl/part/vote_table_classic.tpl @@ -5,7 +5,7 @@

{__('Poll results\\Votes of the poll')}

-
+ diff --git a/tpl/part/vote_table_date.tpl b/tpl/part/vote_table_date.tpl index ab00563..2e8416d 100644 --- a/tpl/part/vote_table_date.tpl +++ b/tpl/part/vote_table_date.tpl @@ -5,7 +5,7 @@

{__('Poll results\\Votes of the poll')}

- +
{__('Poll results\\Votes of the poll')} {$poll->title|html}
diff --git a/tpl/studs.tpl b/tpl/studs.tpl index 9f9613e..44a7ce8 100644 --- a/tpl/studs.tpl +++ b/tpl/studs.tpl @@ -1,10 +1,16 @@ {extends file='page.tpl'} +{block name="header"} + +{/block} + {block name=main} - {if !empty($message)} - - {/if} +
+ {if !empty($message)} + + {/if} +
{* Global informations about the current poll *} @@ -37,6 +43,12 @@ + + + {* Vote table *} {if $poll->format === 'D'}
{__('Poll results\\Votes of the poll')} {$poll->title|html}