diff --git a/create_date_poll.php b/create_date_poll.php index df1757d..9bab697 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -67,13 +67,6 @@ if (!isset($form->title) || !isset($form->admin_name) || ($config['use_smtp'] && } switch ($step) { - case 1: - // Step 1/4 : error if $_SESSION from info_sondage are not valid - $smarty->assign('title', __('Error', 'Error!')); - $smarty->assign('error', __('Error', 'You haven\'t filled the first section of the poll creation, or your session has expired.')); - $smarty->display('error.tpl'); - exit; - case 2: // Step 2/4 : Select dates of the poll @@ -186,7 +179,7 @@ switch ($step) { $smarty->assign('default_poll_duration', $config['default_poll_duration']); $smarty->assign('use_smtp', $config['use_smtp']); - $smarty->display('create_poll_step3.tpl'); + $smarty->display('create_poll_step_3.tpl'); exit; case 4: @@ -251,4 +244,12 @@ switch ($step) { // Redirect to poll administration header('Location:' . Utils::getUrlSondage($admin_poll_id, true)); exit; + + case 1: + default: + // Step 1/4 : error if $_SESSION from info_sondage are not valid + $smarty->assign('title', __('Error', 'Error!')); + $smarty->assign('error', __('Error', 'You haven\'t filled the first section of the poll creation, or your session has expired.')); + $smarty->display('error.tpl'); + exit; } diff --git a/js/app/classic_poll.js b/js/app/classic_poll.js index a091f4a..7a22066 100644 --- a/js/app/classic_poll.js +++ b/js/app/classic_poll.js @@ -15,75 +15,74 @@ * Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaƫl DROZ * Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft) */ -(function () { - // 2 choices filled and you can submit - var submitChoicesAvalaible = function () { +$(document).ready(function () { + $(document.formulaire).on('submit', function (e) { + if (!isSubmitChoicesAvalaible()) { + e.preventDefault(); + e.stopPropagation(); + } + }); + + var $next = $('button[name="fin_sondage_autre"]'); + var $removeAChoice = $('#remove-a-choice'); + var $addAChoice = $('#add-a-choice'); + + var updateButtonState = function() { + var $choiceFields = $('.choice-field'); + $removeAChoice.prop('disabled', function() { return $choiceFields.length <= 2; }); + $next.prop('disabled', !isSubmitChoicesAvalaible()); + } + + var isSubmitChoicesAvalaible = function () { + return (countFilledChoices() >= 2); + }; + + var countFilledChoices = function() { var nb_filled_choices = 0; $('.choice-field input').each(function () { if ($(this).val() != '') { nb_filled_choices++; } }); - if (nb_filled_choices >= 1) { - $('button[name="fin_sondage_autre"]').removeClass('disabled'); - return true; - } else { - $('button[name="fin_sondage_autre"]').addClass('disabled'); - return false; - } + return nb_filled_choices; }; - // Handle form submission - $(document.formulaire).on('submit', function (e) { - if (!submitChoicesAvalaible()) { - e.preventDefault(); - e.stopPropagation(); - } + $removeAChoice.on('click', function () { + $('.choice-field:last').remove(); + updateButtonState(); }); - // Button "Add a choice" - - $('#add-a-choice').on('click', function () { - var nb_choices = $('.choice-field').length; - var last_choice = $('.choice-field:last'); - + $addAChoice.on('click', function () { + var $choiceFields = $('.choice-field'); + var nb_choices = $choiceFields.length; + var last_choice = $choiceFields.last(); + var new_choice = last_choice.html(); - + // label var last_choice_label = last_choice.children('label').text(); var choice_text = last_choice_label.substring(0, last_choice_label.indexOf(' ')); - + // for and id var re_id_choice = new RegExp('"choice' + (nb_choices - 1) + '"', 'g'); - + var new_choice_html = new_choice.replace(re_id_choice, '"choice' + nb_choices + '"') .replace(last_choice_label, choice_text + ' ' + (nb_choices + 1)) .replace(/value="(.*?)"/g, 'value=""'); - - last_choice.after('