[gen] Calendar field: allow automatic check/uncheck of validation checkboxes within calendars (month and timeline views).

This commit is contained in:
Gaetan Delannay 2015-03-05 16:35:04 +01:00
parent 9b9853e570
commit a4a9acfcfb
11 changed files with 82 additions and 7 deletions

View file

@ -142,6 +142,7 @@ td.search { padding-top: 8px }
.cellDashed { border: 1px dashed grey !important }
.noStyle { border: 0 !important; padding: 0 !important; margin: 0 !important }
.noStyle td { border:0 !important; padding:0 !important; margin:0 !important }
.simpleLabel { text-transform: none }
.translationLabel { background-color: #EAEAEA; border-bottom: 1px dashed grey;
margin-top: 0.5em; margin-bottom: 0.5em }
.section1 { font-size: 120%; margin: 0.45em 0em 0.1em 0;
@ -198,4 +199,4 @@ td.search { padding-top: 8px }
.highlight { background-color: yellow }
.globalActions { margin-bottom: 4px }
.objectActions { margin: 2px 0 }
.smallbox { margin: 0 }
.smallbox { margin: 0; vertical-align: middle }

View file

@ -124,3 +124,40 @@ function validateEvents(hookId) {
'discarded': discarded, 'mode': 'POST'};
askAjax(hookId, null, params);
}
// Function for (un)-checking checkboxes automatically
function onCheckCbCell(cb, hook) {
// Is automatic selection on/off?
var auto = document.getElementById(hook + '_auto');
if (!auto.checked) return;
// Get the current render mode
var render = document.getElementById(hook)['ajax'].params['render'];
// Change the state of every successive checkbox
var timeline = render == 'timeline'; // Else, render is "month"
// From the checkbox id, extract the date and the remaining part
var elems = cb.id.split('_');
if (timeline) { var date = elems[2], part = elems[0] + '_' + elems[1] + '_'; }
else { var date = elems[0], part = '_' + elems[1] + '_' + elems[2]; }
// Create a Date instance
var year = parseInt(date.slice(0,4)), month = parseInt(date.slice(4,6))-1,
day = parseInt(date.slice(6,8));
var next = new Date(year, month, day);
// Change the status of successive checkboxes if found
var checked = cb.checked;
var nextId = nextCb = null;
while (true) {
// Compute the date at the next day
next.setDate(next.getDate() + 1);
month = (next.getMonth() + 1).toString();
if (month.length == 1) month = '0' + month;
day = next.getDate().toString();
if (day.length == 1) day = '0' + day;
date = next.getFullYear().toString() + month + day;
// Find the next checkbox
if (timeline) nextId = part + date;
else nextId = date + part;
nextCb = document.getElementById(nextId);
if (!nextCb) break;
nextCb.checked = checked;
}
}