274 lines
16 KiB
XML
274 lines
16 KiB
XML
<tal:comment replace="nothing"> We begin with some sub-macros used within
|
|
macro "showReference" defined below.</tal:comment>
|
|
|
|
<metal:objectTitle define-macro="objectTitle">
|
|
<tal:comment replace="nothing">Displays the title of a referenced object, with a link on
|
|
it to reach the consult view for this object. If we are on a back reference, the link
|
|
allows to reach the correct page where the forward reference is defined.</tal:comment>
|
|
<a tal:define="viewUrl obj/getUrl;
|
|
fullUrl python: test(isBack, viewUrl + '/?pageName=%s&phase=%s' % (appyType['page'], appyType['phase']), viewUrl)"
|
|
tal:attributes="href fullUrl" tal:content="obj/Title"></a>
|
|
</metal:objectTitle>
|
|
|
|
<metal:objectActions define-macro="objectActions">
|
|
<tal:comment replace="nothing">Displays icons for triggering actions on a given
|
|
referenced object (edit, delete, etc).</tal:comment>
|
|
<table class="no-style-table" cellpadding="0" cellspacing="0">
|
|
<tr>
|
|
<tal:comment replace="nothing">Edit the element</tal:comment>
|
|
<td class="noPadding"><a tal:attributes="href python: obj.absolute_url() + '/skyn/edit'"
|
|
tal:condition="python: member.has_permission('Modify portal content', obj)">
|
|
<img src="edit.gif" title="label_edit" i18n:domain="plone" i18n:attributes="title" />
|
|
</a></td>
|
|
<tal:comment replace="nothing">Delete the element</tal:comment>
|
|
<td class="noPadding">
|
|
<img tal:condition="python: member.has_permission('Delete objects', obj)"
|
|
src="delete_icon.gif" title="Delete" i18n:domain="plone" i18n:attributes="title" style="cursor:pointer"
|
|
tal:attributes="onClick python:'javascript:onDeleteObject(\'%s\')' % obj.UID()"/>
|
|
</td>
|
|
<tal:comment replace="nothing">Arrows for moving objects up or down</tal:comment>
|
|
<td class="noPadding" tal:condition="python: (len(objs)>1) and member.has_permission('Modify portal content', obj)">
|
|
<tal:moveRef define="objectIndex python:contextObj.getAppyRefIndex(fieldName, obj);
|
|
baseUrl python: contextObj.getUrl('showRef', **{'fieldName': fieldName, 'isBack': isBack, 'innerRef': innerRef, 'labelId': labelId, 'descrId': descrId, '%s_startNumber' % ajaxHookId: startNumber, 'action':'ChangeRefOrder', 'refObjectUid': obj.UID()})">
|
|
<tal:comment replace="nothing">Move up</tal:comment>
|
|
<img tal:define="ajaxUrl python: baseUrl + '&move=up'" tal:condition="python: objectIndex > 0"
|
|
tal:attributes="src string: $portal_url/skyn/arrowUp.png;
|
|
title python: tool.translate('move_up');
|
|
onClick python: 'askAjaxChunk(\'%s\', \'%s\')' % (ajaxHookId, ajaxUrl)"
|
|
style="cursor:pointer"/>
|
|
<tal:comment replace="nothing">Move down</tal:comment>
|
|
<img tal:define="ajaxUrl python: baseUrl + '&move=down'" tal:condition="python: objectIndex < (totalNumber-1)"
|
|
tal:attributes="src string: $portal_url/skyn/arrowDown.png;
|
|
title python: tool.translate('move_down');
|
|
onClick python: 'askAjaxChunk(\'%s\', \'%s\')' % (ajaxHookId, ajaxUrl)"
|
|
style="cursor:pointer"/>
|
|
</tal:moveRef>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</metal:objectActions>
|
|
|
|
<metal:plusIcon define-macro="plusIcon">
|
|
<tal:comment replace="nothing">Displays the "plus" icon that allows to add new object
|
|
through a reference widget. Indeed, If field was declared as "addable", we must provide
|
|
an icon for creating a new linked object (at least if multiplicities allow it).</tal:comment>
|
|
<img style="cursor:pointer" tal:condition="showPlusIcon"
|
|
tal:attributes="src string:$portal_url/skyn/plus.png;
|
|
title python: tool.translate('add_ref');
|
|
onClick python: 'href: window.location=\'%s/skyn/do?action=Create&initiator=%s&field=%s&type_name=%s\'' % (folder.absolute_url(), contextObj.UID(), fieldName, linkedPortalType)"/>
|
|
</metal:plusIcon>
|
|
|
|
<tal:comment replace="nothing">
|
|
This macro shows a reference field. More precisely, it shows nothing, but calls
|
|
a Javascript function that will asynchonously call (via a XmlHttpRequest object) the
|
|
macro 'showReferenceContent' defined below, that will really show content.
|
|
It requires:
|
|
- isBack (bool) Is the reference a backward or forward reference?
|
|
- fieldName (string) The name of the reference field (if it is a forward reference)
|
|
or the name of the Archetypes relationship (if it is a backward reference)
|
|
- innerRef (bool) Are we rendering a reference within a reference or not?
|
|
- contextObj (object) the object from which the reference starts
|
|
- labelId (string) the i18n id of the reference field label
|
|
- descrId (string) the i18n id of the reference field description
|
|
</tal:comment>
|
|
<div metal:define-macro="showReference"
|
|
tal:define="ajaxHookId python: contextObj.UID()+fieldName;
|
|
ajaxUrl python: contextObj.getUrl('showRef', **{'fieldName': fieldName, 'isBack': isBack, 'innerRef': innerRef, 'labelId': labelId, 'descrId': descrId})"
|
|
tal:attributes="id ajaxHookId">
|
|
<script language="javascript"
|
|
tal:content="python: 'askAjaxChunk(\'%s\',\'%s\')' % (ajaxHookId, ajaxUrl)">
|
|
</script>
|
|
</div>
|
|
|
|
<tal:comment replace="nothing">
|
|
This macro is called by a XmlHttpRequest for displaying the paginated referred objects
|
|
of a reference field.
|
|
</tal:comment>
|
|
<div metal:define-macro="showReferenceContent"
|
|
tal:define="fieldName request/fieldName;
|
|
isBack python: test(request['isBack']=='True', True, False);
|
|
innerRef python: test(request['innerRef']=='True', True, False);
|
|
labelId request/labelId;
|
|
descrId request/descrId;
|
|
ajaxHookId python: contextObj.UID()+fieldName;
|
|
startNumber python: int(request.get('%s_startNumber' % ajaxHookId, 0));
|
|
appyType python: contextObj.getAppyType(fieldName, not isBack);
|
|
tool contextObj/getTool;
|
|
refObjects python:contextObj.getAppyRefs(fieldName, not isBack, startNumber);
|
|
objs refObjects/objects;
|
|
totalNumber refObjects/totalNumber;
|
|
batchSize refObjects/batchSize;
|
|
folder python: test(contextObj.isPrincipiaFolderish, contextObj, contextObj.getParentNode());
|
|
flavour python:tool.getFlavour(contextObj);
|
|
linkedPortalType python:flavour.getPortalType(appyType['klass']);
|
|
addPermission python: '%s: Add %s' % (tool.getAppName(), linkedPortalType);
|
|
multiplicity python:test(isBack, appyType['backd']['multiplicity'], appyType['multiplicity']);
|
|
maxReached python:(multiplicity[1] != None) and (len(objs) >= multiplicity[1]);
|
|
showPlusIcon python:not isBack and appyType['add'] and not maxReached and member.has_permission(addPermission, folder);
|
|
atMostOneRef python: (multiplicity[1] == 1) and (len(objs)<=1);
|
|
label python: tool.translate(labelId);
|
|
description python: tool.translate(descrId);
|
|
baseUrl python: contextObj.getUrl('showRef', **{'fieldName': fieldName, 'isBack': isBack, 'innerRef': innerRef, 'labelId': labelId, 'descrId': descrId}) + '&%s_startNumber=' % ajaxHookId">
|
|
|
|
<tal:comment replace="nothing">This macro displays the Reference widget on a "consult" page.
|
|
|
|
The definition of "atMostOneRef" above may sound strange: we shouldn't check the actual number
|
|
of referenced objects. But for back references people often forget to specify multiplicities.
|
|
So concretely, multiplicities (0,None) are coded as (0,1).</tal:comment>
|
|
|
|
<tal:atMostOneReference condition="atMostOneRef">
|
|
<tal:comment replace="nothing">Display a simplified widget if maximum number of
|
|
referenced objects is 1.</tal:comment>
|
|
<table class="no-style-table" cellpadding="0" cellspacing="0"><tr valign="top">
|
|
<td><span class="appyLabel" tal:condition="not: innerRef" tal:content="label"></span></td>
|
|
|
|
<tal:comment replace="nothing">If there is no object...</tal:comment>
|
|
<tal:noObject condition="not:objs">
|
|
<td tal:content="python: tool.translate('no_ref')"></td>
|
|
<td><metal:plusIcon use-macro="here/skyn/ref/macros/plusIcon"/></td>
|
|
</tal:noObject>
|
|
|
|
<tal:comment replace="nothing">If there is an object...</tal:comment>
|
|
<tal:objectIsPresent condition="python: len(objs) == 1">
|
|
<tal:obj define="obj python:objs[0]">
|
|
<td><metal:showObjectTitle use-macro="here/skyn/ref/macros/objectTitle" /></td>
|
|
<td tal:condition="not: isBack">
|
|
<metal:showObjectActions use-macro="here/skyn/ref/macros/objectActions" />
|
|
</td>
|
|
</tal:obj>
|
|
</tal:objectIsPresent>
|
|
</tr></table>
|
|
</tal:atMostOneReference>
|
|
|
|
<tal:comment replace="nothing">Display a fieldset in all other cases.</tal:comment>
|
|
<tal:anyNumberOfReferences condition="not: atMostOneRef">
|
|
<fieldset tal:attributes="class python:test(innerRef, 'innerAppyFieldset', '')">
|
|
<legend tal:condition="python: not innerRef or showPlusIcon">
|
|
<span tal:condition="not: innerRef" tal:content="label"/>
|
|
<metal:plusIcon use-macro="here/skyn/ref/macros/plusIcon"/>
|
|
</legend>
|
|
|
|
<tal:comment replace="nothing">Object description</tal:comment>
|
|
<p tal:condition="python: not innerRef and description.strip()"
|
|
tal:content="description" class="discreet" ></p>
|
|
|
|
<tal:comment replace="nothing">Appy (top) navigation</tal:comment>
|
|
<metal:nav use-macro="here/skyn/macros/macros/appyNavigate"/>
|
|
|
|
<tal:comment replace="nothing">No object is present</tal:comment>
|
|
<p tal:condition="not:objs" tal:content="python: tool.translate('no_ref')"></p>
|
|
|
|
<table width="100%" cellspacing="0" cellpadding="0" tal:condition="objs"
|
|
tal:attributes="class python:test(innerRef, 'innerAppyTable', '')">
|
|
<tr valign="bottom"><td>
|
|
|
|
<tal:comment replace="nothing">Show backward reference(s)</tal:comment>
|
|
<table class="no-style-table" cellspacing="0" cellpadding="0"
|
|
tal:condition="python: isBack and objs">
|
|
<tr tal:repeat="obj objs">
|
|
<td><metal:showObjectTitle use-macro="here/skyn/ref/macros/objectTitle" />
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<tal:comment replace="nothing">Show forward reference(s)</tal:comment>
|
|
<table tal:attributes="class python:test(innerRef, '', 'vertical listing');
|
|
width python:test(innerRef, '100%', test(appyType['wide'], '100%', ''))"
|
|
align="right" tal:condition="python: not isBack and objs" cellpadding="0" cellspacing="0">
|
|
<tr tal:condition="appyType/showHeaders">
|
|
<th tal:condition="python: 'title' not in appyType['shownInfo']"
|
|
tal:content="python: tool.translate('ref_name')"></th>
|
|
<th tal:repeat="shownField appyType/shownInfo">
|
|
<tal:showHeader condition="python: objs[0].getField(shownField)">
|
|
<tal:titleHeader condition="python: shownField == 'title'"
|
|
content="python: tool.translate('ref_name')"/>
|
|
<tal:otherHeader condition="python: shownField != 'title'"
|
|
define="labelId python: objs[0].getField(shownField).widget.label_msgid"
|
|
content="python: tool.translate(labelId)"/>
|
|
</tal:showHeader>
|
|
</th>
|
|
<th tal:content="python: tool.translate('ref_actions')"></th>
|
|
</tr>
|
|
<tr tal:repeat="obj objs" valign="top">
|
|
<tal:comment replace="nothing">Object title, shown here if not specified somewhere
|
|
else in appyType.shownInfo.</tal:comment>
|
|
<td tal:condition="python: 'title' not in appyType['shownInfo']"><metal:showObjectTitle
|
|
use-macro="here/skyn/ref/macros/objectTitle"/>
|
|
</td>
|
|
<tal:comment replace="nothing">Additional fields that must be shown</tal:comment>
|
|
<td tal:repeat="shownField appyType/shownInfo">
|
|
<tal:showTitle condition="python: shownField == 'title'">
|
|
<metal:showObjectTitle use-macro="here/skyn/ref/macros/objectTitle"/>
|
|
</tal:showTitle>
|
|
<tal:showOtherField define="appyType python: obj.getAppyType(shownField);
|
|
field python:obj.getField(shownField);
|
|
contextObj python:obj;"
|
|
condition="python: appyType and (shownField != 'title')">
|
|
<tal:showNormalField condition="python: appyType['type'] not in ('Ref', 'Computed', 'Action')">
|
|
<metal:viewField use-macro="python: obj.widget(shownField, 'view', use_label=0)"/>
|
|
</tal:showNormalField>
|
|
<tal:showRef condition="python: appyType['type'] == 'Ref'">
|
|
<tal:ref tal:define="isBack python:appyType['isBack'];
|
|
fieldName python: test(isBack, field.relationship, field.getName());
|
|
innerRef python:True">
|
|
<metal:showField use-macro="here/skyn/ref/macros/showReference" />
|
|
</tal:ref>
|
|
</tal:showRef>
|
|
<tal:showComputed condition="python: appyType['type'] == 'Computed'">
|
|
<tal:computed content="python: obj.getComputedValue(appyType)"/>
|
|
</tal:showComputed>
|
|
<tal:showAction condition="python: appyType['type'] == 'Action'">
|
|
<metal:action use-macro="here/skyn/macros/macros/showActionField" />
|
|
</tal:showAction>
|
|
</tal:showOtherField>
|
|
</td>
|
|
<tal:comment replace="nothing">Actions</tal:comment>
|
|
<td align="right">
|
|
<metal:showObjectActions use-macro="here/skyn/ref/macros/objectActions" />
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
|
|
</td></tr>
|
|
</table>
|
|
|
|
<tal:comment replace="nothing">Appy (bottom) navigation</tal:comment>
|
|
<metal:nav use-macro="here/skyn/macros/macros/appyNavigate"/>
|
|
|
|
</fieldset>
|
|
<tal:comment replace="nothing">A carriage return needed in some cases.</tal:comment>
|
|
<br tal:define="widgetDescr widgetDescr|nothing"
|
|
tal:condition="python: not widgetDescr or (widgetDescr['widgetType'] != 'group')"/>
|
|
</tal:anyNumberOfReferences>
|
|
</div>
|
|
|
|
<div metal:define-macro="editReference"
|
|
tal:define="refPortalType python:here.getAppyRefPortalType(field.getName());
|
|
appyType python:here.getAppyType(field.getName());
|
|
allBrains python:here.uid_catalog(portal_type=refPortalType);
|
|
brains python:here.callAppySelect(appyType['select'], allBrains);
|
|
refUids python: [o.UID() for o in here.getAppyRefs(field.getName())['objects']];
|
|
isMultiple python:test(appyType['multiplicity'][1]!=1, 'multiple', '');
|
|
appyFieldName python: 'appy_ref_%s' % field.getName();
|
|
inError python:test(errors.has_key(field.getName()), True, False);
|
|
defaultValue python: contextObj.getDefault(field.getName());
|
|
defaultValueUID defaultValue/UID|nothing;
|
|
isBeingCreated python: contextObj.portal_factory.isTemporary(contextObj) or ('/portal_factory/' in contextObj.absolute_url())"
|
|
tal:attributes="class python:'appyRefEdit field' + test(inError, ' error', '')">
|
|
|
|
<tal:comment replace="nothing">This macro displays the Reference widget on an "edit" page</tal:comment>
|
|
|
|
<label tal:attributes="for python:appyFieldName" tal:content="label"></label>
|
|
<span class="fieldRequired" tal:condition="python: appyType['multiplicity'][0]>0"></span><br/>
|
|
<div tal:condition="inError" tal:content="python: errors[field.getName()]"></div>
|
|
<select tal:define="valueIsInReq python:test(request.get(appyFieldName, None) != None, True, False)"
|
|
tal:attributes="name python:'appy_ref_%s' % field.getName();
|
|
multiple isMultiple">
|
|
<option tal:condition="not: isMultiple" value="" i18n:translate="choose_a_value"/>
|
|
<option tal:repeat="brain brains"
|
|
tal:content="python: tool.getReferenceLabel(brain, appyType)"
|
|
tal:attributes="value brain/UID;
|
|
selected python:test((valueIsInReq and (brain.UID in request.get(appyFieldName, []))) or (not valueIsInReq and ((brain.UID in refUids) or (isBeingCreated and (brain.UID==defaultValueUID)))), True, False)"/>
|
|
</select>
|
|
</div>
|