trying to use Dojo ComboBox for searching...
git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1330 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
029632fde7
commit
a843474545
4 changed files with 60 additions and 3 deletions
|
@ -13,6 +13,10 @@ function focusOpener() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function listConceptsForComboBox() {
|
||||||
|
return [['Zope', 'zope'], ]
|
||||||
|
}
|
||||||
|
|
||||||
function submitReplacing(targetId, formId, actionUrl) {
|
function submitReplacing(targetId, formId, actionUrl) {
|
||||||
dojo.io.updateNode(targetId, {
|
dojo.io.updateNode(targetId, {
|
||||||
url: actionUrl,
|
url: actionUrl,
|
||||||
|
|
|
@ -23,6 +23,7 @@ loops.search package.
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from zope.app import zapi
|
||||||
from zope import interface, component
|
from zope import interface, component
|
||||||
from zope.app.catalog.interfaces import ICatalog
|
from zope.app.catalog.interfaces import ICatalog
|
||||||
from zope.app.pagetemplate import ViewPageTemplateFile
|
from zope.app.pagetemplate import ViewPageTemplateFile
|
||||||
|
@ -49,6 +50,16 @@ class Search(BaseView):
|
||||||
def macro(self):
|
def macro(self):
|
||||||
return template.macros['search']
|
return template.macros['search']
|
||||||
|
|
||||||
|
def initDojo(self):
|
||||||
|
self.registerDojo()
|
||||||
|
cm = self.controller.macros
|
||||||
|
jsCall = 'dojo.require("dojo.widget.ComboBox")'
|
||||||
|
cm.register('js-execute', jsCall, jsCall=jsCall)
|
||||||
|
|
||||||
|
@Lazy
|
||||||
|
def catalog(self):
|
||||||
|
return component.getUtility(ICatalog)
|
||||||
|
|
||||||
@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
|
||||||
|
@ -67,6 +78,27 @@ class Search(BaseView):
|
||||||
for t in ITypeManager(self.context).types
|
for t in ITypeManager(self.context).types
|
||||||
if 'concept' in t.qualifiers]))
|
if 'concept' in t.qualifiers]))
|
||||||
|
|
||||||
|
def listConcepts(self):
|
||||||
|
request = self.request
|
||||||
|
request.response.setHeader('Content-Type', 'text/json; charset=UTF-8')
|
||||||
|
text = request.get('searchString', '')
|
||||||
|
print 'text:', text
|
||||||
|
#if not text:
|
||||||
|
# return ''
|
||||||
|
type = request.get('search.3.type', 'loops:concept:*')
|
||||||
|
if type.endswith('*'):
|
||||||
|
start = type[:-1]
|
||||||
|
end = start + '\x7f'
|
||||||
|
else:
|
||||||
|
start = end = type
|
||||||
|
cat = self.catalog
|
||||||
|
if text:
|
||||||
|
result = cat.searchResults(loops_type=(start, end), loops_text=text+'*')
|
||||||
|
else:
|
||||||
|
result = cat.searchResults(loops_type=(start, end))
|
||||||
|
return str([[o.title.encode('UTF-8'), zapi.getName(o).encode('UTF-8')]
|
||||||
|
for o in result])
|
||||||
|
|
||||||
def submitReplacing(self, targetId, formId, view):
|
def submitReplacing(self, targetId, formId, view):
|
||||||
self.registerDojo()
|
self.registerDojo()
|
||||||
return 'return submitReplacing("%s", "%s", "%s")' % (
|
return 'return submitReplacing("%s", "%s", "%s")' % (
|
||||||
|
@ -93,11 +125,15 @@ class SearchResults(BaseView):
|
||||||
result = set()
|
result = set()
|
||||||
request = self.request
|
request = self.request
|
||||||
r3 = self.queryConcepts()
|
r3 = self.queryConcepts()
|
||||||
type = request.get('search.1.text', 'loops:resource:*')
|
type = request.get('search.1.text', 'loops:*')
|
||||||
text = request.get('search.2.text')
|
text = request.get('search.2.text')
|
||||||
if not r3 and not text and '*' in type: # there should be some sort of selection...
|
if not r3 and not text and '*' in type: # there should be some sort of selection...
|
||||||
return result
|
return result
|
||||||
if text or not '*' in type:
|
#if r3 and type != 'loops:*':
|
||||||
|
# typeName = type.split(':')[-1]
|
||||||
|
# r3 = set(o for o in r3 if self.isType(o, typeName))
|
||||||
|
#if text or not '*' in loops:
|
||||||
|
if text or type != 'loops:*': # TODO: this may be highly inefficient! see above
|
||||||
useTitle = request.get('search.2.title')
|
useTitle = request.get('search.2.title')
|
||||||
useFull = request.get('search.2.full')
|
useFull = request.get('search.2.full')
|
||||||
r1 = set()
|
r1 = set()
|
||||||
|
|
|
@ -15,6 +15,14 @@
|
||||||
permission="zope.View"
|
permission="zope.View"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<browser:page
|
||||||
|
name="listConceptsForComboBox.js"
|
||||||
|
for="loops.interfaces.ILoopsObject"
|
||||||
|
class="loops.search.browser.Search"
|
||||||
|
attribute="listConcepts"
|
||||||
|
permission="zope.View"
|
||||||
|
/>
|
||||||
|
|
||||||
<browser:page
|
<browser:page
|
||||||
name="searchresults.html"
|
name="searchresults.html"
|
||||||
for="loops.interfaces.ILoopsObject"
|
for="loops.interfaces.ILoopsObject"
|
||||||
|
|
|
@ -127,7 +127,7 @@
|
||||||
|
|
||||||
<metal:text define-macro="concept">
|
<metal:text define-macro="concept">
|
||||||
<div>
|
<div>
|
||||||
<h3>Search via related conceps</h3>
|
<h3>Search via related concepts</h3>
|
||||||
<label for="type"
|
<label for="type"
|
||||||
tal:attributes="for string:$idPrefix.type">Type:</label>
|
tal:attributes="for string:$idPrefix.type">Type:</label>
|
||||||
<select name="type"
|
<select name="type"
|
||||||
|
@ -148,6 +148,15 @@
|
||||||
<input type="button" value="+"
|
<input type="button" value="+"
|
||||||
title="Add type"
|
title="Add type"
|
||||||
tal:condition="nothing" />
|
tal:condition="nothing" />
|
||||||
|
<div tal:define="dummy item/initDojo">
|
||||||
|
<select dojoType="comboBox"
|
||||||
|
dataUrl="listConceptsForComboBox.js"
|
||||||
|
dataProviderClass="dojo.widget.incrementalComboBoxDataProvider"
|
||||||
|
tal:attributes="name string:$namePrefix.text1;
|
||||||
|
dataUrl string:${context/@@absolute_url}/listConceptsForComboBox.js?searchString=%{searchString}">
|
||||||
|
<option value="zope">Zope</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</metal:text>
|
</metal:text>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue