Using last added day number as base for new day

This commit is contained in:
Antonin 2016-08-07 12:24:41 +02:00
parent 4d14dd1b70
commit fcf8f5d621

View File

@ -74,25 +74,25 @@ $(document).ready(function () {
};
function newDateFields(dateStr) {
var nb_days = $selected_days.find('fieldset').length;
var last_day = $selected_days.find('fieldset:last');
var last_day = $selected_days.find('fieldset').filter(':last');
var last_day_title = last_day.find('legend input').attr('title');
var new_day_number = parseInt(/^d([0-9]+)-h[0-9]+$/.exec(last_day.find('.hours').filter(':first').attr('id'))[1]) + 1;
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 re_id_hours = new RegExp('"d' + (new_day_number - 1) + '-h', 'g');
var re_name_hours = new RegExp('name="horaires' + (new_day_number - 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)
var new_day_html = last_day.html().replace(re_id_hours, '"d' + new_day_number + '-h')
.replace('id="day' + (new_day_number - 1) + '"', 'id="day' + new_day_number + '"')
.replace('for="day' + (new_day_number - 1) + '"', 'for="day' + new_day_number + '"')
.replace(re_name_hours, 'name="horaires' + new_day_number)
.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) + '"');
.replace('title="' + last_day_title + '"', 'title="' + last_day_title.substring(0, last_day_title.indexOf(' ')) + ' ' + (new_day_number + 1) + '"');
last_day
.after('<fieldset>' + new_day_html + '</fieldset>')
.next().find('legend input').val(dateStr);
$('#day' + (nb_days)).focus();
$('#day' + (new_day_number)).focus();
$removeaday_and_copyhours.removeClass('disabled');
}