products/CPSonFive.old

view form/widget.py @ 3:637830cb0c2a

Various rendering improvements
author lregebro
date Mon, 27 Jun 2005 10:14:54 +0000
parents edfc69361929
children c6b4dc97c687
line source
1 # -*- coding: ISO-8859-15 -*-
2 # (C) Copyright 2005 Nuxeo SARL <http://nuxeo.com>
3 # Author: Lennart Regebro <regebro@nuxeo.com>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 2 as published
7 # by the Free Software Foundation.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17 # 02111-1307, USA.
18 #
19 # $Id: calendar.py 24398 2005-06-24 12:34:57Z lregebro $
21 from zope.app.form.browser import TextWidget
22 from zope.app.form.browser.widget import renderElement
23 from zope.app.datetimeutils import DateTimeError
24 from zope.app.form.interfaces import ConversionError, WidgetInputError
25 from zope.app.form.interfaces import InputErrors
26 from zope.schema.interfaces import ValidationError
27 from Products.CMFCore.utils import getToolByName
29 from zope.i18nmessageid import MessageIDFactory
30 _ = MessageIDFactory("calendar")
32 class DocumentBrowserWidget(TextWidget):
34 displayWidth = 30
36 def _toFieldValue(self, input):
37 try:
38 if not input:
39 return input
40 input = str(input)
41 context = self.context.context
42 portal_url = getToolByName(context, 'portal_url')
43 portal_path = portal_url.getPortalPath()
44 if not input.startswith(portal_path):
45 if input[0] != '/':
46 input = '/' + input
47 input = portal_path + input
49 obj = context.unrestrictedTraverse(input)
50 return u'/'.join(obj.getPhysicalPath())
51 except (AttributeError, KeyError), v:
52 raise ConversionError("Selected object not found", v)
54 def __call__(self):
55 value = self._getFormValue()
56 res = renderElement(self.tag,
57 type=self.type,
58 name=self.name,
59 id=self.name,
60 value=value,
61 cssClass=self.cssClass,
62 style=self.style,
63 size=self.displayWidth,
64 extra=self.extra)
65 style = "text-decoration:none;border:1px solid black;padding:0.2em 0.3em;"
66 js = "window.open('documentnavigation_popup?input_id=" + \
67 self.name + "', 'DirectoryMultiEntryFinder', " \
68 "'toolbar=0, scrollbars=1, location=0, " \
69 "statusbar=0, menubar=0, resizable=1, dependent=1, " \
70 "width=500, height=480')"
71 btn = renderElement("input", type="button", style=style, onClick=js,
72 value=_("..."))
73 return res + "&nbsp;" + btn