Commit 2df67c70 authored by Nicolas Dumazet's avatar Nicolas Dumazet

Generic jQuery extension to provide autocompletion on fields.

ERP5Site_getCompletionList serves as a backend for jQuery, and
polls the catalog. getCompletionList should be extensible and quite
flexible, even if it only supports portal_type and one key filtering for
now.

Most common usage should be something like:

   $("input.custom_class_defined_in_field").ERP5Autocomplete({
     portal_type: "Product",
     search_key: "title",
   });

 ( produces catalog(portal_type="Product", title="xy%", limit=20) )

but any catalog parameter can used as a key, which means that

   $("input.custom_class_defined_in_field").ERP5Autocomplete({
     portal_type: "Product",
     search_key: "xxcustomer_product_reference",
   });

will work if xxcustomer_product_reference is a custom catalog key



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37465 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 066d7c58
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_body</string> </key>
<value> <string>req = container.REQUEST.get\n
kw = dict(limit=20)\n
\n
term = req("starts_with")\n
key = req("key")\n
if term is not None and key is not None:\n
kw[key] = "%s%%" % term\n
\n
portal_type = req("portal_type")\n
if portal_type is not None:\n
kw["portal_type"] = portal_type\n
\n
result = [o.title for o in context.portal_catalog(**kw)]\n
\n
\n
from Products.ERP5Type.JSON import dumps\n
return dumps(result, indent=4)\n
</string> </value>
</item>
<item>
<key> <string>_code</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>errors</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>func_code</string> </key>
<value>
<object>
<klass>
<global name="FuncCode" module="Shared.DC.Scripts.Signature"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>co_argcount</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>co_varnames</string> </key>
<value>
<tuple>
<string>_getattr_</string>
<string>container</string>
<string>req</string>
<string>dict</string>
<string>kw</string>
<string>term</string>
<string>key</string>
<string>None</string>
<string>_write_</string>
<string>portal_type</string>
<string>append</string>
<string>$append0</string>
<string>_getiter_</string>
<string>_apply_</string>
<string>context</string>
<string>o</string>
<string>result</string>
<string>Products.ERP5Type.JSON</string>
<string>dumps</string>
</tuple>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>func_defaults</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getCompletionList</string> </value>
</item>
<item>
<key> <string>warnings</string> </key>
<value>
<tuple/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<tuple>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
<tuple/>
</tuple>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_text</string> </key>
<value> <string encoding="cdata"><![CDATA[
<tal:block tal:define="update_path python: container.ERP5Site_getCompletionList.absolute_url()">\n
$(function() {\n
// private\n
function generateSource(params) {\n
var data = {};\n
\n
if (params.portal_type) data.portal_type = params.portal_type;\n
if (params.search_key) data.key = params.search_key;\n
\n
return function(request, response) {\n
$.extend(data, {starts_with: request.term});\n
$.ajax({\n
url: "<tal:block tal:replace="update_path" />",\n
dataType: "json",\n
data: data,\n
success: response,\n
});\n
};\n
}\n
\n
/*\n
* Wrapper around jQuery.ui.autocomplete that queries catalog\n
* to return matching terms. Titles are displayed.\n
*\n
* Parameters:\n
* - search_key: catalog key that should be matched against\n
* user input. For example, "title" to match titles,\n
* your_custom_reference to search for customized reference, etc\n
* - optional portal_type\n
*\n
* Example:\n
* $(".your_input").ERP5Autocomplete({\n
* portal_type: "Product",\n
* search_key: "title",\n
* });\n
*/\n
$.fn.ERP5Autocomplete = function(kw) {\n
return this.autocomplete({source: generateSource(kw)});\n
};\n
});\n
</tal:block>\n
]]></string> </value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>jquery.erp5.js</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Wrappers and helpers for ERP5</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
10
\ No newline at end of file
11
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment