r13794 - in Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField: . browser examples

"Gauthier Bastien" <[email protected]> Thu, 08 Sep 2011 09:01:46 +0000
Newsgroups gmane.comp.web.zope.plone.archetypes.cvs
Message-ID <[email protected]>
Author: gbastien
Date: Thu Sep  8 09:01:45 2011
New Revision: 13794

Modified:
   Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/AutocompleteColumn.py
   Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/browser/jsonsearchview.py
   Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/examples/DataGridDemoType.py
Log:
Index to search on can now be passed to the view

Modified: Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/AutocompleteColumn.py
==============================================================================
--- Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/AutocompleteColumn.py	(original)
+++ Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/AutocompleteColumn.py	Thu Sep  8 09:01:45 2011
@@ -22,7 +22,7 @@
 
     security = ClassSecurityInfo()
 
-    def __init__(self, title, json_view_params={}, json_view_name="jsonsearchview"):
+    def __init__(self, title, json_view_params={}, json_view_name="jsonsearchview", json_view_termfield="SearchableText"):
         """ Create an AutocompleteColumn
         @param json_view_params parameters. The default jsonsearchview will use
                these parameters to query the portal_catalog
@@ -32,6 +32,7 @@
         Column.__init__(self, title)
         self.json_view_params = json_view_params
         self.json_view_name = json_view_name
+        self.json_view_termfield = json_view_termfield
 
     security.declarePublic('getMacro')
     def getMacro(self):
@@ -44,10 +45,11 @@
 <script type="text/javascript">jQuery(function(){
      // Autocomplete
      jq(".DemoField2_autocomplete").autocomplete({
-        source: "@@""" + self.json_view_name + "?json_view_params=" + str(self.json_view_params) + """"     });
+        source: "@@%s?json_view_params=%s&json_view_termfield=%s"
+        });
      });
 </script>
-"""
+""" % (self.json_view_name, str(self.json_view_params), self.json_view_termfield)
 
 # Initializes class security
 InitializeClass(AutocompleteColumn)

Modified: Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/browser/jsonsearchview.py
==============================================================================
--- Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/browser/jsonsearchview.py	(original)
+++ Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/browser/jsonsearchview.py	Thu Sep  8 09:01:45 2011
@@ -8,9 +8,11 @@
 
 class JSONSearchView(BrowserView):
     """
+      This view manage the search result to return to the autocomplete widget
     """
     def getData(self, term):
         """
+          Returns data corresponding to the term received and respecting the widgets search attributes
         """
         context = aq_inner(self.context)
         json_view_params = context.REQUEST.get('json_view_params', None)
@@ -20,9 +22,14 @@
         except:
             logger.error("The parameters passed to the jsonsearchview could not be evaluated to a dict : '%s'" % json_view_params)
             return ''
+        json_view_termfield = context.REQUEST.get('json_view_termfield', None)
+        if not json_view_termfield:
+            logger.warn("No 'json_view_termfield' received, we will use 'SearchableText'")
+            json_view_termfield = "SearchableText"
         #activate wildcard search
         term = '*%s*' % term
         portal_catalog = getToolByName(context, 'portal_catalog')
-        res = portal_catalog(json_view_params, SearchableText=term)
+        json_view_params[json_view_termfield] = term
+        res = portal_catalog(json_view_params)
         res = [brain.Title for brain in res]
         return json.dumps(res)

Modified: Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/examples/DataGridDemoType.py
==============================================================================
--- Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/examples/DataGridDemoType.py	(original)
+++ Products.DataGridField/branches/cp-autocompletecolumn/Products/DataGridField/examples/DataGridDemoType.py	Thu Sep  8 09:01:45 2011
@@ -88,7 +88,7 @@
                         'column1' : Column(_(u"Toholampi city rox")),
                         'column2' : Column(_(u"My friendly name"), default=_(u"Some default text")),
                         'select_sample' : SelectColumn(_(u"Friendly name"), vocabulary="getSampleVocabulary", default="sample2"),
-                        'autocomplete' : AutocompleteColumn(_(u"Autocomplete"), json_view_params={'portal_type': 'Document', 'review_state': 'published'}, json_view_name="jsonsearchview")
+                        'autocomplete' : AutocompleteColumn(_(u"Autocomplete"), json_view_params={'portal_type': 'Document', 'review_state': 'published'}, json_view_name="jsonsearchview", json_view_termfield="SearchableText")
                     },
                  ),
          ),

------------------------------------------------------------------------------
Doing More with Less: The Next Generation Virtual Desktop 
What are the key obstacles that have prevented many mid-market businesses
from deploying virtual desktops?   How do next-generation virtual desktops
provide companies an easier-to-deploy, easier-to-manage and more affordable
virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/