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:
parent
4c48396c13
commit
689b6ca34a
9 changed files with 107 additions and 41 deletions
|
@ -184,6 +184,21 @@ class BaseView(object):
|
|||
return self.request.principal.id == 'rootadmin'
|
||||
#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):
|
||||
""" Provide the ITerms interface, e.g. for usage in selection
|
||||
|
|
|
@ -530,6 +530,15 @@
|
|||
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 -->
|
||||
|
||||
<page
|
||||
|
|
|
@ -21,3 +21,11 @@ function submitReplacing(targetId, formId, actionUrl) {
|
|||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function inlineEdit(id) {
|
||||
var editor = dojo.widget.fromScript("Editor",
|
||||
{items: ["save", "|", "formatblock", "|",
|
||||
"insertunorderedlist", "insertorderedlist", "|",
|
||||
"bold", "italic", "|", "createLink"]}, dojo.byId(id));
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
|
||||
<metal:block fill-slot="ecmascript_slot"
|
||||
tal:condition="nothing">
|
||||
tal:condition="view/inlineEditingActive | nothing">
|
||||
<script>
|
||||
dojo.require("dojo.widget.Editor");
|
||||
</script>
|
||||
|
|
|
@ -39,6 +39,7 @@ from zope.proxy import removeAllProxies
|
|||
from zope.security import canAccess, canWrite
|
||||
from zope.security.proxy import removeSecurityProxy
|
||||
|
||||
from cybertools.ajax import innerHtml
|
||||
from cybertools.browser import configurator
|
||||
from cybertools.typology.interfaces import ITypeManager
|
||||
from loops.interfaces import IConcept, IResource, IDocument, IMediaAsset, INode
|
||||
|
@ -227,19 +228,25 @@ class NodeView(BaseView):
|
|||
return u''
|
||||
|
||||
@Lazy
|
||||
def virtualTarget(self):
|
||||
def virtualTargetObject(self):
|
||||
target = self.request.annotations.get('loops.view', {}).get('target')
|
||||
if target is None:
|
||||
target = self.targetObject
|
||||
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
|
||||
def targetId(self):
|
||||
target = self.virtualTarget
|
||||
target = self.virtualTargetObject
|
||||
if target is not None:
|
||||
return BaseView(target, self.request).uniqueId
|
||||
#return target.uniqueId
|
||||
#return zapi.getUtility(IIntIds).getId(target)
|
||||
|
||||
@Lazy
|
||||
def virtualTargetUrl(self):
|
||||
|
@ -249,18 +256,35 @@ class NodeView(BaseView):
|
|||
|
||||
@Lazy
|
||||
def realTargetUrl(self):
|
||||
target = self.virtualTarget
|
||||
target = self.virtualTargetObject
|
||||
if target is not None:
|
||||
return BaseView(target, self.request).url
|
||||
|
||||
@Lazy
|
||||
def richEditable(self):
|
||||
def inlineEditable(self):
|
||||
target = self.virtualTarget
|
||||
if target is None:
|
||||
return False
|
||||
return canWrite(target, 'title')
|
||||
return target and target.inlineEditable or False
|
||||
|
||||
|
||||
# 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):
|
||||
|
||||
@Lazy
|
||||
|
|
|
@ -11,13 +11,10 @@
|
|||
</metal:block>
|
||||
|
||||
|
||||
<!-- dojoType="Editor"
|
||||
items="formatblock;|;insertunorderedlist;insertorderedlist;|;bold;italic;|;createLink;"
|
||||
-->
|
||||
|
||||
<metal:body define-macro="textbody">
|
||||
<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"
|
||||
tal:condition="body"
|
||||
tal:attributes="class string:content-$level;
|
||||
|
@ -26,7 +23,8 @@
|
|||
tal:content="structure body">
|
||||
The body
|
||||
</div>
|
||||
<div>
|
||||
<div tal:define="target item/target"
|
||||
tal:condition="target">
|
||||
<div class="subcolumn"
|
||||
tal:condition="item/xeditable | nothing">
|
||||
<a href="#" title="Edit" style="padding: 5px"
|
||||
|
@ -35,9 +33,15 @@
|
|||
src="edit.gif" alt="Edit"
|
||||
tal:attributes="src context/++resource++edit.gif" /></a>
|
||||
</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"
|
||||
tal:define="target item/target"
|
||||
tal:condition="target"
|
||||
tal:attributes="class string:content-$level;
|
||||
id id;
|
||||
ondblclick python: item.openEditWindow('configure.html')"
|
||||
|
@ -60,7 +64,6 @@
|
|||
<tal:concepts define="item item/target;
|
||||
macro item/macro">
|
||||
<div metal:use-macro="macro" />
|
||||
<!--<div metal:use-macro="views/concept_macros/conceptlisting2" />-->
|
||||
</tal:concepts>
|
||||
</tal:body>
|
||||
</metal:body>
|
||||
|
@ -159,7 +162,24 @@
|
|||
</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">
|
||||
<a target="zmi"
|
||||
|
|
|
@ -29,24 +29,22 @@ from zope.cachedescriptors.property import Lazy
|
|||
from zope.formlib.namedtemplate import NamedTemplate, NamedTemplateImplementation
|
||||
from zope.i18nmessageid import MessageFactory
|
||||
|
||||
from cybertools.ajax import innerHtml
|
||||
from loops.browser.common import BaseView
|
||||
|
||||
_ = MessageFactory('zope')
|
||||
|
||||
|
||||
search_macros = NamedTemplateImplementation(
|
||||
ViewPageTemplateFile('search.pt'))
|
||||
|
||||
template = ViewPageTemplateFile('search.pt')
|
||||
|
||||
class Search(BaseView):
|
||||
|
||||
template = NamedTemplate('loops.search_macros')
|
||||
|
||||
maxRowNum = 0
|
||||
|
||||
template = template
|
||||
|
||||
@Lazy
|
||||
def macro(self):
|
||||
return self.template.macros['search']
|
||||
return template.macros['search']
|
||||
|
||||
@property
|
||||
def rowNum(self):
|
||||
|
@ -67,11 +65,12 @@ class Search(BaseView):
|
|||
|
||||
|
||||
class SearchResults(BaseView):
|
||||
""" Provides results as inner HTML """
|
||||
|
||||
innerHtml_template = NamedTemplate('loops.search_macros')
|
||||
innerHtml_macro = 'search_results'
|
||||
template = NamedTemplate('ajax.inner.html')
|
||||
@Lazy
|
||||
def macro(self):
|
||||
return template.macros['search_results']
|
||||
|
||||
def __call__(self):
|
||||
return self.template(self)
|
||||
return innerHtml(self)
|
||||
|
||||
|
|
|
@ -6,15 +6,6 @@
|
|||
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
|
||||
name="search"
|
||||
for="loops.interfaces.IConcept
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
id="1.results">
|
||||
<fieldset class="box">
|
||||
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>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue