Commit e8e385dc authored by Arnaud Fontaine's avatar Arnaud Fontaine

RelationField: Implement autocompletion and use it by default once...

RelationField: Implement autocompletion and use it by default once erp5_autocompletion_ui is installed.
parent befe4a3a
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</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>return (\'jquery/ui/css/erp5-theme/jquery-ui.css\',)\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getCssRelativeUrlList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</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>js_list = (\'jquery/core/jquery.min.js\', \'erp5.js\',\n
\'jquery/ui/js/jquery-ui.js\', \'jquery.erp5.autocompletion.js\')\n
return js_list\n
</string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>ERP5Site_getJavaScriptRelativeUrlList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
2014-01-27 arnaud.fontaine
* RelationField: Implement autocompletion and use it by default once erp5_autocompletion_ui is installed.
2014-01-27 arnaud.fontaine
* Clean up and make parameters names consistent with ERP5.
......
Support for autocompletion on fields.
\ No newline at end of file
Support for autocompletion on fields. Installing this bt5 will automatically use autocompletion for Relation Fields.
\ No newline at end of file
11
\ No newline at end of file
12
\ No newline at end of file
......@@ -277,11 +277,22 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
value_instance, sub_index in render_parameter_list:
sub_html_string = widget_instance.render(field, key,
value_instance, REQUEST)
here = self._getContextValue(field, REQUEST)
portal = here.getPortalObject()
autocomplete_enabled = getattr(portal.portal_skins,
'erp5_autocompletion_ui',
None)
if autocomplete_enabled:
sub_html_string += self.render_autocomplete(field, key)
if relation_item_list is not None:
####################################
# Render wheel
####################################
sub_html_string += self.render_wheel(
if not autocomplete_enabled:
sub_html_string += self.render_wheel(
field, value_instance, REQUEST,
relation_index=relation_field_index,
sub_index=sub_index)
......@@ -360,6 +371,31 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
html_string = "<span class='%s'>%s</span>" % (css_class, html_string)
return html_string
def render_autocomplete(self, field, key):
"""
Use jquery-ui autocompletion for all relation fields by default, requiring
only erp5_autocompletion_ui bt5 to be installed
"""
# XXX: Allow to specify more parameters to jquery-ui autocomplete widget?
import json
return """
<script type="text/javascript">
$(document).ready(function() {
$("input[name='%s']").ERP5Autocomplete({search_portal_type: %s,
search_catalog_key: "%s"})
.data("ui-autocomplete")._renderItem = function(ul, item) {
return $("<li></li>").data("item.autocomplete", item)
.append("<a><b>" +
item.label +
"</b><br><span style='font-size:70%%;'>" +
item.description + "</span></a>" )
.appendTo(ul);
};
});
</script>""" % (key,
json.dumps(map(lambda x: x[0], field.get_value('portal_type'))),
field.get_value('catalog_index'))
def render_wheel(self, field, value, REQUEST, relation_index=0,
sub_index=None, render_prefix=None):
"""
......@@ -385,7 +421,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
Render link to the related object.
"""
html_string = ''
here = self._getContextValue(field, REQUEST)
here = REQUEST.get('cell', self._getContextValue(field, REQUEST))
portal_url = here.getPortalObject().portal_url
portal_url_string = portal_url()
if (value not in ((), [], None, '')) and \
......
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