[gen] Take into account Calendar.maxEventLength.

This commit is contained in:
Gaetan Delannay 2012-10-06 05:20:35 +02:00
parent 64e1ace32c
commit fdd9f4c375
3 changed files with 8 additions and 4 deletions

View file

@ -141,7 +141,7 @@ class Calendar(Type):
events.append(event) events.append(event)
# Span the event on the successive days if required # Span the event on the successive days if required
if handleEventSpan and rq['eventSpan']: if handleEventSpan and rq['eventSpan']:
nbOfDays = int(rq['eventSpan']) nbOfDays = min(int(rq['eventSpan']), self.maxEventLength)
for i in range(nbOfDays): for i in range(nbOfDays):
date = date + 1 date = date + 1
self.createEvent(obj, date, handleEventSpan=False) self.createEvent(obj, date, handleEventSpan=False)

View file

@ -23,7 +23,7 @@ function openEventPopup(action, fieldName, day, spansDays) {
openPopup(prefix + 'Popup'); openPopup(prefix + 'Popup');
} }
function triggerCalendarEvent(action, hookId, fieldName, objectUrl) { function triggerCalendarEvent(action, hookId, fieldName, objectUrl, maxEventLength) {
/* Sends an Ajax request for triggering a calendar event (create or delete an /* Sends an Ajax request for triggering a calendar event (create or delete an
event) and refreshing the view month. */ event) and refreshing the view month. */
var prefix = fieldName + '_' + action + 'Event'; var prefix = fieldName + '_' + action + 'Event';
@ -32,7 +32,8 @@ function triggerCalendarEvent(action, hookId, fieldName, objectUrl) {
// Check that eventSpan is empty or contains a valid number // Check that eventSpan is empty or contains a valid number
var spanNumber = f.eventSpan.value.replace(' ', ''); var spanNumber = f.eventSpan.value.replace(' ', '');
if (spanNumber) { if (spanNumber) {
if (isNaN(parseInt(spanNumber))) { spanNumber = parseInt(spanNumber);
if (isNaN(spanNumber) || (spanNumber > maxEventLength)) {
f.eventSpan.style.background = wrongTextInput; f.eventSpan.style.background = wrongTextInput;
return; return;
} }

View file

@ -14,6 +14,9 @@
objUrl contextObj/absolute_url" objUrl contextObj/absolute_url"
tal:attributes="id ajaxHookId"> tal:attributes="id ajaxHookId">
<script type="text/javascript"
tal:content="python: 'var %s_maxEventLength = %d;' % (fieldName, widget['maxEventLength'])">
</script>
<tal:comment replace="nothing">Month chooser</tal:comment> <tal:comment replace="nothing">Month chooser</tal:comment>
<div style="margin-bottom: 5px"> <div style="margin-bottom: 5px">
<img style="cursor:pointer" <img style="cursor:pointer"
@ -102,7 +105,7 @@
</div> </div>
<input type="button" <input type="button"
tal:attributes="value python:_('object_save'); tal:attributes="value python:_('object_save');
onClick python: 'triggerCalendarEvent(\'new\',\'%s\',\'%s\',\'%s\')' % (ajaxHookId,fieldName,objUrl)"/> onClick python: 'triggerCalendarEvent(\'new\',\'%s\',\'%s\',\'%s\',%s_maxEventLength)' % (ajaxHookId,fieldName,objUrl,fieldName)"/>
<input type="button" <input type="button"
tal:attributes="value python:_('object_cancel'); tal:attributes="value python:_('object_cancel');
onclick python: 'closePopup(\'%s\')' % popupId"/> onclick python: 'closePopup(\'%s\')' % popupId"/>