diff --git a/adminstuds.php b/adminstuds.php index a26bbd225ebc827b5897344892e8128c9114967a..e613d51723a4bdf3fc98dee3c199875c9612a811 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 0000000000000000000000000000000000000000..7a32203aa43f27bd5d8e364236bae2cabd5e6c56 --- /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 = "<div class='alert alert-dismissible alert-danger' role='alert'>"; + addedDiv += errorMessage; + addedDiv += "<button type='button' class='close' data-dismiss='alert' aria-label='Close'><span aria-hidden='true'>×</span></button></div>"; + $("#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 281fdc971fa81c022b0300b5d73799cae0d528fc..1bfbb525bd99c0a569bd980c2626353376a407f1 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 3b8bbaca4540e1d319ab28c4232d46fe8dbab236..401a271aa6dce76882b46b654bfca673741233eb 100644 --- a/tpl/head.tpl +++ b/tpl/head.tpl @@ -24,6 +24,8 @@ <script src="{'nav/nav.js'|resource}" id="nav_js" type="text/javascript" charset="utf-8"></script><!-- /Framanav --> {/if} + {block name="header"}{/block} + </head> <body> <div class="container ombre"> \ No newline at end of file diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index e36559d3083f61d80301fc681b0a40e49c4f1353..ab0a6524552a660fdbe968ede2d7e7340748178f 100644 --- a/tpl/part/vote_table_classic.tpl +++ b/tpl/part/vote_table_classic.tpl @@ -5,7 +5,7 @@ <h3>{__('Poll results\\Votes of the poll')}</h3> <div id="tableContainer" class="tableContainer"> - <form action="" method="POST"> + <form action="" method="POST" id="poll_form"> <table class="results"> <caption class="sr-only">{__('Poll results\\Votes of the poll')} {$poll->title|html}</caption> <thead> diff --git a/tpl/part/vote_table_date.tpl b/tpl/part/vote_table_date.tpl index ab00563c9ba7ad53d30768995bb8d8de75ff8be1..2e8416dd85855b51843c22b6431b27c5ebeba862 100644 --- a/tpl/part/vote_table_date.tpl +++ b/tpl/part/vote_table_date.tpl @@ -5,7 +5,7 @@ <h3>{__('Poll results\\Votes of the poll')}</h3> <div id="tableContainer" class="tableContainer"> - <form action="" method="POST"> + <form action="" method="POST" id="poll_form"> <table class="results"> <caption class="sr-only">{__('Poll results\\Votes of the poll')} {$poll->title|html}</caption> <thead> diff --git a/tpl/studs.tpl b/tpl/studs.tpl index 9f9613e59192352585c635a11de5b1415ecb9498..44a7ce842e3e3ef3b36c72ca8de7e1094f6156e6 100644 --- a/tpl/studs.tpl +++ b/tpl/studs.tpl @@ -1,10 +1,16 @@ {extends file='page.tpl'} +{block name="header"} + <script src="{"js/app/studs.js"|resource}" type="text/javascript"></script> +{/block} + {block name=main} - {if !empty($message)} - <div class="alert alert-dismissible alert-{$message->type|html}" role="alert">{$message->message|html}<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button></div> - {/if} + <div id="message-container"> + {if !empty($message)} + <div class="alert alert-dismissible alert-{$message->type|html}" role="alert">{$message->message|html}<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button></div> + {/if} + </div> {* Global informations about the current poll *} @@ -37,6 +43,12 @@ </div> </div> +<div class="hidden"> + <p id="parameter_name_regex">{$parameter_name_regex}</p> + <p id="parameter_name_error">{$parameter_name_error}</p> +</div> + + {* Vote table *} {if $poll->format === 'D'}