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)); }, dojo.byId(id));
return false; 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$ $Id$
""" """
from zope.app import zapi
from zope.component import adapts
from zope.interface import Interface, Attribute, implements from zope.interface import Interface, Attribute, implements
from zope.i18nmessageid import MessageFactory
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
from zope import schema from zope import schema
from zope.security.proxy import removeSecurityProxy
from cybertools.typology.type import BaseType, TypeManager
from loops.interfaces import IConcept from loops.interfaces import IConcept
from loops.common import AdapterBase from loops.common import AdapterBase
from loops.type import TypeInterfaceSourceList from loops.type import TypeInterfaceSourceList
from loops.util import _
_ = MessageFactory('loops')
class IQuery(Interface): class IQuery(Interface):

View file

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

View file

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