appypod-rattail/gen/ui/widgets/ref.pt

262 lines
15 KiB
Plaintext
Raw Normal View History

<tal:comment replace="nothing">
We begin with some sub-macros used within macro "show" defined below.
</tal:comment>
2009-06-29 07:06:01 -05:00
<metal:objectTitle define-macro="objectTitle">
2009-06-29 07:06:01 -05:00
<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
2009-11-17 03:05:19 -06:00
allows to reach the correct page where the forward reference is defined. If we are
on a forward reference, the "nav" parameter is added to the URL for allowing to navigate
2011-11-25 11:01:20 -06:00
from one object to the next/previous on ui/view.</tal:comment>
<a tal:define="includeShownInfo includeShownInfo | python:False;
navInfo python:'ref.%s.%s:%s.%d.%d' % (contextObj.UID(), fieldName, appyType['pageName'], repeat['obj'].number()+startNumber, totalNumber);
navInfo python: test(appyType['isBack'], '', navInfo);
pageName python: appyType['isBack'] and appyType['backd']['pageName'] or 'main';
fullUrl python: obj.getUrl(page=pageName, nav=navInfo)"
tal:attributes="href fullUrl" tal:content="python: (not includeShownInfo) and obj.Title() or contextObj.getReferenceLabel(fieldName, obj.appy())"></a>
2009-06-29 07:06:01 -05:00
</metal:objectTitle>
<metal:objectActions define-macro="objectActions">
2009-06-29 07:06:01 -05:00
<tal:comment replace="nothing">Displays icons for triggering actions on a given
referenced object (edit, delete, etc).</tal:comment>
2011-09-18 08:00:05 -05:00
<table class="noStyle">
2009-06-29 07:06:01 -05:00
<tr>
<tal:comment replace="nothing">Arrows for moving objects up or down</tal:comment>
2011-09-18 08:00:05 -05:00
<td tal:condition="python: not appyType['isBack'] and (len(objs)&gt;1) and context.allows('Modify portal content')">
<tal:moveRef define="objectIndex python: contextObj.getAppyRefIndex(fieldName, obj);
ajaxBaseCall python: navBaseCall.replace('**v**', '\'%s\',\'ChangeRefOrder\', {\'refObjectUid\':\'%s\', \'move\':\'**v**\'}' % (startNumber, obj.UID()))">
<tal:comment replace="nothing">Move up</tal:comment>
<img tal:condition="python: objectIndex &gt; 0"
2011-11-25 11:01:20 -06:00
tal:attributes="src string: $appUrl/ui/arrowUp.png;
title python: _('move_up');
onClick python: ajaxBaseCall.replace('**v**', 'up')"
style="cursor:pointer"/>
<tal:comment replace="nothing">Move down</tal:comment>
<img tal:condition="python: objectIndex &lt; (totalNumber-1)"
2011-11-25 11:01:20 -06:00
tal:attributes="src string: $appUrl/ui/arrowDown.png;
title python: _('move_down');
onClick python: ajaxBaseCall.replace('**v**', 'down')"
style="cursor:pointer"/>
</tal:moveRef>
2009-06-29 07:06:01 -05:00
</td>
<tal:comment replace="nothing">Edit the element</tal:comment>
2011-09-18 08:00:05 -05:00
<td tal:condition="python: obj.allows('Modify portal content') and not appyType['noForm']">
<a tal:define="navInfo python:'ref.%s.%s:%s.%d.%d' % (contextObj.UID(), fieldName, appyType['pageName'], repeat['obj'].number()+startNumber, totalNumber);"
tal:attributes="href python: obj.getUrl(mode='edit', page='main', nav=navInfo)">
<img title="Edit" tal:attributes="src string: $appUrl/ui/edit.gif"/>
</a>
</td>
<tal:comment replace="nothing">Delete the element</tal:comment>
2011-09-18 08:00:05 -05:00
<td>
<img tal:condition="python: not appyType['isBack'] and obj.allows('Delete objects') and obj.mayDelete()"
title="Delete" style="cursor:pointer"
2011-11-25 11:01:20 -06:00
tal:attributes="src string: $appUrl/ui/delete.png;
onClick python:'onDeleteObject(\'%s\')' % obj.UID()"/>
</td>
2009-06-29 07:06:01 -05:00
</tr>
</table>
</metal:objectActions>
<metal:plusIcon define-macro="plusIcon">
2009-06-29 07:06:01 -05:00
<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:define="navInfo python:'ref.%s.%s:%s.%d.%d' % (contextObj.UID(), fieldName, appyType['pageName'], 0, totalNumber);
2011-11-25 11:01:20 -06:00
formCall python:'window.location=\'%s/do?action=Create&className=%s&nav=%s\'' % (folder.absolute_url(), linkedPortalType, navInfo);
formCall python: test(appyType['addConfirm'], 'askConfirm(\'script\', &quot;%s&quot;, &quot;%s&quot;)' % (formCall, addConfirmMsg), formCall);
noFormCall python: navBaseCall.replace('**v**', '%d, \'CreateWithoutForm\'' % startNumber);
noFormCall python: test(appyType['addConfirm'], 'askConfirm(\'script\', &quot;%s&quot;, &quot;%s&quot;)' % (noFormCall, addConfirmMsg), noFormCall)"
2011-11-25 11:01:20 -06:00
tal:attributes="src string:$appUrl/ui/plus.png;
title python: _('add_ref');
onClick python: test(appyType['noForm'], noFormCall, formCall)"/>
2009-06-29 07:06:01 -05:00
</metal:plusIcon>
<tal:comment replace="nothing">
This macro displays, in a cell header from a ref table, icons for sorting the
ref field according to the field that corresponds to this column.
</tal:comment>
<metal:sortIcons define-macro="sortIcons"
tal:define="ajaxBaseCall python: navBaseCall.replace('**v**', '\'%s\',\'SortReference\', {\'sortKey\':\'%s\', \'reverse\':\'**v**\'}' % (startNumber, widget['name']))"
tal:condition="python: canWrite and tool.isSortable(widget['name'], objs[0].meta_type, 'ref')">
<img style="cursor:pointer"
2011-11-25 11:01:20 -06:00
tal:attributes="src string:$appUrl/ui/sortAsc.png;
onClick python: ajaxBaseCall.replace('**v**', 'False')"/>
<img style="cursor:pointer"
2011-11-25 11:01:20 -06:00
tal:attributes="src string:$appUrl/ui/sortDesc.png;
onClick python: ajaxBaseCall.replace('**v**', 'True')"/>
</metal:sortIcons>
<tal:comment replace="nothing">View macro for a Ref.</tal:comment>
<metal:view metal:define-macro="view"
tal:define="singleRef python: widget['multiplicity'][1] == 1">
<tal:comment replace="nothing">
For performance reasons, multivalued references are called via Ajax, while single-valued aren't.
</tal:comment>
<tal:ajax condition="not: singleRef">
<div tal:define= "innerRef innerRef|python:False;
ajaxHookId python: contextObj.UID() + name"
tal:attributes = "id ajaxHookId">
<script name="appyHook" tal:content="python: 'askRefField(\'%s\',\'%s\',\'%s\',\'%s\',0)' % (ajaxHookId, contextObj.absolute_url(), name, innerRef)">
</script>
</div>
</tal:ajax>
<div tal:condition="singleRef">
<tal:request define="dummy python: request.set('fieldName', widget['name'])">
<metal:ref use-macro="app/ui/widgets/ref/macros/viewContent"/>
</tal:request>
</div>
</metal:view>
<tal:comment replace="nothing">
This macro is called by a XmlHttpRequest (or directly by the macro above)
for displaying the referred objects of a reference field.
</tal:comment>
<div metal:define-macro="viewContent"
tal:define="fieldName request/fieldName;
appyType python: contextObj.getAppyType(fieldName, asDict=True);
innerRef python: test(request.get('innerRef', False)=='True', True, False);
ajaxHookId python: contextObj.UID()+fieldName;
startNumber python: int(request.get('%s_startNumber' % ajaxHookId, 0));
tool contextObj/getTool;
_ python: tool.translate;
refObjects python:contextObj.getAppyRefs(fieldName, startNumber);
objs refObjects/objects;
totalNumber refObjects/totalNumber;
batchSize refObjects/batchSize;
folder python: contextObj.isPrincipiaFolderish and contextObj or contextObj.getParentNode();
linkedPortalType python: tool.getPortalType(appyType['klass']);
2011-09-18 08:00:05 -05:00
canWrite python: not appyType['isBack'] and contextObj.allows(appyType['writePermission']);
showPlusIcon python: contextObj.mayAddReference(fieldName, folder);
atMostOneRef python: (appyType['multiplicity'][1] == 1) and (len(objs)&lt;=1);
addConfirmMsg python: appyType['addConfirm'] and _('%s_addConfirm' % appyType['labelId']) or '';
navBaseCall python: 'askRefField(\'%s\',\'%s\',\'%s\',\'%s\',**v**)' % (ajaxHookId, contextObj.absolute_url(), fieldName, innerRef)">
2009-06-29 07:06:01 -05:00
2011-09-18 08:00:05 -05:00
<tal:comment replace="nothing">This macro displays the Reference widget on a "view" page.
2009-06-29 07:06:01 -05:00
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>
2011-09-18 08:00:05 -05:00
<table><tr valign="top">
2009-06-29 07:06:01 -05:00
<tal:comment replace="nothing">If there is no object...</tal:comment>
<tal:noObject condition="not:objs">
<td tal:content="python: _('no_ref')"></td>
2011-11-25 11:01:20 -06:00
<td><metal:plusIcon use-macro="app/ui/widgets/ref/macros/plusIcon"/></td>
2009-06-29 07:06:01 -05:00
</tal:noObject>
<tal:comment replace="nothing">If there is an object...</tal:comment>
<tal:objectIsPresent condition="python: objs">
2009-11-17 03:05:19 -06:00
<tal:obj repeat="obj objs">
2011-11-25 11:01:20 -06:00
<td tal:define="includeShownInfo python:True"><metal:showObjectTitle use-macro="app/ui/widgets/ref/macros/objectTitle" /></td>
2009-06-29 07:06:01 -05:00
</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">
2009-11-17 03:05:19 -06:00
(<span tal:replace="totalNumber"/>)
2011-11-25 11:01:20 -06:00
<metal:plusIcon use-macro="app/ui/widgets/ref/macros/plusIcon"/>
<tal:comment replace="nothing">The search icon if field is queryable</tal:comment>
<a tal:condition="python: objs and appyType['queryable']"
2011-11-25 11:01:20 -06:00
tal:attributes="href python: '%s/ui/search?className=%s&ref=%s:%s' % (tool.absolute_url(), linkedPortalType, contextObj.UID(), appyType['name'])">
<img src="search.gif" tal:attributes="title python: _('search_objects')"/></a>
2009-06-29 07:06:01 -05:00
</legend>
<tal:comment replace="nothing">Appy (top) navigation</tal:comment>
2011-11-25 11:01:20 -06:00
<metal:nav use-macro="here/ui/navigate/macros/appyNavigate"/>
2009-06-29 07:06:01 -05:00
<tal:comment replace="nothing">No object is present</tal:comment>
<p tal:condition="not:objs" tal:content="python: _('no_ref')"></p>
2009-06-29 07:06:01 -05:00
2011-09-18 08:00:05 -05:00
<table width="100%" tal:condition="python: objs"
2009-06-29 07:06:01 -05:00
tal:attributes="class python:test(innerRef, 'innerAppyTable', '')">
<tr valign="bottom"><td>
<tal:comment replace="nothing">Show forward or backward reference(s)</tal:comment>
2011-09-18 08:00:05 -05:00
<table tal:attributes="class python:test(innerRef, '', 'list');
width python:test(innerRef, '100%', appyType['layouts']['view']['width']);">
<tal:widgets define="widgets python: objs[0].getAppyTypesFromNames(appyType['shownInfo'])">
2009-06-29 07:06:01 -05:00
<tr tal:condition="appyType/showHeaders">
<th tal:repeat="widget widgets">
<span tal:content="python: _(widget['labelId'])"></span>
2011-11-25 11:01:20 -06:00
<metal:sortIcons use-macro="app/ui/widgets/ref/macros/sortIcons" />
2009-06-29 07:06:01 -05:00
</th>
<th tal:content="python: _('ref_actions')"></th>
2009-06-29 07:06:01 -05:00
</tr>
2009-12-15 14:30:43 -06:00
<tal:row repeat="obj objs">
2011-09-18 08:00:05 -05:00
<tr valign="middle" tal:define="odd repeat/obj/odd"
2009-12-15 14:30:43 -06:00
tal:attributes="class python:test(odd, 'even', 'odd')">
<td tal:repeat="widget widgets"
tal:attributes="width python: appyType['shownInfoWidths'][repeat['widget'].index]">
<tal:title condition="python: widget['name'] == 'title'">
2011-11-25 11:01:20 -06:00
<metal:showObjectTitle use-macro="app/ui/widgets/ref/macros/objectTitle"/>
</tal:title>
<tal:state condition="python: widget['name'] == 'state'"
content="python: _(obj.getWorkflowLabel())">
</tal:state>
<tal:other condition="python: widget['name'] not in ('title', 'state')">
<tal:field define="contextObj python:obj;
layoutType python: 'cell';
innerRef python:True">
2011-11-25 11:01:20 -06:00
<metal:field use-macro="app/ui/widgets/show/macros/field" />
</tal:field>
</tal:other>
2009-06-29 07:06:01 -05:00
</td>
<tal:comment replace="nothing">Actions</tal:comment>
<td align="right">
<tal:show condition="obj/mayAct">
<metal:showObjectActions use-macro="app/ui/widgets/ref/macros/objectActions" />
</tal:show>
2009-06-29 07:06:01 -05:00
</td>
</tr>
2009-12-15 14:30:43 -06:00
</tal:row>
</tal:widgets>
2009-06-29 07:06:01 -05:00
</table>
</td></tr>
</table>
<tal:comment replace="nothing">Appy (bottom) navigation</tal:comment>
2011-11-25 11:01:20 -06:00
<metal:nav use-macro="context/ui/navigate/macros/appyNavigate"/>
2009-06-29 07:06:01 -05:00
</fieldset>
<tal:comment replace="nothing">A carriage return needed in some cases.</tal:comment>
</tal:anyNumberOfReferences>
</div>
<tal:comment replace="nothing">Edit macro for an Ref.</tal:comment>
<metal:editRef define-macro="edit"
tal:condition="widget/link"
tal:define="requestValue python: request.get(name, []);
inRequest python: request.has_key(name);
allObjects python: contextObj.getSelectableAppyRefs(name);
refUids python: [o.UID() for o in contextObj.getAppyRefs(name)['objects']];
isBeingCreated python: contextObj.isTemporary() or ('/portal_factory/' in contextObj.absolute_url())">
2009-06-29 07:06:01 -05:00
<select tal:attributes="name name;
size python: test(isMultiple, widget['height'], '');
multiple python: test(isMultiple, 'multiple', '')">
2012-03-02 08:42:22 -06:00
<option value="" tal:condition="not: isMultiple" tal:content="python: _('choose_a_value')"></option>
<tal:ref repeat="refObj allObjects">
<option tal:define="uid python: contextObj.getReferenceUid(refObj)"
tal:content="python: contextObj.getReferenceLabel(name, refObj)"
tal:attributes="value uid;
selected python:(inRequest and (uid in requestValue) or (not inRequest and ((uid in refUids)))) and True or False">
</option>
</tal:ref>
</select>
</metal:editRef>
<tal:comment replace="nothing">Cell macro for a Ref.</tal:comment>
<metal:cell define-macro="cell">
2011-11-25 11:01:20 -06:00
<metal:call use-macro="app/ui/widgets/ref/macros/view"/>
</metal:cell>
<tal:comment replace="nothing">Search macro for a Ref.</tal:comment>
<metal:search define-macro="search"></metal:search>