[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Formulator/Widgets/Browser - BrowserWidget.py:1.1.4.1 CheckBoxWidget.py:1.1.4.1 DateTimeWidget.py:1.1.4.1 FileWidget.py:1.1.4.1 IBrowserWidget.py:1.1.4.1 ItemsWidget.py:1.1.4.1 LinesTextAreaWidget.py:1.1.4.1 ListTextAreaWidget.py:1.1.4.1 ListWidget.py:1.1.4.1 MultiItemsWidget.py:1.1.4.1 MultiListWidget.py:1.1.4.1 MultipleCheckBoxWidget.py:1.1.4.1 PasswordWidget.py:1.1.4.1 RadioWidget.py:1.1.4.1 SingleItemsWidget.py:1.1.4.1 TextAreaWidget.py:1.1.4.1 TextWidget.py:1.1.4.1 __init__.py:1.1.4.1 browser.zcml:1.1.4.1 datetime.pt:1.1.4.1

Stephan Richter srichter@cbu.edu
Mon, 1 Apr 2002 21:10:25 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Formulator/Widgets/Browser
In directory cvs.zope.org:/tmp/cvs-serv6377/Formulator/Widgets/Browser

Added Files:
      Tag: Zope-3x-branch
	BrowserWidget.py CheckBoxWidget.py DateTimeWidget.py 
	FileWidget.py IBrowserWidget.py ItemsWidget.py 
	LinesTextAreaWidget.py ListTextAreaWidget.py ListWidget.py 
	MultiItemsWidget.py MultiListWidget.py 
	MultipleCheckBoxWidget.py PasswordWidget.py RadioWidget.py 
	SingleItemsWidget.py TextAreaWidget.py TextWidget.py 
	__init__.py browser.zcml datetime.pt 
Log Message:
Issue 25: Resolved by janko & srichter

This checkin fixes all the license headers of all the files that needed
fixing it. :) This was made possible by Janko Hauser's script, which is now
available in the ZopeRoot/utilities directory.

Also, cleaned up the Formualtor tag insanity!


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/BrowserWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: BrowserWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from IBrowserWidget import IBrowserWidget
from Zope.App.Formulator.Widget import Widget
from Zope.App.Formulator.IPropertyFieldAdapter import IPropertyFieldAdapter
from Zope.ComponentArchitecture import getAdapter


class BrowserWidget(Widget):
    """A field widget that knows how to display itself as HTML.
    """

    __implements__ = IBrowserWidget

    propertyNames = Widget.propertyNames + \
                    ['tag', 'type', 'cssClass', 'hidden', 'extra']
    
    tag = 'input'
    type = 'text'
    cssClass = ''
    hidden = 0
    extra = ''

    def __init__(self, field):
        ''' '''
        self._field = field


    def getValueFromRequest(self, REQUEST):
        """ """
        return REQUEST.get('field_'+self.getContext().id, None)


    def _getValueToInsert(self, REQUEST):
        """ """
        field = self.getContext()
        if REQUEST and REQUEST.has_key('field_'+field.id):
            return REQUEST['field_'+field.id]
        else:
            return getAdapter(field, IPropertyFieldAdapter).\
                   getPropertyInContext()
            

    def render(self, REQUEST=None):
        """Renders this widget as HTML using property values in field.
        """
        return renderElement(self.getValue('tag'),
                             type = self.getValue('type'),
                             name = self.getContext().id,
                             value = self._getValueToInsert(REQUEST),
                             cssClass = self.getValue('cssClass'),
                             extra = self.getValue('extra'))

        
    def render_hidden(self, REQUEST=None):
        """Renders this widget as a hidden field.
        """
        return renderElement(self.getValue('tag'),
                             type = 'hidden',
                             name = self.getContext().id,
                             value = self._getValueToInsert(REQUEST),
                             cssClass = self.getValue('cssClass'),
                             extra = self.getValue('extra'))



def renderTag(tag, **kw):
    """Render the tag. Well, not all of it, as we may want to / it.
    """
    attr_list = []

    kw['name'] = 'field_' + kw['name']

    # special case handling for css_class
    if kw.has_key('cssClass'):
        if kw['cssClass'] != "":
            attr_list.append('class="%s"' % kw['cssClass'])
        del kw['cssClass']

    # special case handling for extra 'raw' code
    if kw.has_key('extra'):
        extra = kw['extra'] # could be empty string but we don't care
        del kw['extra']
    else:
        extra = ""

    # handle other attributes
    for key, value in kw.items():
        if value == None:
            value = key
        attr_list.append('%s="%s"' % (key, str(value)))
            
    attr_str = " ".join(attr_list)
    return "<%s %s %s" % (tag, attr_str, extra)


def renderElement(tag, **kw):
    if kw.has_key('contents'):
        contents = kw['contents']
        del kw['contents']
        return "%s>%s</%s>" % (apply(renderTag, (tag,), kw), contents, tag)
    else:
        return apply(renderTag, (tag,), kw) + " />"
    








=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/CheckBoxWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: CheckBoxWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from Zope.App.Formulator.Widgets.Browser.BrowserWidget import BrowserWidget
from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement


class CheckBoxWidget(BrowserWidget):
    """Text widget
    """

    __implements__ = BrowserWidget.__implements__

    propertyNames = BrowserWidget.propertyNames + \
                     ['extra', 'default']

    type = 'checkbox'
    default = 0
    extra = ''

    
    def render(self, REQUEST=None):
        """Renders this widget as HTML using property values in field.
        """
        if self._getValueToInsert(REQUEST):
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 checked = None,
                                 cssClass = self.getValue('cssClass'),
                                 extra = self.getValue('extra'))
        else:
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 cssClass = self.getValue('cssClass'),
                                 size = self.getValue('displayWidth'),
                                 extra = self.getValue('extra'))


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/DateTimeWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: DateTimeWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from Zope.PageTemplate.PageTemplateFile import PageTemplateFile
from Widget import Widget
from DateTime import DateTime


class DateTimeWidget(CompositeWidget):


    __implements__ = CompositeWidget.__implements__
    

    propertyNames = Widget.property_names +\
                     ['dateSeparator', 'timeSeparator',
                      'inputStyle', 'inputOrder', 'dateOnly']

    template = PageTemplateFile('datetime.pt')

    widgets = {'year': IntegerWidget(start=0, end=6000),
               'month': IntegerWidget(start=0, end=12),
               'day': IntegerWidget(start=0, end=31),
               'hour': IntegerWidget(start=0, end=23),
               'minute': IntegerWidget(start=0, end=59)}

    default = None
    defaultNow = 0                      
    dateSeparator = '/'
    timeSeparator = ':'
    inputStyle = "text"
    inputOrder = ('year', 'month', 'day')
    dateOnly = 0


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/FileWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: FileWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from TextWidget import TextWidget
from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement


class FileWidget(TextWidget):

    __implements__ = TextWidget.__implements__

    type = 'file'


    def render(self, REQUEST=None):
        """Renders this widget as HTML using property values in field.
        """
        displayMaxWidth = self.getValue('displayMaxWidth') or 0
        if displayMaxWidth > 0:
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 cssClass = self.getValue('cssClass'),
                                 size = self.getValue('displayWidth'),
                                 maxlength = displayMaxWidth,
                                 extra = self.getValue('extra'))
        else:
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 cssClass = self.getValue('cssClass'),
                                 size = self.getValue('displayWidth'),
                                 extra = self.getValue('extra'))


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/IBrowserWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: IBrowserWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from Interface import Interface


class IBrowserWidget(Interface):
    """A field widget contains all the properties that are required
       to represent a field. Properties include css_sheet, 
       default value and so on.

    """


    def render(field, key, value, REQUEST):
        """Renders this widget as HTML using property values in field.
        """

        
    def render_hidden(field, key, value, REQUEST):
        """Renders this widget as a hidden field.
        """
        


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/ItemsWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: ItemsWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from Widget import Widget

class ItemsWidget(Widget):
    """A widget that has a number of items in it.
    """
    
    items = []



=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/LinesTextAreaWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: LinesTextAreaWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from TextAreaWidget import TextAreaWidget


class LinesTextAreaWidget(TextAreaWidget):

    default = []

    def render(self, REQUEST=None):
        value = string.join(value, "\n")
        return TextAreaWidget.render(self, REQUEST)


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/ListTextAreaWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: ListTextAreaWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from Zope.App.Formulator.Widgets.Browser.TextAreaWidget import TextAreaWidget
from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement


class ListTextAreaWidget(TextAreaWidget):
    """ListTextArea widget
    """

    __implements__ = TextAreaWidget.__implements__

    propertyNames = TextAreaWidget.propertyNames + \
                     ['extra', 'default']

    default = []
    extra = ''

    
    def render(self, REQUEST=None):
        """Renders this widget as HTML using property values in field.
        """
        lines = []
        for element_text, element_value in value:
            lines.append("%s | %s" % (element_text, element_value))
        return Widget.TextAreaWidget.render(self, field, key,
                                            string.join(lines, '\n'),
                                            REQUEST)


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/ListWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: ListWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from SingleItemsWidget import SingleItemsWidget


class ListWidget(SingleItemsWidget):
    """List widget.
    """
    __implements__ = SingleItemsWidget.__implements__

    property_names = Widget.property_names +\
                     ['firstItem', 'items', 'size', 'extra']
    size = 5

    def render(self, REQUEST=None):

        renderedItems = self.renderItems(field, key, value, REQUEST)

        return render_element('select',
                              name='',
                              cssClass=field.get_value('cssClass'),
                              size=field.get_value('size'),
                              contents=string.join(renderedItems, "\n"),
                              extra=field.get_value('extra'))

    
    def renderItem(self, text, value, key, css_class):
        return render_element('option', contents=text, value=value)


    def renderSelectedItem(self, text, value, key, css_class):
        return render_element('option', contents=text, value=value,
                              selected=None)


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/MultiItemsWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: MultiItemsWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from ItemsWidget import ItemsWidget
from types import ListType

        
class MultiItemsWidget(ItemsWidget):
    """A widget with a number of items that has multiple selectable
    items.
    """
    default = []
        
    def render_items(self, field, key, value, REQUEST):
        # need to deal with single item selects
        if not isinstance(values, ListType):
            value = [value]
        items = field.get_value('items')
        css_class = field.get_value('css_class')
        rendered_items = []
        for item in items:
            try:
                item_text, item_value = item
            except ValueError:
                item_text = item
                item_value = item

            if item_value in value:
                rendered_item = self.render_selected_item(item_text,
                                                          item_value,
                                                          key,
                                                          css_class)
            else:
                rendered_item = self.render_item(item_text,
                                                 item_value,
                                                 key,
                                                 css_class)

            rendered_items.append(rendered_item)

        return rendered_items


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/MultiListWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: MultiListWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from MultiItemsWidget import MultiItemsWidget


class MultiListWidget(MultiItemsWidget):
    """List widget with multiple select.
    """
    property_names = Widget.property_names +\
                     ['items', 'size', 'extra']
    
    size = 5

    def render(self, REQUEST=None):
        rendered_items = self.render_items(field, key, value, REQUEST)

        return render_element('select',
                              name=key,
                              multiple=None,
                              css_class=field.get_value('css_class'),
                              size=field.get_value('size'),
                              contents=string.join(rendered_items, "\n"),
                              extra=field.get_value('extra'))
    
    def render_item(self, text, value, key, css_class):
        return render_element('option', contents=text, value=value)

    def render_selected_item(self, text, value, key, css_class):
        return render_element('option', contents=text, value=value,
                              selected=None)
    
MultiListWidgetInstance = MultiListWidget()


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/MultipleCheckBoxWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: MultipleCheckBoxWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from MultiItemsWidget import MultiItemsWidget


class MultiCheckBoxWidget(MultiItemsWidget):
    """multiple checkbox widget.
    """
    property_names = Widget.property_names +\
                     ['items', 'orientation']
    
    orientation = "vertical"
                                   
    def render(self, REQUEST=None):
        rendered_items = self.render_items(field, key, value, REQUEST)
        orientation = field.get_value('orientation')
        if orientation == 'horizontal':
            return string.join(rendered_items, "&nbsp;&nbsp;")
        else:
            return string.join(rendered_items, "<br />")

        
    def render_item(self, text, value, key, css_class):
        return render_element('input',
                              type="checkbox",
                              css_class=css_class,
                              name=key,
                              value=value) + text
    

    def render_selected_item(self, text, value, key, css_class):
        return render_element('input',
                              type="checkbox",
                              css_class=css_class,
                              name=key,
                              value=value,
                              checked=None) + text


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/PasswordWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: PasswordWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from TextWidget import TextWidget


class PasswordWidget(TextWidget):
    
    def render(self, REQUEST=None):
        """Render password input field.
        """
        display_maxwidth = field.get_value('display_maxwidth') or 0
        if display_maxwidth > 0:
            return render_element("input",
                                  type="password",
                                  name=key,
                                  css_class=field.get_value('css_class'),
                                  value=value,
                                  size=field.get_value('display_width'),
                                  maxlength=display_maxwidth,
                                  extra=field.get_value('extra'))
        else:
            return render_element("input",
                                  type="password",
                                  name=key,
                                  css_class=field.get_value('css_class'),
                                  value=value,
                                  size=field.get_value('display_width'),
                                  extra=field.get_value('extra'))


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/RadioWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: RadioWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from SingleItemsWidget import SingleItemsWidget


class RadioWidget(SingleItemsWidget):
    """radio buttons widget.
    """
    property_names = Widget.property_names +\
                     ['first_item', 'items', 'orientation']
    
    orientation = "vertical"
                                   
    def render(self, REQUEST=None):
        rendered_items = self.render_items(field, key, value, REQUEST)
        orientation = field.get_value('orientation')
        if orientation == 'horizontal':
            return string.join(rendered_items, "&nbsp;&nbsp;")
        else:
            return string.join(rendered_items, "<br />")

        
    def render_item(self, text, value, key, css_class):
        return render_element('input',
                              type="radio",
                              css_class=css_class,
                              name=key,
                              value=value) + text
    

    def render_selected_item(self, text, value, key, css_class):
        return render_element('input',
                              type="radio",
                              css_class=css_class,
                              name=key,
                              value=value,
                              checked=None) + text
       


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/SingleItemsWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: SingleItemsWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from ItemsWidget import ItemsWidget


class SingleItemsWidget(ItemsWidget):
    """A widget with a number of items that has only a single
    selectable item.
    """
    default = ""
    first_item = 0    


    def render_items(self, field, key, value, REQUEST):
        # get items
        items = field.get_value('items')
    
        # check if we want to select first item
        if not value and field.get_value('first_item') and len(items) > 0:
            try:
                text, value = items[0]
            except ValueError:
                value = items[0]
                
        css_class = field.get_value('css_class')
        
        # FIXME: what if we run into multiple items with same value?
        rendered_items = []
        for item in items:
            try:
                item_text, item_value = item
            except ValueError:
                item_text = item
                item_value = item

            if item_value == value:
                rendered_item = self.render_selected_item(item_text,
                                                          item_value,
                                                          key,
                                                          css_class)
            else:
                rendered_item = self.render_item(item_text,
                                                 item_value,
                                                 key,
                                                 css_class)

            rendered_items.append(rendered_item)

        return rendered_items


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextAreaWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: TextAreaWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from Zope.App.Formulator.Widgets.Browser.BrowserWidget import BrowserWidget
from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement


class TextAreaWidget(BrowserWidget):
    """Textarea widget
    """
    propertyNames = BrowserWidget.propertyNames +\
                     ['width', 'height', 'extra']
    
    default = ""
    width = 80
    height = 15
    extra=""
    
    def render(self, REQUEST=None):
        return renderElement("textarea",
                             name=self.getContext().id,
                             css_class=self.getValue('cssClass'),
                             cols=self.getValue('width'),
                             rows=self.getValue('height'),
                             contents=self._getValueToInsert(REQUEST),
                             extra=self.getValue('extra'))



=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/TextWidget.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""

$Id: TextWidget.py,v 1.1.4.1 2002/04/02 02:10:22 srichter Exp $
"""

from Zope.App.Formulator.Widgets.Browser.BrowserWidget import BrowserWidget
from Zope.App.Formulator.Widgets.Browser.BrowserWidget import renderElement


class TextWidget(BrowserWidget):
    """Text widget
    """

    __implements__ = BrowserWidget.__implements__

    propertyNames = BrowserWidget.propertyNames + \
                     ['displayWidth', 'displayMaxWidth', 'extra', 'default']

    default = ''
    displayWidth = 20
    displayMaxWidth = ''
    extra = ''

    
    def render(self, REQUEST=None):
        """Renders this widget as HTML using property values in field.
        """
        displayMaxWidth = self.getValue('displayMaxWidth') or 0
        if displayMaxWidth > 0:
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 value = self._getValueToInsert(REQUEST),
                                 cssClass = self.getValue('cssClass'),
                                 size = self.getValue('displayWidth'),
                                 maxlength = displayMaxWidth,
                                 extra = self.getValue('extra'))
        else:
            return renderElement(self.getValue('tag'),
                                 type = self.getValue('type'),
                                 name = self.getContext().id,
                                 value = self._getValueToInsert(REQUEST),
                                 cssClass = self.getValue('cssClass'),
                                 size = self.getValue('displayWidth'),
                                 extra = self.getValue('extra'))


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/__init__.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/browser.zcml ===
<zopeConfigure
   xmlns='http://namespaces.zope.org/zope'
   xmlns:security='http://namespaces.zope.org/security'
>

  <security:protectClass name=".FileWidget."
    			 permission_id="Zope.ManageContent" 
    			 methods="render, getContext" />

  <security:protectClass name=".TextAreaWidget."
    			 permission_id="Zope.ManageContent" 
    			 methods="render, getContext" />

  <security:protectClass name=".TextWidget."
    			 permission_id="Zope.ManageContent" 
    			 methods="render, getContext" />

</zopeConfigure>


=== Added File Zope3/lib/python/Zope/App/Formulator/Widgets/Browser/datetime.pt ===

<input> / <input> / <input>  <input> : <input> : <input?