Example #1
0
    def process(self, ctx, the_form, args, errors):
        # nuke old children
        self.items = form.FormItems(self)        
        self.add = self.items.add
        self.getItemByName = self.items.getItemByName

        # filter away other arguments based on prefix
        ourpath = form.itemKey(self)
        ourpathlen = len(ourpath)
        ourargs = {}
        for k in args.keys():
            if k[:ourpathlen] == ourpath:
                ourargs[k[ourpathlen:]] = args[k]  # foo.bar.list.0.foo -> .0.foo
                                                   # foo.bar.list._collapsedstate_ -> ._collapsedstate_
                                                   
        # Delete existing keys from the form data. Otherwise data from objects deleted by javascripts
        # still exists in form data.
        for k in the_form.data.keys():
            if k[:ourpathlen] == ourpath:
                del(the_form.data[k])

        # Get collapsed state
        collapsed_key = '%s._collapsedstate_' % ourpath
        if args.has_key(collapsed_key):
            val = args[collapsed_key][0]
            if val == '1':
                self.collapsed = True
            else:
                self.collapsed = False
            the_form.data[collapsed_key] = val

        # catch all numbers
        nums = {}
        for k in ourargs.keys():
            t = k.split('.')   # .0.foo -> ['', '0', 'foo']; or ._collapsedstate_ -> ['', '_collapsedstate_']
            try:
                index = int(t[1])
                nums[str(index)] = ourargs[k]
            except ValueError:
                if t[1] == '_collapsedstate_':
                    pass
                else:
                    raise

        # XXX: if there are dups in the entry, we get a list of >1 values here; what to do?

        # iterate over numbers, creating groups
        for i in xrange(1024):  # max elements
            childpath = form.itemKey(self) + '.' + str(i)

            if nums.has_key(str(i)):
                self.add(self.childCreationCallback(i))
            else:
                break

        # process children
        for item in self.items:
            item.process(ctx, the_form, args, errors)
Example #2
0
    def process(self, ctx, the_form, args, errors):
        # Get collapsed state
        collapsed_key = '%s._collapsedstate_' % form.itemKey(self)
        if args.has_key(collapsed_key):
            val = args[collapsed_key][0]
            if val == '1':
                self.collapsed = True
            else:
                self.collapsed = False
            the_form.data[collapsed_key] = val

        return super(CollapsibleGroup, self).process(ctx, the_form, args, errors)
Example #3
0
 def getCollapsedKey(self):
     return form.itemKey(self) + '._collapsedstate_'
Example #4
0
class DynamicList(object):
    itemParent = None

    def __init__(self, name, label=None, description=None, cssClass=None, childCreationCallback=None):
        if label is None:
            label = util.titleFromName(name)
        self.name = name
        self.label = label
        self.description = description
        self.cssClass = cssClass
        if childCreationCallback is None:
            raise Exception('must give childCreationCallback')
        self.childCreationCallback = childCreationCallback
        self.items = form.FormItems(self)
        self.add = self.items.add
        self.getItemByName = self.items.getItemByName
        self.collapsible = False
        self.collapsed = False
        self.summary = None
        
    key = property(lambda self: form.itemKey(self))

    def setItemParent(self, itemParent):
        self.itemParent = itemParent

    def setCollapsible(self, collapsible=True):
        self.collapsible = collapsible

    def setCollapsed(self, collapsed=True):
        self.collapsed = collapsed

    def setSummary(self, summary):
        self.summary = summary

    def getCollapsedKey(self):
        return form.itemKey(self) + '._collapsedstate_'

    def process(self, ctx, the_form, args, errors):
        # nuke old children
        self.items = form.FormItems(self)        
        self.add = self.items.add
        self.getItemByName = self.items.getItemByName

        # filter away other arguments based on prefix
        ourpath = form.itemKey(self)
        ourpathlen = len(ourpath)
        ourargs = {}
        for k in args.keys():
            if k[:ourpathlen] == ourpath:
                ourargs[k[ourpathlen:]] = args[k]  # foo.bar.list.0.foo -> .0.foo
                                                   # foo.bar.list._collapsedstate_ -> ._collapsedstate_
                                                   
        # Delete existing keys from the form data. Otherwise data from objects deleted by javascripts
        # still exists in form data.
        for k in the_form.data.keys():
            if k[:ourpathlen] == ourpath:
                del(the_form.data[k])

        # Get collapsed state
        collapsed_key = '%s._collapsedstate_' % ourpath
        if args.has_key(collapsed_key):
            val = args[collapsed_key][0]
            if val == '1':
                self.collapsed = True
            else:
                self.collapsed = False
            the_form.data[collapsed_key] = val

        # catch all numbers
        nums = {}
        for k in ourargs.keys():
            t = k.split('.')   # .0.foo -> ['', '0', 'foo']; or ._collapsedstate_ -> ['', '_collapsedstate_']
            try:
                index = int(t[1])
                nums[str(index)] = ourargs[k]
            except ValueError:
                if t[1] == '_collapsedstate_':
                    pass
                else:
                    raise

        # XXX: if there are dups in the entry, we get a list of >1 values here; what to do?

        # iterate over numbers, creating groups
        for i in xrange(1024):  # max elements
            childpath = form.itemKey(self) + '.' + str(i)

            if nums.has_key(str(i)):
                self.add(self.childCreationCallback(i))
            else:
                break

        # process children
        for item in self.items:
            item.process(ctx, the_form, args, errors)