Dojo comboBox operative for semantic search

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@1331 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2006-09-07 20:20:29 +00:00
parent a843474545
commit 6dca8dd057
5 changed files with 147 additions and 112 deletions

View file

@ -41,3 +41,12 @@ function inlineEdit(id, saveUrl) {
}, dojo.byId(id));
return false;
}
function setConceptTypeForComboBox(typeId, cbId) {
var t = dojo.byId(typeId).value;
var dp = dojo.widget.manager.getWidgetById(cbId).dataProvider;
var baseUrl = dp.searchUrl.split('&')[0];
var newUrl = baseUrl + '&searchType=' + t;
dp.searchUrl = newUrl;
}

View file

@ -22,20 +22,14 @@ Query management stuff.
$Id$
"""
from zope.app import zapi
from zope.component import adapts
from zope.interface import Interface, Attribute, implements
from zope.i18nmessageid import MessageFactory
from zope.cachedescriptors.property import Lazy
from zope import schema
from zope.security.proxy import removeSecurityProxy
from cybertools.typology.type import BaseType, TypeManager
from loops.interfaces import IConcept
from loops.common import AdapterBase
from loops.type import TypeInterfaceSourceList
_ = MessageFactory('loops')
from loops.util import _
class IQuery(Interface):

View file

@ -35,11 +35,12 @@ from cybertools.ajax import innerHtml
from cybertools.typology.interfaces import ITypeManager
from loops.browser.common import BaseView
from loops import util
from loops.util import _
_ = MessageFactory('zope')
template = ViewPageTemplateFile('search.pt')
class Search(BaseView):
maxRowNum = 0
@ -50,12 +51,6 @@ class Search(BaseView):
def macro(self):
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)
@ -78,14 +73,19 @@ class Search(BaseView):
for t in ITypeManager(self.context).types
if 'concept' in t.qualifiers]))
def initDojo(self):
self.registerDojo()
cm = self.controller.macros
jsCall = 'dojo.require("dojo.widget.ComboBox")'
cm.register('js-execute', jsCall, jsCall=jsCall)
def listConcepts(self):
""" Used for dojo.widget.ComboBox.
"""
request = self.request
request.response.setHeader('Content-Type', 'text/json; charset=UTF-8')
request.response.setHeader('Content-Type', 'text/plain; charset=UTF-8')
text = request.get('searchString', '')
print 'text:', text
#if not text:
# return ''
type = request.get('search.3.type', 'loops:concept:*')
type = request.get('searchType') or 'loops:concept:*'
if type.endswith('*'):
start = type[:-1]
end = start + '\x7f'
@ -96,8 +96,8 @@ class Search(BaseView):
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])
return str(sorted([[`o.title`[2:-1], `zapi.getName(o)`[2:-1]]
for o in result])).replace('\\\\x', '\\x')
def submitReplacing(self, targetId, formId, view):
self.registerDojo()

View file

@ -27,6 +27,7 @@
</td>
</tr>
<tr>
<td></td>
<td colspan="2">
<input type="submit" name="button.search" value="Search" class="submit"
tal:attributes="onclick python:
@ -56,107 +57,137 @@
</metal:search>
<tr metal:define-macro="search_row" id="1.1.row"
tal:define="rowNum item/rowNum;
idPrefix string:$idPrefix.$rowNum;
namePrefix string:search.$rowNum;
param search_param | item/searchParam"
tal:attributes="id string:$idPrefix.row">
<td>
<input type="hidden" name="paramtype" value="type"
tal:attributes="name string:$namePrefix.paramtype;
value param" />
<input type="button" value="&minus;"
title="Remove search parameter"
tal:condition="python: param not in ['type', 'text', 'concept']" />&nbsp;
</td>
<td>
<div metal:use-macro="macros/?param" />
</td>
</tr>
<div metal:define-macro="search_row" id="1.1.row"
tal:define="rowNum item/rowNum;
idPrefix string:$idPrefix.$rowNum;
namePrefix string:search.$rowNum;
param search_param | item/searchParam"
tal:attributes="id string:$idPrefix.row">
<div metal:use-macro="macros/?param" />
</div>
<metal:text define-macro="type">
<div>
<h3>Type(s) to search for</h3>
<label for="text"
tal:attributes="for string:$idPrefix.text">Type:</label>
<select name="text"
tal:attributes="name string:$namePrefix.text;
<tr>
<td metal:use-macro="macros/minus"/>
<td colspan="2">
<h3>Type(s) to search for</h3>
</td>
<tr>
<td></td>
<td>
<label for="text"
tal:attributes="for string:$idPrefix.text">Type:</label>
<select name="text"
tal:attributes="name string:$namePrefix.text;
id string:$idPrefix.text;">
<tal:types repeat="type item/typesForSearch">
<option value="loops:*"
i18n:translate=""
tal:attributes="value type/token"
tal:content="type/title">Topic</option>
</tal:types>
</select>
<input type="button" value="+"
title="Add type"
tal:condition="nothing" />&nbsp;
</div>
<tal:types repeat="type item/typesForSearch">
<option value="loops:*"
i18n:translate=""
tal:attributes="value type/token"
tal:content="type/title">Topic</option>
</tal:types>
</select>
<input type="button" value="+"
title="Add type"
tal:condition="nothing" />&nbsp;
</td>
<td></td>
</tr>
</metal:text>
<metal:text define-macro="text">
<div>
<h3>Search text</h3>
<input type="checkbox" checked
name="title" id="title" value="yes"
tal:attributes="name string:$namePrefix.title;
id string:$idPrefix.title;" />
<label for="title"
tal:attributes="for string:$idPrefix.title">Title</label>
<input type="checkbox"
name="full" id="full" value="yes"
tal:attributes="name string:$namePrefix.full;
id string:$idPrefix.full;" />
<label for="full"
tal:attributes="for string:$idPrefix.full">Full text</label>&nbsp;&nbsp;
<label for="text"
tal:attributes="for string:$idPrefix.text">Search text:</label>
<input type="text" name="text"
tal:attributes="name string:$namePrefix.text;
id string:$idPrefix.text;" />
<input type="button" value="+"
title="Add search word"
tal:condition="nothing" />&nbsp;
</div>
<tr>
<td metal:use-macro="macros/minus"/>
<td colspan="2">
<h3>Search text</h3>
</td>
<tr>
<td></td>
<td>
<input type="checkbox" checked
name="title" id="title" value="yes"
tal:attributes="name string:$namePrefix.title;
id string:$idPrefix.title;" />
<label for="title"
tal:attributes="for string:$idPrefix.title">Title</label>
<input type="checkbox"
name="full" id="full" value="yes"
tal:attributes="name string:$namePrefix.full;
id string:$idPrefix.full;" />
<label for="full"
tal:attributes="for string:$idPrefix.full">Full text</label>&nbsp;&nbsp;
</td>
<td>
<label for="text"
tal:attributes="for string:$idPrefix.text">Search text:</label>
</td>
<td>
<input type="text" name="text"
tal:attributes="name string:$namePrefix.text;
id string:$idPrefix.text;" />
<input type="button" value="+"
title="Add search word"
tal:condition="nothing" />&nbsp;
</td>
</tr>
</metal:text>
<metal:text define-macro="concept">
<div>
<h3>Search via related concepts</h3>
<label for="type"
tal:attributes="for string:$idPrefix.type">Type:</label>
<select name="type"
tal:attributes="name string:$namePrefix.type;
id string:$idPrefix.type;">
<tal:types repeat="type item/conceptTypesForSearch">
<option value="loops:*"
i18n:translate=""
tal:attributes="value type/token"
tal:content="type/title">Topic</option>
</tal:types>
</select>&nbsp;&nbsp;
<label for="text"
tal:attributes="for string:$idPrefix.text">Search text:</label>
<input type="text" name="text"
tal:attributes="name string:$namePrefix.text;
id string:$idPrefix.text;" />
<input type="button" value="+"
title="Add type"
tal:condition="nothing" />&nbsp;
<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>
<tr>
<td metal:use-macro="macros/minus"/>
<td colspan="2">
<h3>Search via related concepts</h3>
</td>
<tr>
<td></td>
<td>
<label for="type"
tal:attributes="for string:$idPrefix.type">Type:</label>
<select name="type"
tal:attributes="name string:$namePrefix.type;
id string:$idPrefix.type;
onChange string:setConceptTypeForComboBox('$idPrefix.type', '$idPrefix.text')">
<tal:types repeat="type item/conceptTypesForSearch">
<option value="loops:*"
i18n:translate=""
tal:attributes="value type/token"
tal:content="type/title">Topic</option>
</tal:types>
</select>&nbsp;&nbsp;
</td>
<td>
<label for="text"
tal:attributes="for string:$idPrefix.text">Search text:</label>
<input type="text" name="text"
tal:condition="nothing"
tal:attributes="name string:$namePrefix.text;
id string:$idPrefix.text;" />
<input type="button" value="+"
title="Add type"
tal:condition="nothing" />&nbsp;
</td>
<td>
<tal:combo tal:define="dummy item/initDojo">
<select dojoType="comboBox"
dataUrl="listConceptsForComboBox.js"
dataProviderClass="dojo.widget.incrementalComboBoxDataProvider"
autoComplete="False"
tal:attributes="name string:$namePrefix.text;
id string:$idPrefix.text;
dataUrl string:${context/@@absolute_url}/listConceptsForComboBox.js?searchString=%{searchString}&searchType=">
<option value="zope">Zope</option>
</select>
</tal:combo>
</td>
</tr>
</metal:text>
<td metal:define-macro="minus">
<input type="button" value="&minus;"
title="Remove search parameter"
tal:condition="python: param not in ['type', 'text', 'concept']" />&nbsp;
</td>

View file

@ -27,7 +27,8 @@ from zope.i18nmessageid import MessageFactory
from zope.schema import vocabulary
#from view import TargetRelation
_ = MessageFactory('loops')
#_ = MessageFactory('loops')
_ = MessageFactory('zope') # it's easier not use a special i18n domain...
class KeywordVocabulary(vocabulary.SimpleVocabulary):