clean-up of editing javascript calls, xedit links; starting to provide specialized add views for adding more than on object with one form

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1173 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-04-11 15:03:35 +00:00
parent 3a5281b047
commit 17a9a55b07
12 changed files with 224 additions and 48 deletions

View file

@ -463,6 +463,18 @@ Node Views
... print item.url, view.selected(item)
http://127.0.0.1/loops/views/m1/m11 True
There is an openEditWindow() method that returns a JavaScript call for
opening a new browser window for editing; but only if the view is
editable:
>>> page.openEditWindow()
''
>>> page.editable = True
>>> page.openEditWindow()
"openEditWindow('http://127.0.0.1/loops/views/m1/m11/@@edit.html')"
>>> page.openEditWindow('configure.html')
"openEditWindow('http://127.0.0.1/loops/views/m1/m11/@@configure.html')"
A Node and its Target
---------------------

73
browser/add.pt Normal file
View file

@ -0,0 +1,73 @@
<html metal:use-macro="context/@@standard_macros/page"
i18n:domain="zope">
<body>
<div metal:fill-slot="body">
<div metal:define-macro="addform">
<form action="." tal:attributes="action request/URL"
method="post" enctype="multipart/form-data">
<div metal:define-macro="formbody">
<h3 tal:condition="view/label"
tal:content="view/label"
metal:define-slot="heading"
i18n:translate=""
>Edit something</h3>
<p tal:define="status view/update"
tal:condition="status"
tal:content="status"
i18n:translate=""/>
<p tal:condition="view/errors" i18n:translate="">
There are <strong tal:content="python:len(view.errors)"
i18n:name="num_errors">6</strong> input errors.
</p>
<div metal:define-slot="extra_info" tal:replace="nothing">
</div>
<div class="row" metal:define-slot="extra_top" tal:replace="nothing">
<div class="label">Extra top</div>
<div class="label"><input type="text" style="width:100%" /></div>
</div>
<div metal:use-macro="context/@@form_macros/widget_rows" />
<div class="separator"></div>
<div class="row"
metal:define-slot="extra_bottom" tal:replace="nothing">
<div class="label">Extra bottom</div>
<div class="field"><input type="text" style="width:100%" /></div>
</div>
<div class="separator"></div>
</div>
<br/><br/>
<div class="row">
<div class="controls"><hr />
<span tal:condition="context/nameAllowed|nothing" tal:omit-tag="">
&nbsp;&nbsp;<b i18n:translate="">Object Name</b>&nbsp;&nbsp;
<input type='text' name='add_input_name'
tal:attributes="value context/contentName" />
</span>
<input type='submit' value='Add' name='UPDATE_SUBMIT'
i18n:attributes='value add-button' />
</div>
</div>
<div class="row" metal:define-slot="extra_buttons" tal:replace="nothing">
</div>
<div class="separator"></div>
</form>
</div>
</div>
</body>
</html>

View file

@ -32,6 +32,7 @@ from zope.interface import implements
from zope.app.publisher.browser import applySkin
from zope.publisher.interfaces.browser import ISkin
from zope.schema.vocabulary import SimpleTerm
from zope.security import canAccess, canWrite
from zope.security.proxy import removeSecurityProxy
from cybertools.typology.interfaces import IType
@ -62,12 +63,6 @@ class BaseView(object):
def getController(self): return self._controller
controller = property(getController, setController)
#@Lazy
#def resourceBase(self):
# skinSetter = self.skin and ('/++skin++' + self.skin.__name__) or ''
# # TODO: put '/@@' etc after path to site instead of directly after URL0
# return self.request.URL[0] + skinSetter + '/@@/'
@Lazy
def modified(self):
""" get date/time of last modification
@ -119,6 +114,19 @@ class BaseView(object):
def uniqueId(self):
return zapi.getUtility(IIntIds).getId(self.context)
@Lazy
def editable(self):
return canWrite(self.context, 'title')
def openEditWindow(self, viewName='edit.html'):
if self.editable:
return "openEditWindow('%s/@@%s')" % (self.url, viewName)
return ''
@Lazy
def xeditable(self):
return getattr(self.context, 'contentType', '').startswith('text/')
class LoopsTerms(object):
""" Provide the ITerms interface, e.g. for usage in selection
@ -138,7 +146,10 @@ class LoopsTerms(object):
return self.context.getLoopsRoot()
def getTerm(self, value):
return BaseView(value, self.request)
#return BaseView(value, self.request)
title = value.title or zapi.getName(value)
token = self.loopsRoot.getLoopsUri(value)
return SimpleTerm(value, token, title)
def getValue(self, token):
return self.loopsRoot.loopsTraverse(token)

View file

@ -52,8 +52,6 @@ class ConceptEditForm(EditForm):
@Lazy
def typeInterface(self):
print IType(self.context)
print IType(self.context).typeInterface
return IType(self.context).typeInterface
@property

View file

@ -1,9 +1,13 @@
<metal:body define-macro="conceptlisting">
<div>
<h3><span i18n:translate="">Concept</span>:
<span tal:content="item/title">Title</span></h3>
<h3 tal:attributes="class string:content-$level;
ondblclick item/openEditWindow">
<span i18n:translate="">Concept</span>:
<span tal:content="item/title">Title</span>
</h3>
<metal:listing define-macro="conceptlisting2">
<div>
<div tal:attributes="class string:content-$level;
ondblclick python: item.openEditWindow('configure.html')">
<h4>Parents</h4>
<div tal:repeat="related item/parents">
<a href="#"
@ -11,7 +15,8 @@
tal:content="related/title">Resource Title</a>
</div>
</div>
<div>
<div tal:attributes="class string:content-$level;
ondblclick python: item.openEditWindow('configure.html')">
<h4>Children</h4>
<div tal:repeat="related item/children">
<a href="#"
@ -19,7 +24,8 @@
tal:content="related/title">Resource Title</a>
</div>
</div>
<div>
<div tal:attributes="class string:content-$level;
ondblclick python: item.openEditWindow('resources.html')">
<h4>Resources</h4>
<div tal:repeat="related item/resources">
<a href="#"

View file

@ -9,7 +9,6 @@
<resource name="node.css" file="node.css" />
<resource name="node.js" file="node.js" />
<resource name="edit.gif" file="edit.gif" />
<!-- macros -->
@ -368,7 +367,7 @@
name="AddLoopsNode.html"
content_factory="loops.view.Node"
schema="loops.interfaces.INode"
fields="title description nodeType body"
fields="title description nodeType viewer body"
permission="zope.ManageContent">
<widget field="description" height="2" />
@ -399,10 +398,30 @@
</editform>
<addform
label="Add Node with Document"
name="AddLoopsNodeDocument.html"
content_factory="loops.view.Node"
schema="loops.interfaces.IDocument"
fields="title contentType data"
template="add.pt"
permission="zope.ManageContent">
</addform>
<view
for="loops.interfaces.INode"
name="+"
menu="zmi_actions" title="Add"
class="loops.browser.node.NodeAdding"
permission="zope.ManageContent"
allowed_attributes="addingInfo isSingleMenuItem hasCustomAddView">
<page name="index.html" template="selectAdd.pt" />
<page name="action.html" attribute="action" />
</view>
<containerViews
for="loops.interfaces.INode"
index="zope.ManageContent"
add="zope.ManageContent"
/>
<page
@ -410,8 +429,8 @@
for="loops.interfaces.INode"
template="node_target.pt"
class="loops.browser.node.ConfigureView"
permission="zope.ManageContent">
</page>
permission="zope.ManageContent"
/>
<menuItem
for="loops.interfaces.INode"

Binary file not shown.

Before

Width:  |  Height:  |  Size: 879 B

View file

@ -26,6 +26,7 @@ from zope.cachedescriptors.property import Lazy
from zope.app import zapi
from zope.app.catalog.interfaces import ICatalog
from zope.app.container.browser.contents import JustContents
from zope.app.container.browser.adding import ContentAdding
from zope.app.event.objectevent import ObjectCreatedEvent, ObjectModifiedEvent
from zope.app.pagetemplate import ViewPageTemplateFile
from zope.app.intid.interfaces import IIntIds
@ -271,3 +272,14 @@ class ConfigureView(NodeView):
continue
yield BaseView(o, request)
class NodeAdding(ContentAdding):
def addingInfo(self):
info = super(NodeAdding, self).addingInfo()
info.append({'title': 'Document',
'action': 'AddLoopsNodeDocument.html',
'selected': '',
'has_custom_add_view': True,
'description': 'This creates a node with an associated document'})
return info

View file

@ -14,19 +14,17 @@
<metal:body define-macro="textbody">
<tal:body define="body item/body">
<div class="content-1"
tal:define="onclick string:openEditWindow('${item/url}/@@edit.html')"
tal:condition="body"
tal:attributes="class string:content-$level;
ondblclick python: item.editable and onclick or ''"
ondblclick item/openEditWindow"
tal:content="structure body">
The body
</div>
<div class="content-1"
tal:define="target item/target;
onclick string:openEditWindow('${item/url}/@@configure.html')"
tal:define="target item/target"
tal:condition="target"
tal:attributes="class string:content-$level;
ondblclick python: item.editable and onclick or ''"
ondblclick python: item.openEditWindow('configure.html')"
tal:content="structure item/renderTarget">
The body
</div>
@ -37,9 +35,8 @@
<metal:body define-macro="conceptbody">
<tal:body define="body item/body;">
<div class="content-1"
tal:define="onclick string:openEditWindow('${item/url}/@@configure.html')"
tal:attributes="class string:content-$level;
ondblclick python: item.editable and onclick or ''">
ondblclick python: item.openEditWindow('configure.html')">
<span tal:content="structure body">Node Body</span>
</div>
<tal:concepts define="item item/target">
@ -52,9 +49,8 @@
<metal:body define-macro="filebody">
<tal:body define="body item/body">
<div class="content-1"
tal:define="onclick string:openEditWindow('${item/url}/@@edit.html')"
tal:attributes="class string:content-$level;
ondblclick python: item.editable and onclick or ''">
ondblclick python: item.openEditWindow('edit_target.html')">
<a href="#"
tal:attributes="href string:${item/url}/.target/view"
tal:content="structure body">The body</a>
@ -66,17 +62,15 @@
<metal:body define-macro="imagebody">
<tal:body define="body item/body">
<div class="content-1" style="margin-top: 12px"
tal:define="onclick string:openEditWindow('${item/url}/@@edit_target.html')"
tal:attributes="class string:content-$level;
ondblclick python: item.editable and onclick or ''">
ondblclick python: item.openEditWindow('edit_target.html')">
<img src="target"
tal:attributes="src string:${item/url}/.target/view" />
</div>
<div class="content-1"
tal:condition="body"
tal:define="onclick string:openEditWindow('${item/url}/@@edit.html')"
tal:attributes="class string:content-$level;
ondblclick python: item.editable and onclick or ''"
ondblclick item/openEditWindow"
tal:content="structure body">
The body
</div>
@ -86,9 +80,8 @@
<metal:body define-macro="listpages">
<div class="content-1"
tal:define="onclick string:openEditWindow('${view/url}/@@edit.html')"
tal:content="structure view/body"
tal:attributes="ondblclick python: view.editable and onclick or ''">
tal:attributes="ondblclick view/openEditWindow">
Listing
</div><br />
<div tal:repeat="item view/pageItems">
@ -124,9 +117,7 @@
<a target="zmi"
tal:define="url string:${item/url}/@@edit.html'"
tal:attributes="href url;
onclick string:
zmi=window.open('$url', 'zmi');;
zmi.focus();; return false;;">
onclick item/openEditWindow;">
<img src="edit.gif"
tal:attributes="src context/++resource++edit.gif" border="0" />
</a>

View file

@ -16,12 +16,10 @@
<a href="#"
tal:attributes="href string:${target/url}/@@configure.html"
tal:content="target/title">Document xy</a>
<a href="#" title="External Editor"
tal:condition="python:
getattr(target.context, 'contentType','').startswith('text')"
tal:attributes="href string:${target/context/@@absolute_url}/external_edit"
><img src="edit.gif" alt="External Editor"
tal:attributes="src context/++resource++edit.gif" /></a>
<tal:xedit define="xeditObjectUrl target/url"
condition="target/xeditable">
<metal:xedit use-macro="views/xedit_macros/editLink" />
</tal:xedit>
</tal:target>
</div>

View file

@ -7,11 +7,9 @@
<h1>
<span tal:content="context/title">Concept Title</span>
<a href="#"
tal:condition="python: context.contentType.startswith('text')"
tal:attributes="href string:${context/@@absolute_url}/external_edit"
><img src="edit.gif"
tal:attributes="src context/++resource++edit.gif" border="0" /></a>
<tal:xedit condition="view/xeditable">
<metal:xedit use-macro="views/xedit_macros/editLink" />
</tal:xedit>
</h1><br />
<div tal:define="items view/concepts;

58
browser/selectAdd.pt Normal file
View file

@ -0,0 +1,58 @@
<html metal:use-macro="context/@@standard_macros/addingdialog"
i18n:domain="zope">
<body>
<div metal:fill-slot="body">
<form method="post" action="action.html">
<table class="TypeListing" cellpadding="3">
<tal:block define="title view/title | nothing">
<caption tal:condition="title" tal:content="title"
i18n:translate="">Inserted title</caption>
<caption tal:condition="not:title"
i18n:translate="">Add Content</caption>
</tal:block>
<tbody tal:define="infos view/addingInfo">
<tr tal:repeat="info infos">
<td class="Selector">
<input type="radio" name="type_name"
tal:attributes="value info/action;
id info/action;
checked python:len(infos)==1" />
</td>
<td class="TypeName">
<label style="font-weight: bold;"
tal:attributes="for info/action">
<span tal:replace="info/title" i18n:translate="">Folder</span>
</label>
<div class="TypeDescription" tal:content="info/description"
i18n:translate="">
Folders are generic containers for content, including other
folders.
</div>
</td>
</tr>
<tr>
<td><br /></td>
<td><input type="text" name="id"
tal:condition="view/nameAllowed"
tal:attributes="value request/id | nothing" />
<input type="submit" name="add" value=" Add "
i18n:attributes="value add-button" />
</td>
</tr>
</tbody>
</table>
</form>
</div>
</body>
</html>