Commit d855e4bc authored by Alexandre Boeglin's avatar Alexandre Boeglin

Added 'Jump Allowed' parameter that hides the jump clickable link and plane.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3228 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 75ba0c70
...@@ -80,7 +80,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R ...@@ -80,7 +80,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R
_v_property_name_list.append(property_name) _v_property_name_list.append(property_name)
_v_dict[property_name] = 1 _v_dict[property_name] = 1
property_names = _v_property_name_list property_names = _v_property_name_list
def render(self, field, key, value, REQUEST): def render(self, field, key, value, REQUEST):
""" """
...@@ -104,32 +104,32 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R ...@@ -104,32 +104,32 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R
need_validation = 0 need_validation = 0
# Check all relation # Check all relation
for i in range( len(value_list) ): for i in range( len(value_list) ):
relation_field_id = 'relation_%s_%s' % ( key, i ) relation_field_id = 'relation_%s_%s' % ( key, i )
relation_item_id = 'item_%s_%s' % ( key, i ) relation_item_id = 'item_%s_%s' % ( key, i )
if REQUEST.has_key(relation_item_id) and value_list[i] != '': if REQUEST.has_key(relation_item_id) and value_list[i] != '':
need_validation = 1 need_validation = 1
break break
html_string = '' html_string = ''
if need_validation: if need_validation:
# Check all relation # Check all relation
for i in range( len(value_list) ): for i in range( len(value_list) ):
value = value_list[i] value = value_list[i]
relation_field_id = 'relation_%s_%s' % ( key, i ) relation_field_id = 'relation_%s_%s' % ( key, i )
relation_item_id = 'item_%s_%s' % ( key, i ) relation_item_id = 'item_%s_%s' % ( key, i )
# If we get a empty string, display nothing ! # If we get a empty string, display nothing !
if value == '': if value == '':
pass pass
else: else:
html_string += Widget.TextWidget.render(self, field, key, value, REQUEST) html_string += Widget.TextWidget.render(self, field, key, value, REQUEST)
if REQUEST.has_key(relation_item_id): if REQUEST.has_key(relation_item_id):
relation_item_list = REQUEST.get(relation_item_id) relation_item_list = REQUEST.get(relation_item_id)
if relation_item_list != []: if relation_item_list != []:
# Define default tales on the fly # Define default tales on the fly
tales_expr = field.tales.get('items', None) tales_expr = field.tales.get('items', None)
...@@ -140,10 +140,10 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R ...@@ -140,10 +140,10 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R
field.tales['items'] = TALESMethod('REQUEST/relation_item_list') field.tales['items'] = TALESMethod('REQUEST/relation_item_list')
REQUEST['relation_item_list'] = relation_item_list REQUEST['relation_item_list'] = relation_item_list
html_string += ' %s ' % Widget.ListWidget.render(self, html_string += ' %s ' % Widget.ListWidget.render(self,
field, relation_field_id, None, REQUEST) field, relation_field_id, None, REQUEST)
REQUEST['relation_item_list'] = None REQUEST['relation_item_list'] = None
if defined_tales: if defined_tales:
# Delete default tales on the fly # Delete default tales on the fly
...@@ -162,7 +162,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R ...@@ -162,7 +162,7 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R
html_string += '&nbsp;<input type="image" src="%s/images/exec16.png" value="update..." name="%s/portal_selections/viewSearchRelatedDocumentDialog%s:method">' \ html_string += '&nbsp;<input type="image" src="%s/images/exec16.png" value="update..." name="%s/portal_selections/viewSearchRelatedDocumentDialog%s:method">' \
% (portal_url_string, portal_object.getPath(), field.aq_parent._v_relation_field_index) % (portal_url_string, portal_object.getPath(), field.aq_parent._v_relation_field_index)
if value_list not in ((), [], None, ['']) and value_list == field.get_value('default'): if value_list not in ((), [], None, ['']) and value_list == field.get_value('default') and field.get_value('jump_allowed') == 1 :
if REQUEST.get('selection_name') is not None: if REQUEST.get('selection_name') is not None:
html_string += '&nbsp;&nbsp;<a href="%s?field_id=%s&form_id=%s&selection_name=%s&selection_index=%s"><img src="%s/images/jump.png"></a>' \ html_string += '&nbsp;&nbsp;<a href="%s?field_id=%s&form_id=%s&selection_name=%s&selection_index=%s"><img src="%s/images/jump.png"></a>' \
% (field.get_value('jump_method'), field.id, field.aq_parent.id, REQUEST.get('selection_name'), REQUEST.get('selection_index'),portal_url_string) % (field.get_value('jump_method'), field.id, field.aq_parent.id, REQUEST.get('selection_name'), REQUEST.get('selection_index'),portal_url_string)
...@@ -171,13 +171,16 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R ...@@ -171,13 +171,16 @@ class MultiRelationStringFieldWidget(Widget.LinesTextAreaWidget, RelationField.R
% (field.get_value('jump_method'), field.id, field.aq_parent.id,portal_url_string) % (field.get_value('jump_method'), field.id, field.aq_parent.id,portal_url_string)
relation_field_index = getattr(field.aq_parent, '_v_relation_field_index', 0) relation_field_index = getattr(field.aq_parent, '_v_relation_field_index', 0)
field.aq_parent._v_relation_field_index = relation_field_index + 1 # Increase index field.aq_parent._v_relation_field_index = relation_field_index + 1 # Increase index
return html_string return html_string
def render_view(self, field, value): def render_view(self, field, value):
""" """
Render text field. Render text field.
""" """
if field.get_value('jump_allowed') == 0 :
return Widget.LinesTextAreaWidget.render_view(self, field, value)
REQUEST = get_request() REQUEST = get_request()
here = REQUEST['here'] here = REQUEST['here']
...@@ -202,7 +205,7 @@ class MultiRelationEditor: ...@@ -202,7 +205,7 @@ class MultiRelationEditor:
""" """
def __init__(self, field_id, base_category, portal_type, portal_type_item, key, relation_setter_id, relation_editor_list): def __init__(self, field_id, base_category, portal_type, portal_type_item, key, relation_setter_id, relation_editor_list):
self.field_id = field_id self.field_id = field_id
self.base_category = base_category self.base_category = base_category
self.portal_type = portal_type self.portal_type = portal_type
...@@ -218,34 +221,34 @@ class MultiRelationEditor: ...@@ -218,34 +221,34 @@ class MultiRelationEditor:
for i, value, uid, display_text in self.relation_editor_list: for i, value, uid, display_text in self.relation_editor_list:
value_list.append(value) value_list.append(value)
if uid is not None: if uid is not None:
# Decorate the request so that we can display # Decorate the request so that we can display
# the select item in a popup # the select item in a popup
#relation_field_id = 'relation_%s_%s' % ( self.key, i ) #relation_field_id = 'relation_%s_%s' % ( self.key, i )
#relation_item_id = 'item_%s_%s' % ( self.key, i ) #relation_item_id = 'item_%s_%s' % ( self.key, i )
relation_field_id = 'relation_field_%s_%s' % ( self.field_id, i ) relation_field_id = 'relation_field_%s_%s' % ( self.field_id, i )
relation_item_id = 'item_field_%s_%s' % ( self.field_id, i ) relation_item_id = 'item_field_%s_%s' % ( self.field_id, i )
REQUEST.set(relation_item_id, ((display_text, uid),)) REQUEST.set(relation_item_id, ((display_text, uid),))
REQUEST.set(relation_field_id, uid) REQUEST.set(relation_field_id, uid)
REQUEST.set(self.field_id, value_list) # XXX Dirty REQUEST.set(self.field_id, value_list) # XXX Dirty
else: else:
# Make sure no default value appears # Make sure no default value appears
#REQUEST.set(self.field_id[len('field_'):], None) #REQUEST.set(self.field_id[len('field_'):], None)
REQUEST.set(self.field_id, None) # XXX Dirty REQUEST.set(self.field_id, None) # XXX Dirty
def view(self): def view(self):
return self.__dict__ return self.__dict__
def edit(self, o): def edit(self, o):
if self.relation_editor_list != None: if self.relation_editor_list != None:
relation_uid_list = [] relation_uid_list = []
relation_object_list = [] relation_object_list = []
for i, value, uid, display_text in self.relation_editor_list: for i, value, uid, display_text in self.relation_editor_list:
if uid is not None: if uid is not None:
if type(uid) is type('a') and uid.startswith(new_content_prefix): if type(uid) is type('a') and uid.startswith(new_content_prefix):
...@@ -255,7 +258,7 @@ class MultiRelationEditor: ...@@ -255,7 +258,7 @@ class MultiRelationEditor:
for p_item in self.portal_type_item: for p_item in self.portal_type_item:
if p_item[0] == portal_type: if p_item[0] == portal_type:
portal_module = o.getPortalObject().getDefaultModuleId( p_item[0] ) portal_module = o.getPortalObject().getDefaultModuleId( p_item[0] )
if portal_module is not None: if portal_module is not None:
portal_module_object = getattr(o.getPortalObject(), portal_module) portal_module_object = getattr(o.getPortalObject(), portal_module)
kw ={} kw ={}
#kw[self.key] = value #kw[self.key] = value
...@@ -265,18 +268,18 @@ class MultiRelationEditor: ...@@ -265,18 +268,18 @@ class MultiRelationEditor:
new_object = portal_module_object.newContent(**kw) new_object = portal_module_object.newContent(**kw)
uid = new_object.getUid() uid = new_object.getUid()
else: else:
raise raise
relation_uid_list.append(int(uid)) relation_uid_list.append(int(uid))
relation_object_list.append( o.portal_catalog.getObject(uid) ) relation_object_list.append( o.portal_catalog.getObject(uid) )
#if relation_uid_list != []: #if relation_uid_list != []:
# Edit relation # Edit relation
if self.relation_setter_id: if self.relation_setter_id:
relation_setter = getattr(o, self.relation_setter_id) relation_setter = getattr(o, self.relation_setter_id)
relation_setter((), portal_type=self.portal_type) relation_setter((), portal_type=self.portal_type)
relation_setter( relation_uid_list , portal_type=self.portal_type) relation_setter( relation_uid_list , portal_type=self.portal_type)
else: else:
# we could call a generic method which create the setter method name # we could call a generic method which create the setter method name
set_method_name = '_set'+convertToUpperCase(self.base_category)+'ValueList' set_method_name = '_set'+convertToUpperCase(self.base_category)+'ValueList'
...@@ -285,20 +288,20 @@ class MultiRelationEditor: ...@@ -285,20 +288,20 @@ class MultiRelationEditor:
else: else:
# Nothing to do # Nothing to do
pass pass
# # Delete relation # # Delete relation
# if self.relation_setter_id: # if self.relation_setter_id:
# relation_setter = getattr(o, self.relation_setter_id) # relation_setter = getattr(o, self.relation_setter_id)
# relation_setter((), portal_type=self.portal_type) # relation_setter((), portal_type=self.portal_type)
# else: # else:
# o._setValueUids(self.base_category, (), portal_type=self.portal_type) # o._setValueUids(self.base_category, (), portal_type=self.portal_type)
allow_class(MultiRelationEditor) allow_class(MultiRelationEditor)
class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField.RelationStringFieldValidator): class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField.RelationStringFieldValidator):
""" """
Validation includes lookup of relared instances Validation includes lookup of relared instances
""" """
message_names = Validator.LinesValidator.message_names + \ message_names = Validator.LinesValidator.message_names + \
RelationField.RelationStringFieldValidator.message_names RelationField.RelationStringFieldValidator.message_names
...@@ -311,7 +314,7 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField ...@@ -311,7 +314,7 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
_v_message_name_list.append(message_name) _v_message_name_list.append(message_name)
_v_dict[message_name] = 1 _v_dict[message_name] = 1
message_names = _v_message_name_list message_names = _v_message_name_list
def validate(self, field, key, REQUEST): def validate(self, field, key, REQUEST):
portal_type = map(lambda x:x[0],field.get_value('portal_type')) portal_type = map(lambda x:x[0],field.get_value('portal_type'))
portal_type_item = field.get_value('portal_type') portal_type_item = field.get_value('portal_type')
...@@ -319,14 +322,14 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField ...@@ -319,14 +322,14 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
# If the value is different, build a query # If the value is different, build a query
portal_selections = getToolByName(field, 'portal_selections') portal_selections = getToolByName(field, 'portal_selections')
portal_catalog = getToolByName(field, 'portal_catalog') portal_catalog = getToolByName(field, 'portal_catalog')
# Get the current value # Get the current value
value_list = Validator.LinesValidator.validate(self, field, key, REQUEST) value_list = Validator.LinesValidator.validate(self, field, key, REQUEST)
# if type(value_list) == type(''): # if type(value_list) == type(''):
# value_list = [value_list] # value_list = [value_list]
# If the value is the same as the current field value, do nothing # If the value is the same as the current field value, do nothing
current_value_list = field.get_value('default') current_value_list = field.get_value('default')
if type(current_value_list) == type(''): if type(current_value_list) == type(''):
...@@ -335,24 +338,24 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField ...@@ -335,24 +338,24 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
catalog_index = field.get_value('catalog_index') catalog_index = field.get_value('catalog_index')
relation_setter_id = field.get_value('relation_setter_id') relation_setter_id = field.get_value('relation_setter_id')
relation_field_id = 'relation_%s' % ( key ) relation_field_id = 'relation_%s' % ( key )
# we must know if user validate the form or click on the wheel button # we must know if user validate the form or click on the wheel button
relation_uid_list = REQUEST.get(relation_field_id, None) relation_uid_list = REQUEST.get(relation_field_id, None)
relation_field_sub_id = 'relation_%s_0' % ( key ) relation_field_sub_id = 'relation_%s_0' % ( key )
if checkSameKeys( value_list, current_value_list ) and (relation_uid_list is None) and (not REQUEST.has_key( relation_field_sub_id )): if checkSameKeys( value_list, current_value_list ) and (relation_uid_list is None) and (not REQUEST.has_key( relation_field_sub_id )):
# XXX Will be interpreted by Base_edit as "do nothing" # XXX Will be interpreted by Base_edit as "do nothing"
#return MultiRelationEditor(field.id, base_category, portal_type, portal_type_item, catalog_index, relation_setter_id, None) #return MultiRelationEditor(field.id, base_category, portal_type, portal_type_item, catalog_index, relation_setter_id, None)
return None return None
else: else:
relation_field_id = 'relation_%s' % ( key ) relation_field_id = 'relation_%s' % ( key )
# We must be able to erase the relation # We must be able to erase the relation
if (value_list == ['']) and (not REQUEST.has_key( relation_field_id )): if (value_list == ['']) and (not REQUEST.has_key( relation_field_id )):
display_text = 'Delete the relation' display_text = 'Delete the relation'
return MultiRelationEditor(field.id, base_category, portal_type, portal_type_item, catalog_index, relation_setter_id, []) return MultiRelationEditor(field.id, base_category, portal_type, portal_type_item, catalog_index, relation_setter_id, [])
# return RelationEditor(key, base_category, portal_type, None, # return RelationEditor(key, base_category, portal_type, None,
# portal_type_item, catalog_index, value, relation_setter_id, display_text) # portal_type_item, catalog_index, value, relation_setter_id, display_text)
# Will be interpreted by Base_edit as "delete relation" (with no uid and value = '') # Will be interpreted by Base_edit as "delete relation" (with no uid and value = '')
...@@ -363,39 +366,39 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField ...@@ -363,39 +366,39 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
relation_editor_list = [] relation_editor_list = []
for i in range( len(relation_uid_list) ): for i in range( len(relation_uid_list) ):
relation_item_id = 'item_%s_%s' % ( key, i ) relation_item_id = 'item_%s_%s' % ( key, i )
relation_uid = relation_uid_list[i] relation_uid = relation_uid_list[i]
related_object = portal_catalog.getObject(relation_uid) related_object = portal_catalog.getObject(relation_uid)
if related_object is not None: if related_object is not None:
display_text = str(related_object.getProperty(catalog_index)) display_text = str(related_object.getProperty(catalog_index))
else: else:
display_text = 'Object has been deleted' display_text = 'Object has been deleted'
# Check # Check
REQUEST.set(relation_item_id, ( (display_text, relation_uid), )) REQUEST.set(relation_item_id, ( (display_text, relation_uid), ))
# Storing display_text as value is needded in this case # Storing display_text as value is needded in this case
relation_editor_list.append( (i, display_text, str(relation_uid), display_text) ) relation_editor_list.append( (i, display_text, str(relation_uid), display_text) )
return MultiRelationEditor(field.id, base_category, portal_type, portal_type_item, catalog_index, relation_setter_id, relation_editor_list) return MultiRelationEditor(field.id, base_category, portal_type, portal_type_item, catalog_index, relation_setter_id, relation_editor_list)
else: else:
# User validate the form # User validate the form
relation_editor_list = [] relation_editor_list = []
raising_error_needed = 0 raising_error_needed = 0
raising_error_value = '' raising_error_value = ''
# Check all relation # Check all relation
for i in range( len(value_list) ): for i in range( len(value_list) ):
relation_field_id = 'relation_%s_%s' % ( key, i ) relation_field_id = 'relation_%s_%s' % ( key, i )
relation_item_id = 'item_%s_%s' % ( key, i ) relation_item_id = 'item_%s_%s' % ( key, i )
relation_uid = REQUEST.get(relation_field_id, None) relation_uid = REQUEST.get(relation_field_id, None)
value = value_list[i] value = value_list[i]
# If we get a empty string, delete this line # If we get a empty string, delete this line
if value == '': if value == '':
# Clean request if necessary # Clean request if necessary
...@@ -412,8 +415,8 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField ...@@ -412,8 +415,8 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
if related_object is not None: if related_object is not None:
display_text = str(related_object.getProperty(catalog_index)) display_text = str(related_object.getProperty(catalog_index))
else: else:
display_text = 'Object has been deleted' display_text = 'Object has been deleted'
# Check # Check
REQUEST.set(relation_item_id, ( (display_text, relation_uid), )) REQUEST.set(relation_item_id, ( (display_text, relation_uid), ))
relation_editor_list.append( (i, value, str(relation_uid), display_text) ) relation_editor_list.append( (i, value, str(relation_uid), display_text) )
...@@ -431,9 +434,9 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField ...@@ -431,9 +434,9 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
menu_item_list = [('', '')] menu_item_list = [('', '')]
new_object_menu_item_list = [] new_object_menu_item_list = []
for p in portal_type: for p in portal_type:
new_object_menu_item_list += [('New %s' % p, '%s%s' % (new_content_prefix,p))] new_object_menu_item_list += [('New %s' % p, '%s%s' % (new_content_prefix,p))]
if len(relation_list) >= MAX_SELECT: if len(relation_list) >= MAX_SELECT:
# If the length is long, raise an error # If the length is long, raise an error
# This parameter means we need listbox help # This parameter means we need listbox help
REQUEST.set(relation_item_id, []) REQUEST.set(relation_item_id, [])
...@@ -447,14 +450,14 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField ...@@ -447,14 +450,14 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
if related_object is not None: if related_object is not None:
display_text = str(related_object.getProperty(catalog_index)) display_text = str(related_object.getProperty(catalog_index))
else: else:
display_text = 'Object has been deleted' display_text = 'Object has been deleted'
REQUEST.set(relation_item_id, ( (display_text, relation_uid), )) REQUEST.set(relation_item_id, ( (display_text, relation_uid), ))
relation_editor_list.append( (0, value, relation_uid, display_text) ) relation_editor_list.append( (0, value, relation_uid, display_text) )
elif len(relation_list) == 0: elif len(relation_list) == 0:
# If the length is 0, raise an error # If the length is 0, raise an error
menu_item_list += new_object_menu_item_list menu_item_list += new_object_menu_item_list
REQUEST.set(relation_item_id, menu_item_list) REQUEST.set(relation_item_id, menu_item_list)
raising_error_needed = 1 raising_error_needed = 1
raising_error_value = 'relation_result_empty' raising_error_value = 'relation_result_empty'
...@@ -462,14 +465,14 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField ...@@ -462,14 +465,14 @@ class MultiRelationStringFieldValidator(Validator.LinesValidator, RelationField
else: else:
# If the length is short, raise an error # If the length is short, raise an error
# len(relation_list) < MAX_SELECT: # len(relation_list) < MAX_SELECT:
#menu_item_list += [('-', '')] #menu_item_list += [('-', '')]
menu_item_list += map(lambda x: (x.getObject().getProperty(catalog_index), x.uid), menu_item_list += map(lambda x: (x.getObject().getProperty(catalog_index), x.uid),
relation_list) relation_list)
REQUEST.set(relation_item_id, menu_item_list) REQUEST.set(relation_item_id, menu_item_list)
raising_error_needed = 1 raising_error_needed = 1
raising_error_value = 'relation_result_ambiguous' raising_error_value = 'relation_result_ambiguous'
# validate MultiRelation field # validate MultiRelation field
if raising_error_needed: if raising_error_needed:
# Raise error # Raise error
......
...@@ -53,7 +53,7 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget): ...@@ -53,7 +53,7 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget):
""" """
property_names = Widget.TextWidget.property_names + \ property_names = Widget.TextWidget.property_names + \
['update_method', 'jump_method', 'base_category', 'portal_type', 'catalog_index', ['update_method', 'jump_method', 'jump_allowed', 'base_category', 'portal_type', 'catalog_index',
'default_module', 'relation_setter_id', 'columns','sort','parameter_list','list_method', 'default_module', 'relation_setter_id', 'columns','sort','parameter_list','list_method',
'first_item', 'items', 'size', 'extra_item'] 'first_item', 'items', 'size', 'extra_item']
...@@ -72,6 +72,13 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget): ...@@ -72,6 +72,13 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget):
default="Base_jumpToRelatedDocument", default="Base_jumpToRelatedDocument",
required=1) required=1)
jump_allowed = fields.CheckBoxField('jump_allowed',
title='Jump Allowed',
description=(
"Do we allow to jump to the relation ?"),
default=1,
required=0)
base_category = fields.StringField('base_category', base_category = fields.StringField('base_category',
title='Base Category', title='Base Category',
description=( description=(
...@@ -116,8 +123,8 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget): ...@@ -116,8 +123,8 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget):
"widget will be displayed as a drop down box by many browsers, " "widget will be displayed as a drop down box by many browsers, "
"if set to something higher, a list will be shown. Required."), "if set to something higher, a list will be shown. Required."),
default=1, default=1,
required=1) required=1)
columns = fields.ListTextAreaField('columns', columns = fields.ListTextAreaField('columns',
title="Columns", title="Columns",
description=( description=(
...@@ -164,9 +171,9 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget): ...@@ -164,9 +171,9 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget):
from Products.Formulator.TALESField import TALESMethod from Products.Formulator.TALESField import TALESMethod
field.tales['items'] = TALESMethod('REQUEST/relation_item_list') field.tales['items'] = TALESMethod('REQUEST/relation_item_list')
REQUEST['relation_item_list'] = REQUEST.get(relation_item_id) REQUEST['relation_item_list'] = REQUEST.get(relation_item_id)
html_string += '&nbsp;%s&nbsp;' % Widget.ListWidget.render(self, html_string += '&nbsp;%s&nbsp;' % Widget.ListWidget.render(self,
field, relation_field_id, None, REQUEST) field, relation_field_id, None, REQUEST)
REQUEST['relation_item_list'] = None REQUEST['relation_item_list'] = None
# We used to add a button which has a path reference to a base category... # We used to add a button which has a path reference to a base category...
# but it really created too many problems # but it really created too many problems
...@@ -176,24 +183,26 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget): ...@@ -176,24 +183,26 @@ class RelationStringFieldWidget(Widget.TextWidget, Widget.ListWidget):
#elif value != field.get_value('default'): #elif value != field.get_value('default'):
else: else:
html_string += '&nbsp;<input type="image" src="%s/images/exec16.png" value="update..." name="%s/portal_selections/viewSearchRelatedDocumentDialog%s:method">' \ html_string += '&nbsp;<input type="image" src="%s/images/exec16.png" value="update..." name="%s/portal_selections/viewSearchRelatedDocumentDialog%s:method">' \
% (portal_url_string, portal_object.getPath(), % (portal_url_string, portal_object.getPath(),
getattr(field.aq_parent, '_v_relation_field_index', 0)) getattr(field.aq_parent, '_v_relation_field_index', 0))
relation_field_index = getattr(field.aq_parent, '_v_relation_field_index', 0) relation_field_index = getattr(field.aq_parent, '_v_relation_field_index', 0)
field.aq_parent._v_relation_field_index = relation_field_index + 1 # Increase index field.aq_parent._v_relation_field_index = relation_field_index + 1 # Increase index
if value not in ( None, '' ) and not REQUEST.has_key(relation_item_id) and value == field.get_value('default'): if value not in ( None, '' ) and not REQUEST.has_key(relation_item_id) and value == field.get_value('default') and field.get_value('jump_allowed') == 1 :
if REQUEST.get('selection_name') is not None: if REQUEST.get('selection_name') is not None:
html_string += '&nbsp;&nbsp;<a href="%s/%s?field_id=%s&form_id=%s&selection_name=%s&selection_index=%s"><img src="%s/images/jump.png"></a>' \ html_string += '&nbsp;&nbsp;<a href="%s/%s?field_id=%s&form_id=%s&selection_name=%s&selection_index=%s"><img src="%s/images/jump.png"></a>' \
% (here.absolute_url(), field.get_value('jump_method'), field.id, field.aq_parent.id, REQUEST.get('selection_name'), REQUEST.get('selection_index'),portal_url_string) % (here.absolute_url(), field.get_value('jump_method'), field.id, field.aq_parent.id, REQUEST.get('selection_name'), REQUEST.get('selection_index'),portal_url_string)
else: else:
html_string += '&nbsp;&nbsp;<a href="%s/%s?field_id=%s&form_id=%s"><img src="%s/images/jump.png"></a>' \ html_string += '&nbsp;&nbsp;<a href="%s/%s?field_id=%s&form_id=%s"><img src="%s/images/jump.png"></a>' \
% (here.absolute_url(), field.get_value('jump_method'), field.id, field.aq_parent.id,portal_url_string) % (here.absolute_url(), field.get_value('jump_method'), field.id, field.aq_parent.id,portal_url_string)
return html_string return html_string
def render_view(self, field, value): def render_view(self, field, value):
"""Render text input field. """Render text input field.
""" """
if field.get_value('jump_allowed') == 0 :
return Widget.TextWidget.render_view(self, field, value)
REQUEST = get_request() REQUEST = get_request()
here = REQUEST['here'] here = REQUEST['here']
html_string = Widget.TextWidget.render_view(self, field, value) html_string = Widget.TextWidget.render_view(self, field, value)
...@@ -210,7 +219,7 @@ class RelationEditor: ...@@ -210,7 +219,7 @@ class RelationEditor:
A class holding all values required to update a relation A class holding all values required to update a relation
""" """
def __init__(self, field_id, base_category, portal_type, uid, portal_type_item, def __init__(self, field_id, base_category, portal_type, uid, portal_type_item,
key, value, relation_setter_id, display_text): key, value, relation_setter_id, display_text):
self.field_id = field_id self.field_id = field_id
self.uid = uid self.uid = uid
...@@ -221,24 +230,24 @@ class RelationEditor: ...@@ -221,24 +230,24 @@ class RelationEditor:
self.value = value self.value = value
self.relation_setter_id = relation_setter_id self.relation_setter_id = relation_setter_id
self.display_text = display_text self.display_text = display_text
def __call__(self, REQUEST): def __call__(self, REQUEST):
if self.uid is not None: if self.uid is not None:
# Decorate the request so that we can display # Decorate the request so that we can display
# the select item in a popup # the select item in a popup
relation_field_id = 'relation_%s' % self.field_id relation_field_id = 'relation_%s' % self.field_id
relation_item_id = 'item_%s' % self.field_id relation_item_id = 'item_%s' % self.field_id
REQUEST.set(relation_item_id, ((self.display_text, self.uid),)) REQUEST.set(relation_item_id, ((self.display_text, self.uid),))
REQUEST.set(relation_field_id, self.uid) REQUEST.set(relation_field_id, self.uid)
REQUEST.set(self.field_id[len('field_'):], self.value) # XXX Dirty REQUEST.set(self.field_id[len('field_'):], self.value) # XXX Dirty
else: else:
# Make sure no default value appears # Make sure no default value appears
REQUEST.set(self.field_id[len('field_'):], None) REQUEST.set(self.field_id[len('field_'):], None)
def view(self): def view(self):
return self.__dict__ return self.__dict__
def edit(self, o): def edit(self, o):
if self.uid is not None: if self.uid is not None:
if type(self.uid) is type('a') and self.uid.startswith(new_content_prefix): if type(self.uid) is type('a') and self.uid.startswith(new_content_prefix):
# Create a new content # Create a new content
...@@ -248,7 +257,7 @@ class RelationEditor: ...@@ -248,7 +257,7 @@ class RelationEditor:
if p_item[0] == portal_type: if p_item[0] == portal_type:
#portal_module = p_item[1] #portal_module = p_item[1]
portal_module = o.getPortalObject().getDefaultModuleId( p_item[0] ) portal_module = o.getPortalObject().getDefaultModuleId( p_item[0] )
if portal_module is not None: if portal_module is not None:
portal_module_object = getattr(o.getPortalObject(), portal_module) portal_module_object = getattr(o.getPortalObject(), portal_module)
kw ={} kw ={}
kw[self.key] = string.join( string.split(self.value,'%'), '' ) kw[self.key] = string.join( string.split(self.value,'%'), '' )
...@@ -257,22 +266,22 @@ class RelationEditor: ...@@ -257,22 +266,22 @@ class RelationEditor:
new_object = portal_module_object.newContent(**kw) new_object = portal_module_object.newContent(**kw)
self.uid = new_object.getUid() self.uid = new_object.getUid()
else: else:
raise raise
# Edit relation # Edit relation
if self.relation_setter_id: if self.relation_setter_id:
relation_setter = getattr(o, self.relation_setter_id) relation_setter = getattr(o, self.relation_setter_id)
relation_setter((), portal_type=self.portal_type) relation_setter((), portal_type=self.portal_type)
relation_setter((int(self.uid),), portal_type=self.portal_type) relation_setter((int(self.uid),), portal_type=self.portal_type)
else: else:
# we could call a generic method which create the setter method name # we could call a generic method which create the setter method name
set_method_name = '_set'+convertToUpperCase(self.base_category)+'Value' set_method_name = '_set'+convertToUpperCase(self.base_category)+'Value'
object = o.portal_catalog.getObject( self.uid ) object = o.portal_catalog.getObject( self.uid )
getattr(o, set_method_name)( object,portal_type=self.portal_type ) getattr(o, set_method_name)( object,portal_type=self.portal_type )
else: else:
if self.value == '': if self.value == '':
# Delete relation # Delete relation
if self.relation_setter_id: if self.relation_setter_id:
relation_setter = getattr(o, self.relation_setter_id) relation_setter = getattr(o, self.relation_setter_id)
relation_setter((), portal_type=self.portal_type) relation_setter((), portal_type=self.portal_type)
...@@ -284,27 +293,27 @@ class RelationEditor: ...@@ -284,27 +293,27 @@ class RelationEditor:
allow_class(RelationEditor) allow_class(RelationEditor)
class RelationStringFieldValidator(Validator.StringValidator): class RelationStringFieldValidator(Validator.StringValidator):
""" """
Validation includes lookup of relared instances Validation includes lookup of relared instances
""" """
message_names = Validator.StringValidator.message_names +\ message_names = Validator.StringValidator.message_names +\
['relation_result_too_long', 'relation_result_ambiguous', 'relation_result_empty',] ['relation_result_too_long', 'relation_result_ambiguous', 'relation_result_empty',]
relation_result_too_long = "Too many documents were found." relation_result_too_long = "Too many documents were found."
relation_result_ambiguous = "Select appropriate document in the list." relation_result_ambiguous = "Select appropriate document in the list."
relation_result_empty = "No such document was found." relation_result_empty = "No such document was found."
def validate(self, field, key, REQUEST): def validate(self, field, key, REQUEST):
relation_field_id = 'relation_%s' % key relation_field_id = 'relation_%s' % key
relation_item_id = 'item_%s' % key relation_item_id = 'item_%s' % key
portal_type = map(lambda x:x[0],field.get_value('portal_type')) portal_type = map(lambda x:x[0],field.get_value('portal_type'))
portal_type_item = field.get_value('portal_type') portal_type_item = field.get_value('portal_type')
base_category = field.get_value( 'base_category') base_category = field.get_value( 'base_category')
# If the value is different, build a query # If the value is different, build a query
portal_selections = getToolByName(field, 'portal_selections') portal_selections = getToolByName(field, 'portal_selections')
portal_catalog = getToolByName(field, 'portal_catalog') portal_catalog = getToolByName(field, 'portal_catalog')
# Get the current value # Get the current value
value = Validator.StringValidator.validate(self, field, key, REQUEST) value = Validator.StringValidator.validate(self, field, key, REQUEST)
# If the value is the same as the current field value, do nothing # If the value is the same as the current field value, do nothing
...@@ -317,15 +326,15 @@ class RelationStringFieldValidator(Validator.StringValidator): ...@@ -317,15 +326,15 @@ class RelationStringFieldValidator(Validator.StringValidator):
if (value == current_value) and (relation_uid is None): if (value == current_value) and (relation_uid is None):
return None return None
# XXX return RelationEditor(key, base_category, portal_type, None, # XXX return RelationEditor(key, base_category, portal_type, None,
# portal_type_item, catalog_index, value, relation_setter_id, None) # portal_type_item, catalog_index, value, relation_setter_id, None)
# Will be interpreted by Base_edit as "do nothing" # Will be interpreted by Base_edit as "do nothing"
if relation_uid not in (None, ''): if relation_uid not in (None, ''):
# A value has been defined by the user # A value has been defined by the user
if type(relation_uid) in (type([]), type(())): if type(relation_uid) in (type([]), type(())):
if len( relation_uid ) == 0: if len( relation_uid ) == 0:
# No object was selected... # No object was selected...
self.raise_error('relation_result_too_long', field) self.raise_error('relation_result_too_long', field)
else: else:
relation_uid = relation_uid[0] relation_uid = relation_uid[0]
...@@ -333,18 +342,18 @@ class RelationStringFieldValidator(Validator.StringValidator): ...@@ -333,18 +342,18 @@ class RelationStringFieldValidator(Validator.StringValidator):
if related_object is not None: if related_object is not None:
display_text = str(related_object.getProperty(catalog_index)) display_text = str(related_object.getProperty(catalog_index))
else: else:
display_text = 'Object has been deleted' display_text = 'Object has been deleted'
return RelationEditor(key, base_category, portal_type, relation_uid, return RelationEditor(key, base_category, portal_type, relation_uid,
portal_type_item, catalog_index, value, relation_setter_id, display_text) portal_type_item, catalog_index, value, relation_setter_id, display_text)
# We must be able to erase the relation # We must be able to erase the relation
if value == '': if value == '':
display_text = 'Delete the relation' display_text = 'Delete the relation'
return RelationEditor(key, base_category, portal_type, None, return RelationEditor(key, base_category, portal_type, None,
portal_type_item, catalog_index, value, relation_setter_id, display_text) portal_type_item, catalog_index, value, relation_setter_id, display_text)
# Will be interpreted by Base_edit as "delete relation" (with no uid and value = '') # Will be interpreted by Base_edit as "delete relation" (with no uid and value = '')
kw ={} kw ={}
kw[catalog_index] = value kw[catalog_index] = value
kw['portal_type'] = portal_type kw['portal_type'] = portal_type
...@@ -359,7 +368,7 @@ class RelationStringFieldValidator(Validator.StringValidator): ...@@ -359,7 +368,7 @@ class RelationStringFieldValidator(Validator.StringValidator):
menu_item_list = [('', '')] menu_item_list = [('', '')]
new_object_menu_item_list = [] new_object_menu_item_list = []
for p in portal_type: for p in portal_type:
new_object_menu_item_list += [('New %s' % p, '%s%s' % (new_content_prefix,p))] new_object_menu_item_list += [('New %s' % p, '%s%s' % (new_content_prefix,p))]
# If the length is 1, return uid # If the length is 1, return uid
if len(relation_list) == 1: if len(relation_list) == 1:
relation_uid = relation_uid_list[0] relation_uid = relation_uid_list[0]
...@@ -367,29 +376,29 @@ class RelationStringFieldValidator(Validator.StringValidator): ...@@ -367,29 +376,29 @@ class RelationStringFieldValidator(Validator.StringValidator):
if related_object is not None: if related_object is not None:
display_text = str(related_object.getProperty(catalog_index)) display_text = str(related_object.getProperty(catalog_index))
else: else:
display_text = 'Object has been deleted' display_text = 'Object has been deleted'
return RelationEditor(key, base_category, portal_type, relation_uid, return RelationEditor(key, base_category, portal_type, relation_uid,
portal_type_item, catalog_index, value, relation_setter_id, display_text) portal_type_item, catalog_index, value, relation_setter_id, display_text)
# If the length is 0, raise an error # If the length is 0, raise an error
elif len(relation_list) == 0: elif len(relation_list) == 0:
menu_item_list += new_object_menu_item_list menu_item_list += new_object_menu_item_list
REQUEST.set(relation_item_id, menu_item_list) REQUEST.set(relation_item_id, menu_item_list)
self.raise_error('relation_result_empty', field) self.raise_error('relation_result_empty', field)
# If the length is short, raise an error # If the length is short, raise an error
elif len(relation_list) < MAX_SELECT: elif len(relation_list) < MAX_SELECT:
#menu_item_list += [('-', '')] #menu_item_list += [('-', '')]
menu_item_list += map(lambda x: (x.getObject().getProperty(catalog_index), x.uid), menu_item_list += map(lambda x: (x.getObject().getProperty(catalog_index), x.uid),
relation_list) relation_list)
REQUEST.set(relation_item_id, menu_item_list) REQUEST.set(relation_item_id, menu_item_list)
self.raise_error('relation_result_ambiguous', field) self.raise_error('relation_result_ambiguous', field)
else: else:
# If the length is long, raise an error # If the length is long, raise an error
# If this error is raise, we don t want to create a new object... # If this error is raise, we don t want to create a new object...
#REQUEST.set(relation_item_id, menu_item_list) #REQUEST.set(relation_item_id, menu_item_list)
self.raise_error('relation_result_too_long', field) self.raise_error('relation_result_too_long', field)
RelationStringFieldWidgetInstance = RelationStringFieldWidget() RelationStringFieldWidgetInstance = RelationStringFieldWidget()
RelationStringFieldValidatorInstance = RelationStringFieldValidator() RelationStringFieldValidatorInstance = RelationStringFieldValidator()
......
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