[Erp5-report] r19898 - /experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Mar 14 14:47:55 CET 2008
Author: bartek
Date: Fri Mar 14 14:47:55 2008
New Revision: 19898
URL: http://svn.erp5.org?rev=19898&view=rev
Log:
Boxover - show customizeable set of information in floating box over listbox line
Modified:
experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py
Modified: experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py
URL: http://svn.erp5.org/experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py?rev=19898&r1=19897&r2=19898&view=diff
==============================================================================
--- experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py (original)
+++ experimental/Experimental/patches/ERP5Form_ListBox_line_marking.py Fri Mar 14 14:47:55 2008
@@ -27,6 +27,11 @@
##############################################################################
"""
+ THIS CODE CONTAINS IN FACT TWO PATCHES
+ (becaue it is rather difficult to apply two monkey patches to the same method...)
+ =================================================================================
+ 1. ListBox line marking
+
This patch creates a new field in listbox formulator form.
It allows entering of the script name, which in turn should return a name
(or names separated by spaces) of the css class(es). They would be usually
@@ -40,6 +45,21 @@
RATIONALE: this is a very handy functionality, since it allows besides
filtering to mark items of special meaning/importance. It is already used
with success in eg. Thunderbird for marking mail messages.
+
+ 2. Boxover
+
+ This, in combination with erp5_xhtml_experimental, shows additional data about
+ a listbox object in a nice "boxover" which pops up onmouseover.
+
+ RATIONALE: to impress clients, and to let a user get more detailed information (which
+ normally wouldn't fit into one line) without clicking too much and reloading page
+ many times.
+
+ CONFIGURATION: in listbox definition, either define Boxover columns OR put a Boxover script
+ which should return a dict with 'header', 'body' and optionally many other values (see
+ boxover.swazz.org for more).
+
+ TODO: make it Ajax-based to make it lazy.
"""
from Products.Formulator.DummyField import fields
@@ -56,6 +76,21 @@
default='',
required=0)
ListBoxWidget.property_names.append('marking_method')
+
+ListBoxWidget.boxover_columns = fields.ListTextAreaField('boxover_columns',
+ title="Boxover Columns",
+ description=(
+ "A list of attributes to be shown in boxover (the first item will be used as boxover title). Can be overwritten by Boxover Method."),
+ default=[],
+ required=0)
+ListBoxWidget.property_names.append('boxover_columns')
+
+ListBoxWidget.boxover_method = fields.StringField('boxover_method',
+ title="Boxover Method",
+ description=('Name of script returning parameters for Boxover display.'),
+ default='',
+ required=0)
+ListBoxWidget.property_names.append('boxover_method')
from Products.ERP5Form.ListBox import ListBoxRenderer
@@ -89,6 +124,37 @@
return marking_method
ListBoxRenderer.getMarkingMethod = lazyMethod(getMarkingMethod)
+
+def getBoxoverMethodName(self):
+ """Returns ers match
+ """
+ boxover_method = self.field.get_value('boxover_method')
+ try:
+ name = getattr(boxover_method, 'method_name')
+ except AttributeError:
+ name = boxover_method
+ return name or None
+
+ListBoxRenderer.getBoxoverMethodName = lazyMethod(getBoxoverMethodName)
+
+
+def getBoxoverMethod(self):
+ """Return the boxover method object in the context of data object.
+ """
+ boxover_method_name = self.getBoxoverMethodName()
+
+ if boxover_method_name is not None:
+ try:
+ boxover_method = getattr(self.getContext(), boxover_method_name)
+ except AttributeError, KeyError:
+ boxover_method = None
+ else:
+ boxover_method = None
+
+ return boxover_method
+
+ListBoxRenderer.getBoxoverMethod = lazyMethod(getBoxoverMethod)
+
def ListBoxRenderer_query(self):
"""Get report sections and construct a list of lines. Note that this method has a side
@@ -150,6 +216,8 @@
else:
marking_css = ''
+ boxover = self.renderBoxover(current_section.object_list[offset].getObject())
+
#LOG('ListBox', 0, 'current_section.__dict__ = %r' % (current_section.__dict__,))
line = line_class(renderer = self,
obj = current_section.object_list[offset],
@@ -160,7 +228,8 @@
selection_domain = current_section.selection_domain,
depth = current_section.depth,
domain_title = current_section.domain_title,
- marking_css = marking_css)
+ marking_css = marking_css,
+ boxover = boxover)
line_list.append(line)
except IndexError:
# If the report section list is empty, nothing to do.
@@ -170,10 +239,48 @@
ListBoxRenderer.query = ListBoxRenderer_query
+
+def ListBoxRenderer_renderBoxover(self, ob):
+ # render title to generate a boxover for the line
+ def renderBoxoverLine(line):
+ # get data in a similar way to normal listbox cells
+ _marker = []
+ prop = ob.getProperty(line[0], _marker)
+ if prop is _marker:
+ try:
+ prop = getattr(ob, line[0])
+ except AttributeError:
+ prop = ''
+ if callable(prop):
+ try:
+ prop = prop()
+ except (AttributeError, KeyError, Unauthorized):
+ prop = 'N/A'
+ if prop is None: prop = ''
+ return '<b>%s: </b>%s' % (line[1], prop)
+ data = {}
+ boxover_method = self.getBoxoverMethod()
+ # if there is a method (script) we use this
+ if boxover_method is not None:
+ data = boxover_method(ob)
+ return ' '.join(['%s=[%s]' % item for item in data.items()])
+ else: # render from columns
+ boxover_column_list = self.field.get_value('boxover_columns')
+ if len(boxover_column_list) > 0:
+ data['header'] = renderBoxoverLine(boxover_column_list[0])
+ line_list = []
+ for item in boxover_column_list[1:]:
+ line_list.append(renderBoxoverLine(item))
+ data['body'] = '<br/>'.join(line_list)
+ return ' '.join(['%s=[%s]' % item for item in data.items()])
+
+ListBoxRenderer.renderBoxover = ListBoxRenderer_renderBoxover
+
+
from Products.ERP5Form.ListBox import ListBoxRendererLine
def ListBoxRendererLine___init__(self, renderer = None, obj = None, index = 0, is_summary = False, context = None,
- is_open = False, selection_domain = None, depth = 0, domain_title=None, marking_css = ''):
+ is_open = False, selection_domain = None, depth = 0, domain_title=None, marking_css = '', boxover = None):
"""In reality, the object is a brain or a brain-like object.
"""
self.renderer = renderer
@@ -186,11 +293,18 @@
self.depth = depth
self.domain_title = domain_title
self.marking_css = marking_css
+ self.boxover = boxover
def ListBoxRendererLine_getMarkingCssName(self):
"""Return name of css used for marking listbox line.
"""
return self.marking_css
+def ListBoxRendererLine_getBoxover(self):
+ """Return boxover string to be used as line's title
+ """
+ return self.boxover
+
ListBoxRendererLine.__init__ = ListBoxRendererLine___init__
ListBoxRendererLine.getMarkingCssName = ListBoxRendererLine_getMarkingCssName
+ListBoxRendererLine.getBoxover = ListBoxRendererLine_getBoxover
More information about the Erp5-report
mailing list