|
1 ### -*- coding: utf-8 -*- #################################################### |
|
2 ############################################################################## |
|
3 # |
|
4 # Copyright (c) 2012 Thierry Florac <tflorac AT ulthar.net> |
|
5 # All Rights Reserved. |
|
6 # |
|
7 # This software is subject to the provisions of the Zope Public License, |
|
8 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. |
|
9 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED |
|
10 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
11 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS |
|
12 # FOR A PARTICULAR PURPOSE. |
|
13 # |
|
14 ############################################################################## |
|
15 |
|
16 |
|
17 # import standard packages |
|
18 |
|
19 # import Zope3 interfaces |
|
20 from z3c.form.interfaces import ITextWidget, IFieldWidget, IFormLayer |
|
21 |
|
22 # import local interfaces |
|
23 from ztfy.utils.schema import IColorField |
|
24 |
|
25 # import Zope3 packages |
|
26 from z3c.form.browser.text import TextWidget |
|
27 from z3c.form.widget import FieldWidget |
|
28 from zope.component import adapter |
|
29 from zope.interface import implementer, implementsOnly |
|
30 |
|
31 # import local packages |
|
32 from ztfy.jqueryui import jquery_colorpicker |
|
33 |
|
34 |
|
35 class IColorWidget(ITextWidget): |
|
36 """Color widget interface""" |
|
37 |
|
38 |
|
39 class ColorWidget(TextWidget): |
|
40 """Color widget""" |
|
41 |
|
42 implementsOnly(IColorWidget) |
|
43 |
|
44 def update(self): |
|
45 TextWidget.update(self) |
|
46 jquery_colorpicker.need() |
|
47 |
|
48 |
|
49 @adapter(IColorField, IFormLayer) |
|
50 @implementer(IFieldWidget) |
|
51 def ColorFieldWidgetFactory(field, request): |
|
52 """IColorField widget factory""" |
|
53 return FieldWidget(field, ColorWidget(request)) |