Skip to content
Snippets Groups Projects
Commit c2cfdf4f authored by Antonin's avatar Antonin
Browse files

Manage button state in the new feature

parent 65c8bb4d
No related branches found
No related tags found
No related merge requests found
...@@ -75,8 +75,8 @@ $(document).ready(function () { ...@@ -75,8 +75,8 @@ $(document).ready(function () {
function getLastDayNumber(last_day) { function getLastDayNumber(last_day) {
if (last_day == null) if (last_day == null)
last_day = $selected_days.find('fieldset').filter(':last') last_day = $selected_days.find('fieldset').filter(':last');
return parseInt(/^d([0-9]+)-h[0-9]+$/.exec(last_day.find('.hours').filter(':first').attr('id'))[1]) return parseInt(/^d([0-9]+)-h[0-9]+$/.exec($(last_day).find('.hours').filter(':first').attr('id'))[1])
} }
function newDateFields(dateStr) { function newDateFields(dateStr) {
...@@ -102,6 +102,14 @@ $(document).ready(function () { ...@@ -102,6 +102,14 @@ $(document).ready(function () {
$removeaday_and_copyhours.removeClass('disabled'); $removeaday_and_copyhours.removeClass('disabled');
} }
function manageRemoveadayAndCopyhoursButtons() {
var nb_days = $selected_days.find('fieldset').length;
$('#day' + (getLastDayNumber() - 1)).focus();
if (nb_days == 1) {
$removeaday_and_copyhours.addClass('disabled');
}
}
var useFirstEmptyDateField = function (dateStr) { var useFirstEmptyDateField = function (dateStr) {
var used = false; var used = false;
$selected_days.find('fieldset legend input').each(function () { $selected_days.find('fieldset legend input').each(function () {
...@@ -225,12 +233,7 @@ $(document).ready(function () { ...@@ -225,12 +233,7 @@ $(document).ready(function () {
$('#remove-a-day').on('click', function () { $('#remove-a-day').on('click', function () {
$selected_days.find('fieldset:last').remove(); $selected_days.find('fieldset:last').remove();
var nb_days = $selected_days.find('fieldset').length; manageRemoveadayAndCopyhoursButtons();
$('#day' + (getLastDayNumber() - 1)).focus();
if (nb_days == 1) {
$removeaday_and_copyhours.addClass('disabled');
}
submitDaysAvalaible(); submitDaysAvalaible();
}); });
...@@ -240,6 +243,7 @@ $(document).ready(function () { ...@@ -240,6 +243,7 @@ $(document).ready(function () {
if ($('#days_container').find('fieldset').length > 1) { if ($('#days_container').find('fieldset').length > 1) {
$(this).parents('fieldset').remove(); $(this).parents('fieldset').remove();
} }
manageRemoveadayAndCopyhoursButtons();
submitDaysAvalaible(); submitDaysAvalaible();
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment