Actions on search results.

Provide checkboxes and delete button; implement delete action (work in progress).
This commit is contained in:
Helmut Merz 2011-05-22 14:09:08 +02:00
parent f0028ae354
commit 5d63df8e70
3 changed files with 53 additions and 0 deletions

View file

@ -71,8 +71,12 @@
</div>
</metal:search>
<div metal:define-macro="search_results" id="search.results"
tal:define="item nocall:item|nocall:view">
<form method="post">
<input type="hidden" name="form.action"
tal:attributes="value item/form_action" />
<fieldset class="box">
<h2 i18n:translate="">Search results</h2>
<metal:results define-macro="results">
@ -80,6 +84,12 @@
i18n:attributes="summary">
<thead>
<tr>
<th tal:condition="item/showActions"
class="checkbox">
<input type="checkbox"
onchange="checked = this.checked;
dojo.query('.select_item').forEach(function(n) {
n.checked = checked;});" /></th>
<th i18n:translate="">Title</th>
<th i18n:translate="">Type</th>
<th i18n:translate=""
@ -97,6 +107,11 @@
description row/description;
targetUrl python:view.getUrlForTarget(row)">
<tr tal:attributes="class class">
<td tal:condition="item/showActions|nothing"
tal:define="uid row/uniqueId"
class="checkbox">
<input type="checkbox" name="selection:list" class="select_item"
tal:attributes="value uid;" /></td>
<td>
<a tal:attributes="href string:$targetUrl?version=this;
title description">
@ -134,7 +149,13 @@
</tbody>
</table>
</metal:results>
<div class="buttons">
<input type="submit" name="action.delete"
value="Delete objects" class="submit"
onClick="confirm('Do you really want to delete the selected objects?')"
i18n:attributes="value; onclick" /></div>
</fieldset>
</form>
</div>

View file

@ -28,6 +28,7 @@ from zope.app.pagetemplate import ViewPageTemplateFile
from zope.cachedescriptors.property import Lazy
from zope.traversing.api import getName, getParent
from cybertools.browser.form import FormController
from cybertools.stateful.interfaces import IStateful, IStatesDefinition
from loops.browser.common import BaseView
from loops.browser.node import NodeView
@ -35,6 +36,7 @@ from loops.common import adapted, AdapterBase
from loops.expert.concept import ConceptQuery, FullQuery
from loops.interfaces import IResource
from loops.organize.personal.browser.filter import FilterView
from loops.security.common import canWriteObject
from loops import util
from loops.util import _
@ -45,6 +47,8 @@ search_template = ViewPageTemplateFile('search.pt')
class QuickSearchResults(NodeView):
""" Provides results listing """
showActions = False
@Lazy
def search_macros(self):
return self.controller.getTemplateMacros('search', search_template)
@ -72,6 +76,7 @@ class QuickSearchResults(NodeView):
class Search(BaseView):
form_action = 'execute_search_action'
maxRowNum = 0
@Lazy
@ -82,6 +87,10 @@ class Search(BaseView):
def macro(self):
return self.search_macros['search']
@Lazy
def showActions(self):
return canWriteObject(self.context)
@property
def rowNum(self):
""" Return the rowNum to be used for identifying the current search
@ -315,3 +324,20 @@ class SearchResults(NodeView):
result = sorted(result, key=lambda x: x.title.lower())
return self.viewIterator(result)
class ActionExecutor(FormController):
def update(self):
form = self.request.form
actions = [k for k in form.keys() if k.startswith('action.')]
if actions:
uids = form.get('selection', [])
action = actions[0]
if action == 'action.delete':
print '*** delete', uids
return True
for uid in uids:
obj = util.getObjectForUid(uid)
parent = getParent(obj)
del parent[getName(obj)]
return True

View file

@ -19,6 +19,12 @@
factory="loops.expert.browser.base.ActionExecutor"
permission="zope.ManageContent" />
<adapter name="execute_search_action"
for="loops.browser.node.NodeView
zope.publisher.interfaces.browser.IBrowserRequest"
factory="loops.expert.browser.search.ActionExecutor"
permission="zope.ManageContent" />
<adapter factory="loops.expert.setup.SetupManager"
name="expert" />