extend composer.schema for usage for standard form rendering
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2060 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
		
							parent
							
								
									2d56418344
								
							
						
					
					
						commit
						a4dfb9b209
					
				
					 3 changed files with 136 additions and 1 deletions
				
			
		|  | @ -23,6 +23,7 @@ $Id$ | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| from zope import component | from zope import component | ||||||
|  | from zope.app.pagetemplate import ViewPageTemplateFile | ||||||
| from zope.app.session.interfaces import ISession | from zope.app.session.interfaces import ISession | ||||||
| from zope.cachedescriptors.property import Lazy | from zope.cachedescriptors.property import Lazy | ||||||
| 
 | 
 | ||||||
|  | @ -30,10 +31,18 @@ from cybertools.composer.interfaces import IInstance | ||||||
| from cybertools.composer.schema.interfaces import IClientFactory | from cybertools.composer.schema.interfaces import IClientFactory | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | schema_macros = ViewPageTemplateFile('schema_macros.pt') | ||||||
|  | schema_edit_macros = schema_macros  # default: no editing | ||||||
|  | 
 | ||||||
| packageId = 'cybertools.composer.schema' | packageId = 'cybertools.composer.schema' | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class BaseView(object): | class BaseView(object): | ||||||
|  |     """ Base class for views that have schema objects as their context. | ||||||
|  | 
 | ||||||
|  |         Do not use this base class for views on typical content objects | ||||||
|  |         that are not schemas! | ||||||
|  |     """ | ||||||
| 
 | 
 | ||||||
|     clientName = None |     clientName = None | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										123
									
								
								composer/schema/browser/schema_macros.pt
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										123
									
								
								composer/schema/browser/schema_macros.pt
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,123 @@ | ||||||
|  | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" | ||||||
|  |       i18n:domain="loops"> | ||||||
|  | <body> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <metal:fields define-macro="fields"> | ||||||
|  |   <tal:define define="manageMode manageMode|view/manageMode|nothing; | ||||||
|  |                       fields view/fields; | ||||||
|  |                       data view/data"> | ||||||
|  |     <table class="listing" style="width: auto"> | ||||||
|  |       <tal:fields repeat="field fields"> | ||||||
|  |         <tal:field define="name field/name; | ||||||
|  |                            typeInfo field/getFieldTypeInfo; | ||||||
|  |                            errors state/fieldInstances/?name/errors|python: [];"> | ||||||
|  |           <metal:field use-macro="python: view.schemaMacros[typeInfo.fieldMacro]" /> | ||||||
|  |         </tal:field> | ||||||
|  |       </tal:fields> | ||||||
|  |     </table> | ||||||
|  |     <tal:add condition="manageMode"> | ||||||
|  |       <metal:add use-macro="view/schemaEditMacros/add_buttons" /> | ||||||
|  |     </tal:add> | ||||||
|  |   </tal:define> | ||||||
|  | </metal:fields> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <metal:field define-macro="field"> | ||||||
|  |       <tbody tal:omit-tag="not:errors" | ||||||
|  |              class="error" | ||||||
|  |              style="padding: 4px; margin-bottom: 4px;"> | ||||||
|  |         <tal:errors repeat="error errors"> | ||||||
|  |           <tr> | ||||||
|  |             <td colspan="2" style="padding: 4px" | ||||||
|  |                 i18n:translate="" | ||||||
|  |                 tal:content="error/description">???</td> | ||||||
|  |           </tr> | ||||||
|  |         </tal:errors> | ||||||
|  |         <tr> | ||||||
|  |           <tal:field> | ||||||
|  |             <td style="padding: 4px; border-top: none" | ||||||
|  |                 tal:attributes="title field/description"> | ||||||
|  |               <b tal:content="field/title">...</b> | ||||||
|  |               <span tal:condition="field/required">*</span> | ||||||
|  |             </td> | ||||||
|  |             <td class="field" style="border-top: none"> | ||||||
|  |               <metal:input use-macro="python: | ||||||
|  |                     view.schemaMacros[typeInfo.inputMacro]" /> | ||||||
|  |             </td> | ||||||
|  |           </tal:field> | ||||||
|  |         </tr> | ||||||
|  |         <tr style="border-bottom: 1px solid #dddddd" | ||||||
|  |             tal:condition="manageMode"> | ||||||
|  |           <td style="border-top: none"> | ||||||
|  |             <metal:move use-macro="view/editMacros/move_icons" /> | ||||||
|  |           </td> | ||||||
|  |           <td style="border-top: none"> | ||||||
|  |             <metal:edit use-macro="view/schemaEditMacros/edit_buttons" /> | ||||||
|  |           </td> | ||||||
|  |         </tr> | ||||||
|  |       </tbody> | ||||||
|  | </metal:field> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <metal:textline define-macro="input_textline"> | ||||||
|  |     <input type="text" name="field" style="width: 300px" | ||||||
|  |            tal:define="width field/width|python:300" | ||||||
|  |            tal:attributes="name name; | ||||||
|  |                            style python: 'width: %ipx' % (width or 300); | ||||||
|  |                            value data/?name|field/defaultValue|string:" /> | ||||||
|  | </metal:textline> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <metal:textarea define-macro="input_textarea"> | ||||||
|  |     <textarea name="field" rows="3" style="width: 300px" | ||||||
|  |            tal:define="width field/width|python:300; | ||||||
|  |                        height field/height|python:3" | ||||||
|  |            tal:attributes="name name; | ||||||
|  |                            rows python: height or 3; | ||||||
|  |                            style python: 'width: %ipx' % (width or 300)" | ||||||
|  |            tal:content="data/?name|field/defaultValue|string:"> | ||||||
|  |     </textarea> | ||||||
|  | </metal:textarea> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <metal:dropdown define-macro="input_dropdown"> | ||||||
|  |     <select name="field" style="width: 100px" | ||||||
|  |            tal:define="width field/width|python:100" | ||||||
|  |            tal:attributes="name name; | ||||||
|  |                            style python: 'width: %ipx' % (width or 100);"> | ||||||
|  |       <option tal:repeat="item field/getVocabularyItems" | ||||||
|  |               tal:content="item/title" | ||||||
|  |               tal:attributes="value item/token; | ||||||
|  |                               selected python: | ||||||
|  |                     item['token'] == data.get(name, field.defaultValue)">Mrs</option> | ||||||
|  |     </select> | ||||||
|  | </metal:dropdown> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | <metal:spacer define-macro="field_spacer"> | ||||||
|  |   <tr> | ||||||
|  |     <td colspan="2" style="border-top:none; font-size: 50%"> </td> | ||||||
|  |   </tr> | ||||||
|  |   <tr> | ||||||
|  |     <td colspan="2" | ||||||
|  |         style="border-top: 1px solid #bbbbbb; padding: 8px 4px; | ||||||
|  |                margin-top: 10px;"> | ||||||
|  |       <div><b tal:content="field/title"></b></div> | ||||||
|  |       <div tal:content="structure field/description"></div> | ||||||
|  |     </td> | ||||||
|  |   </tr> | ||||||
|  |   <tr style="border-bottom: 1px solid #dddddd" | ||||||
|  |       tal:condition="manageMode"> | ||||||
|  |       <td style="border-top: none"> | ||||||
|  |         <metal:move use-macro="view/schemaEditMacros/move_icons" /> | ||||||
|  |       </td> | ||||||
|  |       <td style="border-top: none"> | ||||||
|  |         <metal:edit use-macro="view/schemaEditMacros/edit_buttons" /> | ||||||
|  |       </td> | ||||||
|  |   </tr> | ||||||
|  | </metal:spacer> | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
|  | @ -40,6 +40,7 @@ class Field(Component): | ||||||
|     required = False |     required = False | ||||||
|     standardFieldName = None |     standardFieldName = None | ||||||
|     vocabulary = None |     vocabulary = None | ||||||
|  |     defaultValue = None | ||||||
|     renderFactory = None |     renderFactory = None | ||||||
| 
 | 
 | ||||||
|     def __init__(self, name, title=None, fieldType='textline', **kw): |     def __init__(self, name, title=None, fieldType='textline', **kw): | ||||||
|  | @ -63,7 +64,9 @@ class Field(Component): | ||||||
|         voc = (self.vocabulary or '') |         voc = (self.vocabulary or '') | ||||||
|         if isinstance(voc, basestring): |         if isinstance(voc, basestring): | ||||||
|             voc = voc.splitlines() |             voc = voc.splitlines() | ||||||
|         return [dict(token=v, title=v) for v in voc if v.strip()] |             return [dict(token=t, title=t) for t in voc if t.strip()] | ||||||
|  |         else: | ||||||
|  |             return [dict(token=t.token, title=t.title) for t in voc] | ||||||
| 
 | 
 | ||||||
|     def getFieldTypeInfo(self): |     def getFieldTypeInfo(self): | ||||||
|         return fieldTypes.getTerm(self.fieldType) |         return fieldTypes.getTerm(self.fieldType) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 helmutm
						helmutm