1 # (c) 2003 Centre de Recherche en Informatique ENSMP Fontainebleau <http://cri.ensmp.fr>
2 # (c) 2003 Benoît PIN <mailto:pin@cri.ensmp.fr>
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 from Products
.CMFCore
.permissions
import View
, ModifyPortalContent
22 factory_type_information
= ( {'id' : 'String Slot',
23 'meta_type' : 'String Slot',
24 'description' : "String Slot for Mosaic Document",
25 'icon' : 'mosaic_tool/str_icon.gif',
26 'product' : 'MosaicDocument',
27 'factory' : 'addStringSlot',
28 'immediate_view' : 'view',
32 'action' : 'slot_string_view',
33 'permissions' : (View
, )
38 'action' : 'slot_string_form',
39 'permissions' : (ModifyPortalContent
, )
45 'meta_type' : 'Text Slot',
46 'description' : "Text Slot for Mosaic Document",
47 'icon' : 'mosaic_tool/txt_icon.gif',
48 'product' : 'MosaicDocument',
49 'factory' : 'addStringSlot',
50 'immediate_view' : 'view',
54 'action' : 'slot_text_view',
55 'permissions' : (View
, )
60 'action' : 'slot_text_form',
61 'permissions' : (ModifyPortalContent
, )
67 'meta_type' : 'List Slot',
68 'description' : "List Slot for Mosaic Document",
69 'icon' : 'mosaic_tool/str_icon.gif',
70 'product' : 'MosaicDocument',
71 'factory' : 'addStringSlot',
72 'immediate_view' : 'view',
76 'action' : 'slot_list_view',
77 'permissions' : (View
, )
82 'action' : 'slot_text_form',
83 'permissions' : (ModifyPortalContent
, )
89 from AccessControl
import ClassSecurityInfo
90 from Globals
import InitializeClass
91 from Products
.CMFCore
.Expression
import Expression
92 from Products
.CMFDefault
.Document
import Document
93 from OFS
.PropertyManager
import PropertyManager
94 from BaseSlot
import BaseSlot
96 class StringSlot(BaseSlot
, Document
, PropertyManager
) :
98 meta_type
= 'String Slot'
99 _editableFields
= ('text', 'text_format', 'size', 'cols', 'rows')
100 _indexableFields
= ('text',)
102 manage_options
= Document
.manage_options
[:2] + PropertyManager
.manage_options
+ Document
.manage_options
[2:]
104 _properties
= ({'id' : 'choices', 'type' : 'lines', 'mode' : 'w'},
105 {'id' : 'castOperator', 'type' : 'string', 'mode' : 'w'},
106 {'id' : 'size', 'type' : 'int', 'mode' : 'w'},
107 {'id' : 'cols', 'type' : 'int', 'mode' : 'w'},
108 {'id' : 'rows', 'type' : 'int', 'mode' : 'w'},
109 {'id' : 'url_expression', 'type': 'expr', 'mode' : 'w'})
111 security
= ClassSecurityInfo()
114 def __init__(self
, id, text
='', text_format
='plain',
115 choices
= [], castOperator
= 'string', size
= 60,
116 cols
=50, rows
=50, url_expression
= None) :
118 Document
.__init
__(self
, id, text_format
= text_format
, text
= text
)
120 self
.choices
= choices
121 self
.castOperator
= castOperator
125 if url_expression
is None :
126 self
.url_expression
= Expression("python:None")
128 self
.url_expression
= url_expression
130 security
.declareProtected(ModifyPortalContent
, 'setFormat')
131 def setFormat(self
, format
):
132 """ Set text format and Dublin Core resource format.
135 if value
== 'text/html' or value
== 'html':
136 self
.text_format
= 'html'
137 elif value
== 'text/plain':
138 if self
.text_format
not in ('structured-text', 'plain'):
139 self
.text_format
= 'structured-text'
140 elif value
== 'plain':
141 self
.text_format
= 'plain'
143 self
.text_format
= 'structured-text'
146 InitializeClass(StringSlot
)
149 def addStringSlot(dispatcher
, id, text
='', text_format
='plain',
150 choices
= [], castOperator
= 'string', size
=60,
151 cols
=50, rows
=50, url_expression
= None) :
153 Add a new TextSlot object.
155 stringSlot
= StringSlot(id,
157 text_format
=text_format
,
159 castOperator
=castOperator
,
163 url_expression
=url_expression
)
164 parentContainer
= dispatcher
.Destination()
165 parentContainer
._setObject
(id, stringSlot
)