Move custom widgets to ZTFY.skin ZTK-1.1
authorThierry Florac <tflorac@ulthar.net>
Fri, 01 Mar 2013 19:13:31 +0100
branchZTK-1.1
changeset 202 00845ce1f3b4
parent 201 783dcf82b3dc
child 203 7cb9e4f51936
Move custom widgets to ZTFY.skin
src/ztfy/utils/browser/color.py
src/ztfy/utils/browser/configure.zcml
src/ztfy/utils/browser/daterange.py
src/ztfy/utils/browser/templates/color_display.pt
src/ztfy/utils/browser/templates/color_input.pt
src/ztfy/utils/browser/templates/daterange_display.pt
src/ztfy/utils/browser/templates/daterange_input.pt
src/ztfy/utils/browser/templates/textlinelist_display.pt
src/ztfy/utils/browser/templates/textlinelist_input.pt
src/ztfy/utils/browser/textlinelist.py
--- a/src/ztfy/utils/browser/color.py	Fri Mar 01 17:54:40 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,53 +0,0 @@
-### -*- coding: utf-8 -*- ####################################################
-##############################################################################
-#
-# Copyright (c) 2012 Thierry Florac <tflorac AT ulthar.net>
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-
-
-# import standard packages
-
-# import Zope3 interfaces
-from z3c.form.interfaces import ITextWidget, IFieldWidget, IFormLayer
-
-# import local interfaces
-from ztfy.utils.schema import IColorField
-
-# import Zope3 packages
-from z3c.form.browser.text import TextWidget
-from z3c.form.widget import FieldWidget
-from zope.component import adapter
-from zope.interface import implementer, implementsOnly
-
-# import local packages
-from ztfy.jqueryui import jquery_colorpicker
-
-
-class IColorWidget(ITextWidget):
-    """Color widget interface"""
-
-
-class ColorWidget(TextWidget):
-    """Color widget"""
-
-    implementsOnly(IColorWidget)
-
-    def update(self):
-        TextWidget.update(self)
-        jquery_colorpicker.need()
-
-
-@adapter(IColorField, IFormLayer)
-@implementer(IFieldWidget)
-def ColorFieldWidgetFactory(field, request):
-    """IColorField widget factory"""
-    return FieldWidget(field, ColorWidget(request))
--- a/src/ztfy/utils/browser/configure.zcml	Fri Mar 01 17:54:40 2013 +0100
+++ b/src/ztfy/utils/browser/configure.zcml	Fri Mar 01 19:13:31 2013 +0100
@@ -37,71 +37,4 @@
 			permission="zope.Public" />
 	</class>
 
-	<!-- Color selection widget -->
-	<adapter factory=".color.ColorFieldWidgetFactory" />
-
-	<class class=".color.ColorWidget">
-		<require
-			interface=".color.IColorWidget"
-			permission="zope.Public" />
-	</class>
-
-	<z3c:widgetTemplate
-		mode="input"
-		template="templates/color_input.pt"
-		widget=".color.IColorWidget"
-		layer="ztfy.skin.layer.IZTFYBrowserLayer" />
-
-	<z3c:widgetTemplate
-		mode="display"
-		template="templates/color_display.pt"
-		widget=".color.IColorWidget"
-		layer="ztfy.skin.layer.IZTFYBrowserLayer" />
-
-	<!-- Dates range widget -->
-	<adapter factory=".daterange.DatesRangeDataConverter" />
-
-	<adapter factory=".daterange.DatesRangeFieldWidgetFactory" />
-
-	<class class=".daterange.DatesRangeWidget">
-		<require
-			interface=".daterange.IDatesRangeWidget"
-			permission="zope.Public" />
-	</class>
-
-	<z3c:widgetTemplate
-		mode="input"
-		template="templates/daterange_input.pt"
-		widget=".daterange.IDatesRangeWidget"
-		layer="ztfy.skin.layer.IZTFYBrowserLayer" />
-
-	<z3c:widgetTemplate
-		mode="display"
-		template="templates/daterange_display.pt"
-		widget=".daterange.IDatesRangeWidget"
-		layer="ztfy.skin.layer.IZTFYBrowserLayer" />
-
-	<!-- TextLine list widget -->
-	<adapter factory=".textlinelist.TextLineListDataConverter" />
-
-	<adapter factory=".textlinelist.TextLineListFieldWidgetFactory" />
-
-	<class class=".textlinelist.TextLineListWidget">
-		<require
-			interface=".textlinelist.ITextLineListWidget"
-			permission="zope.Public" />
-	</class>
-
-	<z3c:widgetTemplate
-		mode="input"
-		template="templates/textlinelist_input.pt"
-		widget=".textlinelist.ITextLineListWidget"
-		layer="ztfy.skin.layer.IZTFYBrowserLayer" />
-
-	<z3c:widgetTemplate
-		mode="display"
-		template="templates/textlinelist_display.pt"
-		widget=".textlinelist.ITextLineListWidget"
-		layer="ztfy.skin.layer.IZTFYBrowserLayer" />
-
 </configure>
\ No newline at end of file
--- a/src/ztfy/utils/browser/daterange.py	Fri Mar 01 17:54:40 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,116 +0,0 @@
-### -*- coding: utf-8 -*- ####################################################
-##############################################################################
-#
-# Copyright (c) 2012 Thierry Florac <tflorac AT ulthar.net>
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-
-
-# import standard packages
-
-# import Zope3 interfaces
-from z3c.form.interfaces import IMultiWidget, IFieldWidget, NO_VALUE
-
-# import local interfaces
-from ztfy.skin.layer import IZTFYBrowserLayer
-from ztfy.utils.schema import IDatesRangeField
-
-# import Zope3 packages
-from z3c.form.browser.widget import HTMLFormElement
-from z3c.form.converter import SequenceDataConverter, FormatterValidationError
-from z3c.form.widget import FieldWidget, Widget
-from zope.component import adapter, adapts
-from zope.interface import implementer, implements
-from zope.i18n.format import DateTimeParseError
-
-# import local packages
-from ztfy.jqueryui import jquery_datetime
-
-
-class IDatesRangeWidget(IMultiWidget):
-    """Dates range widget interface"""
-
-
-class DatesRangeDataConverter(SequenceDataConverter):
-    """Dates range data converter"""
-
-    adapts(IDatesRangeField, IDatesRangeWidget)
-
-    def toWidgetValue(self, value):
-        if value is self.field.missing_value:
-            return (u'', u'')
-        locale = self.widget.request.locale
-        formatter = locale.dates.getFormatter('date', 'short')
-        return (formatter.format(value[0]) if value[0] else None,
-                formatter.format(value[1]) if value[1] else None)
-
-    def toFieldValue(self, value):
-        if not value:
-            return self.field.missing_value
-        try:
-            locale = self.widget.request.locale
-            formatter = locale.dates.getFormatter('date', 'short')
-            return (formatter.parse(value[0]) if value[0] else None,
-                    formatter.parse(value[1]) if value[1] else None)
-        except DateTimeParseError, err:
-            raise FormatterValidationError(err.args[0], value)
-
-
-class DatesRangeWidget(HTMLFormElement, Widget):
-    """Dates range widget"""
-
-    implements(IDatesRangeWidget)
-
-    @property
-    def pattern(self):
-        result = self.request.locale.dates.getFormatter('date', 'short').getPattern()
-        return result.replace('dd', '%d').replace('MM', '%m').replace('yy', '%y')
-
-    @property
-    def begin_id(self):
-        return '%s-begin' % self.id
-
-    @property
-    def begin_name(self):
-        return '%s.begin' % self.name
-
-    @property
-    def begin_date(self):
-        return (self.value[0] or '') if self.value else ''
-
-    @property
-    def end_id(self):
-        return '%s-end' % self.id
-
-    @property
-    def end_name(self):
-        return '%s.end' % self.name
-
-    @property
-    def end_date(self):
-        return (self.value[1] or '') if self.value else ''
-
-    def extract(self, default=NO_VALUE):
-        begin_date = self.request.get(self.begin_name)
-        end_date = self.request.get(self.end_name)
-        return (begin_date, end_date)
-
-    def render(self):
-        result = super(DatesRangeWidget, self).render()
-        if result:
-            jquery_datetime.need()
-        return result
-
-@adapter(IDatesRangeField, IZTFYBrowserLayer)
-@implementer(IFieldWidget)
-def DatesRangeFieldWidgetFactory(field, request):
-    """IDatesRangeField widget factory"""
-    return FieldWidget(field, DatesRangeWidget(request))
--- a/src/ztfy/utils/browser/templates/color_display.pt	Fri Mar 01 17:54:40 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,14 +0,0 @@
-<div class="colorSelector"
-	 tal:attributes="id string:${view/id}_selector">
-	<input type="hidden"
-		   tal:attributes="id view/id;
-						   name view/name;
-						   lang view/lang;
-						   value view/value;" />
-	<div></div>
-	<script type="text/javascript" tal:content="string:
-		$$(document).ready(function() {
-			$$('DIV[id=${view/id}_selector] div').css('backgroundColor', '#${view/value}');
-		});
-	"></script>
-</div>
\ No newline at end of file
--- a/src/ztfy/utils/browser/templates/color_input.pt	Fri Mar 01 17:54:40 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,32 +0,0 @@
-<div class="colorSelector"
-	 tal:attributes="id string:${view/id}_selector">
-	<input type="hidden"
-		   tal:attributes="id view/id;
-						   name view/name;
-						   lang view/lang;
-						   value view/value;" />
-	<div></div>
-	<script type="text/javascript" tal:content="string:
-		$$(document).ready(function() {
-			$$('DIV[id=${view/id}_selector] div').css('backgroundColor', '#${view/value}');
-			$$('DIV[id=${view/id}_selector]').ColorPicker({
-				color: '#${view/value}',
-				onShow: function (colpkr) {
-					$$(colpkr).fadeIn(500);
-					return false;
-				},
-				onHide: function (colpkr) {
-					$$(colpkr).fadeOut(500);
-					return false;
-				},
-				onChange: function (hsb, hex, rgb) {
-					$$('DIV[id=${view/id}_selector] div').css('backgroundColor', '#' + hex);
-					$$('INPUT[id=${view/id}]').val(hex);
-				},
-				onSubmit: function() {
-					$$('DIV[id=${view/id}_selector]').ColorPickerHide();
-				}
-			});
-		});
-	"></script>
-</div>
\ No newline at end of file
--- a/src/ztfy/utils/browser/templates/daterange_display.pt	Fri Mar 01 17:54:40 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,6 +0,0 @@
-<div tal:attributes="class string:daterange ${view/klass}" i18n:domain="ztfy.utils">
-	<span i18n:translate="">Between:</span>
-	<span tal:content="python:view.begin_date or '--'" />&nbsp;
-	<span i18n:translate="">and:</span>
-	<span tal:content="python:view.end_date or '--';" />
-</div>
\ No newline at end of file
--- a/src/ztfy/utils/browser/templates/daterange_input.pt	Fri Mar 01 17:54:40 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,25 +0,0 @@
-<div tal:attributes="class string:daterange ${view/klass}" i18n:domain="ztfy.utils">
-	<label tal:attributes="for view/begin_id" i18n:translate="">Between:</label>
-	<input type="text" class="date-field" tal:attributes="id view/begin_id;
-														  name view/begin_name;
-														  value view/begin_date;" />&nbsp;
-	<label tal:attributes="for view/end_id" i18n:translate="">and:</label>
-	<input type="text" class="date-field" tal:attributes="id view/end_id;
-														  name view/end_name;
-														  value view/end_date;" />
-</div>
-<script type="text/javascript" tal:content="structure string:
-	// <![CDATA[
-	$$(document).ready(function() {
-		if (typeof($$.i18n_calendar) == 'undefined') {
-			var lang = $$('html').attr('lang') || $$('html').attr('xml:lang');
-			$$.i18n_calendar = lang;
-			$$.getScript('/--static--/ztfy.jqueryui/js/lang/calendar-' + lang + '-utf8.js');
-		}
-		$$('#${view/begin_id},#${view/end_id}').dynDateTime({
-			showsTime: false,
-			ifFormat: '${view/pattern}'
-		});
-	});
-	// ]]>
-" />
\ No newline at end of file
--- a/src/ztfy/utils/browser/templates/textlinelist_display.pt	Fri Mar 01 17:54:40 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,31 +0,0 @@
-<input type="text"
-	data-ztfy-widget="multiselect"
-	data-multiselect-readonly="true"
-	data-multiselect-separator="|"
-	tal:condition="view/value"
-	tal:attributes="id view/id;
-					name view/name;
-					class view/klass;
-					style view/style;
-					title view/title;
-					value view/value;
-					lang view/lang;
-					onclick view/onclick;
-					ondblclick view/ondblclick;
-					onmousedown view/onmousedown;
-					onmouseup view/onmouseup;
-					onmouseover view/onmouseover;
-					onmousemove view/onmousemove;
-					onmouseout view/onmouseout;
-					onkeypress view/onkeypress;
-					onkeydown view/onkeydown;
-					onkeyup view/onkeyup;
-					disabled view/disabled;
-					tabindex view/tabindex;
-					onfocus view/onfocus;
-					onblur view/onblur;
-					onchange view/onchange;
-					readonly view/readonly;
-					accesskey view/accesskey;
-					onselect view/onselect;" />
-<span tal:condition="not:view/value">--</span>
\ No newline at end of file
--- a/src/ztfy/utils/browser/templates/textlinelist_input.pt	Fri Mar 01 17:54:40 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-<input type="text" autocomplete="off"
-	data-ztfy-widget="multiselect"
-	data-multiselect-class="directory"
-	data-multiselect-separator="|",
-	data-multiselect-max-results="0"
-	data-multiselect-enable-new="true"
-	data-multiselect-search-timeout="1"
-	data-multiselect-complex-search="false"
-	data-multiselect-max-selection-length="1"
-	tal:attributes="id view/id;
-					name view/name;
-					class view/klass;
-					style view/style;
-					title view/title;
-					value view/value;
-					lang view/lang;
-					onclick view/onclick;
-					ondblclick view/ondblclick;
-					onmousedown view/onmousedown;
-					onmouseup view/onmouseup;
-					onmouseover view/onmouseover;
-					onmousemove view/onmousemove;
-					onmouseout view/onmouseout;
-					onkeypress view/onkeypress;
-					onkeydown view/onkeydown;
-					onkeyup view/onkeyup;
-					disabled view/disabled;
-					tabindex view/tabindex;
-					onfocus view/onfocus;
-					onblur view/onblur;
-					onchange view/onchange;
-					readonly view/readonly;
-					accesskey view/accesskey;
-					onselect view/onselect;" />
-<input name="field-empty-marker" type="hidden" value="1"
-	   tal:attributes="name string:${view/name}-empty-marker" />
\ No newline at end of file
--- a/src/ztfy/utils/browser/textlinelist.py	Fri Mar 01 17:54:40 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,69 +0,0 @@
-### -*- coding: utf-8 -*- ####################################################
-##############################################################################
-#
-# Copyright (c) 2012 Thierry Florac <tflorac AT ulthar.net>
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.1 (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.
-#
-##############################################################################
-
-
-# import standard packages
-
-# import Zope3 interfaces
-from z3c.form.interfaces import IWidget, IFieldWidget, ITextWidget, IFormLayer
-
-# import local interfaces
-from ztfy.utils.schema import ITextLineListField
-
-# import Zope3 packages
-from z3c.form.browser.text import TextWidget
-from z3c.form.converter import SequenceDataConverter
-from z3c.form.widget import FieldWidget
-from zope.component import adapter, adapts
-from zope.interface import implementer, implementsOnly
-
-# import local packages
-from ztfy.jqueryui import jquery_multiselect
-
-
-class ITextLineListWidget(ITextWidget):
-    """TextLineList widget interface"""
-
-
-class TextLineListDataConverter(SequenceDataConverter):
-    """TextLineList field data converter"""
-
-    adapts(ITextLineListField, IWidget)
-
-    def toWidgetValue(self, value):
-        if value is self.field.missing_value:
-            return []
-        return '|'.join(value)
-
-    def toFieldValue(self, value):
-        if not value:
-            return self.field.missing_value
-        return value.split('|')
-
-
-class TextLineListWidget(TextWidget):
-    """TextLineList field widget"""
-
-    implementsOnly(ITextLineListWidget)
-
-    def render(self):
-        jquery_multiselect.need()
-        return super(TextLineListWidget, self).render()
-
-
-@adapter(ITextLineListField, IFormLayer)
-@implementer(IFieldWidget)
-def TextLineListFieldWidgetFactory(field, request):
-    return FieldWidget(field, TextLineListWidget(request))