[gen] Calendar field: total columns finalized.

This commit is contained in:
Gaetan Delannay 2015-03-21 11:20:52 +01:00
parent e5088771e7
commit 71e4f978e0
2 changed files with 33 additions and 20 deletions

View file

@ -243,7 +243,7 @@ class Calendar(Field):
<tbody id=":'%s_trs' % ajaxHookId" <tbody id=":'%s_trs' % ajaxHookId"
var="totals=field.computeTotals('row', zobj, grid, others, \ var="totals=field.computeTotals('row', zobj, grid, others, \
preComputed)"> preComputed)">
<script>:field.getAjaxDataTotalRow(ajaxHookId)</script> <script>:field.getAjaxDataTotals('rows', ajaxHookId)</script>
<tr for="row in field.totalRows" var2="rowTitle=_(row.label)"> <tr for="row in field.totalRows" var2="rowTitle=_(row.label)">
<td class="tlLeft"> <td class="tlLeft">
<acronym title=":rowTitle"><b>:row.name</b></acronym></td> <acronym title=":rowTitle"><b>:row.name</b></acronym></td>
@ -253,22 +253,13 @@ class Calendar(Field):
</tr> </tr>
</tbody>''') </tbody>''')
# Ajax-call the previous PX
pxTotalRowsFromAjax = Px('''
<x var="month=req.get('month');
ajaxHookId=zobj.id + field.name;
monthDayOne=field.DateTime('%s/01' % month);
grid=field.getGrid(month, 'timeline');
preComputed=field.getPreComputedInfo(zobj, monthDayOne, grid);
others=field.getOthers(zobj, \
preComputed)">:field.pxTotalRows</x>''')
# Displays the total columns besides the calendar, as a separate table # Displays the total columns besides the calendar, as a separate table
pxTotalCols = Px(''' pxTotalCols = Px('''
<table cellpadding="0" cellspacing="0" class="list timeline" <table cellpadding="0" cellspacing="0" class="list timeline"
style="float:right" id=":'%s_tcs' % ajaxHookId" style="float:right" id=":'%s_tcs' % ajaxHookId"
var="totals=field.computeTotals('col', zobj, grid, others, \ var="totals=field.computeTotals('col', zobj, grid, others, \
preComputed)"> preComputed)">
<script>:field.getAjaxDataTotals('cols', ajaxHookId)</script>
<tr for="i in range(2)"> <!-- 2 empty rows --> <tr for="i in range(2)"> <!-- 2 empty rows -->
<td for="col in field.totalCols" class="hidden">&nbsp;</td> <td for="col in field.totalCols" class="hidden">&nbsp;</td>
</tr> </tr>
@ -300,6 +291,17 @@ class Calendar(Field):
</tr> </tr>
</table>''') </table>''')
# Ajax-call pxTotalRows or pxTotalCols
pxTotalsFromAjax = Px('''
<x var="month=req['month'];
totalType=req['totalType'].capitalize();
ajaxHookId=zobj.id + field.name;
monthDayOne=field.DateTime('%s/01' % month);
grid=field.getGrid(month, 'timeline');
preComputed=field.getPreComputedInfo(zobj, monthDayOne, grid);
others=field.getOthers(zobj, \
preComputed)">:getattr(field, 'pxTotal%s' % totalType)</x>''')
# Timeline view for a calendar # Timeline view for a calendar
pxViewTimeline = Px(''' pxViewTimeline = Px('''
<table cellpadding="0" cellspacing="0" class="list timeline" <table cellpadding="0" cellspacing="0" class="list timeline"
@ -475,7 +477,7 @@ class Calendar(Field):
if="mayValidate and (event.eventType in field.validation.schema)" if="mayValidate and (event.eventType in field.validation.schema)"
id=":'%s_%s_%s' % (date.strftime('%Y%m%d'), event.eventType, \ id=":'%s_%s_%s' % (date.strftime('%Y%m%d'), event.eventType, \
event.timeslot)" event.timeslot)"
onclick=":'onCheckCbCell(this,%s,false)' % q(ajaxHookId)"/> onclick=":'onCheckCbCell(this,%s)' % q(ajaxHookId)"/>
<x>::event.getName(allEventNames)</x> <x>::event.getName(allEventNames)</x>
<!-- Icon for delete this particular event --> <!-- Icon for delete this particular event -->
<img if="mayDelete and not single" class="clickable" <img if="mayDelete and not single" class="clickable"
@ -885,9 +887,11 @@ class Calendar(Field):
cbId = '%s_%s_%s' % (other.obj.id, other.field.name, cbId = '%s_%s_%s' % (other.obj.id, other.field.name,
date.strftime('%Y%m%d')) date.strftime('%Y%m%d'))
totalRows = self.totalRows and 'true' or 'false' totalRows = self.totalRows and 'true' or 'false'
totalCols = self.totalCols and 'true' or 'false'
content = '<input type="checkbox" checked="checked" ' \ content = '<input type="checkbox" checked="checked" ' \
'class="smallbox" id="%s" onclick="onCheckCbCell(this,' \ 'class="smallbox" id="%s" onclick="onCheckCbCell(this,' \
'\'%s\',%s)"/>' % (cbId, c['ajaxHookId'], totalRows) '\'%s\',%s,%s)"/>' % \
(cbId, c['ajaxHookId'], totalRows, totalCols)
break break
elif len(events) == 1: elif len(events) == 1:
# A single event: if not colored, show a symbol. When there are # A single event: if not colored, show a symbol. When there are
@ -1523,11 +1527,13 @@ class Calendar(Field):
return "new AjaxData('%s', '%s:pxView', %s, null, '%s')" % \ return "new AjaxData('%s', '%s:pxView', %s, null, '%s')" % \
(hook, self.name, params, zobj.absolute_url()) (hook, self.name, params, zobj.absolute_url())
def getAjaxDataTotalRow(self, hook): def getAjaxDataTotals(self, type, hook):
'''Initializes an AjaxData object on the DOM node corresponding to '''Initializes an AjaxData object on the DOM node corresponding to
the zone containing the total rows in a timeline calendar.''' the zone containing the total rows/cols (depending on p_type) in a
return "new AjaxData('%s_trs', '%s:pxTotalRowsFromAjax', {}, '%s')" % \ timeline calendar.'''
(hook, self.name, hook) suffix = (type == 'rows') and 'trs' or 'tcs'
return "new AjaxData('%s_%s', '%s:pxTotalsFromAjax', {}, '%s')" % \
(hook, suffix, self.name, hook)
def validateEvents(self, obj): def validateEvents(self, obj):
'''Validate or discard events from the request''' '''Validate or discard events from the request'''

View file

@ -132,7 +132,7 @@ function validateEvents(hookId, month) {
} }
// Function for (un)-checking checkboxes automatically // Function for (un)-checking checkboxes automatically
function onCheckCbCell(cb, hook, totalRows) { function onCheckCbCell(cb, hook, totalRows, totalCols) {
// Is automatic selection on/off? // Is automatic selection on/off?
var auto = document.getElementById(hook + '_auto'); var auto = document.getElementById(hook + '_auto');
if (auto.checked) { if (auto.checked) {
@ -169,9 +169,16 @@ function onCheckCbCell(cb, hook, totalRows) {
} }
} }
// Refresh the total rows if requested // Refresh the total rows if requested
if (totalRows) { if (totalRows || totalCols) {
var params = getValidationStatus(hook); var params = getValidationStatus(hook);
params['mode'] = 'POST'; params['mode'] = 'POST';
askAjax(hook + '_trs', null, params, 'loadingPod'); if (totalRows) {
params['totalType'] = 'rows';
askAjax(hook + '_trs', null, params, 'loadingPod');
}
if (totalCols) {
params['totalType'] = 'cols';
askAjax(hook + '_tcs', null, params, 'loadingPod');
}
} }
} }