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> </div>
</metal:search> </metal:search>
<div metal:define-macro="search_results" id="search.results" <div metal:define-macro="search_results" id="search.results"
tal:define="item nocall:item|nocall:view"> 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"> <fieldset class="box">
<h2 i18n:translate="">Search results</h2> <h2 i18n:translate="">Search results</h2>
<metal:results define-macro="results"> <metal:results define-macro="results">
@ -80,6 +84,12 @@
i18n:attributes="summary"> i18n:attributes="summary">
<thead> <thead>
<tr> <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="">Title</th>
<th i18n:translate="">Type</th> <th i18n:translate="">Type</th>
<th i18n:translate="" <th i18n:translate=""
@ -97,6 +107,11 @@
description row/description; description row/description;
targetUrl python:view.getUrlForTarget(row)"> targetUrl python:view.getUrlForTarget(row)">
<tr tal:attributes="class class"> <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> <td>
<a tal:attributes="href string:$targetUrl?version=this; <a tal:attributes="href string:$targetUrl?version=this;
title description"> title description">
@ -134,7 +149,13 @@
</tbody> </tbody>
</table> </table>
</metal:results> </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> </fieldset>
</form>
</div> </div>

View file

@ -28,6 +28,7 @@ from zope.app.pagetemplate import ViewPageTemplateFile
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope.traversing.api import getName, getParent from zope.traversing.api import getName, getParent
from cybertools.browser.form import FormController
from cybertools.stateful.interfaces import IStateful, IStatesDefinition from cybertools.stateful.interfaces import IStateful, IStatesDefinition
from loops.browser.common import BaseView from loops.browser.common import BaseView
from loops.browser.node import NodeView 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.expert.concept import ConceptQuery, FullQuery
from loops.interfaces import IResource from loops.interfaces import IResource
from loops.organize.personal.browser.filter import FilterView from loops.organize.personal.browser.filter import FilterView
from loops.security.common import canWriteObject
from loops import util from loops import util
from loops.util import _ from loops.util import _
@ -45,6 +47,8 @@ search_template = ViewPageTemplateFile('search.pt')
class QuickSearchResults(NodeView): class QuickSearchResults(NodeView):
""" Provides results listing """ """ Provides results listing """
showActions = False
@Lazy @Lazy
def search_macros(self): def search_macros(self):
return self.controller.getTemplateMacros('search', search_template) return self.controller.getTemplateMacros('search', search_template)
@ -72,6 +76,7 @@ class QuickSearchResults(NodeView):
class Search(BaseView): class Search(BaseView):
form_action = 'execute_search_action'
maxRowNum = 0 maxRowNum = 0
@Lazy @Lazy
@ -82,6 +87,10 @@ class Search(BaseView):
def macro(self): def macro(self):
return self.search_macros['search'] return self.search_macros['search']
@Lazy
def showActions(self):
return canWriteObject(self.context)
@property @property
def rowNum(self): def rowNum(self):
""" Return the rowNum to be used for identifying the current search """ 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()) result = sorted(result, key=lambda x: x.title.lower())
return self.viewIterator(result) 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" factory="loops.expert.browser.base.ActionExecutor"
permission="zope.ManageContent" /> 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" <adapter factory="loops.expert.setup.SetupManager"
name="expert" /> name="expert" />