Commit 35ed3fa9 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 6d0bc978
<?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 2014-01-27 arnaud.fontaine
* Clean up and make parameters names consistent with ERP5. * Clean up and make parameters names consistent with ERP5.
......
Support for autocompletion on fields. Support for autocompletion on fields. Installing this bt5 will automatically use autocompletion for Relation Fields.
\ No newline at end of file \ No newline at end of file
9 10
\ No newline at end of file \ No newline at end of file
...@@ -277,10 +277,21 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, ...@@ -277,10 +277,21 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
value_instance, sub_index in render_parameter_list: value_instance, sub_index in render_parameter_list:
sub_html_string = widget_instance.render(field, key, sub_html_string = widget_instance.render(field, key,
value_instance, REQUEST) 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: if relation_item_list is not None:
#################################### ####################################
# Render wheel # Render wheel
#################################### ####################################
if not autocomplete_enabled:
sub_html_string += self.render_wheel( sub_html_string += self.render_wheel(
field, value_instance, REQUEST, field, value_instance, REQUEST,
relation_index=relation_field_index, relation_index=relation_field_index,
...@@ -360,6 +371,31 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, ...@@ -360,6 +371,31 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
html_string = "<span class='%s'>%s</span>" % (css_class, html_string) html_string = "<span class='%s'>%s</span>" % (css_class, html_string)
return 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, def render_wheel(self, field, value, REQUEST, relation_index=0,
sub_index=None, render_prefix=None): sub_index=None, render_prefix=None):
""" """
...@@ -385,7 +421,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, ...@@ -385,7 +421,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget,
Render link to the related object. Render link to the related object.
""" """
html_string = '' html_string = ''
here = self._getContextValue(field, REQUEST) here = REQUEST.get('cell', self._getContextValue(field, REQUEST))
portal_url = here.getPortalObject().portal_url portal_url = here.getPortalObject().portal_url
portal_url_string = portal_url() portal_url_string = portal_url()
if (value not in ((), [], None, '')) and \ 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