[gen] Added a new calendar field, allowing to add a single (typed) event by day.

This commit is contained in:
Gaetan Delannay 2012-10-03 14:44:34 +02:00
parent 3bd66e3264
commit 93bde7a0f5
12 changed files with 523 additions and 19 deletions

View file

@ -6,6 +6,7 @@
</tal:comment>
<tal:ajax define="contextObj context/getParentNode;
tool contextObj/getTool;
_ python: contextObj.translate;
req python: request;
resp req/RESPONSE;
page req/page;

View file

@ -183,7 +183,7 @@ function askRefField(hookId, objectUrl, fieldName, innerRef, startNumber,
if (actionParams) {
for (key in actionParams) { params[key] = actionParams[key]; };
}
askAjaxChunk(hookId, 'GET', objectUrl, 'widgets/ref', 'viewContent',params);
askAjaxChunk(hookId, 'GET', objectUrl, 'widgets/ref', 'viewContent', params);
}
function askComputedField(hookId, objectUrl, fieldName) {
@ -384,8 +384,10 @@ function generatePodDocument(contextUid, fieldName, podFormat, queryData) {
// Functions for opening and closing a popup
function openPopup(popupId, msg) {
// Put the message into the popup
var confirmElem = document.getElementById('appyConfirmText');
confirmElem.innerHTML = msg;
if (msg) {
var confirmElem = document.getElementById('appyConfirmText');
confirmElem.innerHTML = msg;
}
// Open the popup
var popup = document.getElementById(popupId);
// Put it at the right place on the screen
@ -451,8 +453,8 @@ function doConfirm() {
}
}
var wrongTextInput = '#F0C36D none';
// Function triggered when the user ask password reinitialisation
var wrongTextInput = '#F9EDBE none';
// Function triggered when the user asks password reinitialisation
function doAskPasswordReinit() {
// Check that the user has typed a login
var theForm = document.getElementById('askPasswordReinitForm');

View file

@ -14,11 +14,6 @@
groupedWidgets python: contextObj.getGroupedAppyTypes(layoutType, page, cssJs=cssJs);"
tal:on-error="structure python: tool.manageError(error)">
<tal:comment replace="nothing">Include type-specific CSS and JS.</tal:comment>
<link tal:repeat="cssFile cssJs/css" rel="stylesheet" type="text/css"
tal:attributes="href string:$appUrl/ui/$cssFile"/>
<script tal:repeat="jsFile cssJs/js" type="text/javascript"
tal:attributes="src string:$appUrl/ui/$jsFile"></script>
<metal:prologue use-macro="context/ui/page/macros/prologue"/>
<form id="appyEditForm" name="appyEditForm" method="post" enctype="multipart/form-data"
tal:attributes="action python: contextObj.absolute_url()+'/do';

View file

@ -2,6 +2,14 @@
This macro contains global page-related Javascripts.
</tal:comment>
<div metal:define-macro="prologue">
<tal:comment replace="nothing">Include type-specific CSS and JS.</tal:comment>
<tal:include condition="cssJs|nothing">
<link tal:repeat="cssFile cssJs/css" rel="stylesheet" type="text/css"
tal:attributes="href string:$appUrl/ui/$cssFile"/>
<script tal:repeat="jsFile cssJs/js" type="text/javascript"
tal:attributes="src string:$appUrl/ui/$jsFile"></script>
</tal:include>
<tal:comment replace="nothing">Javascript messages</tal:comment>
<script language="javascript" tal:content="tool/getJavascriptMessages"></script>
@ -10,7 +18,7 @@
<input type="hidden" name="action" value="Delete"/>
<input type="hidden" name="objectUid"/>
</form>
<tal:comment replace="nothing">Global form for generating a document from a pod template.</tal:comment>
<tal:comment replace="nothing">Global form for generating a document from a pod template</tal:comment>
<form name="podTemplateForm" method="post"
tal:attributes="action python: tool.absolute_url() + '/generateDocument'">
<input type="hidden" name="objectUid"/>

View file

@ -8,12 +8,14 @@
layout python: contextObj.getPageLayout(layoutType);
phaseInfo python: contextObj.getAppyPhases(currentOnly=True, layoutType='view');
phase phaseInfo/name;
cssJs python: {};
page req/page|python:contextObj.getDefaultViewPage();
groupedWidgets python: contextObj.getGroupedAppyTypes(layoutType, page);"
groupedWidgets python: contextObj.getGroupedAppyTypes(layoutType, page, cssJs=cssJs);"
tal:on-error="structure python: tool.manageError(error)">
<metal:prologue use-macro="context/ui/page/macros/prologue"/>
<metal:show use-macro="context/ui/page/macros/show"/>
<metal:footer use-macro="context/ui/page/macros/footer"/>
</metal:fill>
<metal:prologue use-macro="context/ui/page/macros/prologue"/>
<metal:show use-macro="context/ui/page/macros/show"/>
<metal:footer use-macro="context/ui/page/macros/footer"/>
</metal:fill>
</html>
</tal:main>

View file

@ -0,0 +1,49 @@
function askMonthView(hookId, objectUrl, fieldName, month) {
// Sends an Ajax request for getting the view month of a calendar field
var params = {'fieldName': fieldName, 'month': month};
askAjaxChunk(hookId,'GET',objectUrl,'widgets/calendar','viewMonth', params);
}
function openEventPopup(action, fieldName, day, spansDays) {
/* Opens the popup for creating (or deleting, depending on p_action) a
calendar event at some p_day. When action is "del", we need to know
(from p_spansDays) if the event spans more days, in order to propose a
checkbox allowing to delete events for those successive days. */
var prefix = fieldName + '_' + action + 'Event';
var f = document.getElementById(prefix + 'Form');
f.day.value = day;
if (action == 'del') {
var elem = document.getElementById(prefix + 'DelNextEvent');
var cb = elem.getElementsByTagName('input');
cb[0].checked = false;
cb[1].value = 'False';
if (spansDays == 'True') { elem.style.display = 'block' }
else { elem.style.display = 'none' }
}
openPopup(prefix + 'Popup');
}
function triggerCalendarEvent(action, hookId, fieldName, objectUrl) {
/* Sends an Ajax request for triggering a calendar event (create or delete an
event) and refreshing the view month. */
var prefix = fieldName + '_' + action + 'Event';
var f = document.getElementById(prefix + 'Form');
if (action == 'new') {
// Check that eventSpan is empty or contains a valid number
var spanNumber = f.eventSpan.value.replace(' ', '');
if (spanNumber) {
if (isNaN(parseInt(spanNumber))) {
f.eventSpan.style.background = wrongTextInput;
return;
}
}
}
var elems = f.elements;
var params = {};
// Put form elements into "params".
for (var i=0; i < elems.length; i++) {
params[elems[i].name] = elems[i].value;
}
closePopup(prefix + 'Popup');
askAjaxChunk(hookId,'POST',objectUrl,'widgets/calendar','viewMonth',params);
}

163
gen/ui/widgets/calendar.pt Normal file
View file

@ -0,0 +1,163 @@
<tal:comment replace="nothing">View macro</tal:comment>
<div metal:define-macro="viewMonth"
tal:define="fieldName request/fieldName;
ajaxHookId python: contextObj.UID() + fieldName;
month request/month;
monthDayOne python: DateTime('%s/01' % month);
today python: DateTime('00:00');
todayMonth python: today.strftime('%Y/%m');
grid python: contextObj.callField(fieldName, 'getMonthGrid', month);
previousMonth python: contextObj.callField(fieldName, 'getSiblingMonth', month, 'previous');
nextMonth python: contextObj.callField(fieldName, 'getSiblingMonth', month, 'next');
widget python: contextObj.getAppyType(fieldName, asDict=True);
mayEdit python: contextObj.allows(widget['writePermission']);
objUrl contextObj/absolute_url"
tal:attributes="id ajaxHookId">
<tal:comment replace="nothing">Month chooser</tal:comment>
<div style="margin-bottom: 5px">
<img style="cursor:pointer"
tal:attributes="src string: $appUrl/ui/arrowLeftSimple.png;
onclick python: 'askMonthView(\'%s\',\'%s\',\'%s\',\'%s\')' % (ajaxHookId,objUrl,fieldName,previousMonth)"/>
<input type="button"
tal:attributes="value python: _('today');
onclick python: 'askMonthView(\'%s\',\'%s\',\'%s\',\'%s\')' % (ajaxHookId,objUrl,fieldName,todayMonth);
disabled monthDayOne/isCurrentMonth"/>
<img style="cursor:pointer"
tal:attributes="src string: $appUrl/ui/arrowRightSimple.png;
onclick python: 'askMonthView(\'%s\',\'%s\',\'%s\',\'%s\')' % (ajaxHookId,objUrl,fieldName,nextMonth)"/>
<span tal:content="python: _('month_%s' % monthDayOne.aMonth())"></span>
<span tal:content="python: month.split('/')[0]"></span>
</div>
<tal:comment replace="nothing">Calendar month view</tal:comment>
<table cellpadding="0" cellspacing="0" width="100%" class="list" style="font-size: 95%"
tal:define="rowHeight python: int(widget['height']/float(len(grid)))">
<tal:comment replace="nothing">1st row: names of days</tal:comment>
<tr height="22px">
<th tal:repeat="dayName python: contextObj.callField(fieldName, 'getNamesOfDays', contextObj)"
tal:content="dayName" width="14%">
</th>
</tr>
<tal:comment replace="nothing">The calendar in itself</tal:comment>
<tr tal:repeat="row grid" valign="top" tal:attributes="height rowHeight">
<tal:cell repeat="date row">
<td tal:define="events python: contextObj.callField(fieldName, 'getEventsAt', contextObj, date);
spansDays python: contextObj.callField(fieldName, 'hasEventsAt', contextObj, date+1, events);
mayCreate python: mayEdit and not events;
mayDelete python: mayEdit and events;"
tal:attributes="style python: test(date.isCurrentDay(), 'font-weight:bold', 'font-weight:normal');
class python: test(date &lt; today, 'even', 'odd');
onmouseover python: test(mayEdit, 'this.getElementsByTagName(\'img\')[0].style.visibility=\'visible\'', '');
onmouseout python: test(mayEdit, 'this.getElementsByTagName(\'img\')[0].style.visibility=\'hidden\'', '')">
<tal:day define="day date/day;
dayString python: date.strftime('%Y/%m/%d')">
<span tal:content="day"></span>
<span tal:condition="python: day == 1"
tal:content="python: _('month_%s_short' % date.aMonth())"></span>
<tal:comment replace="nothing">Icon for adding an event</tal:comment>
<img tal:condition="mayCreate" style="visibility:hidden; cursor:pointer"
tal:attributes="src string: $appUrl/ui/plus.png;
onclick python: 'openEventPopup(\'new\',\'%s\',\'%s\')' % (fieldName, dayString)"/>
<tal:comment replace="nothing">Icon for deleting an event</tal:comment>
<img tal:condition="mayDelete" style="visibility:hidden; cursor:pointer"
tal:attributes="src string: $appUrl/ui/delete.png;
onclick python: 'openEventPopup(\'del\',\'%s\',\'%s\',\'%s\')' % (fieldName, dayString, str(spansDays))"/>
<tal:events condition="events">
<tal:comment replace="nothing">A single event is allowed for the moment</tal:comment>
<div tal:define="eventType python: events[0]['eventType']">
<span style="color: grey"
tal:content="python: _('%s_event_%s' % (widget['labelId'], eventType))"></span>
</div>
</tal:events>
</tal:day>
</td>
</tal:cell>
</tr>
</table>
<tal:comment replace="nothing">Popup for creating a calendar event</tal:comment>
<div tal:define="prefix python: '%s_newEvent' % fieldName;
popupId python: prefix + 'Popup'"
tal:attributes="id popupId" class="popup" align="center">
<form tal:attributes="id python: prefix + 'Form'" method="post">
<input type="hidden" name="fieldName" tal:attributes="value fieldName"/>
<input type="hidden" name="month" tal:attributes="value month"/>
<input type="hidden" name="name" tal:attributes="value fieldName"/>
<input type="hidden" name="action" value="Process"/>
<input type="hidden" name="actionType" value="createEvent"/>
<input type="hidden" name="day"/>
<div align="center" style="margin-bottom: 3px" tal:content="python: _('which_event')"></div>
<select name="eventType">
<option tal:repeat="eventType widget/eventTypes"
tal:content="python: _('%s_event_%s' % (widget['labelId'], eventType))"
tal:attributes="value eventType">
</option>
</select><br/><br/>
<tal:comment replace="nothing">Span the event on several days</tal:comment>
<div align="center" class="discreet" style="margin-bottom: 3px">
<span tal:content="python: _('event_span')"></span>
<input type="text" size="3" name="eventSpan"/>
</div>
<input type="button"
tal:attributes="value python:_('object_save');
onClick python: 'triggerCalendarEvent(\'new\',\'%s\',\'%s\',\'%s\')' % (ajaxHookId,fieldName,objUrl)"/>
<input type="button"
tal:attributes="value python:_('object_cancel');
onclick python: 'closePopup(\'%s\')' % popupId"/>
</form>
</div>
<tal:comment replace="nothing">Popup for deleting a calendar event</tal:comment>
<div tal:define="prefix python: '%s_delEvent' % fieldName;
popupId python: prefix + 'Popup'"
tal:attributes="id popupId" class="popup" align="center">
<form tal:attributes="id python: prefix + 'Form'" method="post">
<input type="hidden" name="fieldName" tal:attributes="value fieldName"/>
<input type="hidden" name="month" tal:attributes="value month"/>
<input type="hidden" name="name" tal:attributes="value fieldName"/>
<input type="hidden" name="action" value="Process"/>
<input type="hidden" name="actionType" value="deleteEvent"/>
<input type="hidden" name="day"/>
<div align="center" style="margin-bottom: 5px"
tal:content="python: _('delete_confirm')"></div>
<tal:comment replace="nothing">Delete successive events?</tal:comment>
<div class="discreet" style="margin-bottom: 10px"
tal:attributes="id python: prefix + 'DelNextEvent'">
<input type="checkbox" name="deleteNext_cb"
tal:attributes="id python: prefix + '_cb';
onClick python:'toggleCheckbox(\'%s_cb\', \'%s_hd\')' % (prefix, prefix);"/>
<input type="hidden" tal:attributes="id python: prefix + '_hd'" name="deleteNext"/>
<span tal:content="python: _('del_next_events')"/>
</div>
<input type="button"
tal:attributes="value python:_('yes');
onClick python: 'triggerCalendarEvent(\'del\',\'%s\',\'%s\',\'%s\')' % (ajaxHookId,fieldName,objUrl)"/>
<input type="button"
tal:attributes="value python:_('no');
onclick python: 'closePopup(\'%s\')' % popupId"/>
</form>
</div>
</div>
<tal:comment replace="nothing">View macro</tal:comment>
<metal:view define-macro="view"
tal:define="now python: DateTime();
dummy python: request.set('fieldName', widget['name']);
dummy python: request.set('month', now.strftime('%Y/%m'))">
<metal:call use-macro="app/ui/widgets/calendar/macros/viewMonth"/>
</metal:view>
<tal:comment replace="nothing">Edit macro</tal:comment>
<metal:edit define-macro="edit"></metal:edit>
<tal:comment replace="nothing">Cell macro</tal:comment>
<metal:cell define-macro="cell">
<metal:call use-macro="app/ui/widgets/calendar/macros/view"/>
</metal:cell>
<tal:comment replace="nothing">Search macro</tal:comment>
<metal:search define-macro="search"></metal:search>