64c2524f66d57127ee15170c973cba708a49c50d
1 # -*- coding: utf-8 -*-
2 # (c) 2003 Centre de Recherche en Informatique ENSMP Fontainebleau <http://cri.ensmp.fr>
3 # (c) 2003 BenoƮt PIN <mailto:pin@cri.ensmp.fr>
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.
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.
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
21 from Products
.CMFCore
.permissions
import View
, ModifyPortalContent
23 factory_type_information
= ( {'id' : 'String Slot',
24 'meta_type' : 'String Slot',
25 'description' : "String Slot for Mosaic Document",
26 'icon' : 'mosaic_tool/str_icon.gif',
27 'product' : 'MosaicDocument',
28 'factory' : 'addStringSlot',
29 'immediate_view' : 'view',
33 'action' : 'slot_string_view',
34 'permissions' : (View
, )
39 'action' : 'slot_string_form',
40 'permissions' : (ModifyPortalContent
, )
46 'meta_type' : 'Text Slot',
47 'description' : "Text Slot for Mosaic Document",
48 'icon' : 'mosaic_tool/txt_icon.gif',
49 'product' : 'MosaicDocument',
50 'factory' : 'addStringSlot',
51 'immediate_view' : 'view',
55 'action' : 'slot_text_view',
56 'permissions' : (View
, )
61 'action' : 'slot_text_form',
62 'permissions' : (ModifyPortalContent
, )
68 'meta_type' : 'List Slot',
69 'description' : "List Slot for Mosaic Document",
70 'icon' : 'mosaic_tool/str_icon.gif',
71 'product' : 'MosaicDocument',
72 'factory' : 'addStringSlot',
73 'immediate_view' : 'view',
77 'action' : 'slot_list_view',
78 'permissions' : (View
, )
83 'action' : 'slot_text_form',
84 'permissions' : (ModifyPortalContent
, )
90 from AccessControl
import ClassSecurityInfo
91 from Globals
import InitializeClass
92 from Products
.CMFCore
.Expression
import Expression
93 from Products
.CMFDefault
.Document
import Document
94 from OFS
.PropertyManager
import PropertyManager
95 from BaseSlot
import BaseSlot
97 class StringSlot(BaseSlot
, Document
, PropertyManager
) :
99 meta_type
= 'String Slot'
100 _editableFields
= ('text', 'text_format', 'size', 'cols', 'rows')
101 _indexableFields
= ('text',)
103 manage_options
= Document
.manage_options
[:2] + PropertyManager
.manage_options
+ Document
.manage_options
[2:]
105 _properties
= ({'id' : 'choices', 'type' : 'lines', 'mode' : 'w'},
106 {'id' : 'castOperator', 'type' : 'string', 'mode' : 'w'},
107 {'id' : 'size', 'type' : 'int', 'mode' : 'w'},
108 {'id' : 'cols', 'type' : 'int', 'mode' : 'w'},
109 {'id' : 'rows', 'type' : 'int', 'mode' : 'w'},
110 {'id' : 'url_expression', 'type': 'expr', 'mode' : 'w'})
112 security
= ClassSecurityInfo()
115 def __init__(self
, id, text
='', text_format
='plain',
116 choices
= [], castOperator
= 'string', size
= 60,
117 cols
=50, rows
=50, url_expression
= None) :
119 Document
.__init
__(self
, id, text_format
= text_format
, text
= text
)
121 self
.choices
= choices
122 self
.castOperator
= castOperator
126 if url_expression
is None :
127 self
.url_expression
= Expression("python:None")
129 self
.url_expression
= url_expression
131 security
.declareProtected(ModifyPortalContent
, 'setFormat')
132 def setFormat(self
, format
):
133 """ Set text format and Dublin Core resource format.
136 if value
== 'text/html' or value
== 'html':
137 self
.text_format
= 'html'
138 elif value
== 'text/plain':
139 if self
.text_format
not in ('structured-text', 'plain'):
140 self
.text_format
= 'structured-text'
141 elif value
== 'plain':
142 self
.text_format
= 'plain'
144 self
.text_format
= 'structured-text'
147 InitializeClass(StringSlot
)
150 def addStringSlot(dispatcher
, id, text
='', text_format
='plain',
151 choices
= [], castOperator
= 'string', size
=60,
152 cols
=50, rows
=50, url_expression
= None) :
154 Add a new TextSlot object.
156 stringSlot
= StringSlot(id,
158 text_format
=text_format
,
160 castOperator
=castOperator
,
164 url_expression
=url_expression
)
165 parentContainer
= dispatcher
.Destination()
166 parentContainer
._setObject
(id, stringSlot
)