Added IInnerForm interface to handle forms located inside another container
authorThierry Florac <thierry.florac@onf.fr>
Tue, 14 Oct 2014 14:35:34 +0200
changeset 85 1b31fa7e2ca3
parent 84 67b61a2eb943
child 86 aba8d4e80ea9
Added IInnerForm interface to handle forms located inside another container
src/ztfy/myams/configure.zcml
src/ztfy/myams/interfaces/__init__.py
src/ztfy/myams/templates/forms/inner-form.pt
--- a/src/ztfy/myams/configure.zcml	Tue Oct 14 14:34:41 2014 +0200
+++ b/src/ztfy/myams/configure.zcml	Tue Oct 14 14:35:34 2014 +0200
@@ -148,6 +148,11 @@
 		template="templates/forms/form.pt"
 		layer=".layer.MyAMSLayer" />
 
+	<z3c:template
+		for=".interfaces.IInnerForm"
+		template="templates/forms/inner-form.pt"
+		layer=".layer.MyAMSLayer" />
+
 	<z3c:layout
 		for="ztfy.baseskin.interfaces.IDialog"
 		template="templates/modal-layout.pt"
--- a/src/ztfy/myams/interfaces/__init__.py	Tue Oct 14 14:34:41 2014 +0200
+++ b/src/ztfy/myams/interfaces/__init__.py	Tue Oct 14 14:35:34 2014 +0200
@@ -7,6 +7,7 @@
 # import standard packages
 
 # import Zope3 interfaces
+from z3c.form.interfaces import IInputForm
 from ztfy.baseskin.interfaces import ISkinnable
 from ztfy.baseskin.interfaces.form import checkSubmitButton
 
@@ -89,3 +90,7 @@
     """Modal display form buttons"""
 
     close = CloseButton(name='close', title=_("Close"))
+
+
+class IInnerForm(IInputForm):
+    """Inner form marker interface"""
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/ztfy/myams/templates/forms/inner-form.pt	Tue Oct 14 14:35:34 2014 +0200
@@ -0,0 +1,117 @@
+<div class="no-padding" i18n:domain="ztfy.myams">
+	<div tal:replace="structure provider:form_prefix">Form prefix</div>
+	<form method="post"
+		  data-async
+		  tal:attributes="id view/id;
+						  name view/name;
+						  action view/action;
+						  method view/method;
+						  enctype view/enctype;
+						  acceptCharset view/acceptCharset;
+						  accept view/accept;
+						  autocomplete view/autocomplete;
+						  class view/css_class;
+						  data-ams-data view/myams:data;
+						  data-ams-form-handler view/handler;
+						  data-ams-form-options view/getFormOptions;
+						  data-ams-warn-on-change view/warnOnChange;">
+		<div class="modal-viewport">
+			<fieldset>
+				<legend tal:define="legend view/legend"
+						tal:condition="legend"
+						tal:content="legend">Legend</legend>
+				<div class="widgets-prefix"
+					 tal:define="prefix provider:widgets_prefix"
+					 tal:condition="prefix"
+					 tal:content="structure prefix">Widgets prefix</div>
+				<tal:loop repeat="group view/groups">
+					<fieldset tal:define="legend group/legend"
+							  tal:omit-tag="not:legend">
+						<tal:if condition="group/checkbox_switch">
+							<legend tal:condition="legend"
+									tal:content="legend"
+									tal:attributes="class group/css_class;
+													data-ams-checker-fieldname group/checker_field/getName;
+													data-ams-checker-state group/checker_state;">Legend</legend>
+						</tal:if>
+						<tal:if condition="not:group/checkbox_switch">
+							<legend tal:condition="legend"
+									tal:content="legend"
+									tal:attributes="class group/css_class;
+													data-ams-switcher-state group/switcher_state;">Legend</legend>
+						</tal:if>
+						<tal:var define="help group/help" condition="help">
+							<div class=""
+								 tal:define="i18n_help help/i18n:translate"
+								 tal:content="structure i18n_help/html:text"></div>
+						</tal:var>
+						<tal:loop repeat="widget group/visible_widgets">
+							<input type="hidden"
+								   tal:condition="python:widget.mode == 'hidden'"
+								   tal:replace="structure widget/render" />
+							<tal:if condition="python:widget.mode != 'hidden'">
+								<div tal:define="required python:'required-field' if widget.required and (widget.mode != 'display') else ''"
+									 tal:attributes="class string:form-group ${required}">
+									<label tal:attributes="class view/label_css_class">
+										<span>
+											<tal:var content="widget/label" />
+											<i class="fa fa-question-circle hint" title="Input hint"
+											   tal:define="description widget/field/description"
+											   tal:condition="description"
+											   tal:attributes="title description;
+															   data-ams-hint-html python:'<' in description;"></i>
+										</span>
+									</label>
+									<div tal:attributes="class view/input_css_class">
+										<label class="input"
+											   tal:attributes="data-ams-data widget/myams:data;
+															   data-ams-form-validator python:view.getWidgetCallback(widget.field.getName())">
+											<input tal:replace="structure widget/render" />
+										</label>
+									</div>
+								</div>
+							</tal:if>
+						</tal:loop>
+					</fieldset>
+				</tal:loop>
+				<div class="widgets-suffix"
+					 tal:define="suffix provider:widgets_suffix"
+					 tal:condition="suffix"
+					 tal:content="structure suffix">Widgets suffix</div>
+				<div class="subforms"
+					 tal:condition="view/subforms">
+					<fieldset tal:define="title view/subforms_legend"
+							  tal:omit-tag="not:title">
+						<legend tal:condition="title" tal:content="title" i18n:translate="">legend</legend>
+						<tal:loop repeat="subform view/subforms">
+							<tal:var replace="structure subform/render" />
+						</tal:loop>
+					</fieldset>
+				</div>
+				<div class="tabforms"
+					 tal:condition="view/tabforms">
+					<ul class="nav nav-tabs">
+						<li tal:repeat="tabform view/tabforms"
+							tal:attributes="class python:tabform.widgets.errors and 'state-error' or ''">
+							<a data-toggle="tab"
+							   tal:attributes="href string:#${tabform/id}"
+							   tal:content="tabform/tabLabel" i18n:translate="">Tab label</a>
+						</li>
+					</ul>
+					<div class="tab-content">
+						<div class="tab-pane fade in"
+							 tal:repeat="tabform view/tabforms">
+							 tal:attributes="id tabform/id"
+							 tal:content="structure tabform/render" />
+						</div>
+					</div>
+				</div>
+			</fieldset>
+		</div>
+		<footer>
+			<button tal:repeat="action view/actions/values"
+					tal:replace="structure action/render">Action</button>
+		</footer>
+	</form>
+	<div tal:replace="structure provider:form_suffix">Form suffix</div>
+</div>