more on inline editing with dojo

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1299 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-08-13 21:59:01 +00:00
parent 4c48396c13
commit 689b6ca34a
9 changed files with 107 additions and 41 deletions

View file

@ -184,6 +184,21 @@ class BaseView(object):
return self.request.principal.id == 'rootadmin' return self.request.principal.id == 'rootadmin'
#return getattr(self.context, 'contentType', '').startswith('text/') #return getattr(self.context, 'contentType', '').startswith('text/')
@Lazy
def inlineEditingActive(self):
return self.request.principal.id == 'rootadmin'
# this may depend on system and user settings...
return True
@Lazy
def inlineEditable(self):
if not self.inlineEditingActive:
return False
return canWrite(self.context, 'title')
def inlineEdit(self, id):
return 'return inlineEdit("%s")' %id
class LoopsTerms(object): class LoopsTerms(object):
""" Provide the ITerms interface, e.g. for usage in selection """ Provide the ITerms interface, e.g. for usage in selection

View file

@ -530,6 +530,15 @@
permission="zope.View" permission="zope.View"
/> />
<!-- inner HTML views -->
<page
name="inline_edit.html"
for="loops.interfaces.INode"
class="loops.browser.node.InlineEdit"
permission="zope.View"
/>
<!-- render file or image assigned to a node as target --> <!-- render file or image assigned to a node as target -->
<page <page

View file

@ -21,3 +21,11 @@ function submitReplacing(targetId, formId, actionUrl) {
}); });
return false; return false;
} }
function inlineEdit(id) {
var editor = dojo.widget.fromScript("Editor",
{items: ["save", "|", "formatblock", "|",
"insertunorderedlist", "insertorderedlist", "|",
"bold", "italic", "|", "createLink"]}, dojo.byId(id));
return false;
}

View file

@ -14,7 +14,7 @@
<metal:block fill-slot="ecmascript_slot" <metal:block fill-slot="ecmascript_slot"
tal:condition="nothing"> tal:condition="view/inlineEditingActive | nothing">
<script> <script>
dojo.require("dojo.widget.Editor"); dojo.require("dojo.widget.Editor");
</script> </script>

View file

@ -39,6 +39,7 @@ from zope.proxy import removeAllProxies
from zope.security import canAccess, canWrite from zope.security import canAccess, canWrite
from zope.security.proxy import removeSecurityProxy from zope.security.proxy import removeSecurityProxy
from cybertools.ajax import innerHtml
from cybertools.browser import configurator from cybertools.browser import configurator
from cybertools.typology.interfaces import ITypeManager from cybertools.typology.interfaces import ITypeManager
from loops.interfaces import IConcept, IResource, IDocument, IMediaAsset, INode from loops.interfaces import IConcept, IResource, IDocument, IMediaAsset, INode
@ -227,19 +228,25 @@ class NodeView(BaseView):
return u'' return u''
@Lazy @Lazy
def virtualTarget(self): def virtualTargetObject(self):
target = self.request.annotations.get('loops.view', {}).get('target') target = self.request.annotations.get('loops.view', {}).get('target')
if target is None: if target is None:
target = self.targetObject target = self.targetObject
return target return target
@Lazy
def virtualTarget(self):
obj = self.virtualTargetObject
if obj is not None:
basicView = zapi.getMultiAdapter((obj, self.request))
basicView._viewName = self.context.viewName
return basicView.view
@Lazy @Lazy
def targetId(self): def targetId(self):
target = self.virtualTarget target = self.virtualTargetObject
if target is not None: if target is not None:
return BaseView(target, self.request).uniqueId return BaseView(target, self.request).uniqueId
#return target.uniqueId
#return zapi.getUtility(IIntIds).getId(target)
@Lazy @Lazy
def virtualTargetUrl(self): def virtualTargetUrl(self):
@ -249,18 +256,35 @@ class NodeView(BaseView):
@Lazy @Lazy
def realTargetUrl(self): def realTargetUrl(self):
target = self.virtualTarget target = self.virtualTargetObject
if target is not None: if target is not None:
return BaseView(target, self.request).url return BaseView(target, self.request).url
@Lazy @Lazy
def richEditable(self): def inlineEditable(self):
target = self.virtualTarget target = self.virtualTarget
if target is None: return target and target.inlineEditable or False
return False
return canWrite(target, 'title')
# inner HTML views
class InlineEdit(NodeView):
""" Provides inline editor as inner HTML - OBSOLETE, use as an example only!"""
@Lazy
def macro(self):
return self.template.macros['inline_edit']
def __call__(self):
return innerHtml(self)
@property
def body(self):
return self.virtualTargetObject.data
# special (named) views for nodes
class ListPages(NodeView): class ListPages(NodeView):
@Lazy @Lazy

View file

@ -11,13 +11,10 @@
</metal:block> </metal:block>
<!-- dojoType="Editor"
items="formatblock;|;insertunorderedlist;insertorderedlist;|;bold;italic;|;createLink;"
-->
<metal:body define-macro="textbody"> <metal:body define-macro="textbody">
<tal:body define="body item/body; <tal:body define="body item/body;
id string:${view/itemNum}.body"> itemNum view/itemNum;
id string:$itemNum.body;">
<div class="content-1" id="1.body" <div class="content-1" id="1.body"
tal:condition="body" tal:condition="body"
tal:attributes="class string:content-$level; tal:attributes="class string:content-$level;
@ -26,7 +23,8 @@
tal:content="structure body"> tal:content="structure body">
The body The body
</div> </div>
<div> <div tal:define="target item/target"
tal:condition="target">
<div class="subcolumn" <div class="subcolumn"
tal:condition="item/xeditable | nothing"> tal:condition="item/xeditable | nothing">
<a href="#" title="Edit" style="padding: 5px" <a href="#" title="Edit" style="padding: 5px"
@ -35,9 +33,15 @@
src="edit.gif" alt="Edit" src="edit.gif" alt="Edit"
tal:attributes="src context/++resource++edit.gif" /></a> tal:attributes="src context/++resource++edit.gif" /></a>
</div> </div>
<div class="subcolumn"
tal:condition="item/inlineEditable">
<a href="#" title="Edit" style="padding: 5px"
tal:attributes="title string:Edit ${item/title};
onclick python: item.inlineEdit(id)"><img
src="edit.gif" alt="Edit"
tal:attributes="src context/++resource++edit.gif" /></a>
</div>
<div class="content-1 subcolumn" id="1.body" <div class="content-1 subcolumn" id="1.body"
tal:define="target item/target"
tal:condition="target"
tal:attributes="class string:content-$level; tal:attributes="class string:content-$level;
id id; id id;
ondblclick python: item.openEditWindow('configure.html')" ondblclick python: item.openEditWindow('configure.html')"
@ -60,7 +64,6 @@
<tal:concepts define="item item/target; <tal:concepts define="item item/target;
macro item/macro"> macro item/macro">
<div metal:use-macro="macro" /> <div metal:use-macro="macro" />
<!--<div metal:use-macro="views/concept_macros/conceptlisting2" />-->
</tal:concepts> </tal:concepts>
</tal:body> </tal:body>
</metal:body> </metal:body>
@ -159,7 +162,24 @@
</metal:menu> </metal:menu>
<!-- and other stuff --> <!-- inner HTML macros -->
<div metal:define-macro="inline_edit"
class="content-1" id="1.body">
<form action="." method="post" id="1.form">
<div dojoType="Editor"
tal:content="structure view/body">
The body
</div>
</form>
</div>
<!-- dojoType="Editor"
items="formatblock;|;insertunorderedlist;insertorderedlist;|;bold;italic;|;createLink;"
-->
<!-- edit and other links -->
<metal:editlink define-macro="editlink"> <metal:editlink define-macro="editlink">
<a target="zmi" <a target="zmi"

View file

@ -29,24 +29,22 @@ from zope.cachedescriptors.property import Lazy
from zope.formlib.namedtemplate import NamedTemplate, NamedTemplateImplementation from zope.formlib.namedtemplate import NamedTemplate, NamedTemplateImplementation
from zope.i18nmessageid import MessageFactory from zope.i18nmessageid import MessageFactory
from cybertools.ajax import innerHtml
from loops.browser.common import BaseView from loops.browser.common import BaseView
_ = MessageFactory('zope') _ = MessageFactory('zope')
template = ViewPageTemplateFile('search.pt')
search_macros = NamedTemplateImplementation(
ViewPageTemplateFile('search.pt'))
class Search(BaseView): class Search(BaseView):
template = NamedTemplate('loops.search_macros')
maxRowNum = 0 maxRowNum = 0
template = template
@Lazy @Lazy
def macro(self): def macro(self):
return self.template.macros['search'] return template.macros['search']
@property @property
def rowNum(self): def rowNum(self):
@ -67,11 +65,12 @@ class Search(BaseView):
class SearchResults(BaseView): class SearchResults(BaseView):
""" Provides results as inner HTML """
innerHtml_template = NamedTemplate('loops.search_macros') @Lazy
innerHtml_macro = 'search_results' def macro(self):
template = NamedTemplate('ajax.inner.html') return template.macros['search_results']
def __call__(self): def __call__(self):
return self.template(self) return innerHtml(self)

View file

@ -6,15 +6,6 @@
i18n_domain="zope" i18n_domain="zope"
> >
<!-- named templates -->
<zope:adapter
factory="loops.search.browser.search_macros"
for="loops.browser.common.BaseView"
name="loops.search_macros" />
<!-- the real view -->
<zope:adapter <zope:adapter
name="search" name="search"
for="loops.interfaces.IConcept for="loops.interfaces.IConcept

View file

@ -39,7 +39,7 @@
id="1.results"> id="1.results">
<fieldset class="box"> <fieldset class="box">
Search results Search results
<p tal:content="python:request.get('1.search.1.text', 'nothing')" /> <p tal:content="python:request.get('2.search.1.text', 'nothing')" />
</fieldset> </fieldset>
</div> </div>