# HG changeset patch # User Richard Jones # Date 1119594465 0 # Node ID 7bc1e9c42a2620b9f5baa9e03e350d0e31b8cf2f # Parent 64cc03598c8ace4fcb8859a3543372ea39689ad8 allow specification of pagesize, sorting and filtering in "classhelp" popups [SF#1211800] diff -r 64cc03598c8a -r 7bc1e9c42a26 CHANGES.txt --- a/CHANGES.txt Fri Jun 24 05:42:21 2005 +0000 +++ b/CHANGES.txt Fri Jun 24 06:27:45 2005 +0000 @@ -22,6 +22,8 @@ - have 'roundup-admin security' display property restrictions (sf bug 1222135) - fixed templating menu() sort_on handling (sf bug 1221936) +- allow specification of pagesize, sorting and filtering in "classhelp" + popups (sf bug 1211800) 2005-05-02 0.8.3 diff -r 64cc03598c8a -r 7bc1e9c42a26 doc/customizing.txt --- a/doc/customizing.txt Fri Jun 24 05:42:21 2005 +0000 +++ b/doc/customizing.txt Fri Jun 24 06:27:45 2005 +0000 @@ -2,7 +2,7 @@ Customising Roundup =================== -:Version: $Revision: 1.181 $ +:Version: $Revision: 1.182 $ .. This document borrows from the ZopeBook section on ZPT. The original is at: http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx @@ -1764,6 +1764,32 @@ classhelp display a link to a javascript popup containing this class' "help" template. + + This generates a link to a popup window which displays the + properties indicated by "properties" of the class named by + "classname". The "properties" should be a comma-separated list + (eg. 'id,name,description'). Properties defaults to all the + properties of a class (excluding id, creator, created and + activity). + + You may optionally override the "label" displayed, the "width", + the "height", the number of items per page ("pagesize") and + the field on which the list is sorted ("sort"). + + With the "filter" arg it is possible to specify a filter for + which items are supposed to be displayed. It has to be of + the format "=;=;...". + + The popup window will be resizable and scrollable. + + If the "property" arg is given, it's passed through to the + javascript help_window function. This allows updating of a + property in the calling HTML page. + + If the "form" arg is given, it's passed through to the + javascript help_window function - it's the name of the form + the "property" belongs to. + submit generate a submit button (and action hidden element) renderWith render this class with the given template. history returns 'New node - no history' :) @@ -1953,7 +1979,9 @@ lists properties which should be included in the label sort_on indicates the property to sort the list on as (direction, - property) where direction is '+' or '-'. + (direction, property) where direction is '+' or '-'. A + single string with the direction prepended may be used. + For example: ('-', 'order'), '+name'. The remaining keyword arguments are used as conditions for filtering the items in the list - they're passed as the diff -r 64cc03598c8a -r 7bc1e9c42a26 roundup/cgi/templating.py --- a/roundup/cgi/templating.py Fri Jun 24 05:42:21 2005 +0000 +++ b/roundup/cgi/templating.py Fri Jun 24 06:27:45 2005 +0000 @@ -621,7 +621,8 @@ return l def classhelp(self, properties=None, label=''"(list)", width='500', - height='400', property='', form='itemSynopsis'): + height='400', property='', form='itemSynopsis', + pagesize=50, sort=None, filter=None): '''Pop up a javascript window with class help This generates a link to a popup window which displays the @@ -631,8 +632,16 @@ properties of a class (excluding id, creator, created and activity). - You may optionally override the label displayed, the width and - height. The popup window will be resizable and scrollable. + You may optionally override the label displayed, the width, + the height, the number of items per page and the field on which + the list is sorted (defaults to username if in the displayed + properties). + + With the "filter" arg it is possible to specify a filter for + which items are supposed to be displayed. It has to be of + the format "=;=;...". + + The popup window will be resizable and scrollable. If the "property" arg is given, it's passed through to the javascript help_window function. @@ -645,13 +654,31 @@ properties = self._klass.getprops(protected=0).keys() properties.sort() properties = ','.join(properties) + if sort is None: + if 'username' in properties.split( ',' ): + sort = '&@sort=username' + else: + sort = '' + else: + sort = '&@sort=' + sort if property: property = '&property=%s'%property if form: form = '&form=%s'%form + if filter: + filterprops = filter.split(';') + filtervalues = [] + names = [] + for x in filterprops: + (name, values) = x.split('=') + names.append(name) + filtervalues.append('&%s=%s' % (name, urllib.quote(values))) + filter = '&@filter=%s%s' % (','.join(names), ''.join(filtervalues)) + else: + filter = '' help_url = "%s?@startwith=0&@template=help&"\ - "properties=%s%s%s" % \ - (self.classname, properties, property, form) + "properties=%s%s%s%s&@pagesize=%s%s" % \ + (self.classname, properties, property, form, sort, pagesize, filter) onclick = "javascript:help_window('%s', '%s', '%s');return false;" % \ (help_url, width, height) return '%s' % \ @@ -1659,16 +1686,16 @@ if value is None: s = 'selected="selected" ' l.append(self._('')%s) + if sort_on is not None: if not isinstance(sort_on, tuple): if sort_on[0] in '+-': sort_on = (sort_on[0], sort_on[1:]) else: sort_on = ('+', sort_on) - elif linkcl.getprops().has_key('order'): - sort_on = ('+', 'order') else: - sort_on = ('+', linkcl.labelprop()) + sort_on = ('+', find_sort_key(linkcl)) + options = linkcl.filter(None, conditions, sort_on, (None, None)) # make sure we list the current value if it's retired @@ -1821,7 +1848,9 @@ "additional" lists properties which should be included in the label "sort_on" indicates the property to sort the list on as - (direction, property) where direction is '+' or '-'. + (direction, property) where direction is '+' or '-'. A + single string with the direction prepended may be used. + For example: ('-', 'order'), '+name'. The remaining keyword arguments are used as conditions for filtering the items in the list - they're passed as the @@ -1835,10 +1864,16 @@ value = self._value linkcl = self._db.getclass(self._prop.classname) - if sort_on is None: + + if sort_on is not None: + if not isinstance(sort_on, tuple): + if sort_on[0] in '+-': + sort_on = (sort_on[0], sort_on[1:]) + else: + sort_on = ('+', sort_on) + else: sort_on = ('+', find_sort_key(linkcl)) - else: - sort_on = ('+', sort_on) + options = linkcl.filter(None, conditions, sort_on) height = height or min(len(options), 7) l = ['