diff --git a/create_classic_poll.php b/create_classic_poll.php index ffaaecab05dd2c200af553417b687217d6d7461b..5ae301e568ef5c96c92c4bac4ff079934c66c7bd 100644 --- a/create_classic_poll.php +++ b/create_classic_poll.php @@ -179,7 +179,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || ( } $summary .= '</ol>'; - $end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_expiry_time)); //textual date + $end_date_str = utf8_encode(strftime($date_format['txt_date'], $max_expiry_time)); //textual date echo ' <form name="formulaire" action="' . Utils::get_server_name() . 'create_classic_poll.php" method="POST" class="form-horizontal" role="form"> diff --git a/create_date_poll.php b/create_date_poll.php index 4b6e2b92f966ed899139aa8c1ccb09c726b914fe..304e9ed8080391cfc170de8a4e841b205fe047b2 100644 --- a/create_date_poll.php +++ b/create_date_poll.php @@ -133,6 +133,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) || if (!empty($day)) { // Add choice to Form data + // TODO Fix the parse $time = mktime(0, 0, 0, substr($_POST["days"][$i],3,2),substr($_POST["days"][$i],0,2),substr($_POST["days"][$i],6,4)); $choice = new Choice($time); $_SESSION['form']->addChoice($choice); @@ -154,7 +155,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) || Utils::print_header ( __('Step 3', 'Removal date and confirmation (3 on 3)') ); bandeau_titre(__('Step 3', 'Removal date and confirmation (3 on 3)')); - $end_date_str = utf8_encode(strftime('%d/%m/%Y', $max_expiry_time)); // textual date + $end_date_str = utf8_encode(strftime($date_format['txt_date'], $max_expiry_time)); // textual date // Summary $summary = '<ul>'; diff --git a/js/app/date_poll.js b/js/app/date_poll.js index 6e894d2c03513ae48a9d87370b2976e4f69443ce..50195f74760c71f835cbdb8b53cd77537fac692f 100644 --- a/js/app/date_poll.js +++ b/js/app/date_poll.js @@ -43,6 +43,72 @@ $(document).ready(function () { } }; + /** + * Parse a string date + * @param dateStr The string date + * @param format The format PHP style (allowed: %Y, %m and %d) + */ + var parseDate = function (dateStr, format) { + var dtsplit = dateStr.split(/[\/ .:-]/); + var dfsplit = format.split(/[\/ .:-]/); + + // creates assoc array for date + var df = []; + for (var dc = 0; dc < 6; dc++) { + df[dfsplit[dc]] = dtsplit[dc]; + } + + // Build date + return new Date(parseInt(df['%Y']), parseInt(df['%m']) - 1, parseInt(df['%d']), 0, 0, 0, 0); + }; + + var formatDate = function (date, format) { + return format + .replace('%d', date.getDate()) + .replace('%m', date.getMonth() + 1) + .replace('%Y', date.getFullYear()); + }; + + function newDateFields(dateStr) { + var nb_days = $selected_days.find('fieldset').length; + var last_day = $selected_days.find('fieldset:last'); + var last_day_title = last_day.find('legend input').attr('title'); + + var re_id_hours = new RegExp('"d' + (nb_days - 1) + '-h', 'g'); + var re_name_hours = new RegExp('name="horaires' + (nb_days - 1), 'g'); + + // TODO Faire mieux que remplacer des chaines de caractères + var new_day_html = last_day.html().replace(re_id_hours, '"d' + nb_days + '-h') + .replace('id="day' + (nb_days - 1) + '"', 'id="day' + nb_days + '"') + .replace('for="day' + (nb_days - 1) + '"', 'for="day' + nb_days + '"') + .replace(re_name_hours, 'name="horaires' + nb_days) + .replace(/value="(.*?)"/g, 'value=""') + .replace(/hours" title="(.*?)"/g, 'hours" title="" p') + .replace('title="' + last_day_title + '"', 'title="' + last_day_title.substring(0, last_day_title.indexOf(' ')) + ' ' + (nb_days + 1) + '"'); + + last_day + .after('<fieldset>' + new_day_html + '</fieldset>') + .next().find('legend input').val(dateStr); + $('#day' + (nb_days)).focus(); + $removeaday_and_copyhours.removeClass('disabled'); + } + + var useFirstEmptyDateField = function (dateStr) { + console.log(dateStr); + var used = false; + $selected_days.find('fieldset legend input').each(function () { + if (!used) { + console.log($(this).val(), $(this)); + if ($(this).val() == '') { + $(this).val(dateStr); + used = true; + } + } + }); + + return used; + }; + // Handle form submission $(document.formulaire).on('submit', function (e) { if (!submitDaysAvalaible()) { @@ -145,24 +211,7 @@ $(document).ready(function () { // Button "Add a day" $('#add-a-day').on('click', function () { - var nb_days = $selected_days.find('fieldset').length; - var last_day = $selected_days.find('fieldset:last'); - var last_day_title = last_day.find('legend input').attr('title'); - - var re_id_hours = new RegExp('"d' + (nb_days - 1) + '-h', 'g'); - var re_name_hours = new RegExp('name="horaires' + (nb_days - 1), 'g'); - - var new_day_html = last_day.html().replace(re_id_hours, '"d' + nb_days + '-h') - .replace('id="day' + (nb_days - 1) + '"', 'id="day' + nb_days + '"') - .replace('for="day' + (nb_days - 1) + '"', 'for="day' + nb_days + '"') - .replace(re_name_hours, 'name="horaires' + nb_days) - .replace(/value="(.*?)"/g, 'value=""') - .replace(/hours" title="(.*?)"/g, 'hours" title="" p') - .replace('title="' + last_day_title + '"', 'title="' + last_day_title.substring(0, last_day_title.indexOf(' ')) + ' ' + (nb_days + 1) + '"'); - - last_day.after('<fieldset>' + new_day_html + '</fieldset>'); - $('#day' + (nb_days)).focus(); - $removeaday_and_copyhours.removeClass('disabled'); + newDateFields(); }); // Button "Remove a day" @@ -177,6 +226,37 @@ $(document).ready(function () { submitDaysAvalaible(); }); + // Add an range of dates + + $('#interval_add').on('click', function (ev) { + var startDateField = $('#range_start'); + var endDateField = $('#range_end'); + var startDate = parseDate(startDateField.val(), window.date_formats.DATE); + var endDate = parseDate(endDateField.val(), window.date_formats.DATE); + + console.log('start_date as date', startDate); + console.log('start_end as date', endDate); + + if (startDate <= endDate && startDate > new Date()) { + while (startDate <= endDate) { + var dateStr = formatDate(startDate, window.date_formats.DATE); + if(!useFirstEmptyDateField(dateStr)) { + newDateFields(dateStr); + } + startDate.setDate(startDate.getDate() + 1); + } + + // Hide modal + startDateField.val(''); + endDateField.val(''); + $('#add_days').modal('hide'); + submitDaysAvalaible(); + } else { + console.log('err'); + } + + }); + // Title update on hours and buttons -/+ hours $(document).on('change', '.input-group.date input', function () { diff --git a/js/app/framadatepicker.js b/js/app/framadatepicker.js index c09a30b802e15b4a4cf32bda3a5be65b81e1e461..b17b8d2f06a4d733d71f272cf69ff39a8112f2d3 100644 --- a/js/app/framadatepicker.js +++ b/js/app/framadatepicker.js @@ -18,7 +18,7 @@ $(document).ready(function () { var init_datepicker = function () { $('.input-group.date').datepicker({ - format: "dd/mm/yyyy", + format: window.date_formats.DATEPICKER || "dd/mm/yyyy", todayBtn: "linked", orientation: "top left", autoclose: true, diff --git a/locale/de.json b/locale/de.json index bc2ba2307d27910af4f85ccd65363733b8f13e02..8edd6860036511bbe2c09b832893382bdc06dedc 100644 --- a/locale/de.json +++ b/locale/de.json @@ -41,14 +41,18 @@ "ASTERISK": "*" }, "Date": { - "dd/mm/yyyy": "jj/mm/aaaa", + "dd/mm/yyyy": "dd/mm/yyyy", + "datepicker": "yyyy-mm-dd", "%A, den %e. %B %Y": "%A %e %B %Y", "FULL": "%A, den %e. %B %Y", "SHORT": "%A %e %B %Y", "DAY": "%a %e", "DATE": "%Y-%m-%d", "MONTH_YEAR": "%B %Y", - "DATETIME": "%Y-%m-%d %H:%M" + "DATETIME": "%Y-%m-%d %H:%M", + "Add range dates": "DE_Ajout d'un intervalle de dates", + "Start date": "DE_Date de début", + "End date": "DE_Date de fin" }, "Language selector": { "Select the language": "Sprache wählen", diff --git a/locale/en.json b/locale/en.json index 3ed4ad9ff780cccd35b8c615fd6d1d8f10e6477f..beed0a2d24d73b699512cd8e7d800cfb936d10ff 100644 --- a/locale/en.json +++ b/locale/en.json @@ -41,14 +41,18 @@ "ASTERISK": "*" }, "Date" : { - "dd/mm/yyyy": "jj/mm/aaaa", + "dd/mm/yyyy": "yyyy-mm-dd", + "datepicker": "yyyy-mm-dd", "%A, den %e. %B %Y": "%A %e %B %Y", "FULL": "%A, %B %e, %Y", "SHORT": "%A %e %B %Y", "DAY": "%a %e", "DATE": "%Y-%m-%d", "MONTH_YEAR": "%B %Y", - "DATETIME": "%m/%d/%Y %H:%M" + "DATETIME": "%m/%d/%Y %H:%M", + "Add range dates": "Add range dates", + "Start date": "Start date", + "End date": "End date" }, "Language selector": { "Select the language": "Select language", diff --git a/locale/es.json b/locale/es.json index a12a988f59cf7ed0a83f76d7b1f129f0c045db06..224bee7a7889d6371c17c0d0cc65cede1538ea5a 100644 --- a/locale/es.json +++ b/locale/es.json @@ -42,13 +42,17 @@ }, "Date": { "dd/mm/yyyy": "ES_jj/mm/aaaa", + "datepicker": "yyyy-mm-dd", "%A, den %e. %B %Y": "%A %e de %B %Y", "FULL": "ES_%A, den %e. %B %Y", "SHORT": "ES_%A %e %B %Y", "DAY": "ES_%a %e", "DATE": "ES_%Y-%m-%d", "MONTH_YEAR": "ES_%B %Y", - "DATETIME": "%d/%m/%Y %H:%M" + "DATETIME": "%d/%m/%Y %H:%M", + "Add range dates": "ES_Ajout d'un intervalle de dates", + "Start date": "ES_Date de début", + "End date": "ES_Date de fin" }, "Language selector": { "Select the language": "ES_Choisir la langue", diff --git a/locale/fr.json b/locale/fr.json index 40d934916a9941c2541818cfaf0ae2f3030d84fe..ac4e02cecf25056c5fb2f2bcbda59171d735653a 100644 --- a/locale/fr.json +++ b/locale/fr.json @@ -42,13 +42,17 @@ }, "Date": { "dd/mm/yyyy": "jj/mm/aaaa", + "datepicker": "dd/mm/yyyy", "%A, den %e. %B %Y": "%A %e %B %Y", "FULL": "%A %e %B %Y", "SHORT": "%A %e %B %Y", "DAY": "%a %e", - "DATE": "%Y-%m-%d", + "DATE": "%d/%m/%Y", "MONTH_YEAR": "%B %Y", - "DATETIME": "%d-%m-%Y %H:%M" + "DATETIME": "%d-%m-%Y %H:%M", + "Add range dates": "Ajout d'un intervalle de dates", + "Start date": "Date de début", + "End date": "Date de fin" }, "Language selector": { "Select the language": "Choisir la langue", diff --git a/locale/it.json b/locale/it.json index e8a549f276ba46e0e2c99c6584edaebc7fadb081..ddeac9f08542ec117c887a0374ef6a3fb8e90610 100644 --- a/locale/it.json +++ b/locale/it.json @@ -42,13 +42,17 @@ }, "Date": { "dd/mm/yyyy": "gg/mm/aaaa", + "datepicker": "gg/mm/yyyy", "%A, den %e. %B %Y": "%A %e %B %Y", "FULL": "%A %e %B %Y", "SHORT": "%A %e %B %Y", "DAY": "%a %e", "DATE": "%Y-%m-%d", "MONTH_YEAR": "%B %Y", - "DATETIME": "%d/%m/%Y %H:%M" + "DATETIME": "%d/%m/%Y %H:%M", + "Add range dates": "IT_Ajout d'un intervalle de dates", + "Start date": "IT_Date de début", + "End date": "IT_Date de fin" }, "Language selector": { "Select the language": "Scegliere la lingua", @@ -355,4 +359,4 @@ "MISSING_VALUES": "Valori mancanti", "CANT_CONNECT_TO_DATABASE": "Impossibile connettersi al database" } -} \ No newline at end of file +} diff --git a/tpl/create_date_poll_step_2.tpl b/tpl/create_date_poll_step_2.tpl index 82d22b02fc9ebfdace436771517e97982dba79c7..7f6a3b34b7ac2a271ea31325151ba99049abc47f 100644 --- a/tpl/create_date_poll_step_2.tpl +++ b/tpl/create_date_poll_step_2.tpl @@ -1,6 +1,12 @@ {extends file='page.tpl'} {block name="header"} + <script type="text/javascript"> + window.date_formats = { + DATE: '{__('Date', 'DATE')}', + DATEPICKER: '{__('Date', 'datepicker')}' + }; + </script> <script type="text/javascript" src="{'js/app/framadatepicker.js'|resource}"></script> <script type="text/javascript" src="{'js/app/date_poll.js'|resource}"></script> {/block} @@ -26,7 +32,7 @@ {foreach $choices as $i=>$choice} {if $choice->getName()} - {$day_value = strftime('%d/%m/%Y', $choice->getName())} + {$day_value = $choice->getName()|date_format:$date_format['txt_date']} {else} {$day_value = ''} {/if} @@ -79,6 +85,11 @@ <button type="button" id="add-a-day" class="btn btn-default" title="{__('Step 2 date', 'Add a day')}"><span class="glyphicon glyphicon-plus text-success"></span><span class="sr-only">{__('Step 2 date', 'Add a day')}</span></button> </div> + <a href="" data-toggle="modal" data-target="#add_days" class="btn btn-default" title="{__('Date', 'Add range dates')}"> + <span class="glyphicon glyphicon-plus text-success"></span> + <span class="glyphicon glyphicon-plus text-success"></span> + <span class="sr-only">{__('Step 2 date', 'Add days')}</span> + </a> </div> <div class="col-md-8 text-right"> <div class="btn-group"> @@ -99,4 +110,41 @@ </div> </div> </form> + + <div id="add_days" class="modal fade"> + <div class="modal-dialog modal-md"> + <div class="modal-content"> + <div class="modal-header"> + <button type="button" class="close" data-dismiss="modal" aria-label="Close"> + <span aria-hidden="true">×</span> + </button> + <h4 class="modal-title">{__('Date', 'Add range dates')}</h4> + </div> + <div class="modal-body row"> + <div class="col-xs-12"> + <label for="range_start">{__('Date', 'Start date')}</label> + <div class="input-group date"> + <span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span> + <input type="text" class="form-control" id="range_start" + data-date-format="{__('Date', 'dd/mm/yyyy')}" size="10" maxlength="10" + placeholder="{__('Date', 'dd/mm/yyyy')}"/> + </div> + </div> + <div class="col-xs-12"> + <label for="range_end">{__('Date', 'End date')}</label> + <div class="input-group date"> + <span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span> + <input type="text" class="form-control" id="range_end" + data-date-format="{__('Date', 'dd/mm/yyyy')}" size="10" maxlength="10" + placeholder="{__('Date', 'dd/mm/yyyy')}"/> + </div> + </div> + </div> + <div class="modal-footer"> + <button data-dismiss="modal" class="btn btn-default">{__('Generic', 'Cancel')}</button> + <button id="interval_add" class="btn btn-success">{__('Generic', 'Add')}</button> + </div> + </div> + </div> + </div> {/block} diff --git a/tpl/part/vote_table_classic.tpl b/tpl/part/vote_table_classic.tpl index 660dc105318d570289d7a055869ba710077e0e1c..94ca9d7bc3efa7b1d731fc6d7b2671d255bb445d 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')} {if $hidden}<i>({__('PollInfo', 'Results are hidden.')})</i>{/if} {if $accessGranted} - <a href="" data-toggle="modal" data-target="#hint_modal"><i class="glyphicon glyphicon-info-sign"></i></a> + <a href="" data-toggle="modal" data-target="#hint_modal"><i class="glyphicon glyphicon-info-sign"></i></a><!-- TODO Add accessibility --> {/if} </h3>