booking calendar: add js to guide user to possible checkboxes (#16955)
This commit is contained in:
parent
56b47f5a50
commit
726e97dc42
|
@ -165,4 +165,43 @@ $(function() {
|
|||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
function set_booking_calendar_sensitivity(table) {
|
||||
if ($(table).find('input:checked').length == 0) {
|
||||
/* no checked box, enable them all */
|
||||
$(table).find('input').prop('disabled', false);
|
||||
return;
|
||||
}
|
||||
|
||||
/* disable every thing */
|
||||
var column_index = $(table).find('input:checked').parents('td').index();
|
||||
$(table).find('td').removeClass('active-column').removeClass('clickable');
|
||||
$(table).find('input').prop('disabled', true);
|
||||
|
||||
/* enable checkboxes from the active column */
|
||||
$(table).find('td:nth-child(' + (column_index+1) + ') input').prop('disabled', false);
|
||||
/* mark active column */
|
||||
$(table).find('td:nth-child(' + (column_index+1) + ')').addClass('active-column');
|
||||
|
||||
/* enable contiguous checkboxes; this is done by adding a clickable class
|
||||
* to the approriate checkboxes, as all of them need to be kept as enabled
|
||||
* HTML-wise to be transmitted on POST.
|
||||
*/
|
||||
var checkboxes = $(table).find('td:nth-child(' + (column_index+1) + ') input:checked');
|
||||
|
||||
/* enable the preceding one */
|
||||
$(checkboxes[0]).parents('tr').prev().find('td:nth-child(' + (column_index+1) + ')').addClass('clickable');
|
||||
/* enable first one, so it can be unchecked */
|
||||
$(checkboxes[0]).parents('td').addClass('clickable');
|
||||
/* enable last one, so it can be unchecked */
|
||||
$(checkboxes[checkboxes.length-1]).parents('td').addClass('clickable');
|
||||
/* enable the following one */
|
||||
$(checkboxes[checkboxes.length-1]).parents('tr').next().find('td:nth-child(' + (column_index+1) + ')').addClass('clickable');
|
||||
}
|
||||
|
||||
$('.bookingcalendar table').each(function(idx, elem) { set_booking_calendar_sensitivity(elem); });
|
||||
|
||||
$('.bookingcalendar input').on('change', function() {
|
||||
set_booking_calendar_sensitivity($(this).parents('table'));
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue